forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (117 loc) · 3.43 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
-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))
################ Compilation ###########################################
.PHONY: all clean html check distclean maintainer-clean
ALLTGTS := ${MKDEPS}
all: ${ALLTGTS}
ifdef BUILD_SHARED
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
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
LIBA := $Olib${NAME}.a
ALLTGTS += ${LIBA}
all: ${LIBA}
${LIBA}: ${OBJS}
@echo "Linking $@ ..."
@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 bvt/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}
${INCSI}: ${LIDIR}/%.h: %.h
@echo "Installing $@ ..."
@${INSTALLDATA} $< $@
${RINCI}: ${NAME}.h
@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
ifdef BUILD_SHARED
LIBTI := ${LIBDIR}/$(notdir ${SLIBT})
LIBLI := $(addprefix ${LIBDIR}/,$(notdir ${SLINKS}))
install: ${LIBTI} ${LIBLI}
${LIBTI}: ${SLIBT}
@echo "Installing $@ ..."
@${INSTALLLIB} $< $@
${LIBLI}: ${LIBTI}
@(cd ${LIBDIR}; rm -f $@; ln -s $(notdir $<) $(notdir $@))
endif
ifdef BUILD_STATIC
LIBAI := ${LIBDIR}/$(notdir ${LIBA})
install: ${LIBAI}
${LIBAI}: ${LIBA}
@echo "Installing $@ ..."
@${INSTALLLIB} $< $@
endif
uninstall:
@echo "Removing library from ${LIBDIR} ..."
@rm -f ${LIBTI} ${LIBLI} ${LIBSI} ${LIBAI}
endif
################ Maintenance ###########################################
clean:
@if [ -h ${ONAME} ]; then\
rm -f ${OBJS} ${DEPS} ${SLIBT} ${SLINKS} ${LIBA} $O.d ${ONAME};\
${RMPATH} ${BUILDDIR};\
fi
html: ${SRCS} ${INCS} ${NAME}doc.in
@${DOXYGEN} ${NAME}doc.in
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
Config.mk config.h: configure
@if [ -x config.status ]; then \
echo "Reconfiguring ..."; ./config.status; \
else \
echo "Running configure ..."; ./configure; \
fi
-include ${DEPS}