configure: use XC_CONFIGURE_PREAMBLE early checks
[platform/upstream/curl.git] / m4 / zz40-xc-ovr.m4
1 #---------------------------------------------------------------------------
2 #
3 # zz40-xc-ovr.m4
4 #
5 # Copyright (c) 2013 Daniel Stenberg <daniel@haxx.se>
6 #
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #
19 #---------------------------------------------------------------------------
20
21 # serial 1
22
23
24 dnl The funny name of this file is intentional in order to make it
25 dnl sort alphabetically after any libtool, autoconf or automake
26 dnl provided .m4 macro file that might get copied into this same
27 dnl subdirectory. This allows that macro (re)definitions from this
28 dnl file may override those provided in other files.
29
30
31 dnl _XC_CONFIGURE_PREAMBLE_COMMENT
32 dnl -------------------------------------------------
33 dnl Private macro.
34
35 AC_DEFUN([_XC_CONFIGURE_PREAMBLE_COMMENT],
36 [
37 ## ---------------------------- ##
38 ## XC_CONFIGURE_PREAMBLE rev: 1 ##
39 ## ---------------------------- ##
40 ])
41
42
43 dnl _XC_CHECK_COMMAND_TEST
44 dnl -------------------------------------------------
45 dnl Private macro.
46 dnl
47 dnl Check that 'test' command is available, else abort.
48
49 AC_DEFUN([_XC_CHECK_COMMAND_TEST],
50 [dnl
51 #
52 # Require that 'test' command is available.
53 #
54
55 xc_tst_str='unknown'
56 test -n "$xc_tst_str" && xc_tst_str='success'
57 case "x$xc_tst_str" in
58   xsuccess)
59     :
60     ;;
61   *)
62     echo "configure: error: 'test' command not found. Can not continue."
63     exit 1
64     ;;
65 esac
66 ])
67
68
69 dnl _XC_CHECK_PATH
70 dnl -------------------------------------------------
71 dnl Private macro.
72 dnl
73 dnl Check that PATH is set, otherwise abort.
74
75 AC_DEFUN([_XC_CHECK_PATH],
76 [dnl
77 AC_REQUIRE([_XC_CHECK_COMMAND_TEST])dnl
78 #
79 # Require that PATH variable is set.
80 #
81
82 xc_tst_str='unknown'
83 test -n "$PATH" && xc_tst_str='success'
84 case "x$xc_tst_str" in
85   xsuccess)
86     :
87     ;;
88   *)
89     echo "configure: error: PATH variable not set. Can not continue."
90     exit 1
91     ;;
92 esac
93 ])
94
95
96 dnl _XC_CHECK_COMMAND_EXPR
97 dnl -------------------------------------------------
98 dnl Private macro.
99 dnl
100 dnl Check that 'expr' command is available, else abort.
101
102 AC_DEFUN([_XC_CHECK_COMMAND_EXPR],
103 [dnl
104 #
105 # Require that 'expr' command is available.
106 #
107
108 xc_tst_str='unknown'
109 xc_tst_str=`expr "$xc_tst_str" : '.*'`
110 case "x$xc_tst_str" in
111   x7)
112     :
113     ;;
114   *)
115     echo "configure: error: 'expr' command not found. Can not continue."
116     exit 1
117     ;;
118 esac
119 ])
120
121
122 dnl _XC_CHECK_UTILITY_SED
123 dnl -------------------------------------------------
124 dnl Private macro.
125 dnl
126 dnl Check that 'sed' utility is found within PATH. This
127 dnl 'sed' is required in order to allow configure script
128 dnl bootstrapping itself. No fancy testing for a proper
129 dnl 'sed' this early please, that should be done later.
130
131 AC_DEFUN([_XC_CHECK_UTILITY_SED],
132 [dnl
133 #
134 # Require that 'sed' utility is found within PATH.
135 #
136
137 xc_tst_str='unknown'
138 xc_tst_str=`echo "$xc_tst_str" | sed -e 's:unknown:success:'`
139 case "x$xc_tst_str" in
140   xsuccess)
141     :
142     ;;
143   *)
144     echo "configure: error: 'sed' utility not in PATH. Can not continue."
145     exit 1
146     ;;
147 esac
148 ])
149
150
151 dnl _XC_CHECK_UTILITY_GREP
152 dnl -------------------------------------------------
153 dnl Private macro.
154 dnl
155 dnl Check that 'grep' utility is found within PATH. This
156 dnl 'grep' is required in order to allow configure script
157 dnl bootstrapping itself. No fancy testing for a proper
158 dnl 'grep' this early please, that should be done later.
159
160 AC_DEFUN([_XC_CHECK_UTILITY_GREP],
161 [dnl
162 #
163 # Require that 'grep' utility is found within PATH.
164 #
165
166 xc_tst_str='unknown'
167 echo "$xc_tst_str" | grep 'unknown' >/dev/null 2>&1 && xc_tst_str='success'
168 case "x$xc_tst_str" in
169   xsuccess)
170     :
171     ;;
172   *)
173     echo "configure: error: 'grep' utility not in PATH. Can not continue."
174     exit 1
175     ;;
176 esac
177 ])
178
179
180 dnl _XC_CHECK_PATH_SEPARATOR
181 dnl -------------------------------------------------
182 dnl Private macro.
183 dnl
184 dnl Check and compute the path separator for us. This
185 dnl path separator is the symbol used to diferentiate
186 dnl or separate paths inside the PATH environment var.
187 dnl
188 dnl User provided PATH_SEPARATOR always overrides the
189 dnl auto-detected one.
190
191 AC_DEFUN([_XC_CHECK_PATH_SEPARATOR],
192 [dnl
193 AC_REQUIRE([_XC_CHECK_COMMAND_TEST])dnl
194 AC_REQUIRE([_XC_CHECK_PATH])dnl
195 AC_REQUIRE([_XC_CHECK_COMMAND_EXPR])dnl
196 #
197 # Auto-detect and set PATH_SEPARATOR, unless it is already set.
198 #
199
200 # Directory count in PATH when using a colon separator.
201 xc_tst_dirs_col=0
202 xc_tst_prev_IFS=$IFS; IFS=':'
203 for xc_tst_dir in $PATH; do
204   IFS=$xc_tst_prev_IFS
205   test -d "$xc_tst_dir" && xc_tst_dirs_col=`expr $xc_tst_dirs_col + 1`
206 done
207 IFS=$xc_tst_prev_IFS
208
209 # Directory count in PATH when using a semicolon separator.
210 xc_tst_dirs_sem=0
211 xc_tst_prev_IFS=$IFS; IFS=';'
212 for xc_tst_dir in $PATH; do
213   IFS=$xc_tst_prev_IFS
214   test -d "$xc_tst_dir" && xc_tst_dirs_sem=`expr $xc_tst_dirs_sem + 1`
215 done
216 IFS=$xc_tst_prev_IFS
217
218 if test $xc_tst_dirs_sem -eq $xc_tst_dirs_col; then
219   # When both counting methods give the same result we do not want to
220   # chose one over the other, and consider auto-detection not possible.
221   if test -z "$PATH_SEPARATOR"; then
222     # Stop dead until user provides PATH_SEPARATOR definition.
223     echo "configure: error: PATH_SEPARATOR variable not set. Can not continue."
224     exit 1
225   fi
226 else
227   # Separator with the greater directory count is the auto-detected one.
228   if test $xc_tst_dirs_sem -gt $xc_tst_dirs_col; then
229     xc_tst_auto_separator=';'
230   else
231     xc_tst_auto_separator=':'
232   fi
233   if test -z "$PATH_SEPARATOR"; then
234     # Simply use the auto-detected one when not already set.
235     PATH_SEPARATOR="$xc_tst_auto_separator"
236   elif "x$PATH_SEPARATOR" != "x$xc_tst_auto_separator"; then
237     echo "configure: warning: PATH_SEPARATOR does not match auto-detected one."
238   fi
239 fi
240 AC_SUBST([PATH_SEPARATOR])dnl
241 ])
242
243
244 dnl _XC_CONFIGURE_PREAMBLE
245 dnl -------------------------------------------------
246 dnl Private macro.
247
248 AC_DEFUN([_XC_CONFIGURE_PREAMBLE],
249 [dnl
250 AC_REQUIRE([_XC_CONFIGURE_PREAMBLE_COMMENT])dnl
251 AC_REQUIRE([_XC_CHECK_COMMAND_TEST])dnl
252 AC_REQUIRE([_XC_CHECK_PATH])dnl
253 AC_REQUIRE([_XC_CHECK_COMMAND_EXPR])dnl
254 AC_REQUIRE([_XC_CHECK_UTILITY_SED])dnl
255 AC_REQUIRE([_XC_CHECK_UTILITY_GREP])dnl
256 AC_REQUIRE([_XC_CHECK_PATH_SEPARATOR])dnl
257 echo "checking whether some basic commands and utilities are available... yes"
258 ])
259
260
261 dnl XC_CONFIGURE_PREAMBLE
262 dnl -------------------------------------------------
263 dnl Public macro.
264 dnl
265 dnl This macro macro emits shell code which does some
266 dnl very basic checks related with the availability
267 dnl of some commands and utilities needed to allow
268 dnl configure script bootstrapping itself when using
269 dnl these to figure out other settings. Also performs
270 dnl PATH_SEPARATOR auto-detection and sets its value
271 dnl unless it is already set.
272 dnl
273 dnl These basic checks are intended to be placed and
274 dnl executed as early as possible in the resulting
275 dnl configure script, and as such these must be pure
276 dnl shell code.
277 dnl
278 dnl Although this is a public macro it should not be
279 dnl used directly from configure.ac given that in this
280 dnl way its expansion is not placed early enough in
281 dnl generated configure script, it simply makes little
282 dnl sense to perform these basic checks once the script
283 dnl is into more serious business.
284 dnl
285 dnl The proper way of making this macro expand early
286 dnl enough in configure script is using XC_OVR_ZZ40
287 dnl in configure.ac which takes care of everything.
288
289 AC_DEFUN([XC_CONFIGURE_PREAMBLE],
290 [dnl
291 AC_PREREQ([2.50])dnl
292 AC_BEFORE([$0],[_XC_CONFIGURE_PREAMBLE])dnl
293 AC_BEFORE([$0],[_XC_CHECK_COMMAND_TEST])dnl
294 AC_BEFORE([$0],[_XC_CHECK_PATH])dnl
295 AC_BEFORE([$0],[_XC_CHECK_COMMAND_EXPR])dnl
296 AC_BEFORE([$0],[_XC_CHECK_UTILITY_SED])dnl
297 AC_BEFORE([$0],[_XC_CHECK_UTILITY_GREP])dnl
298 AC_BEFORE([$0],[_XC_CHECK_PATH_SEPARATOR])dnl
299 AC_REQUIRE([_XC_CONFIGURE_PREAMBLE])dnl
300 m4_define([$0],[])dnl
301 ])
302
303
304 dnl Override autoconf's PATH_SEPARATOR check
305 dnl -------------------------------------------------
306 dnl This is done to ensure that the same check is
307 dnl used across different autoconf versions and to
308 dnl allow us to expand XC_CONFIGURE_PREAMBLE macro
309 dnl early enough in the generated configure script.
310
311 dnl
312 dnl Override when using autoconf 2.53 and newer.
313 dnl
314
315 m4_defun([_AS_PATH_SEPARATOR_PREPARE],
316 [dnl
317 AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
318 m4_define([$0],[])dnl
319 ])
320
321 dnl
322 dnl Override when using autoconf 2.50 to 2.52
323 dnl
324
325 m4_defun([_AC_INIT_PREPARE_FS_SEPARATORS],
326 [dnl
327 AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
328 ac_path_separator=$PATH_SEPARATOR
329 m4_define([$0],[])dnl
330 ])
331
332 dnl
333 dnl Override when using libtool 1.4.2
334 dnl
335
336 m4_defun([_LT_AC_LIBTOOL_SYS_PATH_SEPARATOR],
337 [dnl
338 AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
339 lt_cv_sys_path_separator=$PATH_SEPARATOR
340 m4_define([$0],[])dnl
341 ])
342
343
344 dnl XC_OVR_ZZ40
345 dnl -------------------------------------------------
346 dnl Placing a call to this macro in configure.ac will
347 dnl make macros in this file visible to other macros
348 dnl used for same configure script, overriding those
349 dnl provided elsewhere.
350 dnl
351 dnl This is the proper and intended way in which macro
352 dnl XC_CONFIGURE_PREAMBLE will expand early enough in
353 dnl generated configure script.
354
355 AC_DEFUN([XC_OVR_ZZ40],
356 [dnl
357 AC_BEFORE([$0],[AC_CHECK_TOOL])dnl
358 AC_BEFORE([$0],[AC_CHECK_PROG])dnl
359 AC_BEFORE([$0],[AC_CHECK_TOOLS])dnl
360 AC_BEFORE([$0],[AC_CHECK_PROGS])dnl
361 dnl
362 AC_BEFORE([$0],[AC_PATH_TOOL])dnl
363 AC_BEFORE([$0],[AC_PATH_PROG])dnl
364 AC_BEFORE([$0],[AC_PATH_PROGS])dnl
365 dnl
366 AC_BEFORE([$0],[AC_PROG_SED])dnl
367 AC_BEFORE([$0],[AC_PROG_GREP])dnl
368 AC_BEFORE([$0],[AC_PROG_LN_S])dnl
369 AC_BEFORE([$0],[AC_PROG_INSTALL])dnl
370 AC_BEFORE([$0],[AC_PROG_MAKE_SET])dnl
371 AC_BEFORE([$0],[AC_PROG_LIBTOOL])dnl
372 dnl
373 AC_BEFORE([$0],[LT_INIT])dnl
374 AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
375 AC_BEFORE([$0],[AC_LIBTOOL_WIN32_DLL])dnl
376 dnl
377 AC_BEFORE([$0],[AC_CONFIG_SRCDIR])dnl
378 AC_BEFORE([$0],[AC_CONFIG_HEADERS])dnl
379 AC_BEFORE([$0],[AC_CONFIG_MACRO_DIR])dnl
380 AC_BEFORE([$0],[AC_CONFIG_MACRO_DIRS])dnl
381 dnl
382 m4_define([$0],[])dnl
383 ])
384