This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
GNUmakefile
117 lines (85 loc) · 2.7 KB
/
GNUmakefile
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
108
109
110
111
112
113
114
115
116
117
SRCDIR = src
TESTSRCDIR = $(SRCDIR)/test
LIBSRCDIR = $(SRCDIR)/lib
BUILDDIR = build
LIBH = $(wildcard $(LIBSRCDIR)/*.h)
LIBSRC = $(wildcard $(LIBSRCDIR)/*.c)
MAINSRC := $(wildcard $(SRCDIR)/*.c)
LIBOBJ := $(LIBSRC:$(LIBSRCDIR)/%.c=$(BUILDDIR)/%.o)
MAINOBJ := $(MAINSRC:$(SRCDIR)/%.c=$(BUILDDIR)/%.o)
LIBNAME = $(BUILDDIR)/libhairgap.a
WIREHAIR = ./wirehair
LIBWIREHAIR = $(WIREHAIR)/bin/libwirehair.a
LIBWIREHAIR_DEBUG = $(WIREHAIR)/bin/libwirehair_debug.a
CC = clang
OPTFLAGS = -Ofast -D_FORTIFY_SOURCE=1
DBGFLAGS = -g -O0 -DDEBUG
IFLAGS = -I$(WIREHAIR)/include -I$(LIBSRCDIR)
GPRFLAGS = -pg -g
CFLAGS = -Wall -Wextra -fPIE -fstack-protector-strong \
-Wno-format-security \
-Werror \
$(IFLAGS)
LDFLAGS = $(IFLAGS) -L$(WIREHAIR)/bin -lpthread -lstdc++ -Wl,-z,now -Wl,-z,relro
INSTALLDIR=/usr/local
BIN=${INSTALLDIR}/bin
all: release
test: debug hgap_test channel_test
./hgap_test
./channel_test
./test/integration_tests.sh
doc: Doxyfile ${LIBSRC} ${MAINSRC} ${LIBH}
doxygen
# Installation
install: release
@echo "Installing to '${INSTALLDIR}'..."
install -d $(BIN)
install -m755 hairgaps hairgapr $(BIN)
@echo "Done."
uninstall:
@echo "Removing from '${INSTALLDIR}'..."
rm ${BIN}/hairgaps ${BIN}/hairgapr
@echo "Done."
# Targets
dirs: build
build:
mkdir -p build
debug: CFLAGS += $(DBGFLAGS)
debug: LIBWIREHAIR_CHOSEN := $(LIBWIREHAIR_DEBUG)
debug: dirs $(LIBWIREHAIR_DEBUG) hairgaps hairgapr
profile: CFLAGS += $(GPRFLAGS)
profile: LDFLAGS += -pg
profile: dirs release
release: CFLAGS += -D_FORTIFY_SOURCE=1 $(OPTFLAGS)
release: LIBWIREHAIR_CHOSEN := $(LIBWIREHAIR)
release: dirs $(LIBWIREHAIR) hairgaps hairgapr
clean:
-rm -r build
-cd wirehair && make clean
dist-clean: clean
-rm -r hairgaps hairgapr channel_test hgap_test doc/*
# Compilation
$(LIBNAME): $(LIBOBJ)
ar rcs $(LIBNAME) $^
hairgapr: $(BUILDDIR)/hairgapr.o $(LIBNAME)
$(CC) $^ -o $@ $(LDFLAGS) $(LIBWIREHAIR_CHOSEN)
hairgaps: $(BUILDDIR)/hairgaps.o $(LIBNAME)
$(CC) $^ -o $@ $(LDFLAGS) $(LIBWIREHAIR_CHOSEN)
$(BUILDDIR)/hairgapr.o: $(LIBSRCDIR)/proto.h
$(BUILDDIR)/hairgaps.o: $(LIBSRCDIR)/proto.h
$(BUILDDIR)/hairproto.o: $(LIBSRCDIR)/proto.h
$(BUILDDIR)/bufpool.o: $(LIBSRCDIR)/bufpool.h
$(LIBOBJ): $(BUILDDIR)/%.o:$(LIBSRCDIR)/%.c
$(CC) -c $< -o $@ $(CFLAGS)
$(MAINOBJ): $(BUILDDIR)/%.o:$(SRCDIR)/%.c
$(CC) -c $< -o $@ $(CFLAGS)
hgap_test: $(TESTSRCDIR)/hgap_test.c $(LIBNAME)
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS) $(LIBWIREHAIR_DEBUG)
channel_test: CFLAGS += $(OPTFLAGS)
channel_test: $(TESTSRCDIR)/channel_test.c $(LIBSRCDIR)/channel.c \
$(LIBSRCDIR)/common.c
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
$(LIBWIREHAIR):
cd $(WIREHAIR) && make clean && make
$(LIBWIREHAIR_DEBUG):
cd $(WIREHAIR) && make clean && make debug