github.com/vmware/govmomi@v0.43.0/program.mk (about) 1 # Copyright (c) 2021 VMware, Inc. All Rights Reserved. 2 # SPDX-License-Identifier: Apache-2.0 3 4 ifneq (,$(strip $(GOOS))) 5 ifeq (,$(strip $(GOARCH))) 6 GOARCH := $(shell go env | grep GOARCH | awk -F= '{print $$2}' | tr -d '"') 7 endif 8 endif 9 10 ifneq (,$(strip $(GOARCH))) 11 ifeq (,$(strip $(GOOS))) 12 GOOS := $(shell go env | grep GOOS | awk -F= '{print $$2}' | tr -d '"') 13 endif 14 endif 15 16 ifeq (2,$(words $(GOOS) $(GOARCH))) 17 PROGRAM := $(PROGRAM)_$(GOOS)_$(GOARCH) 18 endif 19 20 ifeq (windows,$(GOOS)) 21 PROGRAM := $(PROGRAM).exe 22 endif 23 24 all: $(PROGRAM) 25 26 TAGS += netgo 27 ifeq (,$(strip $(findstring -w,$(LDFLAGS)))) 28 LDFLAGS += -w 29 endif 30 BUILD_ARGS := -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -v 31 32 $(PROGRAM): 33 CGO_ENABLED=0 go build -a $(BUILD_ARGS) -o $@ 34 35 install: 36 CGO_ENABLED=0 go install -v $(BUILD_ARGS) 37 38 ifneq (,$(strip $(BUILD_OS))) 39 ifneq (,$(strip $(BUILD_ARCH))) 40 GOOS_GOARCH_TARGETS := $(foreach a,$(BUILD_ARCH),$(patsubst %,%_$a,$(BUILD_OS))) 41 XBUILD := $(addprefix $(PROGRAM)_,$(GOOS_GOARCH_TARGETS)) 42 $(XBUILD): 43 GOOS=$(word 2,$(subst _, ,$@)) GOARCH=$(word 3,$(subst _, ,$@)) $(MAKE) --output-sync=target 44 build-all: $(XBUILD) 45 endif 46 endif 47 48 clean: 49 @rm -f $(PROGRAM) $(XBUILD) 50 51 .PHONY: build-all install clean