aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-08-12 15:42:56 -0300
committerEuAndreh <eu@euandre.org>2024-08-12 15:52:16 -0300
commit6bbc33b9e998af7ee45cca86e1290474603dff48 (patch)
tree5d0aff47783bc20dcf3f7862afdba0445e4c2fae /Makefile
parentAdd Makefile and build skeleton (diff)
downloadgolite-6bbc33b9e998af7ee45cca86e1290474603dff48.tar.gz
golite-6bbc33b9e998af7ee45cca86e1290474603dff48.tar.xz
Build with "go tool" and hackishly bundle code from same package into one file each
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile55
1 files changed, 49 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index bb6e39d..65f5936 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,10 @@ LDLIBS =
.SUFFIXES:
-.SUFFIXES: .go .a .bin .bin-check
+.SUFFIXES: .go .a .c .o .bin .bin-check
+
+.c.o:
+ $(CC) $(iCFLAGS) -o $@ -c $<
@@ -30,10 +33,26 @@ all:
include deps.mk
+cgo-sources = \
+ src/_cgo_export.c \
+ src/_cgo_export.h \
+ src/_cgo_main.c \
+ src/_cgo_gotypes.go \
+ src/_cgo_import.go \
+ src/$(NAME).cgo1.go \
+ src/$(NAME).cgo2.c \
+
+libdeps = \
+ src/_cgo_import.go \
+ src/_cgo_gotypes.go \
+ src/$(NAME).cgo1.go \
+
objects = \
src/$(NAME).a \
tests/$(NAME).a \
tests/main.a \
+ $(cgo-sources) \
+ src/_cgo_.o \
sources = \
src/$(NAME).go \
@@ -42,6 +61,9 @@ sources = \
derived-assets = \
$(objects) \
tests/main.bin \
+ pack2.sentinel \
+ src/_cgo_export.o \
+ src/$(NAME).cgo2.o \
side-assets = \
@@ -54,16 +76,32 @@ all: $(derived-assets)
$(objects): Makefile
-src/$(NAME).a: src/$(NAME).go
+# src/$(NAME).a: src/$(NAME).go
tests/main.a: tests/main.go tests/$(NAME).a
-src/$(NAME).a tests/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
+$(cgo-sources): src/_cgo_.o
+src/_cgo_.o: src/$(NAME).go
+ go tool cgo --objdir $(@D) src/$(NAME).go
+
+src/_cgo_import.go: src/_cgo_.o
+ go tool cgo --dynpackage $(NAME) --dynimport src/_cgo_.o --dynout $@
+
+src/$(NAME).a: $(libdeps)
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $(libdeps)
+
+# FIXME dependency
+pack2.sentinel: src/$(NAME).a src/_cgo_export.o src/$(NAME).cgo2.o
+ go tool pack r $@ src/_cgo_export.o src/$(NAME).cgo2.o
+ touch $@
+
+tests/$(NAME).a: tests/$(NAME).go src/_cgo_gotypes.go src/$(NAME).cgo1.go src/_cgo_import.go src/_cgo_export.o src/$(NAME).cgo2.o
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) tests/$(NAME).go src/_cgo_gotypes.go src/$(NAME).cgo1.go src/_cgo_import.go
+ go tool pack r $@ src/_cgo_export.o src/$(NAME).cgo2.o
tests/main.bin: tests/main.a
- go tool link $(GOLDFLAGS) -o $@ -L $(@D) $*.a
+ go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '-lsqlite3' $*.a
@@ -94,6 +132,11 @@ check: check-unit check-integration
+bench: tests/main.bin
+ $(EXEC)tests/main.bin -test.bench '.*'
+
+
+
## Remove *all* derived artifacts produced during the build.
## A dedicated test asserts that this is always true.
clean: