forked from asg017/sqlite-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
91 lines (70 loc) · 2.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
COMMIT=$(shell git rev-parse HEAD)
VERSION=$(shell cat VERSION)
DATE=$(shell date +'%FT%TZ%z')
GO_BUILD_LDFLAGS=-ldflags '-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE)'
GO_BUILD_CGO_CFLAGS=CGO_CFLAGS=-DSQLITE3_INIT_FN=sqlite3_html_init
ifeq ($(shell uname -s),Darwin)
CONFIG_DARWIN=y
else ifeq ($(OS),Windows_NT)
CONFIG_WINDOWS=y
else
CONFIG_LINUX=y
endif
# framework stuff is needed bc https://github.com/golang/go/issues/42459#issuecomment-896089738
ifdef CONFIG_DARWIN
LOADABLE_EXTENSION=dylib
SQLITE3_CFLAGS=-framework CoreFoundation -framework Security
endif
ifdef CONFIG_LINUX
LOADABLE_EXTENSION=so
endif
ifdef CONFIG_WINDOWS
LOADABLE_EXTENSION=dll
endif
TARGET_LOADABLE=dist/html0.$(LOADABLE_EXTENSION)
TARGET_OBJ=dist/html0.o
TARGET_SQLITE3=dist/sqlite3
TARGET_PACKAGE=dist/package.zip
loadable: $(TARGET_LOADABLE)
sqlite3: $(TARGET_SQLITE3)
package: $(TARGET_PACKAGE)
all: loadable sqlite3 package
$(TARGET_LOADABLE): $(shell find . -type f -name '*.go')
$(GO_BUILD_CGO_CFLAGS) go build -buildmode=c-shared -tags="shared" \
$(GO_BUILD_LDFLAGS) \
-o $@ .
$(TARGET_OBJ): $(shell find . -type f -name '*.go')
$(GO_BUILD_CGO_CFLAGS) CGO_ENABLED=1 go build -buildmode=c-archive \
$(GO_BUILD_LDFLAGS) \
-o $@ .
# I don't think we can include DSQLITE_OMIT_LOAD_EXTENSION - maybe riyaz-ali/sqlite uses it?
# add back later -DHAVE_READLINE -lreadline -lncurses
$(TARGET_SQLITE3): $(TARGET_OBJ) dist/sqlite3-extra.c sqlite/shell.c
gcc \
$(SQLITE3_CFLAGS) \
-lm -pthread \
dist/sqlite3-extra.c sqlite/shell.c $(TARGET_OBJ) \
-L. -I./sqlite \
-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
-DSQLITE_EXTRA_INIT=core_init -DSQLITE3_INIT_FN=sqlite3_html_init \
-o $@
$(TARGET_PACKAGE): $(TARGET_LOADABLE) $(TARGET_OBJ) sqlite/sqlite-html.h $(TARGET_SQLITE3)
zip --junk-paths $@ $(TARGET_LOADABLE) $(TARGET_OBJ) sqlite/sqlite-html.h $(TARGET_SQLITE3)
dist/sqlite3-extra.c: sqlite/sqlite3.c sqlite/core_init.c
cat sqlite/sqlite3.c sqlite/core_init.c > $@
clean:
rm dist/*
test:
make test-loadable
make test-sqlite3
test-loadable: loadable
python3 tests/test-loadable.py
test-loadable-watch: $(TARGET_LOADABLE)
watchexec -w . -w $(TARGET_LOADABLE) -w tests/test-loadable.py --clear -- make test-loadable
test-sqlite3: sqlite3
python3 tests/test-sqlite3.py
format:
gofmt -s -w .
.PHONY: all clean format \
test test-loadable test-sqlite3 \
loadable sqlite3 package