blob: 8bf5b80751ec07075b4189e39083aeba5154c14e [file] [log] [blame]
Joey Armstrong36c9bcd2023-04-05 19:05:56 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong2c039362024-02-04 18:51:52 -05003# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong36c9bcd2023-04-05 19:05:56 -04004#
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_BBSIMCTL_NAME ?= bbsimctl
24
25bbsimctl-config := github.com/opencord/bbsim/internal/bbsimctl/config
26
27# release-target-deps += release-bbsimctl
28
29# -----------------------------
30# release/bbsimctl-darwin-amd64
31# release/bbsimctl-linux-amd64
32# release/bbsimctl-windows-amd64
33# -----------------------------
34release-bbsimctl-deps :=\
35 $(call release-gen-deps,RELEASE_BBSIMCTL_NAME,RELEASE_OS_ARCH,RELEASE_DIR)
36
37## -----------------------------------------------------------------------
38## Intent: Cross-compile bbsimctl binaries as dependency targets
39## o target: release/bbsimctl-linux-amd64
40## o create release/ for VOLUME mounting by docker container
41## o create a response file for passing docker env vars
42## o cross-compile: GOOS= GOARCH= go build
43## -----------------------------------------------------------------------
44release-bbsimctl: $(release-bbsimctl-deps)
45
46.PHONY: $(release-bbsimctl-deps)
47$(release-bbsimctl-deps):
48
49 @echo
50 @echo "** -----------------------------------------------------------------------"
51 @echo "** $(MAKE): processing target [$@]"
52 @echo "** -----------------------------------------------------------------------"
53
54 # Docker container is responsible for compiling
55 # Release target will publish from localhost:release/
56 # Binaries are built into mounted docker volume /app/release=> localhost:release/
57 $(HIDE)mkdir -vp "$(RELEASE_DIR)"
58 $(HIDE)umask 000 && chmod 777 "$(RELEASE_DIR)"
59
60 # -----------------------------------------------------------------------
61 # Create a response file for passing environment vars to docker
62 # -----------------------------------------------------------------------
63 $(HIDE)$(RM) $(notdir $@).env
64 $(HIDE)echo -e '#!/bin/bash\n' \
65 'GOOS=$(call get-hyphen-field,2,$@)\n' \
66 'GOARCH=$(call get-hyphen-field,3,$@)\n' \
67 >> "$(notdir $@).env"
68
69 # -----------------------------------------------------------------------
70 # Compile a platform binary
71 # -----------------------------------------------------------------------
72 $(HIDE) \
73 umask 022 \
74\
75 && echo "** Building: $@" \
76 && set -x \
77 && $(call my-go-sh,$(notdir $@).env) \
78 $(quote-single) \
79 go build -mod vendor \
80 -ldflags "-w -X $(bbsimctl-config).BuildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
81 -X $(bbsimctl-config).CommitHash=$(shell git log --pretty=format:%H -n 1) \
82 -X $(bbsimctl-config).GitStatus=${GIT_STATUS} \
83 -X $(bbsimctl-config).Version=${VERSION}" \
84 -o "$@" ./cmd/bbsimctl \
85 $(quote-single)
86
87 # -----------------------------------------------------------------------
88 # Cleanup and display results
89 # -----------------------------------------------------------------------
90 @$(RM) $(notdir $@).env
91 $(HIDE)umask 000 && chmod 755 "$(RELEASE_DIR)"
92 $(HIDE)file "$@"
93
94## -----------------------------------------------------------------------
95## Intent: Build bbsimctl on localhost
96## -----------------------------------------------------------------------
97build-bbsimctl:
98 @go build -mod vendor \
99 -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
100 -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
101 -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
102 -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
103 ./cmd/bbsimctl
104
105## -----------------------------------------------------------------------
106## Intent: Remove generated targets
107## -----------------------------------------------------------------------
108clean ::
109 $(RM) $(release-bbsimctl-deps)
110 $(RM) *.env
111 $(RM) bbsimclt
112
113## -----------------------------------------------------------------------
114## Intent: Display target help#
115# -----------------------------------------------------------------------
116help ::
117 @echo
118 @echo '[bbsimctl]'
119 @echo ' build-bbsimctl Compile bbsimctl on localhost'
120 @echo ' release-bbsimctl Cross-compile bbsimctl binaries into a docker mounted filesystem'
121
122$(if $(DEBUG),$(warning LEAVE))
123
124# [EOF]