-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
94 lines (69 loc) · 2.19 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
VERSION=0.1.6
SOVERSION=0
NAME=liboleg.so
BIN=olegdb
CFLAGS=-Wall -Werror -g -O2 -Wstrict-aliasing=2 -Wno-format-truncation
SOFLAGS=-Wl,-soname,$(NAME).$(SOVERSION)
OBJ_FILES=vector.o murmur3.o oleg.o logging.o aol.o rehash.o file.o utils.o tree.o lz4.o stack.o cursor.o transaction.o
CGO_CFLAGS=-I$(PWD)/include
CGO_LDFLAGS=-L$(PWD) -loleg
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
DESTDIR?=
PREFIX?=${DESTDIR}/usr
INSTALL_LIB=$(PREFIX)/lib/
INSTALL_BIN=$(PREFIX)/bin/
INSTALL_INCLUDE=$(PREFIX)/include/olegdb/
TEST_OUT=liboleg.test
LIB_OUT=$(NAME).$(VERSION)
STATIC_LIB_OUT=liboleg.a
INCLUDES=-I./include
ifndef CC
CC = gcc
endif
MATH_LINKER=-lm
all: $(TEST_OUT) $(BIN)
test.o: ./src/test.c
$(CC) $(CFLAGS) $(INCLUDES) -c $<
main.o: ./src/main.c
$(CC) $(CFLAGS) $(INCLUDES) -c $<
%.o: ./src/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c -fPIC $<
$(TEST_OUT): liboleg test.o main.o
$(CC) $(INCLUDES) -L$(PWD) -o $(TEST_OUT) test.o main.o $(MATH_LINKER) -loleg
liboleg: $(LIB_OUT)
$(LIB_OUT): $(OBJ_FILES)
$(CC) $(INCLUDES) $(SOFLAGS) -o $(LIB_OUT) $^ -fpic -shared $(MATH_LINKER)
ln -s $(LIB_OUT) $(NAME)
ln -s $(LIB_OUT) $(NAME).$(SOVERSION)
static: $(LIB_OUT) $(OBJ_FILES)
ar rcs $(STATIC_LIB_OUT) $(OBJ_FILES)
uninstall:
rm -rf $(INSTALL_LIB)liboleg*
rm -rf $(INSTALL_BIN)olegdb
rm -rf $(INSTALL_INCLUDE)
$(BIN): liboleg $(LIB_OUT)
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $(BIN) ./cmd/olegdb
install: goinstall
goinstall: olegdb libinstall
@install -D $(BIN) $(INSTALL_BIN)olegdb
libinstall: liboleg
@mkdir -p $(INSTALL_LIB)
@mkdir -p $(INSTALL_INCLUDE)
@install $(LIB_OUT) $(INSTALL_LIB)$(NAME).$(VERSION)
@ln -fsr $(INSTALL_LIB)$(NAME).$(VERSION) $(INSTALL_LIB)$(NAME)
@ln -fsr $(INSTALL_LIB)$(NAME).$(VERSION) $(INSTALL_LIB)$(NAME).$(SOVERSION)
@install ./include/*.h $(INSTALL_INCLUDE)
@echo "OlegDB installed to $(PREFIX) :^)."
test: $(LIB_OUT) $(TEST_OUT) testc testgo
testc:
./run_tests.sh
testgo:
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go test -v ./...
clean:
rm -f $(BIN)
rm -f $(NAME)
rm -f $(NAME).$(SOVERSION)
rm -f $(NAME).$(VERSION)
rm -f $(TEST_OUT)
rm -f *.o
.PHONY: clean test libinstall install uninstall static all