default to pic and helpful
[sddekit.git] / makefile
blobf865fad622edba0cfc202a6b8c780def9c31d3ab
1 # copyright 2016 Apache 2 sddekit authors
3 CC=gcc
4 LDFLAGS = -lm
5 VALFLAGS = --error-exitcode=1 --track-origins=yes --leak-check=full
6 CFLAGS = -fPIC -std=c99 -Isrc
8 # various build types {{{
9 ifeq ($(BUILD),fast)
10 CFLAGS += -Ofast
11 else ifeq ($(BUILD),cov)
12 CFLAGS += -pg -fprofile-arcs -ftest-coverage
13 else
14 CFLAGS += -Wall -Wextra -O0 -g
15 endif
16 # }}}
18 # file lists {{{
19 c_lib=$(wildcard src/*.c)
20 c_test=$(wildcard test/test_*.c)
21 o_lib=$(patsubst src/%.c,%.o,$(c_lib))
22 o_test=$(patsubst test/%.c,%.o,$(c_test))
23 # }}}
25 # platform specific stuff (http://stackoverflow.com/q/19928965) {{{
26 ifeq ($(OS),Windows_NT)
27 DLLEXT=dll
28 RM=del /f
29 EXE=.exe
30 else
31 DLLEXT=so
32 RM=rm -f
33 EXE=
34 endif
35 # except mac
36 ifeq ($(OS),Darwin)
37 DLLEXT=dylib
38 endif
39 ifdef COMSPEC
40 SHELL := $(COMSPEC)
41 endif
42 # }}}
44 # artifacts {{{
46 help:
47 echo "make tests$(EXE) | libSDDEKit.$(DLLEXT) | clean"
49 tests$(EXE): $(o_lib) $(o_test)
50 $(CC) $(CFLAGS) test/main.c $^ -o tests$(BUILD)$(EXE) $(LDFLAGS)
52 libSDDEKit.$(DLLEXT): $(o_lib)
53 $(CC) -shared $^ -o libSDDEKit.$(DLLEXT) $(LDFLAGS)
55 clean:
56 $(RM) $(o_lib) $(o_test) tests* *.dat *.exe *.$(DLLEXT)
58 # }}}
60 # generic rules {{{
62 %.o: src/%.c
63 $(CC) $(CFLAGS) -c $< $(LDFLAGS)
65 %.o: test/%.c
66 $(CC) $(CFLAGS) -c $< $(LDFLAGS)
68 %: bench/%.c $(o_lib)
69 $(CC) $(CFLAGS) $< $(o_lib) $(LDFLAGS)
71 # }}}
73 # vim: foldmethod=marker