summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile67
1 files changed, 50 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index ba9e48f..73d81a2 100644
--- a/Makefile
+++ b/Makefile
@@ -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
@@ -17,14 +18,12 @@ DATADIR = $(SHAREDIR)/$(NAME)
EXEC = ./
## Where to store the installation. Empty by default.
DESTDIR =
-LDLIBS =
-GOFLAGS = -ldflags '-extldflags "-static -lm"' -tags 'linux libsqlite3 \
- json1 fts5 sqlite_foreign_keys sqlite_omit_load_extension'
+LDLIBS = -lsqlite3
.SUFFIXES:
-.SUFFIXES: .go .bin
+.SUFFIXES: .go .a .bin .bin-check
@@ -32,16 +31,24 @@ all:
include deps.mk
+objects = \
+ src/$(NAME).a \
+ src/main.a \
+ tests/$(NAME).a \
+ tests/main.a \
+
sources = \
- src/lib.go \
- src/cmd/main.go \
+ src/$(NAME).go \
+ src/main.go \
$(sources.static) \
$(sources.sql) \
derived-assets = \
+ $(objects) \
+ src/main.bin \
+ tests/main.bin \
$(NAME).bin \
- tests/lib_test.bin \
side-assets = \
papod.public.socket \
@@ -57,22 +64,44 @@ side-assets = \
all: $(derived-assets)
-$(NAME).bin: src/lib.go src/cmd/main.go Makefile
- env CGO_ENABLED=1 go build $(GOFLAGS) -v -o $@ src/cmd/main.go
+$(objects): Makefile
+
+src/$(NAME).a: src/$(NAME).go
+src/main.a: src/main.go src/$(NAME).a
+tests/main.a: tests/main.go tests/$(NAME).a
+src/$(NAME).a src/main.a tests/main.a:
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go
+
+tests/$(NAME).a: tests/$(NAME).go src/$(NAME).go
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go src/$(*F).go
+
+src/main.bin: src/main.a
+tests/main.bin: tests/main.a
+src/main.bin tests/main.bin:
+ go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '$(LDLIBS)' $*.a
+
+$(NAME).bin: src/main.bin
+ ln -fs $? $@
+
-tests/lib_test.bin: src/lib.go tests/lib_test.go Makefile
- env CGO_ENABLED=1 go test $(GOFLAGS) -v -o $@ -c $*.go
+tests.bin-check = \
+ tests/main.bin-check \
+tests/main.bin-check: tests/main.bin
+$(tests.bin-check):
+ $(EXEC)$*.bin
-check-unit: tests/lib_test.bin
- ./tests/lib_test.bin
+check-unit: $(tests.bin-check)
integration-tests = \
tests/cli-opts.sh \
+ tests/integration.sh \
-$(integration-tests): $(NAME).bin ALWAYS
+.PRECIOUS: $(integration-tests)
+$(integration-tests): $(NAME).bin
+$(integration-tests): ALWAYS
sh $@
check-integration: $(integration-tests)
@@ -96,8 +125,11 @@ clean:
install: all
mkdir -p \
'$(DESTDIR)$(BINDIR)' \
+ '$(DESTDIR)$(GOLIBDIR)' \
+ '$(DESTDIR)$(SRCDIR)' \
cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME)
+ cp src/$(NAME).a '$(DESTDIR)$(GOLIBDIR)'
for f in $(sources.sql) $(sources.static); do \
dir='$(DESTDIR)$(DATADIR)'/"`dirname "$${f#src/}"`"; \
mkdir -p "$$dir"; \
@@ -114,9 +146,10 @@ install: all
## A dedicated test asserts that this is always true.
uninstall:
rm -rf \
- '$(DESTDIR)$(BINDIR)'/$(NAME) \
- '$(DESTDIR)$(DATADIR)' \
- '$(DESTDIR)$(SRCDIR)' \
+ '$(DESTDIR)$(BINDIR)'/$(NAME) \
+ '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \
+ '$(DESTDIR)$(DATADIR)' \
+ '$(DESTDIR)$(SRCDIR)' \
run-papod: $(NAME).bin