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"
26 # ADD_INSTALL_RULE.exe - Parameterized "function" that adds a new rule
27 # and phony target for installing an executable.
31 define ADD_INSTALL_RULE.exe
32 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
34 # Global install depends on ${1}
35 install: $${${1}_INSTALLDIR}/$(notdir ${1})
37 # Install executable ${1}
38 $${${1}_INSTALLDIR}/$(notdir ${1}): $${${1}_BUILD}/$${RELINK}${1}
40 @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
41 @$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/$${RELINK}${1} $${${1}_INSTALLDIR}/
46 # ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
47 # and phony target for installing a static library
51 define ADD_INSTALL_RULE.a
52 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
54 # Global install depends on ${1}
55 install: $${${1}_INSTALLDIR}/$(notdir ${1})
57 # Install static library ${1}
58 $${${1}_INSTALLDIR}/$(notdir ${1}): ${1}
60 @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
61 @$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
66 # ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
67 # and phony target for installing a libtool library
69 # FIXME: The libtool install *also* installs a bunch of other files.
70 # ensure that those are removed, too.
74 define ADD_INSTALL_RULE.la
75 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
77 # Global install depends on ${1}
78 install: $${${1}_INSTALLDIR}/$(notdir ${1})
80 # Install libtool library ${1}
81 $${${1}_INSTALLDIR}/$(notdir ${1}): $${${1}_BUILD}/$${RELINK}${1}
83 @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
84 @$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/$${RELINK}${1} $${${1}_INSTALLDIR}/
89 # ADD_INSTALL_RULE.man - Parameterized "function" that adds a new rule
90 # and phony target for installing a "man" page. It will take care of
91 # installing it into the correct subdirectory of "man".
95 define ADD_INSTALL_RULE.man
96 ALL_INSTALL += ${2}/$(notdir ${1})
98 # Global install depends on ${1}
99 install: ${2}/$(notdir ${1})
101 # Install manual page ${1}
102 ${2}/$(notdir ${1}): ${1} ${2}
104 @$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
109 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
110 # which installs everything for the target.
114 define ADD_INSTALL_TARGET
115 # Figure out which target rule to use for installation.
116 ifeq "$${${1}_SUFFIX}" ".exe"
117 ifeq "$${TGT_INSTALLDIR}" ".."
118 TGT_INSTALLDIR := $${bindir}
121 ifeq "$${TGT_INSTALLDIR}" ".."
122 TGT_INSTALLDIR := $${libdir}
126 ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
128 # add rules to install the target
129 ifneq "$${${1}_INSTALLDIR}" ""
130 $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
133 # add rules to install the MAN pages.
134 ifneq "$$(strip $${${1}_MAN})" ""
136 $$(error You must define 'mandir' in order to be able to install MAN pages.)
139 MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
140 MAN := $$(call CANONICAL_PATH,$${MAN})
142 $$(foreach PAGE,$${MAN},\
143 $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
144 $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
153 # Define reasonable defaults for all of the installation directories.
154 # The user can over-ride these, but these are the defaults.
158 ifeq "${exec_prefix}" ""
159 exec_prefix = ${prefix}
162 bindir = ${exec_prefix}/bin
165 sbindir = ${exec_prefix}/sbin
168 libdir = ${exec_prefix}/lib
170 ifeq "${sysconfdir}" ""
171 sysconfdir = ${prefix}/etc
173 ifeq "${localstatedir}" ""
174 localstatedir = ${prefix}/var
176 ifeq "${datarootdir}" ""
177 datarootdir = ${prefix}/share
180 datadir = ${prefix}/share
183 mandir = ${datadir}/man
186 ifneq "${PROJECT_NAME}" ""
187 docdir = ${datadir}/doc/${PROJECT_NAME}
191 logdir = ${localstatedir}/log/
193 ifeq "${includedir}" ""
194 includedir = ${prefix}/include
198 # Un-install any installed programs. We DON'T want to depend on the
199 # install target. Doing so would cause "make uninstall" to build it,
200 # install it, and then remove it.
202 # We also want to uninstall only when there are "install_foo" targets.
205 @rm -f ${ALL_INSTALL} ./.no_such_file
207 # Wrapper around INSTALL
208 ifeq "${PROGRAM_INSTALL}" ""
209 PROGRAM_INSTALL := ${INSTALL}
213 # Make just the installation directories
217 # Be nice to the user. If there is no INSTALL program, then print out
218 # a helpful message. Without this check, the "install" rules defined
219 # above would try to run a command-line with a blank INSTALL, and give
220 # some inscrutable error.
222 install: install_ERROR
224 .PHONY: install_ERROR
226 @echo Please define INSTALL in order to enable the installation rules.