summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile81
-rw-r--r--deps.mk25
-rwxr-xr-xmkdeps.sh25
-rw-r--r--tests/libbuild.go7
4 files changed, 100 insertions, 38 deletions
diff --git a/Makefile b/Makefile
index 66d6deb..0b0505b 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ MANDIR = $(SHAREDIR)/man
EXEC = ./
## Where to store the installation. Empty by default.
DESTDIR =
-LDLIBS =
+LDLIBS = --static
GOCFLAGS = -I $(GOLIBDIR)
GOLDFLAGS = -L $(GOLIBDIR)
@@ -26,17 +26,26 @@ GOLDFLAGS = -L $(GOLIBDIR)
.SUFFIXES:
.SUFFIXES: .go .a .bin .bin-check
+.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
-objects = \
- src/$(NAME).a \
- tests/$(NAME).a \
- tests/main.a \
- tests/libbuild.a \
+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 = \
src/$(NAME).go \
@@ -45,11 +54,13 @@ sources = \
derived-assets = \
src/version.go \
- $(objects) \
- tests/main.bin \
- tests/libbuild.bin \
+ $(libs.a) \
+ $(mains.a) \
+ $(mains.bin) \
side-assets = \
+ tests/fuzz/corpus/ \
+ tests/benchmarks/*/main.txt \
@@ -58,26 +69,13 @@ side-assets = \
all: $(derived-assets)
-$(objects): Makefile
-
-src/$(NAME).a: src/$(NAME).go src/version.go
- go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go src/version.go
-
-tests/main.a: tests/main.go tests/$(NAME).a
-tests/main.a:
- go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go
+$(libs.a): Makefile deps.mk
+$(libs.a): src/$(NAME).go src/version.go
-tests/libbuild.a: tests/libbuild.go src/$(NAME).a
- go tool compile $(GOCFLAGS) -o $@ -p main -I src $*.go
-tests/$(NAME).a: tests/$(NAME).go src/$(NAME).go src/version.go
- go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go src/$(*F).go src/version.go
-
-tests/libbuild.bin: tests/libbuild.a
- go tool link $(GOLDFLAGS) -o $@ -L src $*.a
-
-tests/main.bin: tests/main.a
- go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '$(LDLIBS)' $*.a
+$(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)"' > $@
@@ -85,11 +83,9 @@ src/version.go: Makefile
tests.bin-check = \
- tests/main.bin-check \
- tests/libbuild.bin-check \
+ tests/main.bin-check \
+ $(functional-tests/main.go:.go=.bin-check) \
-tests/main.bin-check: tests/main.bin
-tests/libbuild.bin-check: tests/libbuild.bin
$(tests.bin-check):
$(EXEC)$*.bin
@@ -104,6 +100,7 @@ $(integration-tests): ALWAYS
sh $@
check-integration: $(integration-tests)
+check-integration: fuzz
## Run all tests. Each test suite is isolated, so that a parallel
@@ -113,6 +110,27 @@ check: check-unit check-integration
+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):
+ 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/main.bin-check)
+
+
+
## Remove *all* derived artifacts produced during the build.
## A dedicated test asserts that this is always true.
clean:
@@ -138,4 +156,5 @@ uninstall:
'$(DESTDIR)$(SRCDIR)' \
+
ALWAYS:
diff --git a/deps.mk b/deps.mk
index e69de29..3efeded 100644
--- a/deps.mk
+++ b/deps.mk
@@ -0,0 +1,25 @@
+libs.go = \
+ src/gobang.go \
+ tests/gobang.go \
+
+mains.go = \
+ tests/main.go \
+
+functional-tests/lib.go = \
+
+functional-tests/main.go = \
+
+fuzz-targets/lib.go = \
+
+fuzz-targets/main.go = \
+
+benchmarks/lib.go = \
+
+benchmarks/main.go = \
+
+src/gobang.a: src/gobang.go
+tests/gobang.a: tests/gobang.go
+tests/main.a: tests/main.go
+tests/main.bin: tests/main.a
+tests/main.bin-check: tests/main.bin
+tests/main.a: tests/$(NAME).a
diff --git a/mkdeps.sh b/mkdeps.sh
index e5606ff..e8da8a4 100755
--- a/mkdeps.sh
+++ b/mkdeps.sh
@@ -2,3 +2,28 @@
set -eu
export LANG=POSIX.UTF-8
+
+
+libs() {
+ find src tests -name '*.go' | grep -v '/main\.go$' |
+ grep -v '/version\.go$'
+}
+
+mains() {
+ find src tests -name '*.go' | grep '/main\.go$'
+}
+
+libs | varlist 'libs.go'
+mains | varlist 'mains.go'
+
+find tests/functional/*/*.go -not -name main.go | varlist 'functional-tests/lib.go'
+find tests/functional/*/main.go | varlist 'functional-tests/main.go'
+find tests/fuzz/*/*.go -not -name main.go | varlist 'fuzz-targets/lib.go'
+find tests/fuzz/*/main.go | varlist 'fuzz-targets/main.go'
+find tests/benchmarks/*/*.go -not -name main.go | varlist 'benchmarks/lib.go'
+find tests/benchmarks/*/main.go | varlist 'benchmarks/main.go'
+
+{ libs; mains; } | sort | sed 's/^\(.*\)\.go$/\1.a:\t\1.go/'
+mains | sort | sed 's/^\(.*\)\.go$/\1.bin:\t\1.a/'
+mains | sort | sed 's/^\(.*\)\.go$/\1.bin-check:\t\1.bin/'
+mains | sort | sed 's|^\(.*\)/main\.go$|\1/main.a:\t\1/$(NAME).a|'
diff --git a/tests/libbuild.go b/tests/libbuild.go
deleted file mode 100644
index 8bbed86..0000000
--- a/tests/libbuild.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package main
-
-import "gobang"
-
-func main() {
- gobang.Init()
-}