-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
87 lines (70 loc) · 2.57 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
.PHONY: default clean libs test examples install uninstall doxygen
SRC = src
BIN = bin
CFILES = $(wildcard $(SRC)/*.c) $(wildcard $(SRC)/*/*.c)
OFILES = $(patsubst %.c,%.o,$(CFILES))
TESTFILES = $(wildcard test/*)
EXAMPLES = $(wildcard example/*.c)
CC = cc
CCFLAGS += -Wall -Wextra -pedantic -std=c11 -Wstrict-prototypes -I./include -g -fPIC -O3 $(FLAGS)
AR = ar
ARFLAGS = rcs
INSTALL_PATH ?= /usr/local
default: libs
libs: $(OFILES) | $(BIN)/
@ echo " => $(BIN)/libGDS.so"
@ $(CC) $(CCFLAGS) -shared -o ./$(BIN)/libGDS.so $(OFILES)
@ echo " => $(BIN)/libGDS-static.a"
@ $(AR) $(ARFLAGS) ./$(BIN)/libGDS-static.a $(OFILES)
install: $(BIN)/libGDS.so $(BIN)/libGDS-static.a
@ echo " INSTALL $(INSTALL_PATH)/lib/libGDS.so"
@ echo " INSTALL $(INSTALL_PATH)/lib/libGDS-static.a"
@ mkdir -p -m 755 $(INSTALL_PATH)/lib
@ cp $(BIN)/libGDS* $(INSTALL_PATH)/lib
@ chmod 644 $(INSTALL_PATH)/lib/libGDS*
@ echo " INSTALL $(INSTALL_PATH)/include/GDS/"
@ mkdir -p -m 755 $(INSTALL_PATH)/include
@ cp -r include $(INSTALL_PATH)/include/GDS
@ chmod -R 644 $(INSTALL_PATH)/include/GDS
@ find $(INSTALL_PATH)/include/GDS -type d -exec chmod 755 {} \;
$(BIN)/libGDS.so $(BIN)/libGDS-static.a:
@ $(MAKE) --no-print-directory libs
uninstall:
@ echo " RM $(INSTALL_PATH)/lib/libGDS.so"
@ echo " RM $(INSTALL_PATH)/lib/libGDS-static.a"
@ rm -f $(INSTALL_PATH)/lib/libGDS*
@ echo " RM $(INSTALL_PATH)/include/GDS/"
@ rm -rf $(INSTALL_PATH)/include/GDS
NO-RUN?= false # If true, only builds the test, without running them
test: $(TESTFILES) libs | $(BIN)/
@ $(foreach T,$(filter %.c,$(TESTFILES)), \
$(CC) $(CCFLAGS) -o $(BIN)/$(patsubst %.c,%.out, $(notdir $(T))) $(T) -L./$(BIN)/ -lGDS-static; \
$(NO-RUN) || $(BIN)/$(patsubst %.c,%.out, $(notdir $(T))) || exit 1;)
examples: $(EXAMPLES) $(OFILES) | $(BIN)/
@ $(foreach F,$(EXAMPLES), \
echo " CC $(F)" ; \
$(CC) $(CCFLAGS) -o $(patsubst example/%.c,bin/%,$(F)) $(F) $(OFILES) ;)
doxygen: ./doxygen/
@ echo -e "\
/** @mainpage \n \
@verbinclude README.adoc */" > ./doxygen/doc.doxy
@ echo "/**" >> doxygen/doc.doxy
@ find ./include -name '*.h' -exec bash -c ' \
name={} ; base=$$(basename $$name) ; \
echo -n " * @file $$name " >> doxygen/doc.doxy ; \
cat $$name | grep $$base | sed "s/.*$$base -//"' >> doxygen/doc.doxy \;
@ echo "*/" >> doxygen/doc.doxy
doxygen .doxyfile
@ rm -f doxygen/doc.doxy
.c.o:
@ echo " CC $@"
@ $(CC) $(CCFLAGS) -o $@ -c $<
%/:
@ mkdir $@
clangd:
@ echo -e \
"CompileFlags: \n" \
"Add: [ -I$(shell pwd)/include/ , -xc ]" > .clangd
clean:
@ rm -f $(OFILES)
@ rm -rf doxygen bin