github.com/grafana/synthetic-monitoring-agent@v0.64.2/scripts/make/300_build.mk (about)

     1  ##@ Building
     2  
     3  define build_go_template
     4  BUILD_GO_TARGETS += build-go-$(1)-$(2)-$(3)
     5  
     6  build-go-$(1)-$(2)-$(3) : GOOS := $(1)
     7  build-go-$(1)-$(2)-$(3) : GOARCH := $(2)
     8  build-go-$(1)-$(2)-$(3) : GOPKG := $(3)
     9  build-go-$(1)-$(2)-$(3) : DIST_FILENAME := $(firstword $(OUTPUT_FILE) $(DISTDIR)/$(1)-$(2)/$(notdir $(3)))
    10  
    11  endef
    12  
    13  $(foreach BUILD_PLATFORM,$(PLATFORMS), \
    14  	$(foreach CMD,$(COMMANDS), \
    15  		$(eval $(call build_go_template,$(word 1,$(subst /, ,$(BUILD_PLATFORM))),$(word 2,$(subst /, ,$(BUILD_PLATFORM))),$(CMD)))))
    16  
    17  BUILD_GO_NATIVE_TARGETS := $(filter build-go-$(HOST_OS)-$(HOST_ARCH)-%, $(BUILD_GO_TARGETS))
    18  
    19  .PHONY: $(BUILD_GO_TARGETS)
    20  $(BUILD_GO_TARGETS) : build-go-% :
    21  	$(call build_go_command,$(GOPKG))
    22  
    23  .PHONY: build-go
    24  build-go: $(BUILD_GO_TARGETS) ## Build all Go binaries.
    25  	$(S) echo Done.
    26  
    27  .PHONY: build
    28  build: build-go ## Build everything.
    29  
    30  .PHONY: build-native
    31  build-native: $(BUILD_GO_NATIVE_TARGETS) ## Build only native Go binaries
    32  	$(S) echo Done.
    33  
    34  VERSION_PKG := $(shell $(GO) list $(GO_BUILD_MOD_FLAGS) ./internal/version)
    35  
    36  define build_go_command
    37  	$(S) echo 'Building $(1) ($(GOOS)-$(GOARCH))'
    38  	$(S) mkdir -p $(DISTDIR)/$(GOOS)-$(GOARCH)
    39  	$(V) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build \
    40  		$(GO_BUILD_FLAGS) \
    41  		-o '$(DIST_FILENAME)' \
    42  		'$(1)'
    43  	$(V) test '$(GOOS)' = '$(HOST_OS)' -a '$(GOARCH)' = '$(HOST_ARCH)' && \
    44  		cp -a '$(DIST_FILENAME)' '$(DISTDIR)/$(notdir $(1))' || \
    45  		true
    46  endef