2016-11-05 17:09:05 -07:00
# Copyright 2016 The Rook Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2022-01-18 11:58:39 +01:00
# Linux doesn't guarantee file ordering, so sort the files to make sure order is deterministic.
# And in order to handle file paths with spaces, it's easiest to read the file names into an array.
# Set locale `LC_ALL=C` because different OSes have different sort behavior;
# `C` sorting order is based on the byte values,
# Reference: https://blog.zhimingwang.org/macos-lc_collate-hunt
LC_ALL = C
export LC_ALL
2017-06-26 20:04:53 -07:00
include build/makelib/common.mk
2021-09-29 11:14:15 -06:00
include build/makelib/helm.mk
2017-06-20 20:28:40 -07:00
2016-09-28 16:15:42 -07:00
.PHONY : all
all : build
2021-10-27 13:38:54 +00:00
.DEFAULT_GOAL := all
2016-07-24 22:27:07 -07:00
2016-09-28 16:15:42 -07:00
# ====================================================================================
# Build Options
2016-07-24 22:27:07 -07:00
2021-01-29 18:21:58 +01:00
# Controller-gen version
2021-04-14 17:28:34 -06:00
# f284e2e8... is master ahead of v0.5.0 which has ability to generate embedded objectmeta in CRDs
2024-02-09 17:04:32 +05:30
CONTROLLER_GEN_VERSION = v0.14.0
2021-01-29 18:21:58 +01:00
# Set GOBIN
ifeq (, $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
else
GOBIN = $( shell go env GOBIN)
endif
2016-09-29 15:48:15 -07:00
# set the shell to bash in case some environments use sh
2023-11-17 01:37:05 +01:00
SHELL := /usr/bin/env bash
2016-09-29 15:48:15 -07:00
2017-06-15 12:09:09 -07:00
# Can be used or additional go build flags
2016-08-03 12:38:23 -07:00
BUILDFLAGS ?=
LDFLAGS ?=
2022-04-21 11:38:11 +05:30
TAGS ?=
2016-08-03 12:38:23 -07:00
# turn on more verbose build
V ?= 0
ifeq ( $( V ) ,1)
2017-02-09 17:01:59 -08:00
LDFLAGS += -v -n
2016-08-03 12:38:23 -07:00
BUILDFLAGS += -x
2017-02-02 17:58:41 -08:00
MAKEFLAGS += VERBOSE = 1
2016-08-08 16:39:26 -07:00
else
2016-09-14 21:10:37 -07:00
MAKEFLAGS += --no-print-directory
endif
2017-06-15 12:09:09 -07:00
# whether to generate debug information in binaries. this includes DWARF
# and symbol tables.
DEBUG ?= 0
ifeq ( $( DEBUG ) ,0)
LDFLAGS += -s -w
2017-06-02 13:46:15 -07:00
endif
2016-08-03 12:38:23 -07:00
2017-06-26 20:04:53 -07:00
# platforms
PLATFORMS ?= $( ALL_PLATFORMS)
2021-11-02 18:54:58 +01:00
# PLATFORMS_TO_BUILD_FOR controls for which platforms to build the rook binary for
PLATFORMS_TO_BUILD_FOR ?= linux_amd64 linux_arm64
2017-06-26 20:04:53 -07:00
SERVER_PLATFORMS := $( filter linux_%,$( PLATFORMS))
CLIENT_PLATFORMS := $( filter-out linux_%,$( PLATFORMS))
2017-06-02 13:46:15 -07:00
2017-06-15 12:09:09 -07:00
# server projects that we build on server platforms
2021-09-22 16:39:09 -06:00
SERVER_PACKAGES = $( GO_PROJECT) /cmd/rook
2017-06-15 12:09:09 -07:00
2017-07-21 12:20:37 -07:00
# tests packages that will be compiled into binaries
2017-09-19 01:10:50 -07:00
TEST_PACKAGES = $( GO_PROJECT) /tests/integration
2017-07-21 12:20:37 -07:00
2017-06-02 13:46:15 -07:00
# the root go project
2016-10-26 00:38:39 +02:00
GO_PROJECT = github.com/rook/rook
2016-10-17 09:27:55 -07:00
2017-08-23 22:20:14 -07:00
# inject the version number into the golang version package using the -X linker flag
2016-11-14 14:54:51 -08:00
LDFLAGS += -X $( GO_PROJECT) /pkg/version.Version= $( VERSION)
2021-11-03 15:00:09 +01:00
# CGO_ENABLED value
CGO_ENABLED_VALUE = 0
2016-09-28 16:15:42 -07:00
# ====================================================================================
2017-08-09 12:57:39 -07:00
# Setup projects
2016-09-29 15:48:15 -07:00
2017-08-09 12:57:39 -07:00
# setup go projects
2017-06-15 12:09:09 -07:00
GO_STATIC_PACKAGES =
2017-06-26 20:04:53 -07:00
ifneq ( $( filter $( PLATFORM ) ,$( CLIENT_PLATFORMS ) $( SERVER_PLATFORMS )) ,)
2017-06-15 12:09:09 -07:00
GO_STATIC_PACKAGES += $( CLIENT_PACKAGES)
2017-06-02 13:46:15 -07:00
endif
2017-06-26 20:04:53 -07:00
ifneq ( $( filter $( PLATFORM ) ,$( SERVER_PLATFORMS )) ,)
2017-06-15 12:09:09 -07:00
GO_STATIC_PACKAGES += $( SERVER_PACKAGES)
2016-09-29 15:48:15 -07:00
endif
2016-09-28 16:15:42 -07:00
2016-11-14 11:31:35 -08:00
GO_BUILDFLAGS = $( BUILDFLAGS)
GO_LDFLAGS = $( LDFLAGS)
GO_TAGS = $( TAGS)
2017-07-21 12:20:37 -07:00
GO_TEST_PACKAGES = $( TEST_PACKAGES)
2017-06-26 21:52:06 -07:00
GO_TEST_FLAGS = $( TESTFLAGS)
GO_TEST_SUITE = $( SUITE)
2017-09-19 01:10:50 -07:00
GO_TEST_FILTER = $( TESTFILTER)
2016-11-14 11:31:35 -08:00
2016-09-29 15:48:15 -07:00
include build/makelib/golang.mk
2016-09-28 16:15:42 -07:00
2016-10-10 22:36:15 -07:00
# ====================================================================================
# Targets
2017-08-09 12:57:39 -07:00
build.version :
2017-07-24 13:27:16 -07:00
@mkdir -p $( OUTPUT_DIR)
@echo " $( VERSION) " > $( OUTPUT_DIR) /version
2017-08-09 12:57:39 -07:00
2023-06-15 13:13:03 +05:30
build.common : export SKIP_GEN_CRD_DOCS =true
2021-12-06 11:15:06 -07:00
build.common : build .version helm .build mod .check crds gen -rbac
2017-03-30 15:42:03 +02:00
@$( MAKE) go.init
@$( MAKE) go.validate
2021-10-11 16:03:17 -06:00
@$( MAKE) -C images/ceph list-image
2017-03-30 15:42:03 +02:00
2017-06-15 12:09:09 -07:00
do.build.platform.% :
2017-07-17 17:35:25 -07:00
@$( MAKE) PLATFORM = $* go.build
2017-06-13 14:25:27 -07:00
2021-11-02 18:54:58 +01:00
do.build.parallel : $( foreach p ,$( PLATFORMS_TO_BUILD_FOR ) , do .build .platform .$( p ))
2017-06-15 12:09:09 -07:00
2024-03-11 11:34:30 +05:30
build : build .common ## Only build for linux platform
2018-04-19 15:24:06 +08:00
@$( MAKE) go.build PLATFORM = linux_$( GOHOSTARCH)
@$( MAKE) -C images PLATFORM = linux_$( GOHOSTARCH)
2017-06-13 14:25:27 -07:00
2022-03-16 17:14:59 -06:00
build.all : build .common ## Build source code for all platforms.
2018-04-26 15:28:39 +08:00
ifneq ( $( GOHOSTARCH ) ,amd64)
$( error cross platform image build only supported on amd 64 host currently )
endif
2017-06-15 12:09:09 -07:00
@ $( MAKE ) do.build.parallel
2017-06-20 20:28:40 -07:00
@ $( MAKE ) -C images build.all
2016-09-28 16:15:42 -07:00
2017-03-30 15:42:03 +02:00
install : build .common
2017-03-02 13:50:39 -08:00
@$( MAKE) go.install
2020-02-17 11:06:01 +01:00
check test : ## Runs unit tests.
2017-06-26 21:52:06 -07:00
@$( MAKE) go.test.unit
2020-02-17 11:06:01 +01:00
test-integration : ## Runs integration tests.
2017-06-26 21:52:06 -07:00
@$( MAKE) go.test.integration
2016-09-28 16:15:42 -07:00
2020-02-17 11:06:01 +01:00
lint : ## Check syntax and styling of go sources.
2017-03-30 15:42:03 +02:00
@$( MAKE) go.init
@$( MAKE) go.lint
2017-03-02 11:30:33 -08:00
2020-02-17 11:06:01 +01:00
vet : ## Runs lint checks on go sources.
2017-03-30 15:42:03 +02:00
@$( MAKE) go.init
@$( MAKE) go.vet
2016-09-28 16:15:42 -07:00
2020-02-17 11:06:01 +01:00
fmt : ## Check formatting of go sources.
2017-03-30 15:42:03 +02:00
@$( MAKE) go.init
@$( MAKE) go.fmt
2016-09-29 15:48:15 -07:00
2021-04-20 02:53:36 +00:00
codegen : ${CODE_GENERATOR } ## Run code generators.
2017-10-28 14:08:31 -07:00
@build/codegen/codegen.sh
2020-02-17 11:06:01 +01:00
mod.check : go .mod .check ## Check if any go modules changed.
mod.update : go .mod .update ## Update all go modules.
2016-09-29 15:48:15 -07:00
2024-03-11 11:34:30 +05:30
clean : ## Remove all files that are created by building.
2020-03-10 14:42:15 +09:00
@$( MAKE) go.mod.clean
2017-06-09 13:34:41 -07:00
@$( MAKE) -C images clean
2017-07-07 12:45:04 -07:00
@rm -fr $( OUTPUT_DIR) $( WORK_DIR)
2016-09-29 15:48:15 -07:00
2020-02-17 11:06:01 +01:00
distclean : clean ## Remove all files that are created by building or configuring.
2017-06-26 20:04:53 -07:00
@rm -fr $( CACHE_DIR)
2017-04-01 20:20:18 -07:00
2020-02-17 11:06:01 +01:00
prune : ## Prune cached artifacts.
2017-06-03 10:28:43 -07:00
@$( MAKE) -C images prune
2017-03-30 17:10:42 +02:00
2023-08-22 12:00:45 +02:00
docs : helm -docs
2021-04-08 13:19:14 -06:00
crds : $( CONTROLLER_GEN ) $( YQ )
2021-01-29 18:21:58 +01:00
@echo Updating CRD manifests
2021-03-26 09:21:33 +01:00
@build/crds/build-crds.sh $( CONTROLLER_GEN) $( YQ)
2023-06-15 13:13:03 +05:30
@GOBIN= $( GOBIN) build/crds/generate-crd-docs.sh
2021-01-29 18:21:58 +01:00
2022-06-27 13:29:25 +02:00
gen-rbac : $( HELM ) $( YQ ) ## Generate RBAC from Helm charts
2021-11-17 15:53:30 -07:00
@# output only stdout to the file; stderr for debugging should keep going to stderr
2021-12-06 11:15:06 -07:00
HELM = $( HELM) ./build/rbac/gen-common.sh
2022-04-12 15:20:42 -06:00
HELM = $( HELM) ./build/rbac/gen-nfs-rbac.sh
2022-08-25 10:37:05 -06:00
HELM = $( HELM) ./build/rbac/gen-psp.sh
2021-09-29 11:14:15 -06:00
2022-11-22 18:02:05 -05:00
helm-docs : $( HELM_DOCS ) ## Use helm-docs to generate documentation from helm charts
$( HELM_DOCS) -c deploy/charts/rook-ceph \
-o ../../../Documentation/Helm-Charts/operator-chart.md \
-t ../../../Documentation/Helm-Charts/operator-chart.gotmpl.md \
-t ../../../Documentation/Helm-Charts/_templates.gotmpl
$( HELM_DOCS) -c deploy/charts/rook-ceph-cluster \
-o ../../../Documentation/Helm-Charts/ceph-cluster-chart.md \
-t ../../../Documentation/Helm-Charts/ceph-cluster-chart.gotmpl.md \
-t ../../../Documentation/Helm-Charts/_templates.gotmpl
2023-08-30 12:22:29 +02:00
check-helm-docs :
@$( MAKE) helm-docs
@git diff --exit-code || { \
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" ; \
exit 2 ; \
2023-09-06 19:37:25 +05:30
} ;
2023-08-30 12:22:29 +02:00
check-docs :
@$( MAKE) docs
@git diff --exit-code || { \
echo "Please run 'make docs' locally, commit the updated docs, and push the change." ; \
exit 2 ; \
2023-09-06 19:37:25 +05:30
} ;
2023-08-30 12:22:29 +02:00
2022-06-27 13:29:25 +02:00
docs-preview : ## Preview the documentation through mkdocs
mkdocs serve
docs-build : ## Build the documentation to the `site/` directory
mkdocs build --strict
2023-05-01 19:23:27 -06:00
generate-docs-crds : ## Build the documentation for CRD
2023-06-15 13:13:03 +05:30
@GOBIN= $( GOBIN) build/crds/generate-crd-docs.sh
2023-05-01 19:23:27 -06:00
2022-03-16 17:14:59 -06:00
.PHONY : all build .common
2020-03-10 14:42:15 +09:00
.PHONY : build build .all install test check vet fmt codegen mod .check clean distclean prune
2016-09-28 16:15:42 -07:00
# ====================================================================================
# Help
2018-07-19 12:36:30 -06:00
define HELPTEXT
Options :
DEBUG Whether to generate debug symbols. Default is 0.
IMAGES Backend images to make. All by default. See: /rook/images/ dir
PLATFORM The platform to build.
SUITE The test suite to run.
TESTFILTER Tests to run in a suite.
VERSION The version information compiled into binaries.
The default is obtained from git.
V Set to 1 enable verbose build. Default is 0.
endef
export HELPTEXT
2016-09-28 16:15:42 -07:00
.PHONY : help
2020-02-17 11:06:01 +01:00
help : ## Show this help menu.
@echo "Usage: make [TARGET ...]"
@echo ""
2020-05-18 15:05:38 +05:30
@grep --no-filename -E '^[a-zA-Z_%-. ]+:.*?## .*$$' $( MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2020-02-17 11:06:01 +01:00
@echo ""
2018-07-19 12:36:30 -06:00
@echo " $$ HELPTEXT"