github.com/vmware/govmomi@v0.51.0/program.mk (about)

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