summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 3adad360217bf44c9cbbe4a4809feea9a8883bf0 (plain) (blame)
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
PREFIX ?= /usr/local
INCLDIR ?= /include
LIBDIR ?= /lib

CFLAGS += -I include -I lib/liballoc/include
CFLAGS += -Wunused-function -Wunused-variable -Wno-prototype 
CFLAGS += -Wconversion -Wsign-compare -Werror

ifeq "$(DEBUG)" "1"
CFLAGS += -Og -g
else
CFLAGS += -O2
endif

ifeq "$(ASSERT_ARGS)" "1"
CFLAGS += -DLIBHMAP_ASSERT_ARGS=1
endif

ifeq "$(ASSERT_ALLOC)" "1"
CFLAGS += -DLIBHMAP_ASSERT_ALLLOC=1
endif

all: build/libhmap.so build/libhmap.a build/test

clean:
	rm -rf build

cleanall: clean
	make -C lib/liballoc cleanall

build:
	mkdir build

lib/liballoc/build/liballoc.a:
	make -C lib/liballoc build/liballoc.a

build/libhmap.a: src/hmap.c include/hmap.h libhmap.api | build
	$(CC) -o build/tmp.o src/hmap.c $(CFLAGS) -r
	objcopy --keep-global-symbols=libhmap.api build/tmp.o build/fixed.o
	$(AR) rcs $@ build/fixed.o

build/libhmap.so: src/hmap.c include/hmap.h libhmap.lds | build
	$(CC) -o $@ src/hmap.c -fPIC $(CFLAGS) -shared \
		-Wl,-version-script libhmap.lds

build/test: src/test.c build/libhmap.a lib/liballoc/build/liballoc.a  | build
	$(CC) -o $@ $^ -I include -I lib/liballoc/include -g

install:
	install -m 644 include/hmap.h -t "$(DESTDIR)$(PREFIX)$(INCLDIR)"
	install -m 755 build/libhmap.a -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
	install -m 755 build/libhmap.so -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"

uninstall:
	rm -f "$(DESTDIR)$(PREFIX)$(INCLDIR)/hmap.h"
	rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libhmap.a"
	rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libhmap.so"

.PHONY: all clean cleanall install uninstall