github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/Makefile (about) 1 .DEFAULT_GOAL = build 2 GO := go 3 extension = $(patsubst windows,.exe,$(filter windows,$(1))) 4 PKG_NAME := gomplate 5 DOCKER_REPO ?= hairyhenderson/$(PKG_NAME) 6 PREFIX := . 7 DOCKER_LINUX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le,linux/s390x 8 DOCKER_PLATFORMS ?= $(DOCKER_LINUX_PLATFORMS),windows/amd64 9 # we just load by default, as a "dry run" 10 BUILDX_ACTION ?= --load 11 TAG_LATEST ?= latest 12 TAG_ALPINE ?= alpine 13 14 ifeq ("$(CI)","true") 15 LINT_PROCS ?= 1 16 else 17 LINT_PROCS ?= $(shell nproc) 18 endif 19 20 COMMIT ?= `git rev-parse --short HEAD 2>/dev/null` 21 VERSION ?= $(shell $(GO) run ./version/gen/vgen.go) 22 23 VERSION_PATH ?= `$(GO) list ./version` 24 COMMIT_FLAG ?= -X $(VERSION_PATH).GitCommit=$(COMMIT) 25 VERSION_FLAG ?= -X $(VERSION_PATH).Version=$(VERSION) 26 GO_LDFLAGS ?= $(COMMIT_FLAG) $(VERSION_FLAG) 27 28 GOOS ?= $(shell $(GO) version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/') 29 GOARCH ?= $(shell $(GO) version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/') 30 31 # allow overriding CGO_ENABLED for scenarios where gomplate must be compiled with CGO enabled, such as when using boringcrypto. 32 CGO_ENABLED ?= 0 33 34 ifeq ("$(TARGETVARIANT)","") 35 ifneq ("$(GOARM)","") 36 TARGETVARIANT := v$(GOARM) 37 endif 38 else 39 ifeq ("$(GOARM)","") 40 GOARM ?= $(subst v,,$(TARGETVARIANT)) 41 endif 42 endif 43 44 # platforms := freebsd-amd64 linux-amd64 linux-386 linux-armv5 linux-armv6 linux-armv7 linux-arm64 darwin-amd64 solaris-amd64 windows-amd64.exe windows-386.exe 45 platforms := freebsd-amd64 linux-amd64 linux-386 linux-armv6 linux-armv7 linux-arm64 linux-ppc64le linux-s390x darwin-amd64 darwin-arm64 solaris-amd64 windows-amd64.exe windows-386.exe 46 47 clean: 48 rm -Rf $(PREFIX)/bin/* 49 rm -f $(PREFIX)/*.[ci]id 50 51 build-x: $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%,$(platforms)) 52 53 $(PREFIX)/bin/%.zip: $(PREFIX)/bin/% 54 @zip -j $@ $^ 55 56 $(PREFIX)/bin/$(PKG_NAME)_windows-%.zip: $(PREFIX)/bin/$(PKG_NAME)_windows-%.exe 57 @zip -j $@ $^ 58 59 $(PREFIX)/bin/$(PKG_NAME)_%_checksum_sha256.txt: $(PREFIX)/bin/$(PKG_NAME)_% 60 @sha256sum $< > $@ 61 62 $(PREFIX)/bin/$(PKG_NAME)_%_checksum_sha512.txt: $(PREFIX)/bin/$(PKG_NAME)_% 63 @sha512sum $< > $@ 64 65 $(PREFIX)/bin/checksums.txt: $(PREFIX)/bin/checksums_sha256.txt 66 @cp $< $@ 67 68 $(PREFIX)/bin/checksums_sha256.txt: \ 69 $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%_checksum_sha256.txt,$(platforms)) 70 @cat $^ > $@ 71 72 $(PREFIX)/bin/checksums_sha512.txt: \ 73 $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%_checksum_sha512.txt,$(platforms)) 74 @cat $^ > $@ 75 76 $(PREFIX)/%.signed: $(PREFIX)/% 77 @keybase sign < $< > $@ 78 79 %.iid: Dockerfile 80 @docker build \ 81 --build-arg VCS_REF=$(COMMIT) \ 82 --target $(subst .iid,,$@) \ 83 --iidfile $@ \ 84 . 85 86 docker-multi: Dockerfile 87 docker buildx build \ 88 --build-arg VCS_REF=$(COMMIT) \ 89 --platform $(DOCKER_PLATFORMS) \ 90 --tag $(DOCKER_REPO):$(TAG_LATEST) \ 91 --target gomplate \ 92 $(BUILDX_ACTION) . 93 docker buildx build \ 94 --build-arg VCS_REF=$(COMMIT) \ 95 --platform $(DOCKER_LINUX_PLATFORMS) \ 96 --tag $(DOCKER_REPO):$(TAG_ALPINE) \ 97 --target gomplate-alpine \ 98 $(BUILDX_ACTION) . 99 100 %.cid: %.iid 101 @docker create $(shell cat $<) > $@ 102 103 build-release: artifacts.cid 104 @docker cp $(shell cat $<):/bin/. bin/ 105 106 docker-images: gomplate.iid 107 108 GO_FILES := $(shell find . -type f -name "*.go") 109 110 $(PREFIX)/bin/$(PKG_NAME)_%v5$(call extension,$(GOOS)): $(GO_FILES) 111 GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- ) GOARM=5 CGO_ENABLED=$(CGO_ENABLED) \ 112 $(GO) build \ 113 -ldflags "-w -s $(GO_LDFLAGS)" \ 114 -o $@ \ 115 ./cmd/$(PKG_NAME) 116 117 $(PREFIX)/bin/$(PKG_NAME)_%v6$(call extension,$(GOOS)): $(GO_FILES) 118 GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- ) GOARM=6 CGO_ENABLED=$(CGO_ENABLED) \ 119 $(GO) build \ 120 -ldflags "-w -s $(GO_LDFLAGS)" \ 121 -o $@ \ 122 ./cmd/$(PKG_NAME) 123 124 $(PREFIX)/bin/$(PKG_NAME)_%v7$(call extension,$(GOOS)): $(GO_FILES) 125 GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- ) GOARM=7 CGO_ENABLED=$(CGO_ENABLED) \ 126 $(GO) build \ 127 -ldflags "-w -s $(GO_LDFLAGS)" \ 128 -o $@ \ 129 ./cmd/$(PKG_NAME) 130 131 $(PREFIX)/bin/$(PKG_NAME)_windows-%.exe: $(GO_FILES) 132 GOOS=windows GOARCH=$* GOARM= CGO_ENABLED=$(CGO_ENABLED) \ 133 $(GO) build \ 134 -ldflags "-w -s $(GO_LDFLAGS)" \ 135 -o $@ \ 136 ./cmd/$(PKG_NAME) 137 138 $(PREFIX)/bin/$(PKG_NAME)_%$(TARGETVARIANT)$(call extension,$(GOOS)): $(GO_FILES) 139 GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- ) GOARM=$(GOARM) CGO_ENABLED=$(CGO_ENABLED) \ 140 $(GO) build \ 141 -ldflags "-w -s $(GO_LDFLAGS)" \ 142 -o $@ \ 143 ./cmd/$(PKG_NAME) 144 145 $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)$(TARGETVARIANT)$(call extension,$(GOOS)) 146 cp $< $@ 147 148 build: $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)$(TARGETVARIANT)$(call extension,$(GOOS)) $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) 149 150 ifeq ($(OS),Windows_NT) 151 test: 152 $(GO) test -coverprofile=c.out ./... 153 else 154 test: 155 $(GO) test -race -coverprofile=c.out ./... 156 endif 157 158 .SECONDEXPANSION: 159 testbin/%.test.exe: $$(shell $$(GO) list -f '{{.Dir}}' $$(subst testbin/,,$$(subst .test.exe,,$$@))) 160 @GOOS=windows GOARCH=amd64 $(GO) test -c -o $@ $< 161 162 .SECONDEXPANSION: 163 testbin/%.test: $$(shell $$(GO) list -f '{{.Dir}}' $$(subst testbin/,,$$(subst .test,,$$@))) 164 @$(GO) test -c -o $@ $< 165 166 # this is a special target for testing a package on Windows from a non-Windows 167 # host. It builds the Windows test binary, then SCPs it to the Windows host, and 168 # runs the tests there. This depends on the GO_REMOTE_WINDOWS environment 169 # variable being set as 'username@host'. The Windows host must have Git Bash 170 # installed, or maybe MSYS2, so that a number of standard Unix tools are 171 # available. Git must also be configured with a username and email address. See 172 # the GitHub workflow config in .github/workflows/build.yml for hints. 173 # A recent PowerShell is also required, such as version 7.3 or later. 174 # 175 # An F: drive is expected to be available, with a tmp directory. This is used 176 # to make sure gomplate can deal with files on a different volume. 177 .SECONDEXPANSION: 178 testbin/%.test.exe.remote: $$(shell $$(GO) list -f '{{.Dir}}' $$(subst testbin/,,$$(subst .test.exe.remote,,$$@))) 179 @echo $< 180 @GOOS=windows GOARCH=amd64 $(GO) test -tags timetzdata -c -o $(PREFIX)/testbin/remote-test.exe $< 181 @scp -q $(PREFIX)/testbin/remote-test.exe $(GO_REMOTE_WINDOWS):/$(shell ssh $(GO_REMOTE_WINDOWS) 'echo %TEMP%' | cut -f2 -d= | sed -e 's#\\#/#g')/ 182 @ssh -o 'SetEnv TMP=F:\tmp' $(GO_REMOTE_WINDOWS) '%TEMP%\remote-test.exe' 183 184 # test-remote-windows runs the above target for all packages that have tests 185 .SECONDEXPANSION: 186 test-remote-windows: $$(shell $$(GO) list -f '{{ if not (eq "" (join .TestGoFiles "")) }}testbin/{{.ImportPath}}.test.exe.remote{{end}}' ./...) 187 188 ifeq ($(OS),Windows_NT) 189 integration: $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) 190 $(GO) test -v \ 191 -ldflags "-X `$(GO) list ./internal/tests/integration`.GomplateBinPath=$(shell cygpath -ma .)/$<" \ 192 ./internal/tests/integration 193 else 194 integration: $(PREFIX)/bin/$(PKG_NAME) 195 $(GO) test -v \ 196 -ldflags "-X `$(GO) list ./internal/tests/integration`.GomplateBinPath=$(shell pwd)/$<" \ 197 ./internal/tests/integration 198 endif 199 200 integration.iid: Dockerfile.integration $(PREFIX)/bin/$(PKG_NAME)_linux-amd64$(call extension,$(GOOS)) 201 docker build -f $< --iidfile $@ . 202 203 test-integration-docker: integration.iid 204 docker run -it --rm $(shell cat $<) 205 206 gen-changelog: 207 docker run -it -v $(shell pwd):/app --workdir /app -e CHANGELOG_GITHUB_TOKEN hairyhenderson/github_changelog_generator \ 208 github_changelog_generator --no-filter-by-milestone --exclude-labels duplicate,question,invalid,wontfix,admin 209 210 docs/themes/hugo-theme-relearn: 211 git clone --depth=1 https://github.com/McShelby/hugo-theme-relearn.git $@ 212 213 gen-docs: docs/themes/hugo-theme-relearn 214 cd docs/; hugo 215 216 docs/content/functions/%.md: docs-src/content/functions/%.yml docs-src/content/functions/func_doc.md.tmpl 217 gomplate -d data=$< -f docs-src/content/functions/func_doc.md.tmpl -o $@ 218 219 # run the above target for all files found in docs-src/content/functions/*.yml 220 gen-func-docs: $(shell find docs-src/content/functions -name "*.yml" | sed -e 's#docs-src#docs#' -e 's#\.yml#\.md#') 221 222 # this target doesn't usually get used - it's mostly here as a reminder to myself 223 # hint: make sure CLOUDCONVERT_API_KEY is set ;) 224 gomplate.png: gomplate.svg 225 cloudconvert -f png -c density=288 $^ 226 227 lint: 228 @golangci-lint run --verbose --max-same-issues=0 --max-issues-per-linter=0 229 230 ci-lint: 231 @golangci-lint run --verbose --max-same-issues=0 --max-issues-per-linter=0 --out-format=github-actions 232 233 .PHONY: gen-changelog clean test build-x build-release build test-integration-docker gen-docs lint clean-images clean-containers docker-images integration gen-func-docs 234 .DELETE_ON_ERROR: 235 .SECONDARY: