.POSIX: DATE = 1970-01-01 VERSION = 0.1.0 NAME = golite NAME_UC = $(NAME) LANGUAGES = en ## Installation prefix. Defaults to "/usr". PREFIX = /usr BINDIR = $(PREFIX)/bin LIBDIR = $(PREFIX)/lib GOLIBDIR = $(LIBDIR)/go INCLUDEDIR = $(PREFIX)/include SRCDIR = $(PREFIX)/src/$(NAME) SHAREDIR = $(PREFIX)/share LOCALEDIR = $(SHAREDIR)/locale MANDIR = $(SHAREDIR)/man EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = LDLIBS = -lsqlite3 GOCFLAGS = -I $(GOLIBDIR) GOLDFLAGS = -L $(GOLIBDIR) .SUFFIXES: .SUFFIXES: .go .a .c .o .so .bin .bin-check .c.o: $(CC) $(CFLAGS) -o $@ -c $< all: include deps.mk functional-tests.a = $(functional-tests.go:.go=.a) functional-tests.bin = $(functional-tests.go:.go=.bin) fuzz-targets.a = $(fuzz-targets.go:.go=.a) fuzz-targets.bin = $(fuzz-targets.go:.go=.bin) benchmarks.a = $(benchmarks.go:.go=.a) benchmarks.bin = $(benchmarks.go:.go=.bin) cgo.go = \ src/_cgo_import.go \ src/_cgo_gotypes.go \ src/$(NAME).cgo1.go \ cgo.c = \ src/_cgo_export.c \ src/$(NAME).cgo2.c \ cgo.o = $(cgo.c:.c=.o) sources = \ src/$(NAME).go \ src/version.go \ derived-assets = \ src/version.go \ src/_cgo_.o \ $(cgo.go) \ $(cgo.c) \ $(cgo.o) \ src/$(NAME).a \ tests/$(NAME).a \ tests/main.a \ tests/main.bin \ $(functional-tests.a) \ $(functional-tests.bin) \ tests/functional/streq.so \ $(fuzz-targets.a) \ $(fuzz-targets.bin) \ $(benchmarks.a) \ $(benchmarks.bin) \ side-assets = \ src/_cgo_export.h \ src/_cgo_main.c \ tests/benchmarks/*.txt \ ## Default target. Builds all artifacts required for testing ## and installation. all: $(derived-assets) $(derived-assets): Makefile deps.mk $(cgo.go) $(cgo.c) $(cgo.o): src/_cgo_.o $(functional-tests.a) $(fuzz-targets.a) $(benchmarks.a): src/$(NAME).a src/_cgo_.o: src/$(NAME).go go tool cgo --objdir $(@D) src/$(NAME).go src/_cgo_import.go: src/_cgo_.o go tool cgo --dynpackage $(NAME) --dynimport src/_cgo_.o --dynout $@ src/$(NAME).a: $(cgo.go) $(cgo.o) src/version.go go tool compile $(GOCFLAGS) -o $@ -p $(*F) $(cgo.go) src/version.go go tool pack r $@ $(cgo.o) tests/$(NAME).a: $(cgo.go) $(cgo.o) src/version.go tests/$(NAME).go go tool compile $(GOCFLAGS) -o $@ -p $(*F) $(cgo.go) src/version.go $*.go go tool pack r $@ $(cgo.o) tests/main.a: tests/main.go tests/$(NAME).a go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go tests/main.bin: tests/main.a go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '$(LDLIBS)' $*.a src/version.go: Makefile echo 'package $(NAME); const Version = "$(VERSION)"' > $@ $(functional-tests.a) $(benchmarks.a): go tool compile $(GOCFLAGS) -o $@ -p main -I src $*.go $(fuzz-targets.a): go tool compile -d=libfuzzer $(GOCFLAGS) -o $@ -p main -I src $*.go $(functional-tests.bin) $(fuzz-targets.bin) $(benchmarks.bin): go tool link $(GOLDFLAGS) -o $@ -L src --extldflags '$(LDLIBS)' $*.a tests/functional/streq.so: tests/functional/streq.c $(CC) $(CFLAGS) $(LDFLAGS) -fPIC --shared -o $@ $*.c tests/functional/extension.bin-check: tests/functional/streq.so LD_LIBRARY_PATH=$(@D) $(EXEC)$*.bin functional-tests.bin-check = $(functional-tests-butone.go:.go=.bin-check) tests.bin-check = \ tests/main.bin-check \ $(functional-tests.bin-check) \ tests/main.bin-check: tests/main.bin $(tests.bin-check): $(EXEC)$*.bin check-unit: $(tests.bin-check) check-unit: tests/functional/extension.bin-check integration-tests = \ .PRECIOUS: $(integration-tests) $(integration-tests): $(NAME).bin $(integration-tests): ALWAYS sh $@ check-integration: $(integration-tests) ## 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 FUZZSEC=1 fuzz-targets.bin-check = $(fuzz-targets.go:.go=.bin-check) $(fuzz-targets.bin-check): $(EXEC)$*.bin --test.fuzztime=$(FUZZSEC)s \ --test.fuzz='.*' --test.fuzzcachedir=tests/fuzz/corpus fuzz: $(fuzz-targets.bin-check) benchmarks.bin-check = $(benchmarks.go:.go=.bin-check) $(benchmarks.bin-check): rm -f $*.txt printf '%s\n' '$(EXEC)$*.bin' >> $*.txt LANG=POSIX.UTF-8 time -p $(EXEC)$*.bin 2>> $*.txt printf '%s\n' '$*.txt' bench: $(benchmarks.bin-check) ## Remove *all* derived artifacts produced during the build. ## A dedicated test asserts that this is always true. clean: rm -rf $(derived-assets) $(side-assets) ## Installs into $(DESTDIR)$(PREFIX). Its dependency target ## ensures that all installable artifacts are crafted beforehand. install: all mkdir -p \ '$(DESTDIR)$(GOLIBDIR)' \ '$(DESTDIR)$(SRCDIR)' \ 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)$(GOLIBDIR)'/$(NAME).a \ '$(DESTDIR)$(SRCDIR)' \ ALWAYS: