-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
73 lines (52 loc) · 2.17 KB
/
Makefile
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
60
61
62
63
64
65
66
67
68
69
70
71
CC := clang
CFLAGS := -ggdb3 -march=native -Wall -Wno-unused -O3 -D_GNU_SOURCE # -flto -B/home/abyrd/svn/binutils/build/gold/ld-new -use-gold-plugin
LIBS := -lzmq -lczmq -lm -lwebsockets -lprotobuf-c
SOURCES := $(wildcard *.c)
OBJECTS := $(SOURCES:.c=.o)
BINS := workerrrr-web workerrrr brrrroker client lookup-console testerrrr explorerrrr rrrrealtime otp_api otp_client struct_test rrrrealtime-viz profile testerrrr-viz
HEADERS := $(wildcard *.h)
BIN_BASES := $(subst rrrr,r,$(BINS))
BIN_SOURCES := $(BIN_BASES:=.c)
BIN_OBJECTS := $(BIN_BASES:=.o)
LIB_SOURCES := $(filter-out $(BIN_SOURCES),$(SOURCES))
LIB_OBJECTS := $(filter-out $(BIN_OBJECTS),$(OBJECTS))
LIB_NAME := librrrr.a
.PHONY: clean show check all
all: $(BINS)
# make an archived static library to link into all executables
librrrr.a: $(LIB_OBJECTS)
ar crsT $(LIB_NAME) $(LIB_OBJECTS)
# recompile everything if any headers change
%.o: %.c $(HEADERS)
$(CC) -c $(CFLAGS) $*.c -o $*.o
# re-expand variables in subsequent rules
.SECONDEXPANSION:
# each binary depends on its own .o file and the library
$(filter-out testerrrr-viz,$(filter-out rrrrealtime-viz,$(BINS))): $$(subst rrrr,r,$$@).o $(LIB_NAME)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
# *-viz is exceptional and compiled separately because it uses libSDL, libGL, and libshp
realtime-viz.o: realtime-viz.c
$(CC) -c $(CFLAGS) $(shell sdl-config --cflags) $^ -o $@
tester-viz-sdl.o: tester-viz-sdl.c
$(CC) -c $(CFLAGS) $(shell sdl-config --cflags) $^ -o $@
rrrrealtime-viz: realtime-viz.o $(LIB_NAME)
$(CC) $(CFLAGS) $(shell sdl-config --cflags) $^ $(LIBS) -lSDL -lGL -lshp -lX11 -lGLU -o $@
testerrrr-viz: tester-viz.o $(LIB_NAME)
$(CC) $(CFLAGS) $(shell sdl-config --cflags) $^ $(LIBS) -lSDL -lGL -lshp -lX11 -lGLU -o $@
clean:
rm -f *.o *.d *.a *~ core $(BINS)
rm -f tests/*.o tests/*~ run_tests
show:
# $(SOURCES)
# $(OBJECTS)
# $(BIN_BASES)
# $(BIN_OBJECTS)
# $(OTHER_OBJECTS)
# TESTS using http://check.sourceforge.net/
TEST_SOURCES := $(wildcard tests/*.c)
TEST_OBJECTS := $(TEST_SOURCES:.c=.o)
TEST_LIBS := -lcheck -lprotobuf-c -lm
check: run_tests
./run_tests
run_tests: $(TEST_OBJECTS) $(LIB_NAME)
$(CC) $(CFLAGS) $^ $(TEST_LIBS) -o run_tests