blob: 4e350ee4506e1180f0d9245d4040d3d8dd564a27 [file] [log] [blame]
Phaneendra Manda4c62c802019-03-06 21:37:49 +05301#
2# Copyright 2016 the original author or authors.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15#
16
17ifeq ($(TAG),)
18TAG := latest
19endif
20
21ifeq ($(TARGET_TAG),)
22TARGET_TAG := latest
23endif
24
25# If no DOCKER_HOST_IP is specified grab a v4 IP address associated with
26# the default gateway
27ifeq ($(DOCKER_HOST_IP),)
28DOCKER_HOST_IP := $(shell ifconfig $$(netstat -rn | grep -E '^(default|0.0.0.0)' | head -1 | awk '{print $$NF}') | grep inet | awk '{print $$2}' | sed -e 's/addr://g')
29endif
30
31
32ifneq ($(http_proxy)$(https_proxy),)
33# Include proxies from the environment
34DOCKER_PROXY_ARGS = \
35 --build-arg http_proxy=$(http_proxy) \
36 --build-arg https_proxy=$(https_proxy) \
37 --build-arg ftp_proxy=$(ftp_proxy) \
38 --build-arg no_proxy=$(no_proxy) \
39 --build-arg HTTP_PROXY=$(HTTP_PROXY) \
40 --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
41 --build-arg FTP_PROXY=$(FTP_PROXY) \
42 --build-arg NO_PROXY=$(NO_PROXY)
43endif
44
45DOCKER_BUILD_ARGS = \
46 --build-arg TAG=$(TAG) \
47 --build-arg REGISTRY=$(REGISTRY) \
48 --build-arg REPOSITORY=$(REPOSITORY) \
49 $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \
50 --rm --force-rm \
51 $(DOCKER_BUILD_EXTRA_ARGS)
52
53DOCKER_IMAGE_LIST = \
54 openolt-adapter-go
55
56
57.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) adapters
58
59# This should to be the first and default target in this Makefile
60help:
61 @echo "Usage: make [<target>]"
62 @echo "where available targets are:"
63 @echo
64 @echo "build : Build the docker images.\n\
65 If this is the first time you are building, choose \"make build\" option."
66 @echo
67
68
69# Parallel Build
70$(DIRS):
71 @echo " MK $@"
72 $(Q)$(MAKE) -C $@
73
74# Parallel Clean
75DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
76$(DIRS_CLEAN):
77 @echo " CLEAN $(basename $@)"
78 $(Q)$(MAKE) -C $(basename $@) clean
79
80build: containers
81
82containers: adapter_openolt_go
83
84adapter_openolt_go:
William Kurkianea869482019-04-09 15:16:11 -040085ifdef LOCAL_PROTOS
86 mkdir -p vendor/github.com/opencord/voltha-protos/go
87 cp -rf ${GOPATH}/src/github.com/opencord/voltha-protos/go/ vendor/github.com/opencord/voltha-protos
88endif
89ifdef LOCAL_VOLTHAGO
90 mkdir -p vendor/github.com/opencord/voltha-go/
91 cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/
92 rm -rf vendor/github.com/opencord/voltha-go/vendor
93endif
Phaneendra Manda4c62c802019-03-06 21:37:49 +053094 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-go:${TAG} -f docker/Dockerfile.openolt .
95
Matt Jeanneret384d8c92019-05-06 14:27:31 -040096lint-style:
97ifeq (,$(shell which gofmt))
98 go get -u github.com/golang/go/src/cmd/gofmt
99endif
100 @echo "Running style check..."
101 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
102 if [ ! -z "$$gofmt_out" ]; then \
103 echo "$$gofmt_out" ;\
104 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
105 exit 1 ;\
106 fi
107 @echo "Style check OK"
108
109lint-sanity:
110 @echo "Running sanity check..."
111 @go vet ./...
112 @echo "Sanity check OK"
113
114lint-dep:
115 @echo "Running dependency check..."
116 @dep check
117 @echo "Dependency check OK"
118
119lint: lint-style lint-sanity lint-dep
120
121GO_JUNIT_REPORT:=$(shell which go-junit-report)
122GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
123test:
124ifeq (,$(GO_JUNIT_REPORT))
125 go get -u github.com/jstemmer/go-junit-report
126 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
127endif
128
129ifeq (,$(GOCOVER_COBERTURA))
130 go get -u github.com/t-yuki/gocover-cobertura
131 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
132endif
133
134 @mkdir -p ./tests/results
135
136 @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
137 RETURN=$$? ;\
138 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
139 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
140 exit $$RETURN
141
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530142# end file