github.com/openshift/installer@v1.4.17/terraform/Makefile (about) 1 TARGET_OS_ARCH:=$(shell go env GOOS)_$(shell go env GOARCH) 2 3 TFSUBDIRS:= $(foreach DIR,$(shell find providers -maxdepth 1 -mindepth 1 -type d),$(subst providers/,,$(DIR))) 4 5 GO_MOD_TIDY_TARGETS:= $(foreach DIR,$(TFSUBDIRS), $(subst $(DIR),go-mod-tidy-vendor.$(DIR),$(DIR))) 6 GO_BUILD_TARGETS:= $(foreach DIR,$(TFSUBDIRS), $(subst $(DIR),go-build.$(DIR),$(DIR))) 7 GO_CLEAN_TARGETS:= $(foreach DIR,$(TFSUBDIRS), $(subst $(DIR),go-clean.$(DIR),$(DIR))) 8 TERRAFORM_PROVIDER_TARGETS := $(foreach DIR,$(TFSUBDIRS), bin/$(TARGET_OS_ARCH)/terraform-provider-$(DIR).zip) 9 10 LDFLAGS:= -s -w 11 GCFLAGS:= "" 12 13 ifeq ($(MODE), dev) 14 LDFLAGS:= 15 GCFLAGS:= "all=-N -l" 16 endif 17 18 MODINFOKEY:= main.builtGoModHash 19 20 .PHONY: all 21 all: go-build 22 23 .PHONY: go-mod-tidy-vendor 24 go-mod-tidy-vendor: $(GO_MOD_TIDY_TARGETS) 25 $(GO_MOD_TIDY_TARGETS): go-mod-tidy-vendor.%: 26 cd providers/$* && go mod tidy && go mod vendor 27 28 .PHONY: go-build 29 go-build: $(GO_BUILD_TARGETS) go-build-terraform 30 $(GO_BUILD_TARGETS): go-build.%: bin/$(TARGET_OS_ARCH)/terraform-provider-%.zip 31 32 $(TERRAFORM_PROVIDER_TARGETS): bin/$(TARGET_OS_ARCH)/terraform-provider-%.zip: providers/%/go.mod 33 cd providers/$*; \ 34 if [ -f main.go ]; then path="."; else path=./vendor/`grep _ tools.go|awk '{ print $$2 }'|sed 's|"||g'`; fi; \ 35 go build -gcflags $(GCFLAGS) -ldflags "$(LDFLAGS) -X $(MODINFOKEY)=$$(git hash-object go.mod)" -o ../../bin/$(TARGET_OS_ARCH)/terraform-provider-$* "$$path" && \ 36 zip -1j ../../bin/$(TARGET_OS_ARCH)/terraform-provider-$*.zip ../../bin/$(TARGET_OS_ARCH)/terraform-provider-$*; 37 38 .PHONY: go-build-terraform 39 go-build-terraform: bin/$(TARGET_OS_ARCH)/terraform 40 41 bin/$(TARGET_OS_ARCH)/terraform: terraform/go.mod 42 cd terraform; \ 43 go build -gcflags $(GCFLAGS) -ldflags "$(LDFLAGS) -X $(MODINFOKEY)=$$(git hash-object go.mod)" -o ../bin/$(TARGET_OS_ARCH)/terraform ./vendor/github.com/hashicorp/terraform 44 45 .PHONY: go-clean 46 go-clean: go-clean-providers go-clean-terraform 47 48 $(GO_CLEAN_TARGETS): go-clean.%: 49 rm -f bin/*/terraform-provider-$* 50 rm -f bin/*/terraform-provider-$*.zip 51 52 go-clean-providers: 53 rm -f bin/*/terraform-provider-* 54 55 go-clean-terraform: 56 rm -f bin/*/terraform 57 58 .PHONY: clean 59 clean: go-clean