Debian Codegraph @

src/coucal/Makefile

raw
1 ###############################################################################
2 #
3 # coucal — Cuckoo-hashing hashtable with a stash area
4 #
5 ###############################################################################
6
7 # --- Toolchain (overridable) -------------------------------------------------
8 # cc/ar are the POSIX defaults; CI overrides CC with clang or "gcc -m32".
9 CC ?= cc
10 AR ?= ar
11 RM ?= rm -f
12 INSTALL ?= install
13 PREFIX ?= /usr/local
14
15 # --- Flags -------------------------------------------------------------------
16 # CFLAGS holds the user-overridable optimization/debug flags. Everything
17 # mandatory (PIC, reentrancy, strict warnings, the default hash backend) is
18 # appended with `override` so it survives a command-line CFLAGS=... — e.g. CI
19 # injecting sanitizer flags.
20 CFLAGS ?= -O3 -g
21
22 override CPPFLAGS += -D_REENTRANT -D_GNU_SOURCE -DHTS_INTHASH_USES_MURMUR
23 override CFLAGS += -fPIC -pthread \
24 -W -Wall -Wextra -Werror -Wno-unused-function
25
26 # --- Platform shared-library wiring ------------------------------------------
27 UNAME_S := $(shell uname -s)
28 ifeq ($(UNAME_S),Darwin)
29 SHLIB := libcoucal.dylib
30 SOFLAGS := -dynamiclib -install_name @rpath/$(SHLIB)
31 SOLIBS :=
32 else
33 SHLIB := libcoucal.so
34 SOFLAGS := -shared -Wl,-soname=$(SHLIB) -Wl,--no-undefined
35 SOLIBS := -ldl -lpthread
36 endif
37
38 STATICLIB := libcoucal.a
39
40 # --- Sources -----------------------------------------------------------------
41 LIBSRC := coucal.c
42 LIBOBJ := $(LIBSRC:.c=.o)
43 BINS := tests sample
44
45 # --- Targets -----------------------------------------------------------------
46 .PHONY: all check test clean dist install
47 .DEFAULT_GOAL := all
48
49 all: $(STATICLIB) $(SHLIB) $(BINS)
50
51 # Every object needs the public header; the library object also pulls in the
52 # bundled MurmurHash implementation.
53 %.o: %.c coucal.h
54 $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
55 coucal.o: murmurhash3.h
56
57 $(STATICLIB): $(LIBOBJ)
58 $(AR) rcs $@ $^
59
60 $(SHLIB): $(LIBOBJ)
61 $(CC) $(CFLAGS) $(SOFLAGS) $(LIBOBJ) -o $@ $(LDFLAGS) $(SOLIBS)
62
63 # tests/sample link the static archive: no LD_LIBRARY_PATH, identical run on
64 # Linux and macOS.
65 tests: tests.o $(STATICLIB)
66 $(CC) $(CFLAGS) $< $(STATICLIB) -o $@ $(LDFLAGS)
67 sample: sample.o $(STATICLIB)
68 $(CC) $(CFLAGS) $< $(STATICLIB) -o $@ $(LDFLAGS)
69
70 check test: tests
71 ./tests 100000
72
73 install: all
74 $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include
75 $(INSTALL) -m 644 $(STATICLIB) $(DESTDIR)$(PREFIX)/lib/
76 $(INSTALL) -m 755 $(SHLIB) $(DESTDIR)$(PREFIX)/lib/
77 $(INSTALL) -m 644 coucal.h $(DESTDIR)$(PREFIX)/include/
78
79 dist:
80 $(RM) coucal.tgz
81 tar cvfz coucal.tgz $(LIBSRC) coucal.h murmurhash3.h \
82 sample.c tests.c Makefile LICENSE README.md
83
84 clean:
85 $(RM) *.o $(STATICLIB) $(SHLIB) libcoucal.so.* $(BINS) coucal.tgz