blob: 02bb0e48a80d9bb8659a04c9664ffcb3102c24f7 [file] [log] [blame]
Joey Armstrong36c9bcd2023-04-05 19:05:56 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
17
18$(if $(DEBUG),$(warning ENTER))
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23RELEASE_BBR_NAME ?= bbr
24
25# release-target-deps += release-bbr
26
27# -----------------------------
28# release/bbsimctl-darwin-amd64
29# release/bbsimctl-linux-amd64
30# release/bbsimctl-windows-amd64
31# -----------------------------
32release-bbr-deps :=\
33 $(call release-gen-deps,RELEASE_BBR_NAME,RELEASE_OS_ARCH,RELEASE_DIR)
34
35## -----------------------------------------------------------------------
36## Intent: Cross-compile bbr binaries as dependency targets
37## o target: release/bbr-linux-amd64
38## o create release/ for VOLUME mounting by docker container
39## o create a response file for passing docker env vars
40## o cross-compile: GOOS= GOARCH= go build
41## -----------------------------------------------------------------------
42tans release-bbr: $(release-bbr-deps)
43
44.PHONY: $(release-bbr-deps)
45$(release-bbr-deps):
46
47 @echo
48 @echo "** -----------------------------------------------------------------------"
49 @echo "** $(MAKE): processing target [$@]"
50 @echo "** -----------------------------------------------------------------------"
51
52 # Docker container is responsible for compiling
53 # Release target will publish from localhost:release/
54 # Binaries are built into mounted docker volume /app/release => localhost:release/
55 $(HIDE)mkdir -vp "$(RELEASE_DIR)"
56 $(HIDE)umask 000 && chmod 777 "$(RELEASE_DIR)"
57
58 # -----------------------------------------------------------------------
59 # Create a response file for passing environment vars to docker
60 # -----------------------------------------------------------------------
61 $(HIDE)$(RM) $(notdir $@).env
62 $(HIDE)echo -e '#!/bin/bash\n' \
63 'GOOS=$(call get-hyphen-field,2,$@)\n' \
64 'GOARCH=$(call get-hyphen-field,3,$@)\n' \
65 >> "$(notdir $@).env"
66
67 # -----------------------------------------------------------------------
68 # Compile a platform binary
69 # -----------------------------------------------------------------------
70 $(HIDE) \
71 umask 022 \
72\
73 && echo "** Building: $@" \
74 && set -x \
75 && $(call my-go-sh,$(notdir $@).env) \
76 $(quote-single) \
77 go build -mod vendor \
78 -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
79 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
80 -X main.gitStatus=${GIT_STATUS} \
81 -X main.version=${VERSION}" \
82 -o "$@" ./cmd/bbr \
83 $(quote-single)
84
85 # -----------------------------------------------------------------------
86 # Cleanup and display results
87 # -----------------------------------------------------------------------
88 @$(RM) $(notdir $@).env
89 $(HIDE)umask 000 && chmod 755 "$(RELEASE_DIR)"
90 $(HIDE)file "$@"
91
92## -----------------------------------------------------------------------
93## -----------------------------------------------------------------------
94build-bbr: local-omci-lib-go local-protos
95 @go build -mod vendor \
96 -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
97 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
98 -X main.gitStatus=${GIT_STATUS} \
99 -X main.version=${VERSION}" \
100 ./cmd/bbr
101
102## -----------------------------------------------------------------------
103## Intent: Remove generated targets
104## -----------------------------------------------------------------------
105clean ::
106 $(RM) $(release-bbr-deps)
107 $(RM) *.env
108 $(RM) $(RELEASE_BBR_NAME)
109
110## -----------------------------------------------------------------------
111## Intent: Display target help#
112# -----------------------------------------------------------------------
113help ::
114 @echo
115 @echo '[bbr]'
116 @echo ' build-bbr Compile bbr on localhost'
117 @echo ' release-bbr Cross-compile bbr binary for release'
118
119$(if $(DEBUG),$(warning LEAVE))
120
121# [EOF]