-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
94 lines (71 loc) · 2.51 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
LBITS := $(shell getconf LONG_BIT)
PTHREAD_PATH=
# FIXME: only work for debian and archlinux systems
ifeq ($(LBITS),64)
PTHREAD_PATH=/usr/lib
else
PTHREAD_PATH=/usr/lib/i386-linux-gnu
endif
#-GCC-------------------------------------------------
GCC=gcc
GCC_FLAGS=-Wall -Wextra -O3
GCC_LIBS=-lgenerics
GCC_STATIC_LIBS=$(PTHREAD_PATH)/libpthread.a /usr/lib/libgenerics.a
GCC_SHARED_LIBS=$(PTHREAD_PATH)/libpthread.so /usr/lib/libgenerics.so
#-VARIABLE--------------------------------------------
SRC_PATH=src
HEADER_PATH=include
BUILD_PATH=build
SOURCES=$(wildcard $(SRC_PATH)/*.c)
HEADERS=$(wildcard $(HEADER_PATH)/*.h)
OBJ_PATH=$(BUILD_PATH)/obj
TK_OBJ=$(OBJ_PATH)/tk.o
# libs
LIB_STATIC_PATH=$(BUILD_PATH)/lib/static
LIB_STATIC=$(LIB_STATIC_PATH)/libtk.a
LIB_SHARED_PATH=$(BUILD_PATH)/lib/shared
LIB_SHARED=$(LIB_SHARED_PATH)/libtk.so
# install
INSTALL_HEADER_PATH=/usr/include/tk.h
INSTALL_STATIC_PATH=/usr/lib/libtk.a
INSTALL_SHARED_PATH=/usr/lib/libtk.so
# doc
DOC_PATH=doc
DOX_LATEX=$(DOC_PATH)/doxygen/latex
DOX=$(DOX_LATEX) $(DOC_PATH)/html $(DOC_PATH)/man
MAN_PATH=$(DOC_PATH)/tk.3
#-OBJ-------------------------------------------------
all: $(TK_OBJ) $(LIB_STATIC) $(LIB_SHARED)
$(BUILD_PATH):
[ -d $(BUILD_PATH) ] || mkdir -p $(BUILD_PATH)
$(OBJ_PATH): $(BUILD_PATH)
[ -d $(OBJ_PATH) ] || mkdir -p $(OBJ_PATH)
$(TK_OBJ): $(OBJ_PATH) $(SOURCES) $(HEADERS)
$(GCC) -c -o $(TK_OBJ) $(SOURCES) -I $(HEADER_PATH) $(GCC_FLAGS) $(GCC_LIBS)
#-LIBRARIES-------------------------------------------
$(LIB_STATIC_PATH):
[ -d $(LIB_STATIC_PATH) ] || mkdir -p $(LIB_STATIC_PATH)
$(LIB_SHARED_PATH):
[ -d $(LIB_SHARED_PATH) ] || mkdir -p $(LIB_SHARED_PATH)
$(LIB_STATIC): $(LIB_STATIC_PATH) $(TK_OBJ)
ar -cvq $(LIB_STATIC) $(TK_OBJ) $(GCC_STATIC_LIBS)
$(LIB_SHARED): $(LIB_SHARED_PATH) $(TK_OBJ)
$(GCC) -fPIC -c $(SOURCES) -I $(HEADER_PATH) $(GCC_FLAGS) $(GCC_LIBS)
mv *.o $(LIB_SHARED_PATH)
$(GCC) -shared -Wl,-soname,libtk.so -o $(LIB_SHARED) $(LIB_SHARED_PATH)/*.o $(GCC_SHARED_LIBS)
#-INSTALLATION----------------------------------------
install: $(HEADERS) $(LIB_STATIC) $(LIB_SHARED)
-cp $(MAN_PATH) /usr/share/man/man3
cp $(HEADERS) $(INSTALL_HEADER_PATH)
cp $(LIB_STATIC) $(INSTALL_STATIC_PATH)
cp $(LIB_SHARED) $(INSTALL_SHARED_PATH)
uninstall:
rm $(INSTALL_HEADER_PATH)
rm $(INSTALL_STATIC_PATH)
rm $(INSTALL_SHARED_PATH)
#-DOC-------------------------------------------------
$(DOX): .dox $(SOURCES) $(HEADERS)
doxygen .dox
$(DOC_PATH)/dox.pdf: $(DOX_LATEX)
make -C $(DOX_LATEX)
cp $(DOX_LATEX)/refman.pdf $(DOC_PATH)/doc.pdf