1 # boilermake: A reusable, but flexible, boilerplate Makefile.
3 # Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # ADD_INSTALL_RULE.* - Parameterized "functions" that adds a new
19 # installation to the Makefile. There should be one ADD_INSTALL_RULE
20 # definition for each type of target that is used in the build.
22 # New rules can be added by copying one of the existing ones, and
23 # replacing the line after the "mkdir"
27 # You can watch what it's doing by:
29 # $ VERBOSE=1 make ... args ...
37 # ADD_INSTALL_RULE.exe - Parameterized "function" that adds a new rule
38 # and phony target for installing an executable.
42 define ADD_INSTALL_RULE.exe
43 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
45 # Global install depends on ${1}
46 install: $${${1}_INSTALLDIR}/$(notdir ${1})
48 # Install executable ${1}
49 $${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
51 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${1} $${${1}_INSTALLDIR}/
52 $(Q)$${${1}_POSTINSTALL}
56 # ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
57 # and phony target for installing a static library
61 define ADD_INSTALL_RULE.a
62 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
64 # Global install depends on ${1}
65 install: $${${1}_INSTALLDIR}/$(notdir ${1})
67 # Install static library ${1}
68 $${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} ${1} | $${${1}_INSTALLDIR}
70 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
71 $(Q)$${${1}_POSTINSTALL}
75 # ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
76 # and phony target for installing a libtool library
78 # FIXME: The libtool install *also* installs a bunch of other files.
79 # ensure that those are removed, too.
83 define ADD_INSTALL_RULE.la
84 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
86 # Global install depends on ${1}
87 install: $${${1}_INSTALLDIR}/$(notdir ${1})
89 # Install libtool library ${1}
90 $${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
92 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${LOCAL_FLAGS_MIN} $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
93 $(Q)$${${1}_POSTINSTALL}
97 # ADD_INSTALL_RULE.man - Parameterized "function" that adds a new rule
98 # and phony target for installing a "man" page. It will take care of
99 # installing it into the correct subdirectory of "man".
103 define ADD_INSTALL_RULE.man
104 ALL_INSTALL += ${2}/$(notdir ${1})
106 # Global install depends on ${1}
107 install: ${2}/$(notdir ${1})
109 # Install manual page ${1}
110 ${2}/$(notdir ${1}): ${JLIBTOOL} ${1} | ${2}
111 @$(ECHO) INSTALL $(notdir ${1})
112 $(Q)$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
117 # ADD_INSTALL_RULE.dir - Parameterized "function" that adds a new rule
118 # and phony target for installing a directory
122 define ADD_INSTALL_RULE.dir
126 @$(ECHO) INSTALL -d -m 755 ${1}
127 $(Q)$${PROGRAM_INSTALL} -d -m 755 ${1}
131 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
132 # which installs everything for the target.
136 define ADD_INSTALL_TARGET
137 # Figure out which target rule to use for installation.
138 ifeq "$${${1}_SUFFIX}" ".exe"
139 ifeq "$${TGT_INSTALLDIR}" ".."
140 TGT_INSTALLDIR := $${bindir}
143 ifeq "$${TGT_INSTALLDIR}" ".."
144 TGT_INSTALLDIR := $${libdir}
148 # add rules to install the target
149 ifneq "$${TGT_INSTALLDIR}" ""
150 ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
152 $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
155 # add rules to install the MAN pages.
156 ifneq "$$(strip $${${1}_MAN})" ""
158 $$(error You must define 'mandir' in order to be able to install MAN pages.)
161 MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
162 MAN := $$(call CANONICAL_PATH,$${MAN})
164 $$(foreach PAGE,$${MAN},\
165 $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
166 $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
175 # Define reasonable defaults for all of the installation directories.
176 # The user can over-ride these, but these are the defaults.
180 ifeq "${exec_prefix}" ""
181 exec_prefix = ${prefix}
184 bindir = ${exec_prefix}/bin
187 sbindir = ${exec_prefix}/sbin
190 libdir = ${exec_prefix}/lib
192 ifeq "${sysconfdir}" ""
193 sysconfdir = ${prefix}/etc
195 ifeq "${localstatedir}" ""
196 localstatedir = ${prefix}/var
198 ifeq "${datarootdir}" ""
199 datarootdir = ${prefix}/share
202 datadir = ${prefix}/share
205 mandir = ${datadir}/man
208 ifneq "${PROJECT_NAME}" ""
209 docdir = ${datadir}/doc/${PROJECT_NAME}
213 logdir = ${localstatedir}/log/
215 ifeq "${includedir}" ""
216 includedir = ${prefix}/include
220 # Un-install any installed programs. We DON'T want to depend on the
221 # install target. Doing so would cause "make uninstall" to build it,
222 # install it, and then remove it.
224 # We also want to uninstall only when there are "install_foo" targets.
227 $(Q)rm -f ${ALL_INSTALL} ./.no_such_file
229 # Wrapper around INSTALL
230 ifeq "${PROGRAM_INSTALL}" ""
231 PROGRAM_INSTALL := ${INSTALL}
235 # Make just the installation directories
239 # Be nice to the user. If there is no INSTALL program, then print out
240 # a helpful message. Without this check, the "install" rules defined
241 # above would try to run a command-line with a blank INSTALL, and give
242 # some inscrutable error.
244 install: install_ERROR
246 .PHONY: install_ERROR
248 @$(ECHO) Please define INSTALL in order to enable the installation rules.