diff options
Diffstat (limited to 'makefile')
-rw-r--r-- | makefile | 43 |
1 files changed, 35 insertions, 8 deletions
@@ -6,20 +6,24 @@ ifeq ($(BINDIR),) BINDIR := /bin endif -CMD=qidx +name := qidx +cmd := qidx + +so_major := 0 +so_minor := 1 CC=gcc -DEBUG := -fsanitize=address -O2 -CFLAGS := -Wall -pedantic -g -LDFLAGS := -lhts -lm +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) -c +STD_COMPILE=$(_STD_BUILD) -fPIC -c OBJS = ./util/hash.o OBJS += ./util/prime_search.o @@ -28,13 +32,36 @@ OBJS += ./util/sds/sds.o OBJS += ./util/err.o OBJS += ./qidx.o -make: $(CMD) +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) +$(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) + $(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 |