| 1 | # todo-haskell. Every cabal store and build directory lives under .cache/, |
| 2 | # so nothing here touches ~/.cabal or the arm64 root's /root. |
| 3 | # |
| 4 | # The x86 build uses ghcup's GHC 9.10.3. The shipped linux-arm64 binary is |
| 5 | # built inside the emulated arm64 root (scripts/arm64.sh) with Debian's |
| 6 | # GHC 9.6.6, linked fully static. |
| 7 | |
| 8 | ROOT := $(abspath ../..) |
| 9 | CACHE := $(abspath .cache) |
| 10 | ARM64 := $(ROOT)/scripts/arm64.sh |
| 11 | VERSION := $(shell git rev-parse --short HEAD) |
| 12 | MESSAGE ?= Deploy $(VERSION) |
| 13 | |
| 14 | export PATH := $(HOME)/.ghcup/bin:$(PATH) |
| 15 | |
| 16 | # ghcup's GHC links -lgmp, and this machine has only libgmp.so.10, so |
| 17 | # .cache/x86-lib holds the libgmp.so link the linker looks for. |
| 18 | X86_CABAL := CABAL_DIR=$(CACHE)/cabal-x86 LIBRARY_PATH=$(CACHE)/x86-lib cabal |
| 19 | ARM64_CABAL := $(ARM64) env CABAL_DIR=$(CACHE)/cabal-arm64 cabal |
| 20 | |
| 21 | X86_BIN := $(CACHE)/dist-x86/build/x86_64-linux/ghc-9.10.3/todo-haskell-0.1.0.0/x/todo-haskell/build/todo-haskell/todo-haskell |
| 22 | ARM64_BIN := $(CACHE)/dist-arm64/build/aarch64-linux/ghc-9.6.6/todo-haskell-0.1.0.0/x/todo-haskell/build/todo-haskell/todo-haskell |
| 23 | |
| 24 | .PHONY: build build-arm64 test clean clean-deps bump unbump deploy FORCE |
| 25 | |
| 26 | build: gen/BuildVersion.hs $(CACHE)/x86-lib/libgmp.so |
| 27 | $(X86_CABAL) build -j --builddir=$(CACHE)/dist-x86 exe:todo-haskell |
| 28 | @mkdir -p dist |
| 29 | cp $(X86_BIN) dist/app.new && mv dist/app.new dist/app |
| 30 | |
| 31 | build-arm64: gen/BuildVersion.hs |
| 32 | @[ -d $(CACHE)/cabal-arm64/packages ] || $(ARM64_CABAL) update |
| 33 | $(ARM64_CABAL) build -j --builddir=$(CACHE)/dist-arm64 exe:todo-haskell |
| 34 | @mkdir -p dist |
| 35 | cp $(ARM64_BIN) dist/app-linux-arm64.new && mv dist/app-linux-arm64.new dist/app-linux-arm64 |
| 36 | |
| 37 | test: gen/BuildVersion.hs $(CACHE)/x86-lib/libgmp.so |
| 38 | $(X86_CABAL) test -j --enable-tests --builddir=$(CACHE)/dist-x86-test --test-show-details=direct |
| 39 | |
| 40 | clean: |
| 41 | rm -rf dist $(CACHE)/dist-x86 $(CACHE)/dist-x86-test $(CACHE)/dist-arm64 gen |
| 42 | |
| 43 | # Compiled libraries go; downloaded sources (.cache/cabal-*/packages) stay. |
| 44 | clean-deps: clean |
| 45 | rm -rf $(CACHE)/cabal-x86/store $(CACHE)/cabal-arm64/store |
| 46 | |
| 47 | # The string is Todo.App's serverName, sent as the Server header. |
| 48 | bump: |
| 49 | sed -i 's/^serverName = "todo-haskell"$$/serverName = "todo-haskell (bumped)"/' src/Todo/App.hs |
| 50 | |
| 51 | unbump: |
| 52 | sed -i 's/^serverName = "todo-haskell (bumped)"$$/serverName = "todo-haskell"/' src/Todo/App.hs |
| 53 | |
| 54 | deploy: |
| 55 | carlos deploy --account bfj --app todo-haskell --target linux-arm64 \ |
| 56 | --version $(VERSION) --no-prompt --message "$(MESSAGE)" dist/app-linux-arm64 |
| 57 | |
| 58 | # The build version is the git short SHA, compiled in from a generated |
| 59 | # module. It's rewritten only when the SHA changes, so an unchanged tree |
| 60 | # doesn't recompile. |
| 61 | gen/BuildVersion.hs: FORCE |
| 62 | @mkdir -p gen |
| 63 | @printf 'module BuildVersion (buildVersion) where\n\nbuildVersion :: String\nbuildVersion = "%s"\n' '$(VERSION)' > gen/BuildVersion.hs.new |
| 64 | @if cmp -s gen/BuildVersion.hs.new $@; then rm gen/BuildVersion.hs.new; else mv gen/BuildVersion.hs.new $@; fi |
| 65 | |
| 66 | $(CACHE)/x86-lib/libgmp.so: |
| 67 | @mkdir -p $(dir $@) |
| 68 | ln -sf /usr/lib/x86_64-linux-gnu/libgmp.so.10 $@ |
| 69 | |