@@ -22,6 +22,7 @@ ifndef build_names
2222ifndef exe_build_names
2323$(error build_names and exe_build_names are not set)
2424endif
25+ build_names := # empty
2526endif
2627
2728all_exe_build_names := $(sort $(build_names ) $(exe_build_names ) )
@@ -30,7 +31,28 @@ fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not
3031
3132define check_variables
3233$(call fatal_if_undefined,go_$1_ldflags)
33- $(call fatal_if_undefined,go_$1_source_path)
34+ $(call fatal_if_undefined,go_$1_main_dir)
35+ $(call fatal_if_undefined,go_$1_mod_dir)
36+
37+ ifneq ($(go_$1_main_dir:.%=. ) ,.)
38+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES start with ".")
39+ endif
40+ ifeq ($(go_$1_main_dir:%/=/ ) ,/)
41+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with "/")
42+ endif
43+ ifeq ($(go_$1_main_dir:%.go=.go ) ,.go)
44+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with ".go")
45+ endif
46+ ifneq ($(go_$1_mod_dir:\.%=\. ) ,.)
47+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES start with ".")
48+ endif
49+ ifeq ($(go_$1_mod_dir:%/=/ ) ,/)
50+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with "/")
51+ endif
52+ ifeq ($(go_$1_mod_dir:%.go=.go ) ,.go)
53+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with ".go")
54+ endif
55+
3456endef
3557
3658$(foreach build_name,$(all_exe_build_names),$(eval $(call check_variables,$(build_name))))
@@ -55,18 +77,21 @@ $(bin_dir)/bin:
5577.PHONY : $(run_targets )
5678ARGS ?= # default empty
5779# # Directly run the go source locally.
80+ # # Any Go workfile is ignored.
5881# # @category [shared] Build
5982$(run_targets ) : run-%: | $(NEEDS_GO )
83+ GOWORK=off \
6084 CGO_ENABLED=$(CGO_ENABLED) \
6185 GOEXPERIMENT=$(GOEXPERIMENT) \
6286 $(GO) run \
6387 -ldflags '$(go_$*_ldflags)' \
6488 $(go_$*_source_path) $(ARGS)
6589
6690# # Build the go source locally for development/ testing
67- # # on the local platform.
91+ # # on the local platform. Any Go workfile is ignored.
6892# # @category [shared] Build
6993$(build_targets ) : $(bin_dir ) /bin/% : FORCE | $(NEEDS_GO )
94+ GOWORK=off \
7095 CGO_ENABLED=$(CGO_ENABLED ) \
7196 GOEXPERIMENT=$(GOEXPERIMENT ) \
7297 $(GO ) build \
@@ -76,7 +101,8 @@ $(build_targets): $(bin_dir)/bin/%: FORCE | $(NEEDS_GO)
76101
77102define template_for_target
78103 $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .binary = "$(1 ) ")' | \
79- $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .main = "$(go_$(1 ) _source_path ) ")' | \
104+ $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .main = "$(go_$(1 ) _main_dir ) ")' | \
105+ $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .dir = "$(go_$(1 ) _mod_dir ) ")' | \
80106 $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .env[0] = "CGO_ENABLED={{.Env.CGO_ENABLED}}")' | \
81107 $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .env[1] = "GOEXPERIMENT={{.Env.GOEXPERIMENT}}")' | \
82108 $(YQ ) 'with(.builds[]; select(.id == "$(1 ) ") | .mod_timestamp = "{{.Env.SOURCE_DATE_EPOCH}}")' | \
@@ -106,6 +132,7 @@ ifeq ($(RELEASE_DRYRUN),true)
106132 $(eval extra_args := $(extra_args) --skip=announce,publish,validate,sign)
107133endif
108134
135+ GOWORK=off \
109136 SOURCE_DATE_EPOCH=$(GITEPOCH) \
110137 CGO_ENABLED=$(CGO_ENABLED) \
111138 GOEXPERIMENT=$(GOEXPERIMENT) \
0 commit comments