| 1 | # todo-go: the CARLOS bakeoff's TodoMVC in Go. See README.md. |
| 2 | |
| 3 | VERSION ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev) |
| 4 | LDFLAGS := -s -w -X main.version=$(VERSION) |
| 5 | # make build-arm64 COLD=1 rebuilds every package, dependencies included, |
| 6 | # without touching the shared GOCACHE. |
| 7 | GOFLAGS_COLD := $(if $(COLD),-a,) |
| 8 | |
| 9 | .PHONY: build build-arm64 test clean clean-deps bump unbump deploy css-check |
| 10 | |
| 11 | build: dist/app |
| 12 | build-arm64: dist/app-linux-arm64 |
| 13 | |
| 14 | # Both binaries are always handed to `go build`, which decides from its own |
| 15 | # cache what needs compiling, so a new VERSION or COLD=1 always takes effect. |
| 16 | dist/app: FORCE |
| 17 | CGO_ENABLED=0 go build $(GOFLAGS_COLD) -trimpath -ldflags '$(LDFLAGS)' -o $@ . |
| 18 | |
| 19 | dist/app-linux-arm64: FORCE |
| 20 | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GOFLAGS_COLD) -trimpath -ldflags '$(LDFLAGS)' -o $@ . |
| 21 | |
| 22 | FORCE: |
| 23 | |
| 24 | test: css-check |
| 25 | go vet ./... |
| 26 | CGO_ENABLED=0 go test ./... |
| 27 | |
| 28 | # The served stylesheets must stay byte-for-byte copies of shared/. |
| 29 | css-check: |
| 30 | cmp ../../shared/base.css web/static/base.css |
| 31 | cmp ../../shared/index.css web/static/index.css |
| 32 | |
| 33 | clean: |
| 34 | rm -rf dist |
| 35 | |
| 36 | # Go keeps compiled packages in the shared GOCACHE, which this repo never |
| 37 | # changes or clears. Downloaded sources stay in the module cache; use |
| 38 | # `make build-arm64 COLD=1` to force every package to recompile. |
| 39 | clean-deps: clean |
| 40 | |
| 41 | bump: |
| 42 | sed -i 's/^const bumpMarker = "steady"$$/const bumpMarker = "bumped"/' web/web.go |
| 43 | grep -q '^const bumpMarker = "bumped"$$' web/web.go |
| 44 | |
| 45 | unbump: |
| 46 | sed -i 's/^const bumpMarker = "bumped"$$/const bumpMarker = "steady"/' web/web.go |
| 47 | grep -q '^const bumpMarker = "steady"$$' web/web.go |
| 48 | |
| 49 | # Ships the binary `make build-arm64` made; it doesn't rebuild. |
| 50 | deploy: |
| 51 | test -f dist/app-linux-arm64 || { echo 'run make build-arm64 first' >&2; exit 1; } |
| 52 | carlos deploy --account bfj --app todo-go --target linux-arm64 --no-prompt \ |
| 53 | --version $(VERSION) --message "$(or $(MESSAGE),Deploy todo-go $(VERSION))" dist/app-linux-arm64 |
| 54 | |