print error on deprecated config items
[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}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
50         @$(ECHO) INSTALL ${1}
51         $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${1} $${${1}_INSTALLDIR}/
52         $(Q)$${${1}_POSTINSTALL}
53
54 endef
55
56 # ADD_INSTALL_RULE.a - Parameterized "function" that adds a new rule
57 #   and phony target for installing a static library
58 #
59 #   USE WITH EVAL
60 #
61 define ADD_INSTALL_RULE.a
62     ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
63
64     # Global install depends on ${1}
65     install: $${${1}_INSTALLDIR}/$(notdir ${1})
66
67     # Install static library ${1}
68     $${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} ${1} | $${${1}_INSTALLDIR}
69         @$(ECHO) INSTALL ${1}
70         $(Q)$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
71         $(Q)$${${1}_POSTINSTALL}
72
73 endef
74
75 # ADD_INSTALL_RULE.la - Parameterized "function" that adds a new rule
76 #   and phony target for installing a libtool library
77 #
78 #   FIXME: The libtool install *also* installs a bunch of other files.
79 #          ensure that those are removed, too.
80 #
81 #   USE WITH EVAL
82 #
83 define ADD_INSTALL_RULE.la
84     ALL_INSTALL += $${${1}_INSTALLDIR}/$(notdir ${1})
85
86     # Global install depends on ${1}
87     install: $${${1}_INSTALLDIR}/$(notdir ${1})
88
89     # Install libtool library ${1}
90     $${${1}_INSTALLDIR}/$(notdir ${1}): ${JLIBTOOL} $${${1}_BUILD}/${1} | $${${1}_INSTALLDIR}
91         @$(ECHO) INSTALL ${1}
92         $(Q)$${PROGRAM_INSTALL} -c -m 755 $${LOCAL_FLAGS_MIN} $${BUILD_DIR}/lib/${1} $${${1}_INSTALLDIR}/
93         $(Q)$${${1}_POSTINSTALL}
94
95 endef
96
97 # ADD_INSTALL_RULE.man - Parameterized "function" that adds a new rule
98 #   and phony target for installing a "man" page.  It will take care of
99 #   installing it into the correct subdirectory of "man".
100 #
101 #   USE WITH EVAL
102 #
103 define ADD_INSTALL_RULE.man
104     ALL_INSTALL += ${2}/$(notdir ${1})
105
106     # Global install depends on ${1}
107     install: ${2}/$(notdir ${1})
108
109     # Install manual page ${1}
110     ${2}/$(notdir ${1}): ${JLIBTOOL} ${1} | ${2}
111         @$(ECHO) INSTALL $(notdir ${1})
112         $(Q)$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
113
114 endef
115
116
117 # ADD_INSTALL_RULE.dir - Parameterized "function" that adds a new rule
118 #   and phony target for installing a directory
119 #
120 #   USE WITH EVAL
121 #
122 define ADD_INSTALL_RULE.dir
123     # Install directory
124     .PHONY: ${1}
125     ${1}: ${JLIBTOOL}
126         @$(ECHO) INSTALL -d -m 755 ${1}
127         $(Q)$${PROGRAM_INSTALL} -d -m 755 ${1}
128 endef
129
130
131 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
132 #   which installs everything for the target.
133 #
134 #   USE WITH EVAL
135 #
136 define ADD_INSTALL_TARGET
137     # Figure out which target rule to use for installation.
138     ifeq "$${${1}_SUFFIX}" ".exe"
139         ifeq "$${TGT_INSTALLDIR}" ".."
140             TGT_INSTALLDIR := $${bindir}
141         endif
142     else
143         ifeq "$${TGT_INSTALLDIR}" ".."
144             TGT_INSTALLDIR := $${libdir}
145         endif
146     endif
147
148     # add rules to install the target
149     ifneq "$${TGT_INSTALLDIR}" ""
150         ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
151
152         $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
153     endif
154
155     # add rules to install the MAN pages.
156     ifneq "$$(strip $${${1}_MAN})" ""
157         ifeq "$${mandir}" ""
158             $$(error You must define 'mandir' in order to be able to install MAN pages.)
159         endif
160
161         MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
162         MAN := $$(call CANONICAL_PATH,$${MAN})
163
164         $$(foreach PAGE,$${MAN},\
165             $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
166               $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
167     endif
168 endef
169
170 .PHONY: install
171 install:
172
173 ALL_INSTALL :=
174
175 # Define reasonable defaults for all of the installation directories.
176 # The user can over-ride these, but these are the defaults.
177 ifeq "${prefix}" ""
178     prefix = /usr/local
179 endif
180 ifeq "${exec_prefix}" ""
181     exec_prefix = ${prefix}
182 endif
183 ifeq "${bindir}" ""
184     bindir = ${exec_prefix}/bin
185 endif
186 ifeq "${sbindir}" ""
187     sbindir = ${exec_prefix}/sbin
188 endif
189 ifeq "${libdir}" ""
190     libdir = ${exec_prefix}/lib
191 endif
192 ifeq "${sysconfdir}" ""
193     sysconfdir = ${prefix}/etc
194 endif
195 ifeq "${localstatedir}" ""
196     localstatedir = ${prefix}/var
197 endif
198 ifeq "${datarootdir}" ""
199     datarootdir = ${prefix}/share
200 endif
201 ifeq "${datadir}" ""
202     datadir = ${prefix}/share
203 endif
204 ifeq "${mandir}" ""
205     mandir = ${datadir}/man
206 endif
207 ifeq "${docdir}" ""
208     ifneq "${PROJECT_NAME}" ""
209         docdir = ${datadir}/doc/${PROJECT_NAME}
210     endif
211 endif
212 ifeq "${logdir}" ""
213     logdir = ${localstatedir}/log/
214 endif
215 ifeq "${includedir}" ""
216     includedir = ${prefix}/include
217 endif
218
219
220 # Un-install any installed programs.  We DON'T want to depend on the
221 # install target.  Doing so would cause "make uninstall" to build it,
222 # install it, and then remove it.
223 #
224 # We also want to uninstall only when there are "install_foo" targets.
225 .PHONY: uninstall
226 uninstall:
227         $(Q)rm -f ${ALL_INSTALL} ./.no_such_file
228
229 # Wrapper around INSTALL
230 ifeq "${PROGRAM_INSTALL}" ""
231     PROGRAM_INSTALL := ${INSTALL}
232
233 endif
234
235 # Make just the installation directories
236 .PHONY: installdirs
237 installdirs:
238
239 # Be nice to the user.  If there is no INSTALL program, then print out
240 # a helpful message.  Without this check, the "install" rules defined
241 # above would try to run a command-line with a blank INSTALL, and give
242 # some inscrutable error.
243 ifeq "${INSTALL}" ""
244 install: install_ERROR
245
246 .PHONY: install_ERROR
247 install_ERROR:
248         @$(ECHO) Please define INSTALL in order to enable the installation rules.
249         $(Q)exit 1
250 endif