github.com/giantswarm/apiextensions/v2@v2.6.2/Makefile (about)

     1  # Directories.
     2  APIS_DIR := pkg/apis
     3  CLIENTSET_DIR := pkg/clientset
     4  CRDV1_DIR := config/crd/v1
     5  CRDV1BETA1_DIR := config/crd/v1beta1
     6  SCRIPTS_DIR := hack
     7  TOOLS_DIR := $(SCRIPTS_DIR)/tools
     8  TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
     9  
    10  # Binaries.
    11  # Need to use abspath so we can invoke these from subdirectories
    12  CLIENT_GEN := $(abspath $(TOOLS_BIN_DIR)/client-gen)
    13  CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
    14  GOIMPORTS := $(abspath $(TOOLS_BIN_DIR)/goimports)
    15  KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize)
    16  ESC := $(abspath $(TOOLS_BIN_DIR)/esc)
    17  
    18  BUILD_COLOR = ""
    19  GEN_COLOR = ""
    20  NO_COLOR = ""
    21  
    22  ifneq (, $(shell command -v tput))
    23  ifeq ($(shell test `tput colors` -ge 8 && echo "yes"), yes)
    24  BUILD_COLOR = \033[0;34m
    25  GEN_COLOR = \033[0;32m
    26  NO_COLOR = \033[0m
    27  endif
    28  endif
    29  
    30  DEEPCOPY_BASE = zz_generated.deepcopy
    31  MODULE = $(shell go list -m)
    32  BOILERPLATE = $(SCRIPTS_DIR)/boilerplate.go.txt
    33  PATCH_FILE = $(SCRIPTS_DIR)/generated.patch
    34  YEAR = $(shell date +'%Y')
    35  
    36  INPUT_DIRS := $(shell find ./$(APIS_DIR) -maxdepth 2 -mindepth 2 | paste -s -d, -)
    37  GROUPS := $(shell find $(APIS_DIR) -maxdepth 2 -mindepth 2  | sed 's|pkg/apis/||' | paste -s -d, -)
    38  DEEPCOPY_FILES := $(shell find $(APIS_DIR) -name $(DEEPCOPY_BASE).go)
    39  
    40  all: generate
    41  
    42  $(CLIENT_GEN): $(TOOLS_DIR)/client-gen/go.mod
    43  	@echo "$(BUILD_COLOR)Building client-gen$(NO_COLOR)"
    44  	cd $(TOOLS_DIR)/client-gen \
    45  	&& go build -tags=tools -o $(CLIENT_GEN) k8s.io/code-generator/cmd/client-gen
    46  
    47  $(CONTROLLER_GEN): $(TOOLS_DIR)/controller-gen/go.mod
    48  	@echo "$(BUILD_COLOR)Building controller-gen$(NO_COLOR)"
    49  	cd $(TOOLS_DIR)/controller-gen \
    50   	&& go build -tags=tools -o $(CONTROLLER_GEN) sigs.k8s.io/controller-tools/cmd/controller-gen
    51  
    52  $(GOIMPORTS): $(TOOLS_DIR)/goimports/go.mod
    53  	@echo "$(BUILD_COLOR)Building goimports$(NO_COLOR)"
    54  	cd $(TOOLS_DIR)/goimports \
    55  	&& go build -tags=tools -o $(GOIMPORTS) golang.org/x/tools/cmd/goimports
    56  
    57  $(KUSTOMIZE): $(TOOLS_DIR)/kustomize/go.mod
    58  	@echo "$(BUILD_COLOR)Building kustomize$(NO_COLOR)"
    59  	cd $(TOOLS_DIR)/kustomize \
    60  	&& go build -tags=tools -o $(KUSTOMIZE) sigs.k8s.io/kustomize/kustomize/v3
    61  
    62  $(ESC): $(TOOLS_DIR)/esc/go.mod
    63  	@echo "$(BUILD_COLOR)Building esc$(NO_COLOR)"
    64  	@cd $(TOOLS_DIR)/esc \
    65  	&& go build -tags=tools -o $(ESC) github.com/mjibson/esc
    66  
    67  .PHONY: generate
    68  generate:
    69  	@$(MAKE) generate-clientset
    70  	@$(MAKE) generate-deepcopy
    71  	@$(MAKE) generate-manifests
    72  	@$(MAKE) generate-fs
    73  	@$(MAKE) imports
    74  	@$(MAKE) patch
    75  
    76  .PHONY: verify
    77  verify:
    78  	@$(MAKE) clean-generated
    79  	@$(MAKE) generate
    80  	git diff --exit-code
    81  
    82  .PHONY: generate-clientset
    83  generate-clientset: $(CLIENT_GEN)
    84  	@echo "$(GEN_COLOR)Generating clientset$(NO_COLOR)"
    85  	$(CLIENT_GEN) \
    86  	--clientset-name versioned \
    87  	--input $(GROUPS) \
    88  	--input-base $(MODULE)/$(APIS_DIR) \
    89  	--output-package $(MODULE)/$(CLIENTSET_DIR) \
    90  	--output-base $(SCRIPTS_DIR) \
    91  	--go-header-file $(BOILERPLATE)
    92  	cp -R $(SCRIPTS_DIR)/$(MODULE)/$(CLIENTSET_DIR)/versioned $(CLIENTSET_DIR)
    93  	rm -rf $(SCRIPTS_DIR)/github.com/
    94  
    95  .PHONY: generate-deepcopy
    96  generate-deepcopy: $(CONTROLLER_GEN)
    97  	@echo "$(GEN_COLOR)Generating deepcopy$(NO_COLOR)"
    98  	$(CONTROLLER_GEN) \
    99  	object:headerFile=$(BOILERPLATE),year=$(YEAR) \
   100  	paths=./$(APIS_DIR)/...
   101  
   102  .PHONY: generate-manifests
   103  generate-manifests: $(CONTROLLER_GEN) $(KUSTOMIZE)
   104  	@echo "$(GEN_COLOR)Generating CRDs$(NO_COLOR)"
   105  	cd $(SCRIPTS_DIR); ./generate-manifests.sh
   106  
   107  .PHONY: generate-fs
   108  generate-fs: $(ESC) config/crd
   109  	@echo "$(GEN_COLOR)Generating filesystem$(NO_COLOR)"
   110  	$(ESC) \
   111  	-o pkg/crd/internal/zz_generated.fs.go \
   112  	-pkg internal \
   113  	-modtime 0 \
   114  	config/crd
   115  
   116  .PHONY: imports
   117  imports: $(GOIMPORTS)
   118  	@echo "$(GEN_COLOR)Sorting imports$(NO_COLOR)"
   119  	$(GOIMPORTS) -local $(MODULE) -w ./pkg
   120  
   121  .PHONY: patch
   122  patch:
   123  	@echo "$(GEN_COLOR)Applying patch$(NO_COLOR)"
   124  	git apply $(PATCH_FILE)
   125  
   126  .PHONY: clean-generated
   127  clean-generated:
   128  	@echo "$(GEN_COLOR)Cleaning generated files$(NO_COLOR)"
   129  	rm -rf $(CRDV1_DIR) $(CRDV1BETA1_DIR) $(CLIENTSET_DIR)/versioned $(DEEPCOPY_FILES)
   130  
   131  .PHONY: clean-tools
   132  clean-tools:
   133  	@echo "$(GEN_COLOR)Cleaning tools$(NO_COLOR)"
   134  	rm -rf $(TOOLS_BIN_DIR)