1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# boilermake: A reusable, but flexible, boilerplate Makefile.
#
# Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ADD_INSTALL_RULE.* - Parameterized "functions" that adds a new
# installation to the Makefile. There should be one ADD_INSTALL_RULE
# definition for each type of target that is used in the build.
#
# New rules can be added by copying one of the existing ones, and
# replacing the line after the "mkdir"
#
#
# You can watch what it's doing by:
#
# $ VERBOSE=1 make ... args ...
#
ifeq "${VERBOSE}" ""
Q=@
else
Q=
endif
# ADD_INSTALL_RULE.exe - Parameterized "function" that adds a new rule
# and phony target for installing an executable.
#
# USE WITH EVAL
#
define ADD_INSTALL_RULE.exe
ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
# Global install depends on ${1}
install: $${${1}_INSTALLDIR}/$(notdir ${1})
# Install executable ${1}
$${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
@$(ECHO) INSTALL ${1}
$(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${1} $${${1}_INSTALLDIR}/
$(Q)$${${1}_POSTINSTALL}
endef
# ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
# and phony target for installing a static library
#
# USE WITH EVAL
#
define ADD_INSTALL_RULE.a
ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
# Global install depends on ${1}
install: $${${1}_INSTALLDIR}/$(notdir ${1})
# Install static library ${1}
$${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} ${1} | $${${1}_INSTALLDIR}
@$(ECHO) INSTALL ${1}
$(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
$(Q)$${${1}_POSTINSTALL}
endef
# ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
# and phony target for installing a libtool library
#
# FIXME: The libtool install *also* installs a bunch of other files.
# ensure that those are removed, too.
#
# USE WITH EVAL
#
define ADD_INSTALL_RULE.la
ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
# Global install depends on ${1}
install: $${${1}_INSTALLDIR}/$(notdir ${1})
# Install libtool library ${1}
$${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
@$(ECHO) INSTALL ${1}
$(Q)$${PROGRAM_INSTALL} -c -m 755 $${LOCAL_FLAGS_MIN} $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
$(Q)$${${1}_POSTINSTALL}
endef
# ADD_INSTALL_RULE.man - Parameterized "function" that adds a new rule
# and phony target for installing a "man" page. It will take care of
# installing it into the correct subdirectory of "man".
#
# USE WITH EVAL
#
define ADD_INSTALL_RULE.man
ALL_INSTALL += ${2}/$(notdir ${1})
# Global install depends on ${1}
install: ${2}/$(notdir ${1})
# Install manual page ${1}
${2}/$(notdir ${1}): ${JLIBTOOL} ${1} | ${2}
@$(ECHO) INSTALL $(notdir ${1})
$(Q)$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
endef
# ADD_INSTALL_RULE.dir - Parameterized "function" that adds a new rule
# and phony target for installing a directory
#
# USE WITH EVAL
#
define ADD_INSTALL_RULE.dir
# Install directory
.PHONY: ${1}
${1}: ${JLIBTOOL}
@$(ECHO) INSTALL -d -m 755 ${1}
$(Q)$${PROGRAM_INSTALL} -d -m 755 ${1}
endef
# ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
# which installs everything for the target.
#
# USE WITH EVAL
#
define ADD_INSTALL_TARGET
# Figure out which target rule to use for installation.
ifeq "$${${1}_SUFFIX}" ".exe"
ifeq "$${TGT_INSTALLDIR}" ".."
TGT_INSTALLDIR := $${bindir}
endif
else
ifeq "$${TGT_INSTALLDIR}" ".."
TGT_INSTALLDIR := $${libdir}
endif
endif
# add rules to install the target
ifneq "$${TGT_INSTALLDIR}" ""
${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
$$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
endif
# add rules to install the MAN pages.
ifneq "$$(strip $${${1}_MAN})" ""
ifeq "$${mandir}" ""
$$(error You must define 'mandir' in order to be able to install MAN pages.)
endif
MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
MAN := $$(call CANONICAL_PATH,$${MAN})
$$(foreach PAGE,$${MAN},\
$$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
$${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
endif
endef
.PHONY: install
install:
ALL_INSTALL :=
# Define reasonable defaults for all of the installation directories.
# The user can over-ride these, but these are the defaults.
ifeq "${prefix}" ""
prefix = /usr/local
endif
ifeq "${exec_prefix}" ""
exec_prefix = ${prefix}
endif
ifeq "${bindir}" ""
bindir = ${exec_prefix}/bin
endif
ifeq "${sbindir}" ""
sbindir = ${exec_prefix}/sbin
endif
ifeq "${libdir}" ""
libdir = ${exec_prefix}/lib
endif
ifeq "${sysconfdir}" ""
sysconfdir = ${prefix}/etc
endif
ifeq "${localstatedir}" ""
localstatedir = ${prefix}/var
endif
ifeq "${datarootdir}" ""
datarootdir = ${prefix}/share
endif
ifeq "${datadir}" ""
datadir = ${prefix}/share
endif
ifeq "${mandir}" ""
mandir = ${datadir}/man
endif
ifeq "${docdir}" ""
ifneq "${PROJECT_NAME}" ""
docdir = ${datadir}/doc/${PROJECT_NAME}
endif
endif
ifeq "${logdir}" ""
logdir = ${localstatedir}/log/
endif
ifeq "${includedir}" ""
includedir = ${prefix}/include
endif
# Un-install any installed programs. We DON'T want to depend on the
# install target. Doing so would cause "make uninstall" to build it,
# install it, and then remove it.
#
# We also want to uninstall only when there are "install_foo" targets.
.PHONY: uninstall
uninstall:
$(Q)rm -f ${ALL_INSTALL} ./.no_such_file
# Wrapper around INSTALL
ifeq "${PROGRAM_INSTALL}" ""
PROGRAM_INSTALL := ${INSTALL}
endif
# Make just the installation directories
.PHONY: installdirs
installdirs:
# Be nice to the user. If there is no INSTALL program, then print out
# a helpful message. Without this check, the "install" rules defined
# above would try to run a command-line with a blank INSTALL, and give
# some inscrutable error.
ifeq "${INSTALL}" ""
install: install_ERROR
.PHONY: install_ERROR
install_ERROR:
@$(ECHO) Please define INSTALL in order to enable the installation rules.
$(Q)exit 1
endif
|