Makefile 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # Copyright 2016 The Rook Authors. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Linux doesn't guarantee file ordering, so sort the files to make sure order is deterministic.
  15. # And in order to handle file paths with spaces, it's easiest to read the file names into an array.
  16. # Set locale `LC_ALL=C` because different OSes have different sort behavior;
  17. # `C` sorting order is based on the byte values,
  18. # Reference: https://blog.zhimingwang.org/macos-lc_collate-hunt
  19. LC_ALL=C
  20. export LC_ALL
  21. include build/makelib/common.mk
  22. include build/makelib/helm.mk
  23. .PHONY: all
  24. all: build
  25. .DEFAULT_GOAL := all
  26. # ====================================================================================
  27. # Build Options
  28. # Controller-gen version
  29. # f284e2e8... is master ahead of v0.5.0 which has ability to generate embedded objectmeta in CRDs
  30. CONTROLLER_GEN_VERSION=v0.11.3
  31. # Set GOBIN
  32. ifeq (,$(shell go env GOBIN))
  33. GOBIN=$(shell go env GOPATH)/bin
  34. else
  35. GOBIN=$(shell go env GOBIN)
  36. endif
  37. # set the shell to bash in case some environments use sh
  38. SHELL := /usr/bin/env bash
  39. # Can be used or additional go build flags
  40. BUILDFLAGS ?=
  41. LDFLAGS ?=
  42. TAGS ?=
  43. # turn on more verbose build
  44. V ?= 0
  45. ifeq ($(V),1)
  46. LDFLAGS += -v -n
  47. BUILDFLAGS += -x
  48. MAKEFLAGS += VERBOSE=1
  49. else
  50. MAKEFLAGS += --no-print-directory
  51. endif
  52. # whether to generate debug information in binaries. this includes DWARF
  53. # and symbol tables.
  54. DEBUG ?= 0
  55. ifeq ($(DEBUG),0)
  56. LDFLAGS += -s -w
  57. endif
  58. # platforms
  59. PLATFORMS ?= $(ALL_PLATFORMS)
  60. # PLATFORMS_TO_BUILD_FOR controls for which platforms to build the rook binary for
  61. PLATFORMS_TO_BUILD_FOR ?= linux_amd64 linux_arm64
  62. SERVER_PLATFORMS := $(filter linux_%,$(PLATFORMS))
  63. CLIENT_PLATFORMS := $(filter-out linux_%,$(PLATFORMS))
  64. # server projects that we build on server platforms
  65. SERVER_PACKAGES = $(GO_PROJECT)/cmd/rook
  66. # tests packages that will be compiled into binaries
  67. TEST_PACKAGES = $(GO_PROJECT)/tests/integration
  68. # the root go project
  69. GO_PROJECT=github.com/rook/rook
  70. # inject the version number into the golang version package using the -X linker flag
  71. LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION)
  72. # CGO_ENABLED value
  73. CGO_ENABLED_VALUE=0
  74. # ====================================================================================
  75. # Setup projects
  76. # setup go projects
  77. GO_STATIC_PACKAGES=
  78. ifneq ($(filter $(PLATFORM),$(CLIENT_PLATFORMS) $(SERVER_PLATFORMS)),)
  79. GO_STATIC_PACKAGES += $(CLIENT_PACKAGES)
  80. endif
  81. ifneq ($(filter $(PLATFORM),$(SERVER_PLATFORMS)),)
  82. GO_STATIC_PACKAGES += $(SERVER_PACKAGES)
  83. endif
  84. GO_BUILDFLAGS=$(BUILDFLAGS)
  85. GO_LDFLAGS=$(LDFLAGS)
  86. GO_TAGS=$(TAGS)
  87. GO_TEST_PACKAGES=$(TEST_PACKAGES)
  88. GO_TEST_FLAGS=$(TESTFLAGS)
  89. GO_TEST_SUITE=$(SUITE)
  90. GO_TEST_FILTER=$(TESTFILTER)
  91. include build/makelib/golang.mk
  92. # ====================================================================================
  93. # Targets
  94. build.version:
  95. @mkdir -p $(OUTPUT_DIR)
  96. @echo "$(VERSION)" > $(OUTPUT_DIR)/version
  97. # Change how CRDs are generated for CSVs
  98. ifneq ($(REAL_HOST_PLATFORM),darwin_arm64)
  99. build.common: export NO_OB_OBC_VOL_GEN=true
  100. build.common: export MAX_DESC_LEN=0
  101. endif
  102. build.common: export SKIP_GEN_CRD_DOCS=true
  103. build.common: build.version helm.build mod.check crds gen-rbac
  104. @$(MAKE) go.init
  105. @$(MAKE) go.validate
  106. @$(MAKE) -C images/ceph list-image
  107. do.build.platform.%:
  108. @$(MAKE) PLATFORM=$* go.build
  109. do.build.parallel: $(foreach p,$(PLATFORMS_TO_BUILD_FOR), do.build.platform.$(p))
  110. build: csv-clean build.common ## Only build for linux platform
  111. @$(MAKE) go.build PLATFORM=linux_$(GOHOSTARCH)
  112. @$(MAKE) -C images PLATFORM=linux_$(GOHOSTARCH)
  113. build.all: build.common ## Build source code for all platforms.
  114. ifneq ($(GOHOSTARCH),amd64)
  115. $(error cross platform image build only supported on amd64 host currently)
  116. endif
  117. @$(MAKE) do.build.parallel
  118. @$(MAKE) -C images build.all
  119. install: build.common
  120. @$(MAKE) go.install
  121. check test: ## Runs unit tests.
  122. @$(MAKE) go.test.unit
  123. test-integration: ## Runs integration tests.
  124. @$(MAKE) go.test.integration
  125. lint: ## Check syntax and styling of go sources.
  126. @$(MAKE) go.init
  127. @$(MAKE) go.lint
  128. vet: ## Runs lint checks on go sources.
  129. @$(MAKE) go.init
  130. @$(MAKE) go.vet
  131. fmt: ## Check formatting of go sources.
  132. @$(MAKE) go.init
  133. @$(MAKE) go.fmt
  134. codegen: ${CODE_GENERATOR} ## Run code generators.
  135. @build/codegen/codegen.sh
  136. mod.check: go.mod.check ## Check if any go modules changed.
  137. mod.update: go.mod.update ## Update all go modules.
  138. clean: csv-clean ## Remove all files that are created by building.
  139. @$(MAKE) go.mod.clean
  140. @$(MAKE) -C images clean
  141. @rm -fr $(OUTPUT_DIR) $(WORK_DIR)
  142. distclean: clean ## Remove all files that are created by building or configuring.
  143. @rm -fr $(CACHE_DIR)
  144. prune: ## Prune cached artifacts.
  145. @$(MAKE) -C images prune
  146. # Change how CRDs are generated for CSVs
  147. csv: export MAX_DESC_LEN=0 # sets the description length to 0 since CSV cannot be bigger than 1MB
  148. csv: export NO_OB_OBC_VOL_GEN=true
  149. csv: csv-clean crds ## Generate a CSV file for OLM.
  150. $(MAKE) -C images/ceph csv
  151. csv-clean: ## Remove existing OLM files.
  152. @$(MAKE) -C images/ceph csv-clean
  153. docs: helm-docs
  154. @build/deploy/generate-deploy-examples.sh
  155. crds: $(CONTROLLER_GEN) $(YQ)
  156. @echo Updating CRD manifests
  157. @build/crds/build-crds.sh $(CONTROLLER_GEN) $(YQ)
  158. @GOBIN=$(GOBIN) build/crds/generate-crd-docs.sh
  159. @build/crds/validate-csv-crd-list.sh
  160. gen-rbac: $(HELM) $(YQ) ## Generate RBAC from Helm charts
  161. @# output only stdout to the file; stderr for debugging should keep going to stderr
  162. HELM=$(HELM) ./build/rbac/gen-common.sh
  163. HELM=$(HELM) ./build/rbac/gen-nfs-rbac.sh
  164. HELM=$(HELM) ./build/rbac/gen-psp.sh
  165. helm-docs: $(HELM_DOCS) ## Use helm-docs to generate documentation from helm charts
  166. $(HELM_DOCS) -c deploy/charts/rook-ceph \
  167. -o ../../../Documentation/Helm-Charts/operator-chart.md \
  168. -t ../../../Documentation/Helm-Charts/operator-chart.gotmpl.md \
  169. -t ../../../Documentation/Helm-Charts/_templates.gotmpl
  170. $(HELM_DOCS) -c deploy/charts/rook-ceph-cluster \
  171. -o ../../../Documentation/Helm-Charts/ceph-cluster-chart.md \
  172. -t ../../../Documentation/Helm-Charts/ceph-cluster-chart.gotmpl.md \
  173. -t ../../../Documentation/Helm-Charts/_templates.gotmpl
  174. check-helm-docs:
  175. @$(MAKE) helm-docs
  176. @git diff --exit-code || { \
  177. echo "Please run 'make helm-docs' locally, commit the updated docs, and push the change. See https://rook.io/docs/rook/latest/Contributing/documentation/#making-docs" ; \
  178. exit 2 ; \
  179. };
  180. check-docs:
  181. @$(MAKE) docs
  182. @git diff --exit-code || { \
  183. echo "Please run 'make docs' locally, commit the updated docs, and push the change." ; \
  184. exit 2 ; \
  185. };
  186. docs-preview: ## Preview the documentation through mkdocs
  187. mkdocs serve
  188. docs-build: ## Build the documentation to the `site/` directory
  189. mkdocs build --strict
  190. generate-docs-crds: ## Build the documentation for CRD
  191. @GOBIN=$(GOBIN) build/crds/generate-crd-docs.sh
  192. .PHONY: all build.common
  193. .PHONY: build build.all install test check vet fmt codegen mod.check clean distclean prune
  194. # ====================================================================================
  195. # Help
  196. define HELPTEXT
  197. Options:
  198. DEBUG Whether to generate debug symbols. Default is 0.
  199. IMAGES Backend images to make. All by default. See: /rook/images/ dir
  200. PLATFORM The platform to build.
  201. SUITE The test suite to run.
  202. TESTFILTER Tests to run in a suite.
  203. VERSION The version information compiled into binaries.
  204. The default is obtained from git.
  205. V Set to 1 enable verbose build. Default is 0.
  206. endef
  207. export HELPTEXT
  208. .PHONY: help
  209. help: ## Show this help menu.
  210. @echo "Usage: make [TARGET ...]"
  211. @echo ""
  212. @grep --no-filename -E '^[a-zA-Z_%-. ]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  213. @echo ""
  214. @echo "$$HELPTEXT"