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