forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
168 lines (135 loc) · 3.88 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-include Config.mk
################ Source files ##########################################
SRCS := $(wildcard *.cc)
INCS := $(wildcard *.h)
OBJS := $(addprefix $O,$(SRCS:.cc=.o))
DEPS := ${OBJS:.o=.d}
MKDEPS := Makefile Config.mk config.h $O.d
ONAME := $(notdir $(abspath $O))
SLIBL := $O$(call slib_lnk,${NAME})
SLIBS := $O$(call slib_son,${NAME})
SLIBT := $O$(call slib_tgt,${NAME})
SLINKS := ${SLIBL}
ifneq (${SLIBS},${SLIBT})
SLINKS += ${SLIBS}
endif
LIBA := $Olib${NAME}.a
################ Compilation ###########################################
.PHONY: all clean html check distclean maintainer-clean
ALLTGTS := ${MKDEPS}
all: ${ALLTGTS}
ifdef BUILD_SHARED
ALLTGTS += ${SLIBT} ${SLINKS}
all: ${SLIBT} ${SLINKS}
${SLIBT}: ${OBJS}
@echo "Linking $(notdir $@) ..."
@${LD} -fPIC ${LDFLAGS} $(call slib_flags,$(subst $O,,${SLIBS})) -o $@ $^ ${LIBS}
${SLINKS}: ${SLIBT}
@(cd $(dir $@); rm -f $(notdir $@); ln -s $(notdir $<) $(notdir $@))
endif
ifdef BUILD_STATIC
ALLTGTS += ${LIBA}
all: ${LIBA}
${LIBA}: ${OBJS}
@echo "Linking $(notdir $@) ..."
@rm -f $@
@${AR} qc $@ ${OBJS}
@${RANLIB} $@
endif
$O%.o: %.cc
@echo " Compiling $< ..."
@${CXX} ${CXXFLAGS} -MMD -MT "$(<:.cc=.s) $@" -o $@ -c $<
%.s: %.cc
@echo " Compiling $< to assembly ..."
@${CXX} ${CXXFLAGS} -S -o $@ -c $<
include test/Module.mk
################ Installation ##########################################
.PHONY: install uninstall install-incs uninstall-incs
####### Install headers
ifdef INCDIR # These ifdefs allow cold bootstrap to work correctly
LIDIR := ${INCDIR}/${NAME}
INCSI := $(addprefix ${LIDIR}/,$(filter-out ${NAME}.h,${INCS}))
RINCI := ${LIDIR}.h
install: install-incs
install-incs: ${INCSI} ${RINCI}
${LIDIR}:
@echo "Creating $@ ..."
@mkdir -p $@
${INCSI}: ${LIDIR}/%.h: %.h |${LIDIR}
@echo "Installing $@ ..."
@${INSTALLDATA} $< $@
${RINCI}: ${NAME}.h |${LIDIR}
@echo "Installing $@ ..."
@${INSTALLDATA} $< $@
uninstall: uninstall-incs
uninstall-incs:
@if [ -d ${LIDIR} -o -f ${RINCI} ]; then\
echo "Removing ${LIDIR}/ and ${RINCI} ...";\
rm -f ${INCSI} ${RINCI};\
${RMPATH} ${LIDIR};\
fi
endif
####### Install libraries (shared and/or static)
ifdef LIBDIR
LIBTI := ${LIBDIR}/$(notdir ${SLIBT})
LIBLI := $(addprefix ${LIBDIR}/,$(notdir ${SLINKS}))
LIBAI := ${LIBDIR}/$(notdir ${LIBA})
${LIBDIR}:
@echo "Creating $@ ..."
@mkdir -p $@
ifdef BUILD_SHARED
install: ${LIBTI} ${LIBLI}
${LIBTI}: ${SLIBT} |${LIBDIR}
@echo "Installing $@ ..."
@${INSTALLLIB} $< $@
${LIBLI}: ${LIBTI}
@(cd ${LIBDIR}; rm -f $@; ln -s $(notdir $<) $(notdir $@))
endif
ifdef BUILD_STATIC
install: ${LIBAI}
${LIBAI}: ${LIBA} |${LIBDIR}
@echo "Installing $@ ..."
@${INSTALLLIB} $< $@
endif
uninstall:
@echo "Removing library from ${LIBDIR} ..."
@rm -f ${LIBTI} ${LIBLI} ${LIBSI} ${LIBAI}
endif
ifdef PKGCONFIGDIR
PCI := ${PKGCONFIGDIR}/ustl.pc
install: ${PCI}
${PKGCONFIGDIR}:
@echo "Creating $@ ..."
@mkdir -p $@
${PCI}: ustl.pc |${PKGCONFIGDIR}
@echo "Installing $@ ..."
@${INSTALLDATA} $< $@
uninstall: uninstall-pc
uninstall-pc:
@if [ -f ${PCI} ]; then echo "Removing ${PCI} ..."; rm -f ${PCI}; fi
endif
################ Maintenance ###########################################
clean:
@if [ -h ${ONAME} ]; then\
rm -f ${OBJS} ${DEPS} ${SLIBT} ${SLINKS} ${LIBA} $O.d ${ONAME};\
${RMPATH} ${BUILDDIR} > /dev/null 2>&1 || true;\
fi
distclean: clean
@rm -f Config.mk config.h config.status
maintainer-clean: distclean
@if [ -d docs/html ]; then rm -f docs/html/*; rmdir docs/html; fi
$O.d: ${BUILDDIR}/.d
@[ -h ${ONAME} ] || ln -sf ${BUILDDIR} ${ONAME}
${BUILDDIR}/.d: Makefile
@mkdir -p ${BUILDDIR} && touch ${BUILDDIR}/.d
${OBJS}: ${MKDEPS}
Config.mk: Config.mk.in
config.h: config.h.in
ustl.pc: ustl.pc.in
Config.mk config.h ustl.pc: configure
@if [ -x config.status ]; then \
echo "Reconfiguring ..."; ./config.status; \
else \
echo "Running configure ..."; ./configure; \
fi
-include ${DEPS}