diff options
author | EuAndreh <eu@euandre.org> | 2025-05-02 18:34:58 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-05-02 19:10:40 -0300 |
commit | 715815e3bea7fec41a385742b0a6a8fee4c5cf99 (patch) | |
tree | e752e49b0127cae36724877174579aaff801a0c5 /Makefile | |
parent | WIP: Commit sh code as-is (diff) | |
download | gistatic-715815e3bea7fec41a385742b0a6a8fee4c5cf99.tar.gz gistatic-715815e3bea7fec41a385742b0a6a8fee4c5cf99.tar.xz |
Switch from POSIX sh to Go
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 111 |
1 files changed, 87 insertions, 24 deletions
@@ -8,6 +8,7 @@ LANGUAGES = en PREFIX = /usr BINDIR = $(PREFIX)/bin LIBDIR = $(PREFIX)/lib +GOLIBDIR = $(LIBDIR)/go INCLUDEDIR = $(PREFIX)/include SRCDIR = $(PREFIX)/src/$(NAME) SHAREDIR = $(PREFIX)/share @@ -16,24 +17,52 @@ MANDIR = $(SHAREDIR)/man EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = -LDLIBS = +LDLIBS = --static +GOCFLAGS = -I $(GOLIBDIR) +GOLDFLAGS = -L $(GOLIBDIR) .SUFFIXES: +.SUFFIXES: .go .a .bin .bin-check + +.go.a: + go tool compile -I $(@D) $(GOCFLAGS) -o $@ -p $(*F) \ + `find $< $$(if [ $(*F) != main ]; then \ + echo src/$(NAME).go src/version.go; fi) | uniq` + +.a.bin: + go tool link -L $(@D) $(GOLDFLAGS) -o $@ --extldflags '$(LDLIBS)' $< all: include deps.mk + +libs.a = $(libs.go:.go=.a) +mains.a = $(mains.go:.go=.a) +mains.bin = $(mains.go:.go=.bin) +functional-tests/lib.a = $(functional-tests/lib.go:.go=.a) +fuzz-targets/lib.a = $(fuzz-targets/lib.go:.go=.a) +benchmarks/lib.a = $(benchmarks/lib.go:.go=.a) + sources = \ - $(sources.sh) \ + src/$(NAME).go \ + src/version.go \ + src/main.go \ derived-assets = \ + src/version.go \ + $(libs.a) \ + $(mains.a) \ + $(mains.bin) \ + $(NAME).bin \ side-assets = \ + tests/fuzz/corpus/ \ + tests/benchmarks/*/main.txt \ @@ -41,36 +70,70 @@ side-assets = \ ## and installation. all: $(derived-assets) -tests/resources/repositories/repo-1/.git \ -tests/resources/repositories/repo-2/.git: - ln -s .gitdir $@ -emit-index: src/gistatic - @rm -rf tmp/index/ - @./src/gistatic -i -o tmp/index/ ~/dev/published/git-permalink/ ../capim/ ../libedn/ ../listatic/ ../lisp-cli/ - @ln -rfs tmp/git-permalink tmp/index/git-permalink +$(libs.a): Makefile deps.mk +$(libs.a): src/$(NAME).go src/version.go + + +$(fuzz-targets/lib.a): + go tool compile $(GOCFLAGS) -o $@ -p $(NAME) -d=libfuzzer \ + $*.go src/$(NAME).go src/version.go + +src/version.go: Makefile + echo 'package $(NAME); const Version = "$(VERSION)"' > $@ + +$(NAME).bin: src/main.bin + ln -fs $? $@ + + -emit-repo: src/gistatic - @rm -rf tmp/git-permalink/ - @time ./src/gistatic -o tmp/git-permalink/ -u FIXME-url-1 ~/dev/published/git-permalink/ +tests.bin-check = \ + tests/main.bin-check \ + $(functional-tests/main.go:.go=.bin-check) \ -run: shellcheck emit-index emit-repo +$(tests.bin-check): + $(EXEC)$*.bin +check-unit: $(tests.bin-check) -check-unit: +integration-tests = \ + tests/cli-opts.sh \ + tests/integration.sh \ -check-integration: +.PRECIOUS: $(integration-tests) +$(integration-tests): $(NAME).bin +$(integration-tests): ALWAYS + sh $@ + +check-integration: $(integration-tests) +check-integration: fuzz ## Run all tests. Each test suite is isolated, so that a parallel ## build can run tests at the same time. The required artifacts ## are created if missing. check: check-unit check-integration -# tests/resources/repositories/repo-1/.git -# tests/resources/repositories/repo-2/.git -# sh tests/build-sample.sh -# sh tests/integration.sh + + + +FUZZSEC=1 +fuzz-targets/main.bin-check = $(fuzz-targets/main.go:.go=.bin-check) +$(fuzz-targets/main.bin-check): + $(EXEC)$*.bin --test.fuzztime=$(FUZZSEC)s \ + --test.fuzz='.*' --test.fuzzcachedir=tests/fuzz/corpus + +fuzz: $(fuzz-targets/main.bin-check) + + + +benchmarks/main.bin-check = $(benchmarks/main.go:.go=.bin-check) +$(benchmarks/main.bin-check): + printf '%s\n' '$(EXEC)$*.bin' > $*.txt + LANG=POSIX.UTF-8 time -p $(EXEC)$*.bin 2>> $*.txt + printf '%s\n' '$*.txt' + +bench: $(benchmarks/main.bin-check) @@ -85,22 +148,22 @@ clean: install: all mkdir -p \ '$(DESTDIR)$(BINDIR)' \ + '$(DESTDIR)$(GOLIBDIR)' \ '$(DESTDIR)$(SRCDIR)' \ - cp $(sources.sh) '$(DESTDIR)$(BINDIR)' + cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME) + cp src/$(NAME).a '$(DESTDIR)$(GOLIBDIR)' cp $(sources) '$(DESTDIR)$(SRCDIR)' - ## Uninstalls from $(DESTDIR)$(PREFIX). This is a perfect mirror ## of the "install" target, and removes *all* that was installed. ## A dedicated test asserts that this is always true. uninstall: rm -rf \ + '$(DESTDIR)$(BINDIR)'/$(NAME) \ + '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \ '$(DESTDIR)$(SRCDIR)' \ - for f in $(sources.sh); do \ - rm -f '$(DESTDIR)$(BINDIR)'/"$${f#src/}"; \ - done ALWAYS: |