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}): $${${1}_BUILD}/${1}
51 $(Q)$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
52 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${1} $${${1}_INSTALLDIR}/
53 $(Q)$${${1}_POSTINSTALL}
57 # ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
58 # and phony target for installing a static library
62 define ADD_INSTALL_RULE.a
63 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
65 # Global install depends on ${1}
66 install: $${${1}_INSTALLDIR}/$(notdir ${1})
68 # Install static library ${1}
69 $${${1}_INSTALLDIR}/$(notdir ${1}): ${1}
71 $(Q)$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
72 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
73 $(Q)$${${1}_POSTINSTALL}
77 # ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
78 # and phony target for installing a libtool library
80 # FIXME: The libtool install *also* installs a bunch of other files.
81 # ensure that those are removed, too.
85 define ADD_INSTALL_RULE.la
86 ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
88 # Global install depends on ${1}
89 install: $${${1}_INSTALLDIR}/$(notdir ${1})
91 # Install libtool library ${1}
92 $${${1}_INSTALLDIR}/$(notdir ${1}): $${${1}_BUILD}/${1}
94 $(Q)$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
95 $(Q)$${PROGRAM_INSTALL} -c -m 755 $${RELINK_FLAGS_MIN} $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
96 $(Q)$${${1}_POSTINSTALL}
100 # ADD_INSTALL_RULE.man - Parameterized "function" that adds a new rule
101 # and phony target for installing a "man" page. It will take care of
102 # installing it into the correct subdirectory of "man".
106 define ADD_INSTALL_RULE.man
107 ALL_INSTALL += ${2}/$(notdir ${1})
109 # Global install depends on ${1}
110 install: ${2}/$(notdir ${1})
112 # Install manual page ${1}
113 ${2}/$(notdir ${1}): ${1}
114 @$(ECHO) INSTALL $(notdir ${1})
115 $(Q)[ -d ${2} ] || $${PROGRAM_INSTALL} -d -m 755 ${2}
116 $(Q)$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
121 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
122 # which installs everything for the target.
126 define ADD_INSTALL_TARGET
127 # Figure out which target rule to use for installation.
128 ifeq "$${${1}_SUFFIX}" ".exe"
129 ifeq "$${TGT_INSTALLDIR}" ".."
130 TGT_INSTALLDIR := $${bindir}
133 ifeq "$${TGT_INSTALLDIR}" ".."
134 TGT_INSTALLDIR := $${libdir}
138 # add rules to install the target
139 ifneq "$${TGT_INSTALLDIR}" ""
140 ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
142 $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
145 # add rules to install the MAN pages.
146 ifneq "$$(strip $${${1}_MAN})" ""
148 $$(error You must define 'mandir' in order to be able to install MAN pages.)
151 MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
152 MAN := $$(call CANONICAL_PATH,$${MAN})
154 $$(foreach PAGE,$${MAN},\
155 $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
156 $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
165 # Define reasonable defaults for all of the installation directories.
166 # The user can over-ride these, but these are the defaults.
170 ifeq "${exec_prefix}" ""
171 exec_prefix = ${prefix}
174 bindir = ${exec_prefix}/bin
177 sbindir = ${exec_prefix}/sbin
180 libdir = ${exec_prefix}/lib
182 ifeq "${sysconfdir}" ""
183 sysconfdir = ${prefix}/etc
185 ifeq "${localstatedir}" ""
186 localstatedir = ${prefix}/var
188 ifeq "${datarootdir}" ""
189 datarootdir = ${prefix}/share
192 datadir = ${prefix}/share
195 mandir = ${datadir}/man
198 ifneq "${PROJECT_NAME}" ""
199 docdir = ${datadir}/doc/${PROJECT_NAME}
203 logdir = ${localstatedir}/log/
205 ifeq "${includedir}" ""
206 includedir = ${prefix}/include
210 # Un-install any installed programs. We DON'T want to depend on the
211 # install target. Doing so would cause "make uninstall" to build it,
212 # install it, and then remove it.
214 # We also want to uninstall only when there are "install_foo" targets.
217 $(Q)rm -f ${ALL_INSTALL} ./.no_such_file
219 # Wrapper around INSTALL
220 ifeq "${PROGRAM_INSTALL}" ""
221 PROGRAM_INSTALL := ${INSTALL}
225 # Make just the installation directories
229 # Be nice to the user. If there is no INSTALL program, then print out
230 # a helpful message. Without this check, the "install" rules defined
231 # above would try to run a command-line with a blank INSTALL, and give
232 # some inscrutable error.
234 install: install_ERROR
236 .PHONY: install_ERROR
238 @$(ECHO) Please define INSTALL in order to enable the installation rules.