github.com/giantswarm/apiextensions/v6@v6.6.0/Makefile.custom.mk (about) 1 # Directories. 2 APIS_DIR := pkg/apis 3 CRD_DIR := config/crd 4 SCRIPTS_DIR := hack 5 TOOLS_DIR := $(SCRIPTS_DIR)/tools 6 TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin) 7 8 # Binaries. 9 # Need to use abspath so we can invoke these from subdirectories 10 CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen) 11 GOIMPORTS := $(abspath $(TOOLS_BIN_DIR)/goimports) 12 13 BUILD_COLOR = "" 14 GEN_COLOR = "" 15 NO_COLOR = "" 16 17 ifneq (, $(shell command -v tput)) 18 ifeq ($(shell test `tput colors` -ge 8 && echo "yes"), yes) 19 BUILD_COLOR=$(shell echo -e "\033[0;34m") 20 GEN_COLOR=$(shell echo -e "\033[0;32m") 21 NO_COLOR=$(shell echo -e "\033[0m") 22 endif 23 endif 24 25 DEEPCOPY_BASE = zz_generated.deepcopy 26 MODULE = $(shell go list -m) 27 BOILERPLATE = $(SCRIPTS_DIR)/boilerplate.go.txt 28 PATCH_FILE = $(SCRIPTS_DIR)/generated.patch 29 YEAR = $(shell date +'%Y') 30 31 DEEPCOPY_FILES := $(shell find $(APIS_DIR) -name $(DEEPCOPY_BASE).go) 32 CHART_GENERATED_FILES := $(shell find helm -maxdepth 3 -mindepth 3 -name '*.yaml') 33 34 all: generate 35 36 $(CONTROLLER_GEN): $(TOOLS_DIR)/controller-gen/go.mod 37 @echo "$(BUILD_COLOR)Building controller-gen$(NO_COLOR)" 38 cd $(TOOLS_DIR)/controller-gen \ 39 && go build -tags=tools -o $(CONTROLLER_GEN) sigs.k8s.io/controller-tools/cmd/controller-gen 40 41 $(GOIMPORTS): $(TOOLS_DIR)/goimports/go.mod 42 @echo "$(BUILD_COLOR)Building goimports$(NO_COLOR)" 43 cd $(TOOLS_DIR)/goimports \ 44 && go build -tags=tools -o $(GOIMPORTS) golang.org/x/tools/cmd/goimports 45 46 .PHONY: generate 47 generate: clean-tools 48 @$(MAKE) generate-deepcopy 49 @$(MAKE) generate-manifests 50 @$(MAKE) local-imports 51 52 .PHONY: verify 53 verify: 54 @$(MAKE) clean-generated 55 @$(MAKE) generate 56 git diff --exit-code 57 58 .PHONY: generate-deepcopy 59 generate-deepcopy: $(CONTROLLER_GEN) 60 @echo "$(GEN_COLOR)Generating deepcopy$(NO_COLOR)" 61 $(CONTROLLER_GEN) \ 62 object:headerFile=$(BOILERPLATE),year=$(YEAR) \ 63 paths=./$(APIS_DIR)/... 64 65 .PHONY: generate-manifests 66 generate-manifests: $(CONTROLLER_GEN) 67 @echo "$(GEN_COLOR)Generating CRDs$(NO_COLOR)" 68 cd $(SCRIPTS_DIR); ./generate-crds.sh 69 go generate hack/build-charts.go 70 71 .PHONY: local-imports 72 local-imports: $(GOIMPORTS) 73 @echo "$(GEN_COLOR)Sorting imports$(NO_COLOR)" 74 $(GOIMPORTS) -local $(MODULE) -w ./pkg 75 76 .PHONY: patch 77 patch: 78 @echo "$(GEN_COLOR)Applying patch$(NO_COLOR)" 79 git apply $(PATCH_FILE) 80 81 .PHONY: clean-generated 82 clean-generated: 83 @echo "$(GEN_COLOR)Cleaning generated files$(NO_COLOR)" 84 rm -rf $(CRD_DIR) $(DEEPCOPY_FILES) $(CHART_GENERATED_FILES) 85 86 .PHONY: clean-tools 87 clean-tools: 88 @echo "$(GEN_COLOR)Cleaning tools$(NO_COLOR)" 89 rm -rf $(TOOLS_BIN_DIR)