-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakefile
108 lines (84 loc) · 2.47 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
SHELL = /bin/sh
.SUFFIXES:
PLATFORM=$(shell uname)
ARCH=$(shell uname -m)
# Basically we want to use gcc with c11 semantics
ifndef CC
CC=gcc -std=gnu11
else ifeq "$(CC)" "cc"
CC=gcc -std=gnu11
#else ifeq (,$(findstring gcc,$(CC)))
# CC=gcc -std=gnu11
else ifeq (,$(findstring std,$(CC)))
CC += -std=gnu11
endif
# We will rarely want a release build so only when release is defined
ifdef RELEASE
CFLAGS=-DNDEBUG -Wall -g -c -O3 -fms-extensions -march=native -fno-omit-frame-pointer
LDFLAGS=
ifeq "$(PLATFORM)" "Darwin"
#want to include -flto if using clang rather than gcc TODO lookup make &&
ifeq "clang" "$(findstring clang,$(CC))"
CC+= -Wno-microsoft # TODO look at removing use of the anon union
else
CFLAGS+=-Wa,-q # clang gives warning using this argument
LDFLAGS+=-fwhole-program
endif
else ifeq "$(OS)" "Windows_NT"
# Do nothing - link-time-opt seems to break the program on windwos
else
# using lto seems to make us slower on linux
#CC+=-flto -fuse-linker-plugin #lto-wrapper ignores our -Wa,-q
endif # Platform
else # Not RELEASE
CFLAGS=-g -Wall -c -O0 -fms-extensions
LDFLAGS=
endif # End RELEASE-IF
ifdef PROFILE
CFLAGS=-pg -Wall -c -O0 -fms-extensions -march=native
LDFLAGS=-pg
endif
ifdef SANIT
CC=clang -std=gnu11 -Wno-microsoft
CFLAGS+=-fsanitize=$(SANIT) -fno-omit-frame-pointer -O1
LDFLAGS+=-fsanitize=$(SANIT)
endif
# Use the doxygen checking feature if using clang
ifeq "clang" "$(findstring clang,$(CC))"
CFLAGS+=-Wdocumentation
endif
LDLIBS=-lm
ifeq "$(OS)" "Windows_NT"
LDLIBS+=-lws2_32
endif
ifeq "$(PLATFORM)" "SunOS"
LDLIBS+=-lsocket -lnsl
endif
# Define a function for adding .exe
ifeq "$(OS)" "Windows_NT"
wino = $(1).exe
else
wino = $(1)
endif
TARGETS := fountain server client
TARGETS := $(foreach target,$(TARGETS),$(call wino,$(target)))
TEST_TARGETS := fountain_test
TEST_TARGETS := $(foreach target,$(TEST_TARGETS),$(call wino,$(target)))
all: $(TARGETS)
tests: $(TEST_TARGETS)
tests: CFLAGS+= -DUNIT_TESTS
test: tests
./fountain_test
$(call wino,fountain): main.o fountain.o errors.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(call wino,server): server.o fountain.o errors.o mapping.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(call wino,client): client.o fountain.o errors.o mapping.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(call wino,fountain_test): fountain.o errors.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
%.o: %.c
$(CC) $(CFLAGS) $<
.PHONY: clean
clean:
rm -f *.o $(TARGETS) $(TEST_TARGETS)