aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-18 17:54:26 -0300
committerEuAndreh <eu@euandre.org>2024-10-20 03:36:18 -0300
commitf00c41fd4e6af8cd0db80c118a3bb4abef09604e (patch)
tree46ad14d55cfe591691cf214076e8aea81edbfe18 /Makefile
parent.gitignore: Remove .so (diff)
downloadgolite-f00c41fd4e6af8cd0db80c118a3bb4abef09604e.tar.gz
golite-f00c41fd4e6af8cd0db80c118a3bb4abef09604e.tar.xz
Shoehorn project into default golang skeleton structure
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile86
1 files changed, 37 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index dcaf826..4267fa3 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ MANDIR = $(SHAREDIR)/man
EXEC = ./
## Where to store the installation. Empty by default.
DESTDIR =
-LDLIBS = --static -lacude -lm
+LDLIBS = --static -lsqlite3 -lm
GOCFLAGS = -I $(GOLIBDIR)
GOLDFLAGS = -L $(GOLIBDIR)
@@ -29,18 +29,26 @@ GOLDFLAGS = -L $(GOLIBDIR)
.c.o:
$(CC) $(CFLAGS) -o $@ -c $<
+.go.a:
+ go tool compile $(GOCFLAGS) -I $(@D) -o $@ -p $(*F) \
+ `find $< $$(if [ $(*F) != main ]; then \
+ echo src/$(NAME).go src/version.go; fi) | uniq`
+
+.a.bin:
+ go tool link $(GOLDFLAGS) -L $(@D) -o $@ --extldflags '$(LDLIBS)' $<
+
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)
+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)
cgo.go = \
src/_cgo_import.go \
@@ -58,12 +66,6 @@ objects = \
$(cgo.go) \
$(cgo.c) \
$(cgo.o) \
- src/$(NAME).a \
- tests/$(NAME).a \
- tests/main.a \
- $(functional-tests.a) \
- $(fuzz-targets.a) \
- $(benchmarks.a) \
sources = \
src/$(NAME).go \
@@ -73,15 +75,15 @@ sources = \
derived-assets = \
src/version.go \
$(objects) \
- tests/main.bin \
- $(functional-tests.bin) \
- $(fuzz-targets.bin) \
- $(benchmarks.bin) \
+ $(libs.a) \
+ $(mains.a) \
+ $(mains.bin) \
side-assets = \
src/_cgo_export.h \
src/_cgo_main.c \
- tests/benchmarks/*.txt \
+ tests/fuzz/corpus/ \
+ tests/benchmarks/*/main.txt \
@@ -91,11 +93,12 @@ all: $(derived-assets)
$(objects): Makefile deps.mk
+$(libs.a): Makefile deps.mk
+$(libs.a): src/$(NAME).go src/version.go
+$(libs.a): $(cgo.go) $(cgo.o)
$(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
@@ -103,40 +106,25 @@ src/_cgo_.o: 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
+src/$(NAME).a tests/$(NAME).a $(functional-tests/lib.a) $(benchmarks/lib.a):
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $(cgo.go) src/version.go \
+ `find $*.go | grep -Ev '^src/$(NAME)\.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
+$(fuzz-targets/lib.a):
+ go tool compile $(GOCFLAGS) -o $@ -p $(NAME) -d=libfuzzer \
+ $*.go $(cgo.go) src/version.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
-
-functional-tests.bin-check = $(functional-tests.go:.go=.bin-check)
tests.bin-check = \
- tests/main.bin-check \
- $(functional-tests.bin-check) \
+ tests/main.bin-check \
+ $(functional-tests/main.go:.go=.bin-check) \
-tests/main.bin-check: tests/main.bin
$(tests.bin-check):
$(EXEC)$*.bin
@@ -162,23 +150,23 @@ check: check-unit check-integration
FUZZSEC=1
-fuzz-targets.bin-check = $(fuzz-targets.go:.go=.bin-check)
-$(fuzz-targets.bin-check):
+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.bin-check)
+fuzz: $(fuzz-targets/main.bin-check)
-benchmarks.bin-check = $(benchmarks.go:.go=.bin-check)
-$(benchmarks.bin-check):
+benchmarks/main.bin-check = $(benchmarks/main.go:.go=.bin-check)
+$(benchmarks/main.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)
+bench: $(benchmarks/main.bin-check)