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}/${1}
40 @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
41 @$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${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}/${1}
83 @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
84 @$${PROGRAM_INSTALL} -c -m 755 $${RELINK_FLAGS_MIN} $${BUILD_DIR}/lib/${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}
103 @$(ECHO) INSTALL $(notdir ${1})
104 @[ -d ${2} ] || $${PROGRAM_INSTALL} -d -m 755 ${2}
105 @$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
110 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
111 # which installs everything for the target.
115 define ADD_INSTALL_TARGET
116 # Figure out which target rule to use for installation.
117 ifeq "$${${1}_SUFFIX}" ".exe"
118 ifeq "$${TGT_INSTALLDIR}" ".."
119 TGT_INSTALLDIR := $${bindir}
122 ifeq "$${TGT_INSTALLDIR}" ".."
123 TGT_INSTALLDIR := $${libdir}
127 ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
129 # add rules to install the target
130 ifneq "$${${1}_INSTALLDIR}" ""
131 $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
134 # add rules to install the MAN pages.
135 ifneq "$$(strip $${${1}_MAN})" ""
137 $$(error You must define 'mandir' in order to be able to install MAN pages.)
140 MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
141 MAN := $$(call CANONICAL_PATH,$${MAN})
143 $$(foreach PAGE,$${MAN},\
144 $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
145 $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
154 # Define reasonable defaults for all of the installation directories.
155 # The user can over-ride these, but these are the defaults.
159 ifeq "${exec_prefix}" ""
160 exec_prefix = ${prefix}
163 bindir = ${exec_prefix}/bin
166 sbindir = ${exec_prefix}/sbin
169 libdir = ${exec_prefix}/lib
171 ifeq "${sysconfdir}" ""
172 sysconfdir = ${prefix}/etc
174 ifeq "${localstatedir}" ""
175 localstatedir = ${prefix}/var
177 ifeq "${datarootdir}" ""
178 datarootdir = ${prefix}/share
181 datadir = ${prefix}/share
184 mandir = ${datadir}/man
187 ifneq "${PROJECT_NAME}" ""
188 docdir = ${datadir}/doc/${PROJECT_NAME}
192 logdir = ${localstatedir}/log/
194 ifeq "${includedir}" ""
195 includedir = ${prefix}/include
199 # Un-install any installed programs. We DON'T want to depend on the
200 # install target. Doing so would cause "make uninstall" to build it,
201 # install it, and then remove it.
203 # We also want to uninstall only when there are "install_foo" targets.
206 @rm -f ${ALL_INSTALL} ./.no_such_file
208 # Wrapper around INSTALL
209 ifeq "${PROGRAM_INSTALL}" ""
210 PROGRAM_INSTALL := ${INSTALL}
214 # Make just the installation directories
218 # Be nice to the user. If there is no INSTALL program, then print out
219 # a helpful message. Without this check, the "install" rules defined
220 # above would try to run a command-line with a blank INSTALL, and give
221 # some inscrutable error.
223 install: install_ERROR
225 .PHONY: install_ERROR
227 @$(ECHO) Please define INSTALL in order to enable the installation rules.