-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
122 lines (95 loc) · 3.37 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
.DEFAULT_GOAL := build
.PHONY:default
default: build ;
CLI_BIN := varnamcli
INSTALL_PREFIX := $(or ${PREFIX},${PREFIX},/usr/local)
LIBDIR := /lib
# Try to get the commit hash from git
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),"UNKNOWN")
VERSION := $(or $(shell echo $$(git describe --abbrev=0 --tags || echo "latest") | sed s/v//),"v0.0.0")
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
RELEASE_NAME := govarnam-${VERSION}-${shell uname -m}
UNAME := $(shell uname)
SED := sed
LIB_NAME := libgovarnam.so
SO_NAME := $(shell (echo $(VERSION) | cut -d. -f1))
CURDIR := $(shell pwd)
ifeq ($(UNAME), Darwin)
LIB_NAME = libgovarnam.dylib
else
EXT_LDFLAGS = -extldflags "-Wl,-soname,$(LIB_NAME).$(SO_NAME),--version-script,$(CURDIR)/govarnam.syms"
endif
VERSION_STAMP_LDFLAGS := -X 'github.com/varnamproject/govarnam/govarnam.BuildString=${BUILDSTR}' -X 'github.com/varnamproject/govarnam/govarnam.VersionString=${VERSION}' $(EXT_LDFLAGS)
pc:
${SED} -e "s#@INSTALL_PREFIX@#${INSTALL_PREFIX}#g" \
-e "s#@VERSION@#${VERSION}#g" \
-e "s#@LIBDIR@#${LIBDIR}#g" \
govarnam.pc.in > govarnam.pc.tmp
mv govarnam.pc.tmp govarnam.pc
# Used only for building the CLI
temp-pc:
${SED} -e "s#@INSTALL_PREFIX@#$(realpath .)#g" \
-e "s#@VERSION@#${VERSION}#g" \
-e "s#@LIBDIR@#${LIBDIR}#g" \
-e "s#/include/libgovarnam##g" \
-e "s#/lib\$$##g" \
govarnam.pc.in > govarnam.pc.tmp
mv govarnam.pc.tmp govarnam.pc
install.sh: install.sh.in
${SED} -e "s#@INSTALL_PREFIX@#${INSTALL_PREFIX}#g" \
-e "s#@VERSION@#${VERSION}#g" \
-e "s#@LIBDIR@#${LIBDIR}#g" \
-e "s#@LIB_NAME@#${LIB_NAME}#g" \
-e "s#@SO_NAME@#${SO_NAME}#g" \
install.sh.in > install.sh.tmp
mv install.sh.tmp install.sh
chmod +x install.sh
.PHONY: install
install: install.sh
./install.sh install
.PHONY: uninstall
uninstall: install.sh
./install.sh uninstall
.PHONY: cli
cli:
go build -o ${CLI_BIN} -ldflags "-s -w" ./cli
library-nosqlite:
CGO_ENABLED=1 go build -tags "fts5,libsqlite3" -buildmode=c-shared -ldflags "-s -w ${VERSION_STAMP_LDFLAGS}" -o ${LIB_NAME} .
library:
CGO_ENABLED=1 go build -tags "fts5" -buildmode=c-shared -ldflags "-s -w ${VERSION_STAMP_LDFLAGS}" -o ${LIB_NAME} .
ln -sf "$(realpath ./)/libgovarnam.so" "$(realpath ./)/libgovarnam.so.${SO_NAME}"
library-mac-universal:
GOOS=darwin GOARCH=arm64 $(MAKE) library
mv ${LIB_NAME} ${LIB_NAME}.arm64
GOOS=darwin GOARCH=amd64 $(MAKE) library
mv ${LIB_NAME} ${LIB_NAME}.amd64
lipo -create -output ${LIB_NAME} ${LIB_NAME}.arm64 ${LIB_NAME}.amd64
.PHONY: nix
nix:
$(MAKE) library
$(MAKE) temp-pc
PKG_CONFIG_PATH=$(realpath .):$$PKG_CONFIG_PATH $(MAKE) cli
$(MAKE) pc
$(MAKE) install.sh
.PHONY:
build:
$(MAKE) nix
release:
echo "Hope you have updated version in constants.go"
mkdir -p ${RELEASE_NAME}
cp ${CLI_BIN} ${RELEASE_NAME}/
cp libgovarnam.so* ${RELEASE_NAME}/
cp *.h ${RELEASE_NAME}/
cp *.pc ${RELEASE_NAME}/
cp install.sh ${RELEASE_NAME}/
zip -r ${RELEASE_NAME}.zip ${RELEASE_NAME}/*
test-govarnamgo:
$(MAKE) temp-pc
PKG_CONFIG_PATH=$(realpath .):$$PKG_CONFIG_PATH LD_LIBRARY_PATH=$(realpath .):$$LD_LIBRARY_PATH govarnamgo/run_tests.sh
test:
go test -tags fts5 -count=1 -cover govarnam/*.go
$(MAKE) library
$(MAKE) test-govarnamgo
.PHONY: clean
clean:
rm -f varnamcli libgovarnam.* govarnam.pc install.sh