1 # Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # You can watch what it's doing by:
19 # $ VERBOSE=1 make ... args ...
27 # Add these rules only when LIBTOOL is being used.
30 # JLIBTOOL - check if we're using the local (fast) jlibtool, rather
31 # than the GNU (slow) libtool shell script. If so, add rules
34 ifeq "${LIBTOOL}" "JLIBTOOL"
35 JLIBTOOL := ${BUILD_DIR}/make/jlibtool
37 # Add a rule to build jlibtool BEFORE any other targets. This
38 # means that we can use it to build the later targets.
39 all install: ${JLIBTOOL}
41 # Note that we need to use a compilation rule that does NOT
42 # include referencing ${LIBTOOL}, as we don't have a jlibtool
44 ${JLIBTOOL}: ${top_makedir}/jlibtool.c
45 $(Q)mkdir -p $(dir $@)
46 $(Q)echo CC jlibtool.c
51 .PHONY: jlibtool_clean
55 # Tell GNU Make to use this value, rather than anything specified
56 # on the command line.
57 override LIBTOOL := ${JLIBTOOL}
58 endif # else we're not using jlibtool
60 # When using libtool, it produces a '.libs' directory. Ensure that it
61 # is removed on "make clean", too.
67 $(Q)rm -rf ${BUILD_DIR}/.libs/
69 # Re-define compilers and linkers
72 COMPILE.c = ${LIBTOOL} --silent --mode=compile ${CC}
73 COMPILE.cxx = ${LIBTOOL} --mode=compile ${CXX}
74 LINK.c = ${LIBTOOL} --silent --mode=link ${CC}
75 LINK.cxx = ${LIBTOOL} --mode=link ${CXX}
76 PROGRAM_INSTALL = ${LIBTOOL} --silent --mode=install ${INSTALL}
79 # LIBTOOL_ENDINGS - Given a library ending in ".a" or ".so", replace that
80 # extension with ".la".
82 define LIBTOOL_ENDINGS
83 $(patsubst %.a,%.la,$(patsubst %.so,%.la,${1}))
86 # ADD_TARGET_RULE.la - Build a ".la" target.
90 define ADD_TARGET_RULE.la
91 # So "make ${1}" works
93 ${1}: $${${1}_BUILD}/${1}
95 # Create libtool library ${1}
96 $${${1}_BUILD}/${1}: $${${1}_OBJS} $${${1}_PRLIBS}
97 $(Q)$(strip mkdir -p $(dir $${${1}_BUILD}/${1}))
98 @$(ECHO) LINK $${${1}_BUILD}/${1}
99 $(Q)$${${1}_LINKER} -o $${${1}_BUILD}/${1} $${RPATH_FLAGS} $${LDFLAGS} \
100 $${${1}_LDFLAGS} $${${1}_OBJS} $${LDLIBS} $${${1}_LDLIBS} \
102 $(Q)$${${1}_POSTMAKE}
104 ifneq "${ANALYZE.c}" ""
105 scan.${1}: $${${1}_PLISTS}
109 # ADD_LOCAL_RULE.exe - Parametric "function" that adds a rule to build
110 # a local version of the target.
114 define ADD_LOCAL_RULE.exe
115 ${1}: $${${1}_BUILD}/$${LOCAL}${1}
117 # used to fix up RPATH for ${1} on install.
118 $${${1}_BUILD}/$${${1}_LOCAL}: $${${1}_OBJS} $${${1}_PRBIN} $${${1}_LOCAL_PRLIBS}
119 $(Q)$(strip mkdir -p $${${1}_BUILD}/${LOCAL}/)
120 $(Q)$${${1}_LINKER} -o $${${1}_BUILD}/$${LOCAL}${1} $${LOCAL_FLAGS} $${LDFLAGS} \
121 $${${1}_LDFLAGS} $${${1}_OBJS} $${${1}_LOCAL_PRLIBS} \
122 $${LDLIBS} $${${1}_LDLIBS}
123 $(Q)$${${1}_POSTMAKE}
126 # ADD_LOCAL_RULE.la - Parametric "function" that adds a rule to build
127 # a local version of the target.
131 define ADD_LOCAL_RULE.la
132 ${1}: $${${1}_BUILD}/$${LOCAL}${1}
134 # used to fix up RPATH for ${1} on install.
135 $${${1}_BUILD}/$${${1}_LOCAL}: $${${1}_OBJS} $${${1}_LOCAL_PRLIBS}
136 $(Q)$(strip mkdir -p $${${1}_BUILD}/${LOCAL}/)
137 $(Q)$${${1}_LINKER} -o $${${1}_BUILD}/$${LOCAL}${1} $${LOCAL_FLAGS} $${LDFLAGS} \
138 $${${1}_LDFLAGS} $${${1}_OBJS} $${LDLIBS} $${${1}_LDLIBS} \
139 $${${1}_LOCAL_PRLIBS}
140 $(Q)$${${1}_POSTMAKE}
144 # By default, if libdir is defined, we build shared libraries.
145 # However, we can disable shared libraries if explicitly told to.
147 ifneq "${bm_shared_libs}" "no"
148 bm_shared_libs := yes
152 # Default to building static libraries, too.
153 ifneq "${bm_static_libs}" "no"
154 bm_static_libs := yes
157 # Check if we build shared libraries.
158 ifeq "${bm_shared_libs}" "yes"
161 # RPATH : flags use to build executables that are installed,
162 # with no dependency on the source.
163 # RELINL : flags use to build executables that can be run
164 # from the build directory / source tree.
165 RPATH_FLAGS := -rpath ${libdir}
166 LOCAL_FLAGS := -rpath $(abspath ${BUILD_DIR})/lib/${LOCAL}/.libs
168 LOCAL_FLAGS_MIN := -rpath ${libdir}
170 ifneq "${bm_static_libs}" "yes"
171 RPATH_FLAGS += --shared
172 LOCAL_FLAGS += --shared
175 ifneq "${bm_static_libs}" "yes"
176 $(error Building without static libraries requires you to set 'INSTALL' or 'libdir')
179 RPATH_FLAGS := -static
182 # UPDATE_TARGET_ENDINGS - Function to turn target into a libtool target
183 # e.g. "libfoo.a" -> libfoo.la"
185 # If the target is an executable, then its extension doesn't change
186 # when we use libtool, and we don't do any re-writing.
190 define ADD_LIBTOOL_SUFFIX
191 ifneq "$$(call LIBTOOL_ENDINGS,$${TGT})" "$${TGT}"
192 TGT_NOLIBTOOL := $${TGT}
193 TGT := $$(call LIBTOOL_ENDINGS,$${TGT})
194 $${TGT}_NOLIBTOOL := $${TGT_NOLIBTOOL}
197 ifneq "$${LOCAL_FLAGS}" ""
198 $${TGT}_LOCAL := ${LOCAL}$${TGT}
201 # re-write all of the dependencies to have the libtool endings.
202 TGT_PREREQS := $$(call LIBTOOL_ENDINGS,$${TGT_PREREQS})
205 # ADD_LIBTOOL_TARGET - Function to ensure that the object files depend
206 # on our jlibtool target. This ensures that jlibtool is built before
207 # it's used to build the object files.
211 define ADD_LIBTOOL_TARGET
212 ifneq "${JLIBTOOL}" ""
213 $${$${TGT}_OBJS}: $${JLIBTOOL}
216 ifneq "$${$${TGT}_NOLIBTOOL}" ""
217 $$(notdir $${$${TGT}_NOLIBTOOL}): $${TGT}
220 # If we need to relink, add the relink targets now.
221 ifneq "$${$${TGT}_LOCAL}" ""
222 # add rules to relink the target
224 $${TGT}_LOCAL_PRLIBS := $$(subst $${BUILD_DIR}/lib/,$${BUILD_DIR}/lib/${LOCAL},$${$${TGT}_PRLIBS})
226 $$(eval $$(call ADD_LOCAL_RULE$${$${TGT}_SUFFIX},$${TGT}))
228 $$(eval $$(call ADD_CLEAN_RULE,$${$${TGT}_LOCAL}_libtool))
230 ifneq "$${$${TGT}_NOLIBTOOL}" ""
231 $$(eval $$(call ADD_CLEAN_RULE,$${$${TGT}_NOLIBTOOL}_libtool))