1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2019 Nokia.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 #------------------------------------------------------------------------------
19 #------------------------------------------------------------------------------
21 $(error ROOT_DIR NOT DEFINED)
24 $(error CACHE_DIR NOT DEFINED)
27 #------------------------------------------------------------------------------
29 #------------------------------------------------------------------------------
31 GO_CACHE_DIR?=$(abspath $(CACHE_DIR)/go)
33 #------------------------------------------------------------------------------
35 #------------------------------------------------------------------------------
36 ifndef MAKE_GO_TARGETS
40 .PHONY: FORCE go-build go-test go-test-fmt go-fmt go-clean
45 GOOS=$(shell go env GOOS)
47 GOBUILD=$(GOCMD) build -a -installsuffix cgo
48 GORUN=$(GOCMD) run -a -installsuffix cgo
49 GOCLEAN=$(GOCMD) clean
50 GOTEST=$(GOCMD) test -v
53 GOFILES:=$(shell find $(ROOT_DIR) -name '*.go' -not -name '*_test.go')
54 GOALLFILES:=$(shell find $(ROOT_DIR) -name '*.go')
55 GOMODFILES:=go.mod go.sum
59 $(GO_CACHE_DIR)/%: $(GOFILES) $(GOMODFILES) $$(BUILDDEPS)
61 GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $@ cmd/appmgr.go
65 $(GO_CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES) $$(BUILDDEPS) FORCE
67 GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOTEST) -coverprofile $(COVEROUT) ./pkg/resthooks/ ./pkg/helm/ ./pkg/cm/
68 test -e $@ && (eval $(TESTENV) $@ -test.coverprofile $(COVEROUT) || false) || true
69 test -e $@ && (go tool cover -html=$(COVEROUT) -o $(COVERHTML) || false) || true
73 go-build: GO_TARGETS:=
74 go-build: $$(GO_TARGETS)
78 go-test: $$(GO_TARGETS)
80 go-test-fmt: $(GOFILES)
81 @(RESULT="$$(gofmt -l $^)"; test -z "$${RESULT}" || (echo -e "gofmt failed:\n$${RESULT}" && false) )
87 GO111MODULE=on go mod tidy
89 go-mod-download: FORCE
90 GO111MODULE=on go mod download
92 go-clean: GO_TARGETS:=
94 @echo " > Cleaning build cache"
95 @-rm -rf $(GO_TARGETS)* 2> /dev/null
101 #------------------------------------------------------------------------------
103 #-------------------------------------------------------------------- ----------
105 $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME): BUILDDEPS:=$(XAPP_BUILDDEPS)
108 $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: BUILDDEPS:=$(XAPP_BUILDDEPS)
109 $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVEROUT:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.out)
110 $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVERHTML:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.html)
111 $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: TESTENV:=$(XAPP_TESTENV)
113 go-build: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)
114 go-test: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
115 go-clean: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME) $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test