scooter  ·  2026-04-15

Makefile

 1build: clean
 2	@if command -v nix >/dev/null 2>&1; then \
 3		echo "Building with nix..."; \
 4		nix build; \
 5	else \
 6		echo "Building with go..."; \
 7		mkdir -p result/bin; \
 8		go build -o result/bin/pgit ./cmd/pgit; \
 9		go build -o result/bin/pgit-index ./cmd/pgit-index; \
10	fi
11.PHONY: build
12
13clean:
14	@# Remove result directory/symlink
15	@rm -rf result
16	@rm -rf bin/
17.PHONY: clean
18
19fmt:
20	go fmt ./...
21.PHONY: fmt
22
23lint:
24	golangci-lint run
25.PHONY: lint
26
27test:
28	go test ./...
29.PHONY: test
30
31local:
32	go build -o ~/bin/pgit ./cmd/pgit
33	go build -o ~/bin/pgit-index ./cmd/pgit-index
34.PHONY: local
35
36# Update flake.nix vendorHash when go.mod/go.sum changes
37# This target depends on go.mod and go.sum, so it will only run when they change
38update-vendor-hash: flake.nix go.mod go.sum
39	@echo "Checking if vendorHash needs update..."
40	@nix build 2>&1 | tee /tmp/nix-build.log; \
41	if grep -q "hash mismatch" /tmp/nix-build.log; then \
42		NEW_HASH=$$(grep "got:" /tmp/nix-build.log | sed 's/.*got: *//' | tail -1); \
43		echo "Updating vendorHash to $$NEW_HASH"; \
44		sed -i "s|vendorHash = \"sha256-[^\"]*\";|vendorHash = \"$$NEW_HASH\";|" flake.nix; \
45		sed -i "s|vendorHash = pkgs.lib.fakeHash;|vendorHash = \"$$NEW_HASH\";|" flake.nix; \
46	elif grep -q "error:.*fakeHash" /tmp/nix-build.log; then \
47		NEW_HASH=$$(grep "got:" /tmp/nix-build.log | sed 's/.*got: *//' | tail -1); \
48		echo "Updating vendorHash to $$NEW_HASH"; \
49		sed -i "s|vendorHash = pkgs.lib.fakeHash;|vendorHash = \"$$NEW_HASH\";|" flake.nix; \
50	else \
51		echo "vendorHash is up to date"; \
52	fi
53	@rm -f /tmp/nix-build.log
54	@touch update-vendor-hash
55.PHONY: update-vendor-hash
56
57# Update flake.lock when flake.nix inputs change
58update-flake-lock: flake.nix
59	nix flake lock
60	touch update-flake-lock
61.PHONY: update-flake-lock
62
63# Update both vendor hash and flake lock
64update-flake: update-vendor-hash update-flake-lock
65	@echo "Flake updated successfully"
66.PHONY: update-flake
67
68test-site:
69	mkdir -p testdata.site
70	rm -rf testdata.site/*
71	go run ./cmd/pgit \
72		--repo ./testdata \
73		--out testdata.site \
74		--clone-url "https://test.com/test/test2" \
75		--home-url "https://test.com/test" \
76		--label testdata \
77		--desc "pgit testing site - [link](https://yourmom.com)" \
78		--theme "github-dark" \
79		--revs "main,branch-c" \
80		--issues
81.PHONY: test-site
82
83static: build clean
84	./pgit \
85		--out ./public \
86		--label pgit \
87		--desc "static site generator for git" \
88		--clone-url "https://github.com/picosh/pgit.git" \
89		--home-url "https://git.erock.io" \
90		--theme "dracula" \
91		--revs main
92.PHONY:
93
94dev: static
95	rsync -rv --delete ./public/ pgs.sh:/git-pgit-local/
96.PHONY: dev