]> pd.if.org Git - nbds/blob - makefile
code cleanup
[nbds] / makefile
1 ###################################################################################################
2 # Written by Josh Dybnis and released to the public domain, as explained at
3 # http://creativecommons.org/licenses/publicdomain
4 #
5 ###################################################################################################
6 # Makefile for building programs with whole-program interfile optimization
7 ###################################################################################################
8 OPT        := -fwhole-program -combine -03# -DNDEBUG
9 CFLAGS := -g -Wall -Werror -std=c99 -m64 $(OPT) #-DENABLE_TRACE
10 INCS   := $(addprefix -I, include)
11 TESTS  := output/ll_test output/sl_test output/ht_test output/rcu_test
12 EXES   := $(TESTS)
13
14 RUNTIME_SRCS  := runtime/runtime.c runtime/rcu.c runtime/lwt.c runtime/mem.c
15 TEST_SRCS     := $(RUNTIME_SRCS)
16 rcu_test_SRCS := $(TEST_SRCS) test/rcu_test.c
17 txn_test_SRCS := $(TEST_SRCS) struct/hashtable.c txn/txn.c
18 ll_test_SRCS  := $(TEST_SRCS) struct/list.c test/ll_test.c struct/nstring.c
19 sl_test_SRCS  := $(TEST_SRCS) struct/skiplist.c test/sl_test.c struct/nstring.c
20 ht_test_SRCS  := $(TEST_SRCS) struct/hashtable.c test/ht_test.c test/CuTest.c struct/nstring.c
21
22 tests: $(TESTS)
23
24 ###################################################################################################
25 # Run the tests
26 ###################################################################################################
27 test: $(addsuffix .log, $(TESTS))
28         @echo > /dev/null
29
30 $(addsuffix .log, $(TESTS)) : %.log : %
31         @echo "Running $*" && $* | tee $*.log
32
33 ###################################################################################################
34 # Rebuild an executable if any of it's source files need to be recompiled
35 #
36 # Note: Calculating dependencies as a side-effect of compilation is disabled. There is a bug in
37 #               gcc. Compilation fails when -MM -MF is used and there is more than one source file.
38 #               Otherwise "-MM -MT $@.d -MF $@.d" should be part of the command line for the compile.
39 #
40 #       Also, when calculating dependencies -combine is removed from CFLAGS because of another bug 
41 #               in gcc. It chokes when -MM is used with -combine.
42 ###################################################################################################
43 $(EXES): output/% : output/%.d makefile
44         gcc $(CFLAGS:-combine:) $(INCS) -MM -MT $@ $($*_SRCS) > $@.d
45         gcc $(CFLAGS) $(INCS) -o $@ $($*_SRCS)
46
47 ###################################################################################################
48 # Build tags file for vi
49 ###################################################################################################
50 tags:
51         ctags -R .
52
53 ###################################################################################################
54 #
55 ###################################################################################################
56 clean:
57         rm -rfv output/*
58
59 .PHONY: clean test tags
60
61 -include $(addsuffix .d, $(EXES))
62
63 ###################################################################################################
64 # Dummy rule for boostrapping dependency files
65 ###################################################################################################
66 $(addsuffix .d, $(EXES)) : output/%.d :
67         touch $@