github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/Makefile (about) 1 .DEFAULT_GOAL := help 2 3 Dirs=$(shell ls) 4 GIT_TAG := $(shell git describe --exact-match --tags --abbrev=0 2> /dev/null || echo untagged) 5 GOOS ?= $(shell go env GOOS) 6 GOARCH ?= $(shell go env GOARCH) 7 8 TOOLS_DIR := hack/build.sh 9 10 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 11 ifneq (,$(shell go env GOBIN)) 12 GOBIN=$(shell go env GOPATH)/bin 13 else 14 GOBIN=$(shell go env GOBIN) 15 endif 16 17 ## fmt: Run go fmt against code. 18 fmt: 19 go fmt ./... 20 21 ## vet: Run go vet against code. 22 vet: 23 go vet ./... 24 25 ## lint: Run go lint against code. 26 lint: 27 golangci-lint run -v ./... 28 29 ## style: code style: fmt,vet,lint 30 style: fmt vet lint 31 32 ## build: Build binaries by default 33 build: clean 34 @echo "build sealer and seautil bin" 35 $(TOOLS_DIR) 36 37 ## linux: Build binaries for Linux 38 linux: clean 39 @echo "Building sealer and seautil binaries for Linux (amd64)" 40 GOOS=$(GOOS) GOARCH=$(GOARCH) $(TOOLS_DIR) $(GIT_TAG) 41 42 ## linux-amd64: Build binaries for Linux (amd64) 43 linux-amd64: clean 44 @echo "Building sealer and seautil binaries for Linux (amd64)" 45 GOOS=linux GOARCH=amd64 $(TOOLS_DIR) $(GIT_TAG) 46 47 ## linux-arm64: Build binaries for Linux (arm64) 48 linux-arm64: clean 49 @echo "Building sealer and seautil binaries for Linux (arm64)" 50 GOOS=linux GOARCH=arm64 $(TOOLS_DIR) $(GIT_TAG) 51 52 ## build-in-docker: sealer should be compiled in linux platform, otherwise there will be GraphDriver problem. 53 build-in-docker: 54 docker run --rm -v ${PWD}:/usr/src/sealer -w /usr/src/sealer registry.cn-qingdao.aliyuncs.com/sealer-io/sealer-build:v1 make linux 55 56 ## clean: Remove all files that are created by building. 57 .PHONY: clean 58 clean: 59 @echo "===========> Cleaning all build output" 60 @-rm -rf _output 61 62 ## install-addlicense: check license if not exist install addlicense tools 63 install-addlicense: 64 ifeq (, $(shell which addlicense)) 65 @{ \ 66 set -e ;\ 67 LICENSE_TMP_DIR=$$(mktemp -d) ;\ 68 cd $$LICENSE_TMP_DIR ;\ 69 go mod init tmp ;\ 70 go get -v github.com/google/addlicense ;\ 71 rm -rf $$LICENSE_TMP_DIR ;\ 72 } 73 ADDLICENSE_BIN=$(GOBIN)/addlicense 74 else 75 ADDLICENSE_BIN=$(shell which addlicense) 76 endif 77 78 filelicense: SHELL:=/bin/bash 79 ## filelicense: add license 80 filelicense: 81 for file in ${Dirs} ; do \ 82 if [[ $$file != '_output' && $$file != 'docs' && $$file != 'vendor' && $$file != 'logger' && $$file != 'applications' ]]; then \ 83 $(ADDLICENSE_BIN) -y $(shell date +"%Y") -c "Alibaba Group Holding Ltd." -f hack/LICENSE_TEMPLATE ./$$file ; \ 84 fi \ 85 done 86 87 88 ## install-gosec: check license if not exist install addlicense tools 89 install-gosec: 90 ifeq (, $(shell which gosec)) 91 @{ \ 92 set -e ;\ 93 curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(GOBIN) v2.2.0 ;\ 94 } 95 GOSEC_BIN=$(GOBIN)/gosec 96 else 97 GOSEC_BIN=$(shell which gosec) 98 endif 99 100 gosec: install-gosec 101 $(GOSEC_BIN) ./... 102 103 104 install-deepcopy-gen: 105 ifeq (, $(shell which deepcopy-gen)) 106 @{ \ 107 set -e ;\ 108 LICENSE_TMP_DIR=$$(mktemp -d) ;\ 109 cd $$LICENSE_TMP_DIR ;\ 110 go mod init tmp ;\ 111 go get -v k8s.io/code-generator/cmd/deepcopy-gen ;\ 112 rm -rf $$LICENSE_TMP_DIR ;\ 113 } 114 DEEPCOPY_BIN=$(GOBIN)/deepcopy-gen 115 else 116 DEEPCOPY_BIN=$(shell which deepcopy-gen) 117 endif 118 119 HEAD_FILE := hack/boilerplate.go.txt 120 INPUT_DIR := github.com/sealerio/sealer/types/api 121 deepcopy:install-deepcopy-gen 122 $(DEEPCOPY_BIN) \ 123 --input-dirs="$(INPUT_DIR)/v1" \ 124 -O zz_generated.deepcopy \ 125 --go-header-file "$(HEAD_FILE)" \ 126 --output-base "${GOPATH}/src" 127 $(DEEPCOPY_BIN) \ 128 --input-dirs="$(INPUT_DIR)/v2" \ 129 -O zz_generated.deepcopy \ 130 --go-header-file "$(HEAD_FILE)" \ 131 --output-base "${GOPATH}/src" 132 133 ## help: Display help information 134 help: Makefile 135 @echo "" 136 @echo "Usage:" "\n" 137 @echo " make [target]" "\n" 138 @echo "Targets:" "\n" "" 139 @awk -F ':|##' '/^[^\.%\t][^\t]*:.*##/{printf " \033[36m%-20s\033[0m %s\n", $$1, $$NF}' $(MAKEFILE_LIST) | sort 140 @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'