summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-08-08 18:48:25 -0300
committerEuAndreh <eu@euandre.org>2024-08-08 18:48:25 -0300
commit81ebc234678af08692aad7f3c2d1128f6c2f75c4 (patch)
treefc5ba312b456d2b2ef20424572d9ca4a9a76edc8 /Makefile
parentrm go.mod (diff)
downloadbinder-81ebc234678af08692aad7f3c2d1128f6c2f75c4.tar.gz
binder-81ebc234678af08692aad7f3c2d1128f6c2f75c4.tar.xz
Makefile: Use "go tool {compile,link}" over "go {build,test}"
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile65
1 files changed, 47 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 17bcd03..38ec6d9 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,12 +18,11 @@ EXEC = ./
## Where to store the installation. Empty by default.
DESTDIR =
LDLIBS =
-GOFLAGS =
.SUFFIXES:
-.SUFFIXES: .go .bin
+.SUFFIXES: .go .a .bin .bin-check
@@ -30,14 +30,22 @@ 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 \
derived-assets = \
+ $(objects) \
+ src/main.bin \
+ tests/main.bin \
$(NAME).bin \
- tests/lib_test.bin \
side-assets = \
glaze.socket \
@@ -49,16 +57,37 @@ side-assets = \
all: $(derived-assets)
-$(NAME).bin: src/lib.go src/cmd/main.go Makefile
- go build $(GOFLAGS) -v -o $@ src/cmd/main.go
+$(objects): Makefile
+
+src/$(NAME).a: src/$(NAME).go
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go
+
+tests/$(NAME).a: tests/$(NAME).go src/$(NAME).go
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go src/$(NAME).go
+
+src/main.a: src/main.go src/$(NAME).a
+tests/main.a: tests/main.go tests/$(NAME).a
+src/main.a tests/main.a:
+ go tool compile $(GOCFLAGS) -o $@ -I $(@D) $*.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) $*.a
+
+$(NAME).bin: src/main.bin
+ ln -fs $? $@
+
-tests/lib_test.bin: src/lib.go tests/lib_test.go Makefile
- go test $(GOFLAGS) -v -o $@ -c $*.go
+tests.bin-check = \
+ tests/main.bin-check
+$(tests.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 = \
@@ -91,21 +120,21 @@ clean:
install: all
mkdir -p \
'$(DESTDIR)$(BINDIR)' \
+ '$(DESTDIR)$(GOLIBDIR)' \
+ '$(DESTDIR)$(SRCDIR)' \
cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME)
- for f in $(sources); do \
- dir='$(DESTDIR)$(SRCDIR)'/"`dirname "$${f#src/}"`"; \
- mkdir -p "$$dir"; \
- cp -P "$$f" "$$dir"; \
- done
+ 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)$(SRCDIR)' \
+ '$(DESTDIR)$(BINDIR)'/$(NAME) \
+ '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \
+ '$(DESTDIR)$(SRCDIR)' \