github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/Makefile (about) 1 # Makefile for a standard golang repo with associated container 2 3 # Circleci doesn't seem to provide a decent way to add to path, just adding here, for case where 4 # linux build and linuxbrew is installed. 5 export PATH := $(EXTRA_PATH):$(PATH) 6 7 BUILD_BASE_DIR ?= $(PWD) 8 9 GOTMP=.gotmp 10 SHELL = /bin/bash 11 PWD = $(shell pwd) 12 GOFILES = $(shell find $(SRC_DIRS) -type f) 13 .PHONY: darwin_amd64 darwin_arm64 darwin_amd64_notarized darwin_arm64_notarized darwin_arm64_signed darwin_amd64_signed linux_amd64 linux_arm64 linux_arm windows_amd64 windows_arm64 setup 14 15 # Expands SRC_DIRS into the common golang ./dir/... format for "all below" 16 SRC_AND_UNDER = $(patsubst %,./%/...,$(SRC_DIRS)) 17 18 GOLANGCI_LINT_ARGS ?= --out-format=line-number --disable-all --enable=gofmt --enable=govet --enable=revive --enable=errcheck --enable=staticcheck --enable=ineffassign 19 20 WINDOWS_GSUDO_VERSION=v0.7.3 21 WINNFSD_VERSION=2.4.0 22 NSSM_VERSION=2.24-101-g897c7ad 23 24 TESTTMP=/tmp/testresults 25 26 # This repo's root import path (under GOPATH). 27 PKG := github.com/drud/ddev 28 29 # Top-level directories to build 30 SRC_DIRS := cmd pkg 31 32 # Version variables to replace in build 33 VERSION_VARIABLES ?= DdevVersion SegmentKey 34 35 # These variables will be used as the default unless overridden by the make 36 DdevVersion ?= $(VERSION) 37 # WebTag ?= $(VERSION) # WebTag is normally specified in version_constants.go, sometimes overridden (night-build.mak) 38 # DBTag ?= $(VERSION) # DBTag is normally specified in version_constants.go, sometimes overridden (night-build.mak) 39 # RouterTag ?= $(VERSION) #RouterTag is normally specified in version_constants.go, sometimes overridden (night-build.mak) 40 # DBATag ?= $(VERSION) #DBATag is normally specified in version_constants.go, sometimes overridden (night-build.mak) 41 42 # VERSION can be set by 43 # Default: git tag 44 # make command line: make VERSION=0.9.0 45 # It can also be explicitly set in the Makefile as commented out below. 46 47 # This version-strategy uses git tags to set the version string 48 # VERSION can be overridden on make commandline: make VERSION=0.9.1 push 49 VERSION := $(shell git describe --tags --always --dirty) 50 # Some things insist on having the version without the leading 'v', so provide a 51 # $(NO_V_VERSION) without it. 52 # no_v_version removes the front v, for Chocolatey mostly 53 NO_V_VERSION=$(shell echo $(VERSION) | awk -F"-" '{ OFS="-"; sub(/^./, "", $$1); printf $$0; }') 54 GITHUB_ORG := drud 55 56 BUILD_OS = $(shell go env GOHOSTOS) 57 BUILD_ARCH = $(shell go env GOHOSTARCH) 58 VERSION_LDFLAGS=$(foreach v,$(VERSION_VARIABLES),-X '$(PKG)/pkg/versionconstants.$(v)=$($(v))') 59 LDFLAGS=-extldflags -static $(VERSION_LDFLAGS) 60 DEFAULT_BUILD=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) 61 62 build: $(DEFAULT_BUILD) 63 64 65 # Provide shorthand targets 66 linux_amd64: $(GOTMP)/bin/linux_amd64/ddev 67 linux_arm64: $(GOTMP)/bin/linux_arm64/ddev 68 linux_arm: $(GOTMP)/bin/linux_arm/ddev 69 darwin_amd64: $(GOTMP)/bin/darwin_amd64/ddev 70 darwin_arm64: $(GOTMP)/bin/darwin_arm64/ddev 71 windows_amd64: windows_install 72 windows_arm64: $(GOTMP)/bin/windows_arm64/ddev.exe 73 completions: $(GOTMP)/bin/completions.tar.gz 74 75 TARGETS=$(GOTMP)/bin/linux_amd64/ddev $(GOTMP)/bin/linux_arm64/ddev $(GOTMP)/bin/linux_arm/ddev $(GOTMP)/bin/darwin_amd64/ddev $(GOTMP)/bin/darwin_arm64/ddev $(GOTMP)/bin/windows_amd64/ddev.exe 76 $(TARGETS): mkcert $(GOFILES) 77 @echo "building $@ from $(SRC_AND_UNDER)"; 78 @#echo "LDFLAGS=$(LDFLAGS)"; 79 @rm -f $@ 80 @export TARGET=$(word 3, $(subst /, ,$@)) && \ 81 export GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" CGO_ENABLED=0 GOPATH="$(PWD)/$(GOTMP)" GOCACHE="$(PWD)/$(GOTMP)/.cache" && \ 82 mkdir -p $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \ 83 chmod 777 $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \ 84 go build -o $(GOTMP)/bin/$$TARGET -installsuffix static -ldflags " $(LDFLAGS) " $(SRC_AND_UNDER) 85 $( shell if [ -d $(GOTMP) ]; then chmod -R u+w $(GOTMP); fi ) 86 @echo $(VERSION) >VERSION.txt 87 88 $(GOTMP)/bin/completions.tar.gz: build 89 $(GOTMP)/bin/$(BUILD_OS)_$(BUILD_ARCH)/ddev_gen_autocomplete 90 tar -C $(GOTMP)/bin/completions -cf $(GOTMP)/bin/completions.tar.gz . 91 92 mkcert: $(GOTMP)/bin/darwin_arm64/mkcert $(GOTMP)/bin/darwin_amd64/mkcert $(GOTMP)/bin/linux_arm64/mkcert $(GOTMP)/bin/linux_amd64/mkcert 93 94 # Download mkcert to it can be added to tarball installations 95 $(GOTMP)/bin/darwin_arm64/mkcert $(GOTMP)/bin/darwin_amd64/mkcert $(GOTMP)/bin/linux_arm64/mkcert $(GOTMP)/bin/linux_amd64/mkcert: 96 @export TARGET=$(word 3, $(subst /, ,$@)) && \ 97 export GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" && \ 98 mkdir -p $(GOTMP)/bin/$${GOOS}_$${GOARCH} && \ 99 curl --fail -JL -s -o $(GOTMP)/bin/$${GOOS}_$${GOARCH}/mkcert "https://dl.filippo.io/mkcert/latest?for=$${GOOS}/$${GOARCH}" && chmod +x $(GOTMP)/bin/$${GOOS}_$${GOARCH}/mkcert 100 101 TEST_TIMEOUT=4h 102 BUILD_ARCH = $(shell go env GOARCH) 103 104 DDEVNAME=ddev 105 SHASUM=shasum -a 256 106 ifeq ($(BUILD_OS),windows) 107 DDEVNAME=ddev.exe 108 SHASUM=sha256sum 109 endif 110 111 DDEV_PATH=$(PWD)/$(GOTMP)/bin/$(BUILD_OS)_$(BUILD_ARCH) 112 DDEV_BINARY_FULLPATH=$(DDEV_PATH)/$(DDEVNAME) 113 114 # Override test section with tests specific to ddev 115 test: testpkg testcmd 116 117 testcmd: $(DEFAULT_BUILD) setup 118 @echo LDFLAGS=$(LDFLAGS) 119 @echo DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH) 120 export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./cmd/... $(TESTARGS) 121 122 testpkg: testnotddevapp testddevapp 123 124 testddevapp: $(DEFAULT_BUILD) setup 125 export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./pkg/ddevapp $(TESTARGS) 126 127 testnotddevapp: $(DEFAULT_BUILD) setup 128 export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " $(shell find ./pkg -maxdepth 1 -type d ! -name ddevapp ! -name pkg) $(TESTARGS) 129 130 testfullsitesetup: $(DEFAULT_BUILD) setup 131 export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./pkg/ddevapp -run TestDdevFullSiteSetup $(TESTARGS) 132 133 setup: 134 @mkdir -p $(GOTMP)/{bin/linux_arm64,bin/linux_amd64,bin/darwin_arm64,bin/darwin_amd64,bin/windows_amd64,src,pkg/mod/cache,.cache} 135 @mkdir -p $(TESTTMP) 136 137 # Required static analysis targets used in circleci - these cause fail if they don't work 138 staticrequired: setup golangci-lint markdownlint mkdocs pyspelling 139 140 # Best to install markdownlint-cli locally with "npm install -g markdownlint-cli" 141 markdownlint: 142 @echo "markdownlint: " 143 @CMD="markdownlint *.md docs/content 2>&1"; \ 144 set -eu -o pipefail; \ 145 if command -v markdownlint >/dev/null 2>&1 ; then \ 146 $$CMD; \ 147 else \ 148 echo "Skipping markdownlint as not installed"; \ 149 fi 150 151 # Best to install mkdocs locally with "sudo pip3 install -r docs/mkdocs-pip-requirements" 152 mkdocs: 153 @echo "mkdocs: " 154 @CMD="mkdocs -q build -d /tmp/mkdocsbuild"; \ 155 if command -v mkdocs >/dev/null 2>&1; then \ 156 $$CMD ; \ 157 else \ 158 echo "Not running mkdocs because it's not installed"; \ 159 fi 160 161 # To see what the docs build will be, you can use `make mkdocs-serve` 162 # It works best with mkdocs installed, `pip3 install mkdocs`, 163 # see https://www.mkdocs.org/user-guide/installation/ 164 # But it will also work using docker. 165 mkdocs-serve: 166 if command -v mkdocs >/dev/null ; then \ 167 mkdocs serve; \ 168 else \ 169 docker run -it -p 8000:8000 -v "${PWD}:/docs" -e "ADD_MODULES=mkdocs-material mkdocs-redirects mkdocs-minify-plugin mdx_truly_sane_lists mkdocs-git-revision-date-localized-plugin" -e "LIVE_RELOAD_SUPPORT=true" -e "FAST_MODE=true" -e "DOCS_DIRECTORY=./docs" polinux/mkdocs; \ 170 fi 171 172 # Install markdown-link-check locally with "npm install -g markdown-link-check" 173 markdown-link-check: 174 @echo "markdown-link-check: " 175 if command -v markdown-link-check >/dev/null 2>&1; then \ 176 find docs *.md -name "*.md" -exec markdown-link-check -q -c markdown-link-check.json {} \; 2>&1 ;\ 177 else \ 178 echo "Not running markdown-link-check because it's not installed"; \ 179 fi 180 181 # Best to install pyspelling locally with "sudo -H pip3 install pyspelling pymdown-extensions". Also requries aspell, `sudo apt-get install aspell" 182 pyspelling: 183 @echo "pyspelling: " 184 @CMD="pyspelling --config .spellcheck.yml"; \ 185 set -eu -o pipefail; \ 186 if command -v pyspelling >/dev/null 2>&1 ; then \ 187 $$CMD; \ 188 else \ 189 echo "Not running pyspelling because it's not installed"; \ 190 fi 191 192 darwin_amd64_signed: $(GOTMP)/bin/darwin_amd64/ddev 193 @if [ -z "$(DDEV_MACOS_SIGNING_PASSWORD)" ] ; then echo "Skipping signing ddev for macOS, no DDEV_MACOS_SIGNING_PASSWORD provided"; else echo "Signing $< ..."; \ 194 set -o errexit -o pipefail; \ 195 curl -s https://raw.githubusercontent.com/drud/signing_tools/master/macos_sign.sh | bash -s - --signing-password="$(DDEV_MACOS_SIGNING_PASSWORD)" --cert-file=certfiles/ddev_developer_id_cert.p12 --cert-name="Developer ID Application: Localdev Foundation (9HQ298V2BW)" --target-binary="$<" ; \ 196 fi 197 darwin_arm64_signed: $(GOTMP)/bin/darwin_arm64/ddev 198 @if [ -z "$(DDEV_MACOS_SIGNING_PASSWORD)" ] ; then echo "Skipping signing ddev for macOS, no DDEV_MACOS_SIGNING_PASSWORD provided"; else echo "Signing $< ..."; \ 199 set -o errexit -o pipefail; \ 200 codesign --remove-signature "$(GOTMP)/bin/darwin_arm64/ddev" || true; \ 201 curl -s https://raw.githubusercontent.com/drud/signing_tools/master/macos_sign.sh | bash -s - --signing-password="$(DDEV_MACOS_SIGNING_PASSWORD)" --cert-file=certfiles/ddev_developer_id_cert.p12 --cert-name="Developer ID Application: Localdev Foundation (9HQ298V2BW)" --target-binary="$<" ; \ 202 fi 203 204 darwin_amd64_notarized: darwin_amd64_signed 205 @if [ -z "$(DDEV_MACOS_APP_PASSWORD)" ]; then echo "Skipping notarizing ddev for macOS, no DDEV_MACOS_APP_PASSWORD provided"; else \ 206 set -o errexit -o pipefail; \ 207 echo "Notarizing $(GOTMP)/bin/darwin_amd64/ddev ..." ; \ 208 curl -sSL -f https://raw.githubusercontent.com/drud/signing_tools/master/macos_notarize.sh | bash -s - --app-specific-password=$(DDEV_MACOS_APP_PASSWORD) --apple-id=notarizer@localdev.foundation --primary-bundle-id=com.ddev.ddev --target-binary="$(GOTMP)/bin/darwin_amd64/ddev" ; \ 209 fi 210 darwin_arm64_notarized: darwin_arm64_signed 211 @if [ -z "$(DDEV_MACOS_APP_PASSWORD)" ]; then echo "Skipping notarizing ddev for macOS, no DDEV_MACOS_APP_PASSWORD provided"; else \ 212 set -o errexit -o pipefail; \ 213 echo "Notarizing $(GOTMP)/bin/darwin_arm64/ddev ..." ; \ 214 curl -sSL -f https://raw.githubusercontent.com/drud/signing_tools/master/macos_notarize.sh | bash -s - --app-specific-password=$(DDEV_MACOS_APP_PASSWORD) --apple-id=notarizer@localdev.foundation --primary-bundle-id=com.ddev.ddev --target-binary="$(GOTMP)/bin/darwin_arm64/ddev" ; \ 215 fi 216 217 windows_install: $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe 218 219 $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe: $(GOTMP)/bin/windows_amd64/ddev.exe $(GOTMP)/bin/windows_amd64/sudo_license.txt $(GOTMP)/bin/windows_amd64/mkcert.exe $(GOTMP)/bin/windows_amd64/mkcert_license.txt winpkg/ddev.nsi 220 ls -l .gotmp/bin/windows_amd64 221 @if [ "$(DDEV_WINDOWS_SIGN)" != "true" ] ; then echo "Skipping signing ddev.exe, DDEV_WINDOWS_SIGN not set"; else echo "Signing windows binaries..." && signtool sign -fd SHA256 ".gotmp/bin/windows_amd64/ddev.exe" ".gotmp/bin/windows_amd64/mkcert.exe" ".gotmp/bin/windows_amd64/ddev_gen_autocomplete.exe"; fi 222 @makensis -DVERSION=$(VERSION) winpkg/ddev.nsi # brew install makensis, apt-get install nsis, or install on Windows 223 @if [ "$(DDEV_WINDOWS_SIGN)" != "true" ] ; then echo "Skipping signing ddev_windows_installer, DDEV_WINDOWS_SIGN not set"; else echo "Signing windows installer binary..." && signtool sign -fd SHA256 "$@"; fi 224 $(SHASUM) $@ >$@.sha256.txt 225 226 no_v_version: 227 @echo $(NO_V_VERSION) 228 229 chocolatey: $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe 230 rm -rf $(GOTMP)/bin/windows_amd64/chocolatey && cp -r winpkg/chocolatey $(GOTMP)/bin/windows_amd64/chocolatey 231 perl -pi -e 's/REPLACE_DDEV_VERSION/$(NO_V_VERSION)/g' $(GOTMP)/bin/windows_amd64/chocolatey/*.nuspec 232 perl -pi -e 's/REPLACE_DDEV_VERSION/$(VERSION)/g' $(GOTMP)/bin/windows_amd64/chocolatey/tools/*.ps1 233 perl -pi -e 's/REPLACE_GITHUB_ORG/$(GITHUB_REPOSITORY_OWNER)/g' $(GOTMP)/bin/windows_amd64/chocolatey/*.nuspec $(GOTMP)/bin/windows_amd64/chocolatey/tools/*.ps1 #GITHUB_ORG is for testing, for example when the binaries are on rfay acct 234 perl -pi -e "s/REPLACE_INSTALLER_CHECKSUM/$$(cat $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe.sha256.txt | awk '{ print $$1; }')/g" $(GOTMP)/bin/windows_amd64/chocolatey/tools/* 235 if [[ "$(NO_V_VERSION)" =~ -g[0-9a-f]+ ]]; then \ 236 echo "Skipping chocolatey build on interim version"; \ 237 else \ 238 docker run --rm -v "/$(PWD)/$(GOTMP)/bin/windows_amd64/chocolatey:/tmp/chocolatey" -w "//tmp/chocolatey" linuturk/mono-choco pack ddev.nuspec; \ 239 echo "chocolatey package is in $(GOTMP)/bin/windows_amd64/chocolatey"; \ 240 fi 241 242 $(GOTMP)/bin/windows_amd64/mkcert.exe $(GOTMP)/bin/windows_amd64/mkcert_license.txt: 243 curl --fail -JL -s -o $(GOTMP)/bin/windows_amd64/mkcert.exe "https://dl.filippo.io/mkcert/latest?for=windows/amd64" 244 curl --fail -sSL -o $(GOTMP)/bin/windows_amd64/mkcert_license.txt -O https://raw.githubusercontent.com/FiloSottile/mkcert/master/LICENSE 245 246 $(GOTMP)/bin/windows_amd64/sudo_license.txt: 247 set -x 248 curl --fail -sSL -o "$(GOTMP)/bin/windows_amd64/sudo_license.txt" "https://raw.githubusercontent.com/gerardog/gsudo/master/LICENSE.txt" 249 250 # Best to install golangci-lint locally with "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.31.0" 251 golangci-lint: 252 @echo "golangci-lint: " 253 @CMD="golangci-lint run $(GOLANGCI_LINT_ARGS) $(SRC_AND_UNDER)"; \ 254 set -eu -o pipefail; \ 255 if command -v golangci-lint >/dev/null 2>&1; then \ 256 $$CMD; \ 257 else \ 258 echo "Skipping golanci-lint as not installed"; \ 259 fi 260 261 version: 262 @echo VERSION:$(VERSION) 263 264 clean: bin-clean 265 266 bin-clean: 267 @rm -rf bin 268 $(shell if [ -d $(GOTMP) ]; then chmod -R u+w $(GOTMP) && rm -rf $(GOTMP); fi ) 269 270 # print-ANYVAR prints the expanded variable 271 print-%: ; @echo $* = $($*)