diff options
author | EuAndreh <eu@euandre.org> | 2024-08-08 18:48:25 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-08-08 18:48:25 -0300 |
commit | 81ebc234678af08692aad7f3c2d1128f6c2f75c4 (patch) | |
tree | fc5ba312b456d2b2ef20424572d9ca4a9a76edc8 /Makefile | |
parent | rm go.mod (diff) | |
download | binder-81ebc234678af08692aad7f3c2d1128f6c2f75c4.tar.gz binder-81ebc234678af08692aad7f3c2d1128f6c2f75c4.tar.xz |
Makefile: Use "go tool {compile,link}" over "go {build,test}"
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 65 |
1 files changed, 47 insertions, 18 deletions
@@ -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)' \ |