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/>.
16 # Add these rules only when LIBTOOL is being used.
19 # JLIBTOOL - check if we're using the local (fast) jlibtool, rather
20 # than the GNU (slow) libtool shell script. If so, add rules
23 ifeq "${LIBTOOL}" "JLIBTOOL"
24 JLIBTOOL := ${BUILD_DIR}/make/jlibtool
26 # Add a rule to build jlibtool BEFORE any other targets. This
27 # means that we can use it to build the later targets.
28 all install: ${JLIBTOOL}
30 # Note that we need to use a compilation rule that does NOT
31 # include referencing ${LIBTOOL}, as we don't have a jlibtool
33 ${JLIBTOOL}: ${top_makedir}/jlibtool.c
34 $(Q)mkdir -p $(dir $@)
35 $(Q)echo CC jlibtool.c
40 .PHONY: jlibtool_clean
44 # Tell GNU Make to use this value, rather than anything specified
45 # on the command line.
46 override LIBTOOL := ${JLIBTOOL}
47 endif # else we're not using jlibtool
49 # When using libtool, it produces a '.libs' directory. Ensure that it
50 # is removed on "make clean", too.
56 $(Q)rm -rf ${BUILD_DIR}/.libs/
58 # Re-define compilers and linkers
61 COMPILE.c = ${LIBTOOL} --silent --mode=compile ${CC}
62 COMPILE.cxx = ${LIBTOOL} --mode=compile ${CXX}
63 LINK.c = ${LIBTOOL} --silent --mode=link ${CC}
64 LINK.cxx = ${LIBTOOL} --mode=link ${CXX}
65 PROGRAM_INSTALL = ${LIBTOOL} --silent --mode=install ${INSTALL}
68 # LIBTOOL_ENDINGS - Given a library ending in ".a" or ".so", replace that
69 # extension with ".la".
71 define LIBTOOL_ENDINGS
72 $(patsubst %.a,%.la,$(patsubst %.so,%.la,${1}))
75 # ADD_TARGET_RULE.la - Build a ".la" target.
79 define ADD_TARGET_RULE.la
80 # So "make ${1}" works
82 ${1}: $${${1}_BUILD}/${1}
84 # Create libtool library ${1}
85 $${${1}_BUILD}/${1}: $${${1}_OBJS} $${${1}_PRLIBS}
86 @$(strip mkdir -p $(dir $${${1}_BUILD}/${1}))
87 @$(ECHO) LINK $${${1}_BUILD}/${1}
88 @$${${1}_LINKER} -o $${${1}_BUILD}/${1} $${RPATH_FLAGS} $${LDFLAGS} \
89 $${${1}_LDFLAGS} $${${1}_OBJS} $${LDLIBS} $${${1}_LDLIBS} \
93 ifneq "${ANALYZE.c}" ""
94 scan.${1}: $${${1}_PLISTS}
98 # ADD_RELINK_RULE.exe - Parametric "function" that adds a rule to relink
99 # the target before installation, so that the paths are correct.
103 define ADD_RELINK_RULE.exe
104 ${1}: $${${1}_BUILD}/$${RELINK}${1}
106 # used to fix up RPATH for ${1} on install.
107 $${${1}_BUILD}/$${${1}_RELINK}: $${${1}_OBJS} $${${1}_PRBIN} $${${1}_R_PRLIBS}
108 @$(strip mkdir -p $${${1}_BUILD}/${RELINK}/)
109 @$${${1}_LINKER} -o $${${1}_BUILD}/$${RELINK}${1} $${RELINK_FLAGS} $${LDFLAGS} \
110 $${${1}_LDFLAGS} $${${1}_OBJS} $${${1}_R_PRLIBS} \
111 $${LDLIBS} $${${1}_LDLIBS}
115 # ADD_RELINK_RULE.la - Parametric "function" that adds a rule to relink
116 # the target before installation, so that the paths are correct.
120 define ADD_RELINK_RULE.la
121 ${1}: $${${1}_BUILD}/$${RELINK}${1}
123 # used to fix up RPATH for ${1} on install.
124 $${${1}_BUILD}/$${${1}_RELINK}: $${${1}_OBJS} $${${1}_PRLIBS}
125 @$(strip mkdir -p $${${1}_BUILD}/${RELINK}/)
126 @$${${1}_LINKER} -o $${${1}_BUILD}/$${RELINK}${1} $${RELINK_FLAGS} $${LDFLAGS} \
127 $${${1}_LDFLAGS} $${${1}_OBJS} $${LDLIBS} $${${1}_LDLIBS}
132 # By default, if libdir is defined, we build shared libraries.
133 # However, we can disable shared libraries if explicitly told to.
135 ifneq "${bm_shared_libs}" "no"
136 bm_shared_libs := yes
140 # Default to building static libraries, too.
141 ifneq "${bm_static_libs}" "no"
142 bm_static_libs := yes
145 # Check if we build shared libraries.
146 ifeq "${bm_shared_libs}" "yes"
149 # RPATH : flags use to build executables that are installed,
150 # with no dependency on the source.
151 # RELINL : flags use to build executables that can be run
152 # from the build directory / source tree.
153 RPATH_FLAGS := -rpath ${libdir}
154 RELINK_FLAGS := -rpath $(abspath ${BUILD_DIR})/lib/${RELINK}/.libs
156 RELINK_FLAGS_MIN := -rpath ${libdir}
158 ifneq "${bm_static_libs}" "yes"
159 RPATH_FLAGS += --shared
160 RELINK_FLAGS += --shared
163 ifneq "${bm_static_libs}" "yes"
164 $(error Building without static libraries requires you to set 'INSTALL' or 'libdir')
167 RPATH_FLAGS := -static
170 # UPDATE_TARGET_ENDINGS - Function to turn target into a libtool target
171 # e.g. "libfoo.a" -> libfoo.la"
173 # If the target is an executable, then its extension doesn't change
174 # when we use libtool, and we don't do any re-writing.
178 define ADD_LIBTOOL_SUFFIX
179 ifneq "$$(call LIBTOOL_ENDINGS,$${TGT})" "$${TGT}"
180 TGT_NOLIBTOOL := $${TGT}
181 TGT := $$(call LIBTOOL_ENDINGS,$${TGT})
182 $${TGT}_NOLIBTOOL := $${TGT_NOLIBTOOL}
185 ifneq "$${RELINK_FLAGS}" ""
186 $${TGT}_RELINK := ${RELINK}$${TGT}
189 # re-write all of the dependencies to have the libtool endings.
190 TGT_PREREQS := $$(call LIBTOOL_ENDINGS,$${TGT_PREREQS})
193 # ADD_LIBTOOL_TARGET - Function to ensure that the object files depend
194 # on our jlibtool target. This ensures that jlibtool is built before
195 # it's used to build the object files.
199 define ADD_LIBTOOL_TARGET
200 ifneq "${JLIBTOOL}" ""
201 $${$${TGT}_OBJS}: $${JLIBTOOL}
204 ifneq "$${$${TGT}_NOLIBTOOL}" ""
205 $$(notdir $${$${TGT}_NOLIBTOOL}): $${TGT}
208 # If we need to relink, add the relink targets now.
209 ifneq "$${$${TGT}_RELINK}" ""
210 # add rules to relink the target
212 $${TGT}_R_PRLIBS := $$(subst /lib/,/lib/${RELINK},$${$${TGT}_PRLIBS})
214 $$(eval $$(call ADD_RELINK_RULE$${$${TGT}_SUFFIX},$${TGT}))
216 $$(eval $$(call ADD_CLEAN_RULE,$${$${TGT}_RELINK}_libtool))
218 ifneq "$${$${TGT}_NOLIBTOOL}" ""
219 $$(eval $$(call ADD_CLEAN_RULE,$${$${TGT}_NOLIBTOOL}_libtool))