# TodoMVC in Nim. See README.md. SHELL := bash REPO := $(abspath ../..) ZIGCC := $(REPO)/scripts/zigcc-aarch64-musl CACHE := $(CURDIR)/.cache VERSION ?= $(shell git rev-parse --short HEAD) SQLITE := sqlite-amalgamation-3540100 SQLITE_URL := https://sqlite.org/2026/$(SQLITE).zip SQLITE_SHA256 := 0a9c8e34352dad46006aa82836d5383bff9dc6bc9ce5a60553c05aa30e6ad1f9 SQLITE_C := $(CACHE)/sqlite/sqlite3.c NIMBLE_DIR := $(CACHE)/nimble DEPS_STAMP := $(NIMBLE_DIR)/.installed # zig cc (the arm64 C compiler) keeps compiled musl, compiler-rt and every # object it builds in its caches; keep them here so clean-deps reaches them. export ZIG_GLOBAL_CACHE_DIR := $(CACHE)/zig-global export ZIG_LOCAL_CACHE_DIR := $(CACHE)/zig-local # Every library is compiled from source into a nimcache under .cache/. NIMFLAGS := --hints:off -d:release --opt:speed \ --noNimblePath $$(for p in $(NIMBLE_DIR)/pkgs2/*/; do echo --path:$$p; done) \ --dynlibOverride:sqlite3 -d:sqliteSource=$(SQLITE_C) \ -d:appVersion=$(VERSION) ARM64FLAGS := --cpu:arm64 --os:linux --cc:clang \ --clang.exe=$(ZIGCC) --clang.linkerexe=$(ZIGCC) --passL:-static --passL:-s SOURCES := $(wildcard src/*.nim src/*.nimf static/*) $(REPO)/shared/base.css $(REPO)/shared/index.css .PHONY: build build-arm64 test clean clean-deps deps bump unbump deploy build: dist/app build-arm64: dist/app-linux-arm64 deps: $(DEPS_STAMP) $(SQLITE_C) dist/app: $(SOURCES) deps .FORCE nim c $(NIMFLAGS) --nimcache:$(CACHE)/nimcache-host -o:$@ src/app.nim dist/app-linux-arm64: $(SOURCES) deps .FORCE nim c $(NIMFLAGS) $(ARM64FLAGS) --nimcache:$(CACHE)/nimcache-arm64 -o:$@ src/app.nim test: deps nim c -r $(NIMFLAGS) -d:testing --nimcache:$(CACHE)/nimcache-test -o:$(CACHE)/test_app tests/test_app.nim $(DEPS_STAMP): todo.nimble source $(REPO)/scripts/env.sh && nimble --nimbleDir:$(NIMBLE_DIR) install --depsOnly -y touch $@ $(SQLITE_C): mkdir -p $(CACHE)/dl $(CACHE)/sqlite [ -f $(CACHE)/dl/$(SQLITE).zip ] || curl -sSfL -o $(CACHE)/dl/$(SQLITE).zip $(SQLITE_URL) echo "$(SQLITE_SHA256) $(CACHE)/dl/$(SQLITE).zip" | sha256sum -c --quiet unzip -q -o -j $(CACHE)/dl/$(SQLITE).zip '$(SQLITE)/sqlite3.c' '$(SQLITE)/sqlite3.h' -d $(CACHE)/sqlite touch $@ clean: rm -rf dist # Compiled output only: downloaded sources (.cache/nimble, .cache/dl, # .cache/sqlite) stay, so the next build compiles every library again, # musl and compiler-rt included. clean-deps: clean rm -rf $(CACHE)/nimcache-host $(CACHE)/nimcache-arm64 $(CACHE)/nimcache-test $(CACHE)/test_app \ $(CACHE)/zig-global $(CACHE)/zig-local bump: sed -i 's/serverName = "todo-nim"/serverName = "todo-nim bumped"/' src/app.nim unbump: sed -i 's/serverName = "todo-nim bumped"/serverName = "todo-nim"/' src/app.nim deploy: source $(REPO)/scripts/env.sh && carlos deploy --account bfj --app todo-nim \ --target linux-arm64 --no-prompt --message "$${MESSAGE:-Deploy todo-nim $(VERSION)}" \ dist/app-linux-arm64 .FORCE: