88export GOPATH := $(shell go env GOPATH)
99GOPATH1 := $(firstword $(subst :, ,$(GOPATH ) ) )
1010endif
11+ GOBIN := $(if $(shell go env GOBIN) ,$(shell go env GOBIN) ,$(GOPATH1 ) /bin)
1112SRCPATH := $(shell pwd)
1213ARCH := $(shell ./scripts/archtype.sh)
1314OS_TYPE := $(shell ./scripts/ostype.sh)
1415# overrides for cross-compiling platform-specific binaries
1516ifdef CROSS_COMPILE_ARCH
1617 ARCH := $(CROSS_COMPILE_ARCH )
17- GO_INSTALL := CGO_ENABLED=1 GOOS=$(OS_TYPE ) GOARCH=$(ARCH ) go build -o $(GOPATH1 ) /bin- $( OS_TYPE ) - $( ARCH )
18+ GO_INSTALL := CGO_ENABLED=1 GOOS=$(OS_TYPE ) GOARCH=$(ARCH ) go build -o $(GOBIN )
1819else
1920 GO_INSTALL := go install
2021endif
@@ -105,10 +106,10 @@ fmt:
105106 ./scripts/check_license.sh -i
106107
107108fix : build
108- $(GOPATH1 ) /bin /algofix * /
109+ $(GOBIN ) /algofix * /
109110
110111lint : deps
111- $(GOPATH1 ) /bin /golangci-lint run -c .golangci.yml
112+ $(GOBIN ) /golangci-lint run -c .golangci.yml
112113
113114expectlint :
114115 cd test/e2e-go/cli/goal/expect && python3 expect_linter.py * .exp
@@ -139,7 +140,7 @@ prof:
139140 cd node && go test $(GOTAGS ) -cpuprofile=cpu.out -memprofile=mem.out -mutexprofile=mutex.out
140141
141142generate : deps
142- PATH=$(GOPATH1 ) /bin :$$ PATH go generate ./...
143+ PATH=$(GOBIN ) :$$ PATH go generate ./...
143144
144145msgp : $(patsubst % ,% /msgp_gen.go,$(MSGP_GENERATE ) )
145146
@@ -153,9 +154,9 @@ logic:
153154% /msgp_gen.go : deps ALWAYS
154155 @set +e; \
155156 printf " msgp: $( @D) ..." ; \
156- $(GOPATH1 ) /bin /msgp -file ./$(@D ) -o $@ -warnmask github.com/algorand/go-algorand > ./$@ .out 2>&1 ; \
157+ $(GOBIN ) /msgp -file ./$(@D ) -o $@ -warnmask github.com/algorand/go-algorand > ./$@ .out 2>&1 ; \
157158 if [ " $$ ?" != " 0" ]; then \
158- printf " failed:\n$( GOPATH1 ) /bin /msgp -file ./$( @D) -o $@ -warnmask github.com/algorand/go-algorand\n" ; \
159+ printf " failed:\n$( GOBIN ) /msgp -file ./$( @D) -o $@ -warnmask github.com/algorand/go-algorand\n" ; \
159160 cat ./$@ .out; \
160161 rm ./$@ .out; \
161162 exit 1; \
@@ -178,29 +179,42 @@ crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a:
178179universal :
179180ifeq ($(OS_TYPE ) ,darwin)
180181 # build amd64 Mac binaries
181- mkdir -p $(GOPATH1)/bin -darwin-amd64
182- CROSS_COMPILE_ARCH=amd64 GOBIN=$(GOPATH1)/bin -darwin-amd64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch x86_64 -mmacos-version-min=13.0" --host=x86_64-apple-darwin' $(MAKE)
182+ mkdir -p $(GOBIN) -darwin-amd64
183+ CROSS_COMPILE_ARCH=amd64 GOBIN=$(GOBIN) -darwin-amd64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch x86_64 -mmacos-version-min=13.0" --host=x86_64-apple-darwin' $(MAKE)
183184
184185 # build arm64 Mac binaries
185- mkdir -p $(GOPATH1)/bin -darwin-arm64
186- CROSS_COMPILE_ARCH=arm64 GOBIN=$(GOPATH1)/bin -darwin-arm64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch arm64 -mmacos-version-min=13.0" --host=aarch64-apple-darwin' $(MAKE)
186+ mkdir -p $(GOBIN) -darwin-arm64
187+ CROSS_COMPILE_ARCH=arm64 GOBIN=$(GOBIN) -darwin-arm64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch arm64 -mmacos-version-min=13.0" --host=aarch64-apple-darwin' $(MAKE)
187188
188189 # same for buildsrc-special
189190 cd tools/block-generator && \
190- CROSS_COMPILE_ARCH=amd64 GOBIN=$(GOPATH1)/bin -darwin-amd64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch x86_64 -mmacos-version-min=13.0" --host=x86_64-apple-darwin' $(MAKE)
191- CROSS_COMPILE_ARCH=arm64 GOBIN=$(GOPATH1)/bin -darwin-arm64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch arm64 -mmacos-version-min=13.0" --host=aarch64-apple-darwin' $(MAKE)
191+ CROSS_COMPILE_ARCH=amd64 GOBIN=$(GOBIN) -darwin-amd64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch x86_64 -mmacos-version-min=13.0" --host=x86_64-apple-darwin' $(MAKE)
192+ CROSS_COMPILE_ARCH=arm64 GOBIN=$(GOBIN) -darwin-arm64 MACOSX_DEPLOYMENT_TARGET=13.0 EXTRA_CONFIGURE_FLAGS='CFLAGS="-arch arm64 -mmacos-version-min=13.0" --host=aarch64-apple-darwin' $(MAKE)
192193
193194 # lipo together
194- mkdir -p $(GOPATH1)/bin
195- for binary in $$(ls $(GOPATH1)/bin-darwin-arm64); do \
196- if [ -f $(GOPATH1)/bin-darwin-amd64/$$binary ]; then \
197- lipo -create -output $(GOPATH1)/bin/$$binary \
198- $(GOPATH1)/bin-darwin-arm64/$$binary \
199- $(GOPATH1)/bin-darwin-amd64/$$binary; \
195+ mkdir -p $(GOBIN)
196+ for binary in $$(ls $(GOBIN)-darwin-arm64); do \
197+ skip=false; \
198+ for nongo_file in $(NONGO_BIN_FILES) $(GOBIN)/update.sh ; do \
199+ if [ "$(GOBIN)/$$binary" = "$$nongo_file" ]; then \
200+ echo "Skipping non-binary file: $$binary"; \
201+ skip=true; \
202+ break; \
203+ fi; \
204+ done; \
205+ if [ "$$skip" = "true" ]; then \
206+ continue; \
207+ fi; \
208+ if [ -f $(GOBIN)-darwin-amd64/$$binary ]; then \
209+ lipo -create -output $(GOBIN)/$$binary \
210+ $(GOBIN)-darwin-arm64/$$binary \
211+ $(GOBIN)-darwin-amd64/$$binary; \
200212 else \
201213 echo "Warning: Binary $$binary exists in arm64 but not in amd64"; \
202- fi \
214+ fi; \
203215 done
216+ # for node_exporter cross-compilation is using universal binary already
217+ cp -f $(GOBIN)-darwin-arm64/node_exporter $(GOBIN)/node_exporter
204218else
205219 echo "OS_TYPE must be darwin for universal builds, skipping"
206220endif
@@ -220,7 +234,7 @@ $(KMD_API_SWAGGER_SPEC): $(KMD_API_FILES) crypto/libs/$(OS_TYPE)/$(ARCH)/lib/lib
220234 cd daemon/kmd/lib/kmdapi && \
221235 python3 genSwaggerWrappers.py $(KMD_API_SWAGGER_WRAPPER )
222236 cd daemon/kmd && \
223- PATH=$(GOPATH1 ) /bin :$$ PATH \
237+ PATH=$(GOBIN ) :$$ PATH \
224238 go generate ./...
225239 rm daemon/kmd/lib/kmdapi/$(KMD_API_SWAGGER_WRAPPER )
226240
@@ -274,23 +288,23 @@ check-go-version:
274288# # We overwrite bin-race/kmd with a non -race version due to
275289# # the incredible performance impact of -race on Scrypt.
276290build-race : build
277- @mkdir -p $(GOPATH1 ) /bin -race
278- GOBIN=$(GOPATH1 ) /bin -race go install $(GOTRIMPATH ) $(GOTAGS ) -race -ldflags=" $( GOLDFLAGS) " ./...
279- cp $(GOPATH1 ) /bin/ kmd $(GOPATH1 ) /bin -race
291+ @mkdir -p $(GOBIN ) -race
292+ GOBIN=$(GOBIN ) -race go install $(GOTRIMPATH ) $(GOTAGS ) -race -ldflags=" $( GOLDFLAGS) " ./...
293+ cp $(GOBIN ) / kmd $(GOBIN ) -race
280294
281- NONGO_BIN_FILES =$(GOPATH1 ) /bin/ find-nodes.sh $(GOPATH1 ) /bin/ update.sh $(GOPATH1 ) /bin/ COPYING $(GOPATH1 ) /bin /ddconfig.sh
295+ NONGO_BIN_FILES =$(GOBIN ) / find-nodes.sh $(GOBIN ) / update.sh $(GOBIN ) / COPYING $(GOBIN ) /ddconfig.sh
282296
283297NONGO_BIN : $(NONGO_BIN_FILES )
284298
285- $(GOPATH1 ) /bin /find-nodes.sh : scripts/find-nodes.sh
299+ $(GOBIN ) /find-nodes.sh : scripts/find-nodes.sh
286300
287- $(GOPATH1 ) /bin /update.sh : cmd/updater/update.sh
301+ $(GOBIN ) /update.sh : cmd/updater/update.sh
288302
289- $(GOPATH1 ) /bin /COPYING : COPYING
303+ $(GOBIN ) /COPYING : COPYING
290304
291- $(GOPATH1 ) /bin /ddconfig.sh : scripts/ddconfig.sh
305+ $(GOBIN ) /ddconfig.sh : scripts/ddconfig.sh
292306
293- $(GOPATH1 ) /bin /% :
307+ $(GOBIN ) /% :
294308 cp -f $< $@
295309
296310test : build
@@ -315,7 +329,7 @@ testall: fulltest integration
315329
316330clean :
317331 go clean -i ./...
318- rm -f $(GOPATH1 ) /bin /node_exporter
332+ rm -f $(GOBIN ) /node_exporter
319333 cd crypto/libsodium-fork && \
320334 test ! -e Makefile || make clean
321335 rm -rf crypto/lib
@@ -326,17 +340,17 @@ clean:
326340# clean without crypto
327341cleango :
328342 go clean -i ./...
329- rm -f $(GOPATH1 ) /bin /node_exporter
343+ rm -f $(GOBIN ) /node_exporter
330344
331345# assign the phony target node_exporter the dependency of the actual executable.
332- node_exporter : $(GOPATH1 ) /bin /node_exporter
346+ node_exporter : $(GOBIN ) /node_exporter
333347
334348# The recipe for making the node_exporter is by extracting it from the gzipped&tar file.
335349# The file is was taken from the S3 cloud and it traditionally stored at
336350# /travis-build-artifacts-us-ea-1.algorand.network/algorand/node_exporter/latest/node_exporter-stable-linux-x86_64.tar.gz
337- $(GOPATH1 ) /bin /node_exporter :
338- mkdir -p $(GOPATH1 ) /bin && \
339- cd $(GOPATH1 ) /bin && \
351+ $(GOBIN ) /node_exporter :
352+ mkdir -p $(GOBIN ) && \
353+ cd $(GOBIN ) && \
340354 if [ -z " $( CROSS_COMPILE_ARCH) " ]; then \
341355 tar -xzvf $(SRCPATH ) /installer/external/node_exporter-stable-$(shell ./scripts/ostype.sh) -$(shell uname -m | tr '[:upper:]' '[:lower:]') .tar.gz; \
342356 else \
@@ -358,7 +372,7 @@ gen/%/genesis.dump: gen/%/genesis.json
358372 ./scripts/dump_genesis.sh $< > $@
359373
360374gen/% /genesis.json : gen/% .json gen/generate.go buildsrc
361- $(GOPATH1 ) /bin /genesis -q $(SHORT_PART_PERIOD_FLAG ) -n $(shell basename $(shell dirname $@ ) ) -c $< -d $(subst .json,,$< )
375+ $(GOBIN ) /genesis -q $(SHORT_PART_PERIOD_FLAG ) -n $(shell basename $(shell dirname $@ ) ) -c $< -d $(subst .json,,$< )
362376
363377gen : $(addsuffix gen, $(NETWORKS ) ) mainnetgen
364378
@@ -376,15 +390,15 @@ mainnetgen: gen/mainnet/genesis.dump
376390# This target is preserved as part of the history on how mainnet genesis.json was generated from the CSV file.
377391gen/mainnet/genesis.json : gen/pregen/mainnet/genesis.csv buildsrc
378392 mkdir -p gen/mainnet
379- cat gen/pregen/mainnet/genesis.csv | $(GOPATH1 ) /bin /incorporate -m gen/pregen/mainnet/metadata.json > gen/mainnet/genesis.json
393+ cat gen/pregen/mainnet/genesis.csv | $(GOBIN ) /incorporate -m gen/pregen/mainnet/metadata.json > gen/mainnet/genesis.json
380394
381395capabilities : build
382- sudo setcap cap_ipc_lock+ep $(GOPATH1 ) /bin /kmd
396+ sudo setcap cap_ipc_lock+ep $(GOBIN ) /kmd
383397
384398dump : $(addprefix gen/,$(addsuffix /genesis.dump, $(NETWORKS ) ) )
385399
386400install : build
387- scripts/dev_install.sh -p $(GOPATH1 ) /bin
401+ scripts/dev_install.sh -p $(GOBIN )
388402
389403.PHONY : default fmt lint check_shell sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install % gen gen NONGO_BIN check-go-version rebuild_kmd_swagger universal
390404
0 commit comments