github.com/openshift/installer@v1.4.17/cluster-api/Makefile (about)

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