update recent changes
[freeradius.git] / scripts / install.mk
1 # boilermake: A reusable, but flexible, boilerplate Makefile.
2 #
3 # Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
4 #
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.
9 #
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.
14 #
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/>.
17
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.
21 #
22 #   New rules can be added by copying one of the existing ones, and
23 #   replacing the line after the "mkdir"
24 #
25
26 #
27 #  You can watch what it's doing by:
28 #
29 #       $ VERBOSE=1 make ... args ...
30 #
31 ifeq "${VERBOSE}" ""
32     Q=@
33 else
34     Q=
35 endif
36
37 # ADD_INSTALL_RULE.exe - Parameterized "function" that adds a new rule
38 #   and phony target for installing an executable.
39 #
40 #   USE WITH EVAL
41 #
42 define ADD_INSTALL_RULE.exe
43     ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
44
45     # Global install depends on ${1}
46     install: $${${1}_INSTALLDIR}/$(notdir ${1})
47
48     # Install executable ${1}
49     $${${1}_INSTALLDIR}/$(notdir ${1}): $${${1}_BUILD}/${1}
50         @$(ECHO) INSTALL ${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}
54
55 endef
56
57 # ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
58 #   and phony target for installing a static library
59 #
60 #   USE WITH EVAL
61 #
62 define ADD_INSTALL_RULE.a
63     ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
64
65     # Global install depends on ${1}
66     install: $${${1}_INSTALLDIR}/$(notdir ${1})
67
68     # Install static library ${1}
69     $${${1}_INSTALLDIR}/$(notdir ${1}): ${1}
70         @$(ECHO) INSTALL ${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}
74
75 endef
76
77 # ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
78 #   and phony target for installing a libtool library
79 #
80 #   FIXME: The libtool install *also* installs a bunch of other files.
81 #          ensure that those are removed, too.
82 #
83 #   USE WITH EVAL
84 #
85 define ADD_INSTALL_RULE.la
86     ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
87
88     # Global install depends on ${1}
89     install: $${${1}_INSTALLDIR}/$(notdir ${1})
90
91     # Install libtool library ${1}
92     $${${1}_INSTALLDIR}/$(notdir ${1}): $${${1}_BUILD}/${1}
93         @$(ECHO) INSTALL ${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}
97
98 endef
99
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".
103 #
104 #   USE WITH EVAL
105 #
106 define ADD_INSTALL_RULE.man
107     ALL_INSTALL += ${2}/$(notdir ${1})
108
109     # Global install depends on ${1}
110     install: ${2}/$(notdir ${1})
111
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}/
117
118 endef
119
120
121 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
122 #   which installs everything for the target.
123 #
124 #   USE WITH EVAL
125 #
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}
131         endif
132     else
133         ifeq "$${TGT_INSTALLDIR}" ".."
134             TGT_INSTALLDIR := $${libdir}
135         endif
136     endif
137
138     # add rules to install the target
139     ifneq "$${TGT_INSTALLDIR}" ""
140         ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
141
142         $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
143     endif
144
145     # add rules to install the MAN pages.
146     ifneq "$$(strip $${${1}_MAN})" ""
147         ifeq "$${mandir}" ""
148             $$(error You must define 'mandir' in order to be able to install MAN pages.)
149         endif
150
151         MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
152         MAN := $$(call CANONICAL_PATH,$${MAN})
153
154         $$(foreach PAGE,$${MAN},\
155             $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
156               $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
157     endif
158 endef
159
160 .PHONY: install
161 install:
162
163 ALL_INSTALL :=
164
165 # Define reasonable defaults for all of the installation directories.
166 # The user can over-ride these, but these are the defaults.
167 ifeq "${prefix}" ""
168     prefix = /usr/local
169 endif
170 ifeq "${exec_prefix}" ""
171     exec_prefix = ${prefix}
172 endif
173 ifeq "${bindir}" ""
174     bindir = ${exec_prefix}/bin
175 endif
176 ifeq "${sbindir}" ""
177     sbindir = ${exec_prefix}/sbin
178 endif
179 ifeq "${libdir}" ""
180     libdir = ${exec_prefix}/lib
181 endif
182 ifeq "${sysconfdir}" ""
183     sysconfdir = ${prefix}/etc
184 endif
185 ifeq "${localstatedir}" ""
186     localstatedir = ${prefix}/var
187 endif
188 ifeq "${datarootdir}" ""
189     datarootdir = ${prefix}/share
190 endif
191 ifeq "${datadir}" ""
192     datadir = ${prefix}/share
193 endif
194 ifeq "${mandir}" ""
195     mandir = ${datadir}/man
196 endif
197 ifeq "${docdir}" ""
198     ifneq "${PROJECT_NAME}" ""
199         docdir = ${datadir}/doc/${PROJECT_NAME}
200     endif
201 endif
202 ifeq "${logdir}" ""
203     logdir = ${localstatedir}/log/
204 endif
205 ifeq "${includedir}" ""
206     includedir = ${prefix}/include
207 endif
208
209
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.
213 #
214 # We also want to uninstall only when there are "install_foo" targets.
215 .PHONY: uninstall
216 uninstall:
217         $(Q)rm -f ${ALL_INSTALL} ./.no_such_file
218
219 # Wrapper around INSTALL
220 ifeq "${PROGRAM_INSTALL}" ""
221     PROGRAM_INSTALL := ${INSTALL}
222
223 endif
224
225 # Make just the installation directories
226 .PHONY: installdirs
227 installdirs:
228
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.
233 ifeq "${INSTALL}" ""
234 install: install_ERROR
235
236 .PHONY: install_ERROR
237 install_ERROR:
238         @$(ECHO) Please define INSTALL in order to enable the installation rules.
239         $(Q)exit 1
240 endif