blob: 87b86733d7e5bb6ea7e8cfbf850ebdf27e0025b6 [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_BBSIM_NAME ?= bbsim
24
25# release-target-deps += release-bbsim
26
27# -----------------------------
28# release/bbsim-darwin-amd64
29# release/bbsim-linux-amd64
30# release/bbsim-windows-amd64
31# -----------------------------
32release-bbsim-deps :=\
33 $(call release-gen-deps,RELEASE_BBSIM_NAME,RELEASE_OS_ARCH,RELEASE_DIR)
34
35## -----------------------------------------------------------------------
36## Intent: Cross-compile bbsim binaries as dependency targets
37## o target: release/bbsim-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## -----------------------------------------------------------------------
42release-bbsim: $(release-bbsim-deps)
43
44.PHONY: $(release-bbsim-deps)
45$(release-bbsim-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/bbsim \
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
93release-bbsim-x:
94 @echo "$(RELEASE_BBSIM_NAME)-linux-amd64"
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 -o "$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-linux-amd64" ./cmd/bbsim
101
102## -----------------------------------------------------------------------
103## Intent: Build bbsimctl on localhost
104## -----------------------------------------------------------------------
105build-bbsim:
106 @go build -mod vendor \
107 -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
108 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
109 -X main.gitStatus=${GIT_STATUS} \
110 -X main.version=${VERSION}" \
111 ./cmd/bbsim
112
113## -----------------------------------------------------------------------
114## Intent: Remove generated targets
115## -----------------------------------------------------------------------
116clean ::
117 $(RM) $(release-bbsim-deps)
118 $(RM) *.env
119 $(RM) $(RELEASE_BBSIM_NAME)
120
121## -----------------------------------------------------------------------
122## Intent: Display target help#
123# -----------------------------------------------------------------------
124help ::
125 @echo
126 @echo '[bbsim]'
127 @echo ' build-bbsim Compile bbsim on localhost'
128 @echo ' release-bbsim Cross-compile bbsim binaries into a docker mounted filesystem'
129
130$(if $(DEBUG),$(warning LEAVE))
131
132# [EOF]