forked from augmentable-dev/flite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (55 loc) · 2.52 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
.PHONY: clean vet test test-cover lint
all: clean .build/flite.so .build/flite
# pass these flags to linker to suppress missing symbol errors in intermediate artifacts
export CGO_LDFLAGS = -Wl,--unresolved-symbols=ignore-in-object-files
ifeq ($(shell uname -s),Darwin)
export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup
endif
test: internal/sqlite/sqlite3.c
@CGO_LDFLAGS="${CGO_LDFLAGS}" go test -v -tags="libsqlite3,sqlite_json1" ./...
test-cover:
@CGO_LDFLAGS="${CGO_LDFLAGS}" go test -v -tags="libsqlite3,sqlite_json1" ./... -cover -covermode=count -coverprofile=coverage.out
@CGO_LDFLAGS="${CGO_LDFLAGS}" go tool cover -html=coverage.out
vet: internal/sqlite/sqlite3.c
@CGO_LDFLAGS="${CGO_LDFLAGS}" go vet -v -tags="libsqlite3,sqlite_json1" ./...
lint: internal/sqlite/sqlite3.c
@CGO_LDFLAGS="${CGO_LDFLAGS}" golangci-lint run --build-tags libsqlite3,sqlite_json1
.build/flite.so: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@CGO_CFLAGS="-DUSE_LIBSQLITE3" CPATH="${PWD}/internal/sqlite" \
go build -buildmode=c-shared -o $@ -tags="shared" shared.go
$(call log, $(GREEN), "built $@")
.build/flite: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@CGO_LDFLAGS="${CGO_LDFLAGS}" CGO_CFLAGS="-DUSE_LIBSQLITE3" CPATH="${PWD}/internal/sqlite" \
go build -o $@ -tags="sqlite_json1,static,!shared" main.go
$(call log, $(GREEN), "built $@")
# target to download latest sqlite3 amalgamation code
internal/sqlite/sqlite3.c:
$(call log, $(CYAN), "downloading sqlite3 amalgamation source v3.35.0")
$(eval SQLITE_DOWNLOAD_DIR = $(shell mktemp -d))
@curl -sSLo $(SQLITE_DOWNLOAD_DIR)/sqlite3.zip https://www.sqlite.org/2021/sqlite-amalgamation-3350000.zip
$(call log, $(GREEN), "downloaded sqlite3 amalgamation source v3.35.0")
$(call log, $(CYAN), "unzipping to $(SQLITE_DOWNLOAD_DIR)")
@(cd $(SQLITE_DOWNLOAD_DIR) && unzip sqlite3.zip > /dev/null)
@-rm $(SQLITE_DOWNLOAD_DIR)/sqlite-amalgamation-3350000/shell.c
$(call log, $(CYAN), "moving to internal/sqlite")
@mv $(SQLITE_DOWNLOAD_DIR)/sqlite-amalgamation-3350000/* internal/sqlite
clean:
$(call log, $(YELLOW), "nuking .build/")
@-rm -rf .build/
# ========================================
# some utility methods
# ASCII color codes that can be used with functions that output to stdout
RED := 1;31
GREEN := 1;32
ORANGE := 1;33
YELLOW := 1;33
BLUE := 1;34
PURPLE := 1;35
CYAN := 1;36
# log:
# print out $2 to stdout using $1 as ASCII color codes
define log
@printf "\033[$(strip $1)m-- %s\033[0m\n" $2
endef