forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
153 lines (126 loc) · 3.26 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
-include Config.mk
################ Source files ##########################################
srcs := $(wildcard *.cc)
incs := $(filter-out ${name}.h,$(sort $(wildcard *.h) config.h))
objs := $(addprefix $O,$(srcs:.cc=.o))
deps := ${objs:.o=.d}
confs := Config.mk config.h ${name}.pc
oname := $(notdir $(abspath $O))
liba_r := $Olib${name}.a
liba_d := $Olib${name}_d.a
ifdef debug
liba := ${liba_d}
else
liba := ${liba_r}
endif
################ Compilation ###########################################
.SUFFIXES:
.PHONY: all clean distclean maintainer-clean
all: ${liba}
${liba}: ${objs}
@echo "Linking $@ ..."
@rm -f $@
@${AR} qc $@ $^
@${RANLIB} $@
$O%.o: %.cc
@echo " Compiling $< ..."
@${CXX} ${cxxflags} -MMD -MT "$(<:.cc=.s) $@" -o $@ -c $<
ifndef debug
@strip -d -R .eh_frame $@
endif
%.s: %.cc
@echo " Compiling $< to assembly ..."
@${CXX} ${cxxflags} -S -o $@ -c $<
################ Installation ##########################################
.PHONY: install installdirs install-incs
.PHONY: uninstall uninstall-incs uninstall-lib uninstall-pc
ifdef includedir
incsd := ${DESTDIR}${includedir}/${name}
incsi := $(addprefix ${incsd}/,${incs})
incr := ${incsd}.h
${incsd}:
@echo "Creating $@ ..."
@${INSTALL} -d $@
${incsi}: ${incsd}/%.h: %.h | ${incsd}
@echo "Installing $@ ..."
@${INSTALL_DATA} $< $@
${incr}: ${name}.h | ${incsd}
@echo "Installing $@ ..."
@${INSTALL_DATA} $< $@
installdirs: ${incsd}
install: ${incsi} ${incr}
uninstall: uninstall-incs
uninstall-incs:
@if [ -d ${incsd} ]; then\
echo "Removing headers ...";\
rm -f ${incsi} ${incr};\
rmdir ${incsd};\
fi
endif
ifdef libdir
libad := ${DESTDIR}${libdir}
libai := ${libad}/$(notdir ${liba})
libai_r := ${libad}/$(notdir ${liba_r})
libai_d := ${libad}/$(notdir ${liba_d})
${libad}:
@echo "Creating $@ ..."
@${INSTALL} -d $@
${libai}: ${liba} | ${libad}
@echo "Installing $@ ..."
@${INSTALL_DATA} $< $@
installdirs: ${libad}
install: ${libai}
uninstall: uninstall-lib
uninstall-lib:
@if [ -f ${libai_r} -o -f ${libai_d} ]; then\
echo "Removing ${libai} ...";\
rm -f ${libai_r} ${libai_d};\
fi
endif
ifdef pkgconfigdir
pcd := ${DESTDIR}${pkgconfigdir}
pci := ${pcd}/${name}.pc
${pcd}:
@echo "Creating $@ ..."
@${INSTALL} -d $@
${pci}: ${name}.pc | ${pcd}
@echo "Installing $@ ..."
@${INSTALL_DATA} $< $@
installdirs: ${pcd}
install: ${pci}
uninstall: uninstall-pc
uninstall-pc:
@if [ -f ${pci} ]; then\
echo "Removing ${pci} ...";\
rm -f ${pci};\
fi
endif
################ Maintenance ###########################################
include test/Module.mk
clean:
@if [ -d ${builddir} ]; then\
rm -f ${liba_r} ${liba_d} ${objs} ${deps} $O.d;\
rmdir ${builddir};\
fi
distclean: clean
@rm -f ${oname} ${confs} config.status
maintainer-clean: distclean
${builddir}/.d: Makefile
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
@touch $@
$O.d: | ${builddir}/.d
@[ -h ${oname} ] || ln -sf ${builddir} ${oname}
$O%/.d: | $O.d
@[ -d $(dir $@) ] || mkdir $(dir $@)
@touch $@
${objs}: Makefile ${confs} | $O.d
Config.mk: Config.mk.in
config.h: config.h.in | Config.mk
${name}.pc: ${name}.pc.in | Config.mk
${confs}: configure
@if [ -x config.status ]; then echo "Reconfiguring ...";\
./config.status;\
else echo "Running configure ...";\
./configure;\
fi
-include ${deps}