We don't actually copy...
[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}/${1}
39         @$(ECHO) INSTALL ${1}
40         @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
41         @$${PROGRAM_INSTALL} -c -m 755 $${BUILD_DIR}/bin/${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}/${1}
82         @$(ECHO) INSTALL ${1}
83         @$${PROGRAM_INSTALL} -d -m 755 $${${1}_INSTALLDIR}
84         @$${PROGRAM_INSTALL} -c -m 755 $${RELINK_FLAGS_MIN} $${BUILD_DIR}/lib/${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}
103         @$(ECHO) INSTALL $(notdir ${1})
104         @[ -d ${2} ] || $${PROGRAM_INSTALL} -d -m 755 ${2}
105         @$${PROGRAM_INSTALL} -c -m 644 ${1} ${2}/
106
107 endef
108
109
110 # ADD_INSTALL_TARGET - Parameterized "function" that adds a new rule
111 #   which installs everything for the target.
112 #
113 #   USE WITH EVAL
114 #
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}
120         endif
121     else 
122         ifeq "$${TGT_INSTALLDIR}" ".."
123             TGT_INSTALLDIR := $${libdir}
124         endif
125     endif
126
127     # add rules to install the target
128     ifneq "$${TGT_INSTALLDIR}" ""
129         ${1}_INSTALLDIR := ${LL}$${DESTDIR}$${TGT_INSTALLDIR}
130
131         $$(eval $$(call ADD_INSTALL_RULE$${${1}_SUFFIX},${1}))
132     endif
133
134     # add rules to install the MAN pages.
135     ifneq "$$(strip $${${1}_MAN})" ""
136         ifeq "$${mandir}" ""
137             $$(error You must define 'mandir' in order to be able to install MAN pages.)
138         endif
139
140         MAN := $$(call QUALIFY_PATH,$${DIR},$${MAN})
141         MAN := $$(call CANONICAL_PATH,$${MAN})
142
143         $$(foreach PAGE,$${MAN},\
144             $$(eval $$(call ADD_INSTALL_RULE.man,$${PAGE},\
145               $${DESTDIR}$${mandir}/man$$(subst .,,$$(suffix $${PAGE})))))
146     endif
147 endef
148
149 .PHONY: install
150 install:
151
152 ALL_INSTALL :=
153
154 # Define reasonable defaults for all of the installation directories.
155 # The user can over-ride these, but these are the defaults.
156 ifeq "${prefix}" ""
157     prefix = /usr/local
158 endif
159 ifeq "${exec_prefix}" ""
160     exec_prefix = ${prefix}
161 endif
162 ifeq "${bindir}" ""
163     bindir = ${exec_prefix}/bin
164 endif
165 ifeq "${sbindir}" ""
166     sbindir = ${exec_prefix}/sbin
167 endif
168 ifeq "${libdir}" ""
169     libdir = ${exec_prefix}/lib
170 endif
171 ifeq "${sysconfdir}" ""
172     sysconfdir = ${prefix}/etc
173 endif
174 ifeq "${localstatedir}" ""
175     localstatedir = ${prefix}/var
176 endif
177 ifeq "${datarootdir}" ""
178     datarootdir = ${prefix}/share
179 endif
180 ifeq "${datadir}" ""
181     datadir = ${prefix}/share
182 endif
183 ifeq "${mandir}" ""
184     mandir = ${datadir}/man
185 endif
186 ifeq "${docdir}" ""
187     ifneq "${PROJECT_NAME}" ""
188         docdir = ${datadir}/doc/${PROJECT_NAME}
189     endif
190 endif
191 ifeq "${logdir}" ""
192     logdir = ${localstatedir}/log/
193 endif
194 ifeq "${includedir}" ""
195     includedir = ${prefix}/include
196 endif
197
198
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.
202 #
203 # We also want to uninstall only when there are "install_foo" targets.
204 .PHONY: uninstall
205 uninstall:
206         @rm -f ${ALL_INSTALL} ./.no_such_file
207
208 # Wrapper around INSTALL
209 ifeq "${PROGRAM_INSTALL}" ""
210     PROGRAM_INSTALL := ${INSTALL}
211
212 endif
213
214 # Make just the installation directories
215 .PHONY: installdirs
216 installdirs:
217
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.
222 ifeq "${INSTALL}" ""
223 install: install_ERROR
224
225 .PHONY: install_ERROR
226 install_ERROR:
227         @$(ECHO) Please define INSTALL in order to enable the installation rules.
228         @exit 1
229 endif