Mk/Uses/iconv: support iconv+
[dports.git] / Mk / bsd.autotools.mk
1 #-*- tab-width: 4; -*-
2 # ex:ts=4
3 #
4 # $FreeBSD: Mk/bsd.autotools.mk 325841 2013-09-01 01:18:05Z koobs $
5 #
6 # Please view me with 4 column tabs!
7 #
8 # IMPORTANT NOTE:
9 #       Before making any changes to this file, contact portmgr to arrange
10 #       for an experimental ports run.
11 #       Untested commits will almost certainly break the tree, incur the
12 #       wrath of countless folks, and be unceremoniously backed out by
13 #       the maintainer and/or portmgr.
14
15 Autotools_Include_MAINTAINER=   autotools@FreeBSD.org
16
17 #---------------------------------------------------------------------------
18 # USE_AUTOTOOLS= tool[:env] ...
19 #
20 # 'tool' can currently be one of the following:
21 #               autoconf, autoheader
22 #               autoconf213, autoheader213 (legacy version)
23 #               automake, aclocal
24 #               automake14, aclocal14 (legacy version)
25 #               libtool, libtoolize, libltdl
26 #
27 # ':env' is used to specify that the environmental variables are needed
28 #               but the relevant tool should NOT be run as part of the
29 #               'run-autotools' target
30 #
31 # In addition, these variables can be set in the port Makefile to be
32 # passed to the relevant tools:
33 #
34 # AUTOMAKE_ARGS=...
35 #       - Extra arguments passed to automake during configure step
36 #
37 # ACLOCAL_ARGS=...
38 #       - Arguments passed to aclocal during configure step
39 #
40 # AUTOCONF_ARGS=...
41 #       - Extra arguments passed to autoconf during configure step
42 #
43 # AUTOHEADER_ARGS=...
44 #       - Extra arguments passed to autoheader during configure step
45 #
46 # LIBTOOLIZE_ARGS=...
47 #       - Extra arguments passed to libtoolize during configure step
48 #
49 # LIBTOOLFLAGS=<value>
50 #       - Arguments passed to libtool during configure step
51 #
52 # LIBTOOLFILES=<list-of-files>
53 #       - A list of files to patch during libtool pre-configuration
54 #
55 # AUTOTOOLSFILES=<list-of-files>
56 #       - A list of files to further patch with derived information
57 #         post-patching to reduce churn during component updates
58 #
59 #---------------------------------------------------------------------------
60
61 #---------------------------------------------------------------------------
62 # NO USER-SERVICABLE PARTS BEYOND THIS POINT.  REALLY.  WE MEAN IT.
63 #---------------------------------------------------------------------------
64
65 # Known autotools components
66 _AUTOTOOLS_ALL= autoconf autoheader autoconf213 autoheader213 \
67                                 automake aclocal automake14 aclocal14 \
68                                 libtool libtoolize libltdl
69
70 # Incompatible autotools mixing
71 _AUTOTOOLS_IGN_autoconf=                autoconf213 autoheader213
72 _AUTOTOOLS_IGN_autoheader=              autoconf213 autoheader213
73 _AUTOTOOLS_IGN_autoconf213=             autoconf autoheader
74 _AUTOTOOLS_IGN_autoheader213=           autoconf autoheader
75 _AUTOTOOLS_IGN_automake=                automake14 aclocal14
76 _AUTOTOOLS_IGN_aclocal=                 automake14 aclocal14
77 _AUTOTOOLS_IGN_automake14=              automake aclocal
78 _AUTOTOOLS_IGN_aclocal14=               automake aclocal
79
80 #---------------------------------------------------------------------------
81 # Primary magic to break out the USE_AUTOTOOLS stanza into something
82 # more useful, along with substantial error checking to prevent
83 # foot-shooting
84 #---------------------------------------------------------------------------
85
86 # Break out the stanza
87 #
88 _AUTOTOOLS_IMPL=
89 .for stanza in ${USE_AUTOTOOLS}
90 _AUTOTOOLS_IMPL+= ${stanza:C/^([^:]+).*/\1/}
91 _AUTOTOOL_${stanza:C/^([^:]+).*/\1/}= ${stanza:C/^[^:]+:([^:]+)/\1/}
92 .endfor
93
94 # Verify each component, normalize
95 #
96 _AUTOTOOLS_NOCOMP=
97 .for component in ${_AUTOTOOLS_IMPL}
98 . if ${_AUTOTOOLS_ALL:M${component}}==""
99 _AUTOTOOLS_NOCOMP+=     ${component}
100 . endif
101 . if ${_AUTOTOOL_${component}}==${component}
102 _AUTOTOOL_${component}=  yes
103 . elsif ${_AUTOTOOL_${component}}!="env" && ${_AUTOTOOL_${component}}!="yes"
104 _AUTOTOOLS_BADCOMP+= ${component}:${_AUTOTOOL_${component}}
105 . endif
106 .endfor
107 .if !empty(_AUTOTOOLS_NOCOMP)
108 IGNORE+=        Unknown autotool: ${_AUTOTOOLS_NOCOMP:O:u}
109 .endif
110
111 # Check for anything other than 'yes' or 'env'
112 #
113 _AUTOTOOLS_BADCOMP=
114 .for component in ${_AUTOTOOLS_IMPL}
115 . if ${_AUTOTOOL_${component}}!="env" && ${_AUTOTOOL_${component}}!="yes"
116 _AUTOTOOLS_BADCOMP+= ${component}:${_AUTOTOOL_${component}}
117 . endif
118 .endfor
119 .if !empty(_AUTOTOOLS_BADCOMP)
120 IGNORE+=        Bad autotool stanza: ${_AUTOTOOLS_BADCOMP:O:u}
121 .endif
122
123 # Check for incompatible mixes of components
124 #
125 _AUTOTOOLS_IGN=
126 .for component in ${_AUTOTOOLS_IMPL}
127 . for ignore in ${_AUTOTOOLS_IGN_${component}}
128 .  if defined(_AUTOTOOL_${ignore})
129 _AUTOTOOLS_IGN+=        ${component}
130 .  endif
131 . endfor
132 .endfor
133 .if !empty(_AUTOTOOLS_IGN)
134 IGNORE+=        Incompatible autotools: ${_AUTOTOOLS_IGN:O:u}
135 .endif
136
137 #---------------------------------------------------------------------------
138 # automake and aclocal
139 #---------------------------------------------------------------------------
140
141 .if defined(_AUTOTOOL_aclocal) && ${_AUTOTOOL_aclocal} == "yes"
142 _AUTOTOOL_automake?=            env
143 _AUTOTOOL_rule_aclocal=         yes
144 GNU_CONFIGURE=                          yes
145 .endif
146
147 .if defined(_AUTOTOOL_automake)
148 AUTOMAKE_VERSION=       1.14
149 AUTOMAKE_APIVER=        1.14
150 AUTOMAKE_PORT=          devel/automake
151
152 . if ${_AUTOTOOL_automake} == "yes"
153 _AUTOTOOL_rule_automake=        yes
154 GNU_CONFIGURE?=                         yes
155 . endif
156 .endif
157
158 .if defined(_AUTOTOOL_aclocal14) && ${_AUTOTOOL_aclocal14} == "yes"
159 _AUTOTOOL_automake14?=          env
160 _AUTOTOOL_rule_aclocal14=       yes
161 GNU_CONFIGURE?=                         yes
162 .endif
163
164 .if defined(_AUTOTOOL_automake14)
165 AUTOMAKE_VERSION=       1.4
166 AUTOMAKE_APIVER=        1.4.6
167 AUTOMAKE_PORT=          devel/automake14
168 AUTOMAKE_ARGS+=         -i              # backwards compatibility shim
169
170 . if ${_AUTOTOOL_automake14} == "yes"
171 _AUTOTOOL_rule_automake=        yes
172 GNU_CONFIGURE?=                         yes
173 . endif
174 .endif
175
176 .if defined(AUTOMAKE_VERSION)
177 AUTOMAKE=                       ${LOCALBASE}/bin/automake-${AUTOMAKE_VERSION}
178 AUTOMAKE_DIR=           ${LOCALBASE}/share/automake-${AUTOMAKE_VERSION}
179 ACLOCAL=                        ${LOCALBASE}/bin/aclocal-${AUTOMAKE_VERSION}
180 ACLOCAL_DIR=            ${LOCALBASE}/share/aclocal-${AUTOMAKE_VERSION}
181
182 . if defined(_AUTOTOOL_aclocal)
183 ACLOCAL_ARGS?=          --automake-acdir=${ACLOCAL_DIR}
184 . endif
185 . if defined(_AUTOTOOL_aclocal14)
186 ACLOCAL_ARGS?=          --acdir=${ACLOCAL_DIR}
187 . endif
188
189 AUTOMAKE_VARS=          AUTOMAKE=${AUTOMAKE} \
190                                         AUTOMAKE_DIR=${AUTOMAKE_DIR} \
191                                         AUTOMAKE_VERSION=${AUTOMAKE_VERSION} \
192                                         AUTOMAKE_APIVER=${AUTOMAKE_APIVER} \
193                                         ACLOCAL=${ACLOCAL} \
194                                         ACLOCAL_DIR=${ACLOCAL_DIR}
195
196 AUTOMAKE_DEPENDS=       ${AUTOMAKE}:${PORTSDIR}/${AUTOMAKE_PORT}
197 BUILD_DEPENDS+=         ${AUTOMAKE_DEPENDS}
198 .endif
199
200 #---------------------------------------------------------------------------
201 # autoconf and autoheader
202 #---------------------------------------------------------------------------
203
204 .if defined(_AUTOTOOL_autoheader) && ${_AUTOTOOL_autoheader} == "yes"
205 _AUTOTOOL_autoconf=                     yes
206 _AUTOTOOL_rule_autoheader=      yes
207 GNU_CONFIGURE?=                         yes
208 .endif
209
210 .if defined(_AUTOTOOL_autoconf)
211 AUTOCONF_VERSION=       2.69
212 AUTOCONF_PORT=          devel/autoconf
213
214 . if ${_AUTOTOOL_autoconf} == "yes"
215 _AUTOTOOL_rule_autoconf=        yes
216 GNU_CONFIGURE?=                         yes
217 . endif
218 .endif
219
220 .if defined(_AUTOTOOL_autoheader213) && ${_AUTOTOOL_autoheader213} == "yes"
221 _AUTOTOOL_autoconf213=          yes
222 _AUTOTOOL_rule_autoheader=      yes
223 GNU_CONFIGURE?=                         yes
224 .endif
225
226 .if defined(_AUTOTOOL_autoconf213)
227 AUTOCONF_VERSION=       2.13
228 AUTOCONF_PORT=          devel/autoconf213
229 AUTOM4TE=                       ${FALSE}        # doesn't exist here
230
231 . if ${_AUTOTOOL_autoconf213} == "yes"
232 _AUTOTOOL_rule_autoconf=        yes
233 GNU_CONFIGURE?=                         yes
234 . endif
235 .endif
236
237 .if defined(AUTOCONF_VERSION)
238 AUTOCONF=                       ${LOCALBASE}/bin/autoconf-${AUTOCONF_VERSION}
239 AUTOCONF_DIR=           ${LOCALBASE}/share/autoconf-${AUTOCONF_VERSION}
240 AUTOHEADER=                     ${LOCALBASE}/bin/autoheader-${AUTOCONF_VERSION}
241 AUTOIFNAMES=            ${LOCALBASE}/bin/ifnames-${AUTOCONF_VERSION}
242 AUTOM4TE?=                      ${LOCALBASE}/bin/autom4te-${AUTOCONF_VERSION}
243 AUTORECONF=                     ${LOCALBASE}/bin/autoreconf-${AUTOCONF_VERSION}
244 AUTOSCAN=                       ${LOCALBASE}/bin/autoscan-${AUTOCONF_VERSION}
245 AUTOUPDATE=                     ${LOCALBASE}/bin/autoupdate-${AUTOCONF_VERSION}
246 AUTOCONFWRAP=                   ${LOCALBASE}/bin/autoconf
247 AUTOCWPORT=                     devel/autoconf-wrapper
248
249 AUTOCONF_VARS=          AUTOCONF=${AUTOCONF} \
250                                         AUTOCONF_DIR=${AUTOCONF_DIR} \
251                                         AUTOHEADER=${AUTOHEADER} \
252                                         AUTOIFNAMES=${AUTOIFNAMES} \
253                                         AUTOM4TE=${AUTOM4TE} \
254                                         AUTORECONF=${AUTORECONF} \
255                                         AUTOSCAN=${AUTOSCAN} \
256                                         AUTOUPDATE=${AUTOUPDATE} \
257                                         AUTOCONF_VERSION=${AUTOCONF_VERSION}
258
259 AUTOCONF_DEPENDS=       ${AUTOCONF}:${PORTSDIR}/${AUTOCONF_PORT}
260 AUTOCONF_DEPENDS+=      ${AUTOCONFWRAP}:${PORTSDIR}/${AUTOCWPORT}
261 AUTOCONF_DEPENDS+=      gm4:${PORTSDIR}/devel/m4
262 BUILD_DEPENDS+=         ${AUTOCONF_DEPENDS}
263 .endif
264
265 #---------------------------------------------------------------------------
266 # libltdl
267 #---------------------------------------------------------------------------
268
269 .if defined(_AUTOTOOL_libltdl)
270 LIB_DEPENDS+=           ltdl.7:${PORTSDIR}/devel/libltdl
271 .endif
272
273 #---------------------------------------------------------------------------
274 # libtool/libtoolize
275 #---------------------------------------------------------------------------
276
277 .if defined(_AUTOTOOL_libtool) || defined(_AUTOTOOL_libtoolize)
278 LIBTOOL_VERSION=        2.4
279 LIBTOOL_PORT=           devel/libtool
280
281 . if defined(_AUTOTOOL_libtool) && ${_AUTOTOOL_libtool} == "yes"
282 _AUTOTOOL_rule_libtool=         yes
283 GNU_CONFIGURE?=                         yes
284 . endif
285 . if defined(_AUTOTOOL_libtoolize) && ${_AUTOTOOL_libtoolize} == "yes"
286 _AUTOTOOL_rule_libtoolize=      yes
287 GNU_CONFIGURE?=                         yes
288 . endif
289
290 .endif
291
292 .if defined(LIBTOOL_VERSION)
293 LIBTOOL=                        ${LOCALBASE}/bin/libtool
294 LIBTOOLIZE=                     ${LOCALBASE}/bin/libtoolize
295 LIBTOOL_LIBEXECDIR=     ${LOCALBASE}/libexec/libtool
296 LIBTOOL_SHAREDIR=       ${LOCALBASE}/share/libtool
297 LIBTOOL_M4=                     ${LOCALBASE}/share/aclocal/libtool.m4
298 LTMAIN=                         ${LOCALBASE}/share/libtool/config/ltmain.sh
299
300 LIBTOOL_VARS=           LIBTOOL=${LIBTOOL} \
301                                         LIBTOOLIZE=${LIBTOOLIZE} \
302                                         LIBTOOL_LIBEXECDIR=${LIBTOOL_LIBEXECDIR} \
303                                         LIBTOOL_SHAREDIR=${LIBTOOL_SHAREDIR} \
304                                         LIBTOOL_M4=${LIBTOOL_M4} \
305                                         LTMAIN=${LTMAIN}
306
307 LIBTOOLFLAGS?=          # default to empty
308
309 . if defined(_AUTOTOOL_rule_autoconf) || defined(_AUTOTOOL_rule_autoconf213)
310 LIBTOOLFILES?=          aclocal.m4
311 . elif defined(_AUTOTOOL_rule_libtool)
312 LIBTOOLFILES?=          ${CONFIGURE_SCRIPT}
313 . endif
314
315 LIBTOOL_DEPENDS=        libtool>=2.4:${PORTSDIR}/${LIBTOOL_PORT}
316 BUILD_DEPENDS+=         ${LIBTOOL_DEPENDS}
317 .endif
318
319 #---------------------------------------------------------------------------
320 # Add to the environment
321 #---------------------------------------------------------------------------
322
323 AUTOTOOLS_VARS=         ${AUTOMAKE_VARS} ${AUTOCONF_VARS} ${LIBTOOL_VARS}
324
325 .if defined(AUTOTOOLS_VARS) && !empty(AUTOTOOLS_VARS)
326 . for var in AUTOTOOLS CONFIGURE MAKE SCRIPTS
327 ${var:tu}_ENV+=         ${AUTOTOOLS_VARS}
328 . endfor
329 .endif
330
331 #---------------------------------------------------------------------------
332 # Make targets
333 #---------------------------------------------------------------------------
334
335 .if !target(run-autotools)
336 .ORDER:                 run-autotools run-autotools-aclocal \
337                                 patch-autotools-libtool run-autotools-autoheader \
338                                 run-autotools-libtoolize run-autotools-autoconf \
339                                 run-autotools-automake
340
341 run-autotools:: run-autotools-aclocal \
342                                 patch-autotools-libtool run-autotools-autoheader \
343                                 run-autotools-libtoolize run-autotools-autoconf \
344                                 run-autotools-automake
345 .endif
346
347 .if !target(run-autotools-aclocal)
348 run-autotools-aclocal:
349 . if defined(_AUTOTOOL_rule_aclocal)
350         @(cd ${CONFIGURE_WRKSRC} && ${SETENV} ${AUTOTOOLS_ENV} ${ACLOCAL} \
351                 ${ACLOCAL_ARGS})
352 . else
353         @${DO_NADA}
354 . endif
355 .endif
356
357 .if !target(run-autotools-automake)
358 run-autotools-automake:
359 . if defined(_AUTOTOOL_rule_automake)
360         @(cd ${CONFIGURE_WRKSRC} && ${SETENV} ${AUTOTOOLS_ENV} ${AUTOMAKE} \
361                 ${AUTOMAKE_ARGS})
362 . else
363         @${DO_NADA}
364 . endif
365 .endif
366
367 .if !target(run-autotools-autoconf)
368 run-autotools-autoconf:
369 . if defined(_AUTOTOOL_rule_autoconf)
370         @(cd ${CONFIGURE_WRKSRC} && ${SETENV} ${AUTOTOOLS_ENV} ${AUTOCONF} \
371                 ${AUTOCONF_ARGS})
372 . else
373         @${DO_NADA}
374 . endif
375 .endif
376
377 .if !target(run-autotools-autoheader)
378 run-autotools-autoheader:
379 . if defined(_AUTOTOOL_rule_autoheader)
380         @(cd ${CONFIGURE_WRKSRC} && ${SETENV} ${AUTOTOOLS_ENV} ${AUTOHEADER} \
381                 ${AUTOHEADER_ARGS})
382 . else
383         @${DO_NADA}
384 . endif
385 .endif
386
387 .if !target(run-autotools-libtoolize)
388 run-autotools-libtoolize:
389 . if defined(_AUTOTOOL_rule_libtoolize)
390         @(cd ${CONFIGURE_WRKSRC} && ${SETENV} ${AUTOTOOLS_ENV} ${LIBTOOLIZE} \
391                 ${LIBTOOLIZE_ARGS})
392 . else
393         @${DO_NADA}
394 . endif
395 .endif
396
397 .if !target(patch-autotools-libtool)
398 patch-autotools-libtool::
399 . if defined(_AUTOTOOL_rule_libtool)
400         @for file in ${LIBTOOLFILES}; do \
401                 ${REINPLACE_CMD} -e \
402                         "/^ltmain=/!s|\$$ac_aux_dir/ltmain.sh|${LIBTOOLFLAGS} ${LTMAIN}|g; \
403                         /^LIBTOOL=/s|\$$(top_builddir)/libtool|${LIBTOOL}|g" \
404                         ${PATCH_WRKSRC}/$$file; \
405         done;
406 . else
407         @${DO_NADA}
408 . endif
409 .endif
410
411 #---------------------------------------------------------------------------
412 # Reduce patch churn by auto-substituting data from AUTOTOOLS_VARS
413 # into the correct places.  Code shamelessly stolen from PLIST_SUB.
414
415 AUTOTOOLSFILES?=        # default to empty
416 AUTOTOOLS_VARS?=        # empty if not already set
417
418 .if !target(configure-autotools)
419 configure-autotools::
420 . if ${AUTOTOOLS_VARS}!="" && ${AUTOTOOLSFILES} != ""
421         @for file in ${AUTOTOOLSFILES}; do \
422                 ${REINPLACE_CMD} ${AUTOTOOLS_VARS:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
423                         ${WRKSRC}/$${file} ; \
424         done
425 . else
426         @${DO_NADA}
427 . endif
428 .endif