aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: 8f282030fc90656a9904bdc79f15e1df6b5b7f2a (plain)
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
ifeq ($(PREFIX),)
	PREFIX := /usr/local
endif

ifeq ($(BINDIR),)
	BINDIR := /bin
endif

name := qidx
cmd := qidx

so_major := 0
so_minor := 1

CC=gcc


CFLAGS = -Wall -pedantic $(debug)
LDFLAGS := -lhts -lm -fPIC

# debug = -fsanitize=address -O2 -g
SRC_EXT:=%.c

_STD_BUILD=$(CC) $(CFLAGS) $(filter $(SRC_EXT) %.o, $^) -o $@
STD_BUILD=$(_STD_BUILD) $(LDFLAGS)
STD_COMPILE=$(_STD_BUILD) -fPIC -c

OBJS = ./util/hash.o
OBJS += ./util/prime_search.o
OBJS += ./util/prime_search.o
OBJS += ./util/sds/sds.o
OBJS += ./util/err.o
OBJS += ./qidx.o

devname = lib$(name).so
lib_so = lib$(name).so.$(so_major).$(so_minor)
soname = lib$(name).so.$(so_major)

make: $(cmd) $(lib_so)

$(cmd): ./main.c $(OBJS)
	$(STD_BUILD)

$(lib_so): $(OBJS)
	$(CC) $(LDFLAGS) -shared -Wl,-soname=$(soname) -fPIC -o $@ $^
	[ -n "$(soname)" ] && ln -s $(lib_so) $(soname) || true
	[ -n "$(devname)" ] && ln -s $(soname) $(devname) || true

clean:
	$(RM) $(cmd) $(OBJS) $(devname) $(lib_so) $(soname)
.PHONY: clean

%.o: %.c
	$(STD_COMPILE)

.PHONY: install
install:
	mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
	cp qidx.h $(DESTDIR)$(PREFIX)/include/qidx.h
	cp -d $(lib_so) $(soname) $(devname) $(DESTDIR)$(PREFIX)/lib/

.PHONY: uninstall
uninstall:
	rm -f $(DESTDIR)$(PREFIX)/include/qidx.h
	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
	[ -n "$(soname)" ] && rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) || true
	[ -n "$(devname)" ] && rm -f $(DESTDIR)$(PREFIX)/lib/$(devname) || true