1# Process with autom4te to create an -*- Autotest -*- test suite.
2#
3#   Copyright (C) 2004-2015 Free Software Foundation, Inc.
4#   Written by Gary V. Vaughan, 2004
5#
6#   This file is part of GNU Libtool.
7#
8# GNU Libtool is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; either version 2 of
11# the License, or (at your option) any later version.
12#
13# GNU Libtool is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with GNU Libtool; see the file COPYING.  If not, a copy
20# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
21# or obtained by writing to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23####
24
25m4_divert_push([PREPARE_TESTS])dnl
26: ${tst_dist=dist}
27: ${ACLOCAL=aclocal}
28: ${AUTOHEADER=autoheader}
29: ${AUTOCONF=autoconf}
30: ${AUTOMAKE=automake}
31: ${AUTORECONF=autoreconf}
32test set = "${ECHO+set}" || ECHO=${as_echo-'printf %s\n'}
33: ${ECHO=$as_echo}
34for tool in ACLOCAL AUTOHEADER AUTOCONF AUTOMAKE AUTORECONF; do
35  if eval \$$tool --version >/dev/null 2>&1; then :; else eval $tool=no; fi
36done
37export ACLOCAL AUTOHEADER AUTOCONF AUTOMAKE AUTORECONF
38eval `$LIBTOOL --config | $EGREP '^(objdir|objext)'`
39eval `$LIBTOOL --config | $EGREP '^(host|host_os|host_alias|build|build_alias|to_host_file_cmd|to_tool_file_cmd)='`
40configure_options=--prefix=/nonexistent
41if test -n "$host_alias"; then
42  configure_options="$configure_options --host $host_alias"
43fi
44if test -n "$build_alias"; then
45  configure_options="$configure_options --build $build_alias"
46fi
47if test -n "$to_host_file_cmd"; then
48  configure_options="$configure_options lt_cv_to_host_file_cmd=$to_host_file_cmd"
49fi
50if test -n "$to_tool_file_cmd"; then
51  configure_options="$configure_options lt_cv_to_tool_file_cmd=$to_tool_file_cmd"
52fi
53: ${mkdir_p="$abs_top_srcdir/build-aux/install-sh -d"}
54# Fix relative paths in $lt_INSTALL
55case $lt_INSTALL in
56  *build-aux/install-sh*)
57    lt_INSTALL=$abs_top_srcdir/build-aux/install-sh
58    ;;
59esac
60
61# func_extract_trace support
62. "$abs_top_srcdir/build-aux/funclib.sh"
63. "$abs_top_srcdir/build-aux/extract-trace"
64
65
66# Unset some MAKE... variables that may cause $MAKE to act like a
67# recursively invoked sub-make.  Any $MAKE invocation in a test is
68# conceptually an independent invocation.
69unset MFLAGS MAKEFLAGS MAKELEVEL __MKLVL__ MAKE_JOBS_FIFO
70
71# On AIX, shared libraries remain loaded in memory after use if they
72# are world-readable, until root issues slibclean.  On NFS, this causes
73# a testsuite rerun to fail to clean up test group directories.  Avoid
74# this with a suitable umask.  Do not do this on other systems, for
75# example HP-UX suffers unless shared libraries are mode 555.
76case $host_os in
77aix*) umask o-rwx ;;
78esac
79m4_divert_pop([PREPARE_TESTS])dnl
80
81
82# LT_AT_LIBTOOLIZE([ARGS])
83# ------------------------
84m4_define([LT_AT_LIBTOOLIZE],
85[$LIBTOOLIZE $1
86AT_KEYWORDS([libtoolize])
87])
88
89
90# _LIBTOOLIZE_TRANSFORM(FILE)
91# ---------------------------
92# Fix the expected output of installed libtoolize in presence of --program-*.
93m4_define([_LIBTOOLIZE_TRANSFORM],
94[lt_name=`$ECHO "$LIBTOOLIZE" | $SED "s|^.*/||"`
95$SED "s/libtoolize/$lt_name/g
96s|/usr/local/share/aclocal/|${tst_aclocaldir-$abs_top_srcdir/libltdl/m4}/|" < $1 > $1.t
97mv -f $1.t $1
98])dnl
99
100
101# LT_AT_CHECK_LIBTOOLIZE(ARGS, [EXIT-STATUS = 0], [STDOUT = ''], [STDERR = ''])
102# -----------------------------------------------------------------------------
103m4_define([LT_AT_CHECK_LIBTOOLIZE],
104[m4_if([$3], [expout], [_LIBTOOLIZE_TRANSFORM([$3])])dnl
105m4_if([$4], [experr], [_LIBTOOLIZE_TRANSFORM([$4])])dnl
106AT_CHECK([LT_AT_LIBTOOLIZE([$1])],
107  [$2], [$3], [$4])
108])
109
110
111# LT_AT_ACLOCAL([OPTIONS])
112# --------------------------
113m4_pattern_allow([^(m4_define|m4_defn|m4_ifndef)$])
114m4_define([LT_AT_ACLOCAL],
115[macro_dir=
116func_extract_trace AC_CONFIG_MACRO_DIRS
117test -n "$func_extract_trace_result" \
118    || func_extract_trace AC_CONFIG_MACRO_DIR
119test -n "$func_extract_trace_result" \
120    && macro_dir=" -I $func_extract_trace_result"
121AT_DATA([acinclude.m4],
122[[m4_ifndef([AC_CONFIG_MACRO_DIRS],
123	  [m4_define([AC_CONFIG_MACRO_DIRS], m4_defn([AC_CONFIG_MACRO_DIR]))])
124]])
125LT_AT_CHECK([$ACLOCAL $1$macro_dir], [0], [ignore], [ignore])
126# After the 'aclocal' run sleep 1 second to guarantee that aclocal.m4 is going
127# to have older timestamp than other autotools later-generated files (concretely
128# for libtool case, we speak about config.h.in generated autoheader).
129# Autoreconf does the same (after the first aclocal run).
130sleep 1
131AT_XFAIL_IF([test no = "$ACLOCAL"])
132AT_KEYWORDS([automake])
133])
134
135
136# LT_AT_AUTOCONF([OPTIONS])
137# --------------------------
138m4_define([LT_AT_AUTOCONF],
139[AT_CHECK([$AUTOCONF $1], [0], [ignore], [ignore])
140AT_XFAIL_IF([test no = "$AUTOCONF"])
141AT_KEYWORDS([autoconf])
142])
143
144
145# LT_AT_AUTOMAKE([OPTIONS])
146# --------------------------
147m4_define([LT_AT_AUTOMAKE],
148[AT_CHECK([$AUTOMAKE $1], [0], [ignore], [stderr],
149  [AT_CHECK([$GREP 'require .*but have' stderr && (exit 77)], [1])])
150AT_XFAIL_IF([test no = "$AUTOMAKE"])
151AT_KEYWORDS([automake])
152])
153
154
155# LT_AT_AUTOHEADER([OPTIONS])
156# ---------------------------
157m4_define([LT_AT_AUTOHEADER],
158[AT_CHECK([$AUTOHEADER $1], [0], [ignore], [ignore])
159AT_XFAIL_IF([test no = "$AUTOHEADER"])
160AT_KEYWORDS([autoconf])
161])
162
163
164# LT_AT_AUTORECONF([OPTIONS])
165# --------------------------
166m4_define([LT_AT_AUTORECONF],
167[AT_DATA([acinclude.m4],
168[[m4_ifndef([AC_CONFIG_MACRO_DIRS],
169	  [m4_define([AC_CONFIG_MACRO_DIRS], m4_defn([AC_CONFIG_MACRO_DIR]))])
170]])
171AT_CHECK([$AUTORECONF $1], [0], [ignore], [stderr],
172  [AT_CHECK([$GREP 'require .*but have' stderr && (exit 77)], [1])])
173AT_XFAIL_IF(
174  [case ,$AUTORECONF,$AUTOCONF,$AUTOHEADER,$ACLOCAL,$AUTOMAKE, in *,no,*) :;; *) false;; esac])
175AT_KEYWORDS([autoconf automake])
176])
177
178
179# LT_AT_CONFIGURE([OPTIONS], [CONFIGURE-SCRIPT])
180# ----------------------------------------------
181# Configure CONFIGURE-SCRIPT, defaulting to ./configure, with
182# additional OPTIONS.
183m4_define([LT_AT_CONFIGURE],
184[AT_CHECK([: ${CONFIG_SHELL=/bin/sh}; export CONFIG_SHELL; ]dnl
185	  [$CONFIG_SHELL m4_default([$2], [./configure]) $configure_options ]dnl
186          [--prefix="$prefix" --exec-prefix="$prefix" --bindir="$prefix/bin" --libdir="$prefix/lib" $1],
187	  [0], [ignore], [ignore])
188])
189
190
191# LT_AT_MAKE([TGTS], [VARS])
192# --------------------------
193m4_define([LT_AT_MAKE],
194[for target in m4_default([$1], [all])
195do
196  AT_CHECK([$as_unset LIBTOOL; $as_unset LIBTOOLIZE; $MAKE $target $2], [0], [ignore], [ignore])
197done
198])
199
200
201# LT_AT_BOOTSTRAP([LIBTOOLIZE-ARGS], [ACLOCAL-ARGS], [AUTOHEADER-ARGS],
202#	[AUTOMAKE-ARGS], [AUTOCONF-ARGS], [CONFIGURE-ARGS], [MAKE-ARGS])
203# ----------------------------------------------------------------------
204m4_define([LT_AT_BOOTSTRAP],
205[m4_if([$1], [ignore], [], [LT_AT_LIBTOOLIZE([$1])])
206m4_if([$2], [ignore], [], [LT_AT_ACLOCAL([$2])])
207m4_if([$3], [ignore], [], [LT_AT_AUTOHEADER([$3])])
208m4_if([$4], [ignore], [], [LT_AT_AUTOMAKE([$4])])
209m4_if([$5], [ignore], [], [LT_AT_AUTOCONF([$5])])
210m4_if([$6], [ignore], [], [LT_AT_CONFIGURE([$6])])
211m4_if([$7], [ignore], [], [LT_AT_MAKE([$7])])
212])
213
214
215# LT_ESCAPE(ARG)
216# --------------
217# Escape command for output (expand only parameters).
218m4_define([LT_ESCAPE],
219[m4_bpatsubst([$1],
220	     m4_dquote(m4_default([$2], [\"`])),
221	     [\\\&])])
222
223
224# LT_AT_CHECK
225# -----------
226# Wrapper around AT_CHECK that outputs the command first, with
227# parameters expanded.
228m4_define([LT_AT_CHECK],
229[echo "LT_ESCAPE([$1])"; AT_CHECK($@)])
230
231
232# LT_AT_CHECK_CONFIG (CONFIGURE-ARGS, [GREP-EXPRESSION], ...)
233# -----------------------------------------------------------
234# Bootstrap and configure the project, and check each GREP-EXPRESSION
235# works on the resulting libtool script.
236m4_define([LT_AT_CHECK_CONFIG],
237[LT_AT_BOOTSTRAP([], [-I m4], [], [--add-missing], [], [$1], [ignore])
238m4_if([$#], 0, [],
239      [$#], 1, [], [$0_(m4_shift($@))])
240])
241m4_define([LT_AT_CHECK_CONFIG_],
242[AT_CHECK([$EGREP '$1' libtool], 0, [ignore])
243 m4_if([$#], 1, [], [$0(m4_shift($@))])
244])
245
246
247# LT_AT_CHECK_EXECUTE([TARGETS], [PROGRAM], ...)
248# ----------------------------------------------
249# Run the listed make rules, and check that the following PROGRAMs work.
250m4_define([LT_AT_CHECK_EXECUTE],
251[LT_AT_MAKE([$1])
252m4_if([$#], 0, [],
253      [$#], 1, [], [$0_(m4_shift($@))])
254])
255m4_define([LT_AT_CHECK_EXECUTE_],
256[LT_AT_EXEC_CHECK([$1], 0, [expout])
257m4_if([$#], 1, [], [$0(m4_shift($@))])
258])
259
260
261# LT_AT_CHECK_UNINSTALL
262# ---------------------
263# Make sure uninstallation is complete.
264m4_define([LT_AT_CHECK_UNINSTALL],
265[LT_AT_MAKE([uninstall])
266
267leftovers=`find $prefix ! -type d ! -name '.*' -print`
268AT_CHECK([test -z "$leftovers"])
269])
270
271
272# LT_AT_HOST_DATA(FILE, CONTENTS)
273# -------------------------------
274# Ensure correct line ending for expected output of host executables.
275m4_define([LT_AT_HOST_DATA],
276[AT_DATA([$1], [$2])
277case $host_os in mingw*)
278  awk '{printf ("%s\r\n", [$]0);}' < $1 > $1.t && mv -f $1.t $1 ;;
279esac])
280
281
282# LT_AT_UNIFY_NL(FILE, [RESULT-FILE])
283# -----------------------------------
284# Ensure (text) FILE has predictable line endings.
285# If RESULT-FILE is given, FILE is left untouched. If not, convert in-place.
286m4_define([LT_AT_UNIFY_NL],
287[case $host_os in
288  mingw*)
289    tr -d '\015' < $1 > m4_ifval([$2], [$2], [$1.t
290    mv -f $1.t $1]) ;; m4_ifval([$2], [
291  *)
292    cp $1 $2 ;;])
293esac])
294
295
296# LT_AT_NORMALIZE_COMPILER_OUTPUT(FILE, [RESULT-FILE])
297# ----------------------------------------------------
298# Normalize differences in compiler output stemming from, e.g.,
299# - distcc process numbers,
300# - ccache file location,
301# - newline encoding,
302# - location of the libtool script,
303# - error messages involving unstable temporary file names.
304m4_define([LT_AT_NORMALIZE_COMPILER_OUTPUT],
305[_ltbase=`$ECHO "$LIBTOOL" | $SED 's|^.*/||'`
306[$SED "/^distcc\[[0-9]*\]/d
307      /^$_ltbase: compile/d
308      s/\(tmp\/\{1,\}cc\)\([a-zA-Z0-9_]\{1,\}\)/\1-normalized-tmpname/g" < $1 > $1.t]
309LT_AT_UNIFY_NL([$1.t], [m4_default([$2], [$1])])[]dnl
310])
311
312
313# LT_AT_EXEC_CHECK(EXECUTABLE, [STATUS = 0], [STDOUT], [STDERR],
314#		   [ARGS-OR-STATUS-ADJUST])
315# --------------------------------------------------------------
316# Run EXECUTABLE ARGS-OR-STATUS-ADJUST.  STATUS, STDOUT, and STDERR are
317# handled as in AT_CHECK.
318# However, if we are cross-compiling, then SKIP instead of FAIL.
319# ARGS-OR-STATUS-ADJUST can also contain code like '|| (exit 1)'
320# to unify different possible exit status values.
321m4_define([LT_AT_EXEC_CHECK],
322[lt_exe=$1; if test -f "$1$EXEEXT"; then lt_exe=$lt_exe$EXEEXT; fi
323AT_CHECK([if "$lt_exe" $5; then :; else lt_status=$?; ]dnl
324	 [  m4_ifval([$2], [test "$lt_status" != $2 && ])]dnl
325	 [  test "X$host" != "X$build" && test -x "$lt_exe" && exit 77; ]dnl
326	 [  exit $lt_status; fi],[$2],[$3],[$4])
327])
328
329
330# LT_AT_NOINST_EXEC_CHECK(EXECUTABLE, [NOINST-MODULES],
331#			  [STATUS = 0], [STDOUT], [STDERR],
332#			  [ARGS-OR-STATUS-ADJUST])
333# ---------------------------------------------------------
334# Run EXECUTABLE ARGS-OR-STATUS-ADJUST using 'libtool --mode=execute'
335# with '-dlopen' arguments in NOINST_MODULES.  STATUS, STDOUT, and
336# STDERR are handled as in AT_CHECK.
337# However, if we are cross-compiling, then SKIP instead of FAIL.
338# ARGS-OR-STATUS-ADJUST can also contain code like '|| (exit 1)'
339# to unify different possible exit status values.
340m4_define([LT_AT_NOINST_EXEC_CHECK],
341[lt_exe=$1; if test -f "$1$EXEEXT"; then lt_exe=$lt_exe$EXEEXT; fi
342AT_CHECK([if $LIBTOOL --mode=execute $2 "$lt_exe" $6; then :; else lt_status=$?; ]dnl
343	 [  m4_ifval([$3], [test "$lt_status" != $3 && ])]dnl
344	 [  test "X$host" != "X$build" && test -x "$lt_exe" && exit 77; ]dnl
345	 [  exit $lt_status; fi],[$3],[$4],[$5])
346])
347
348
349# LT_AT_TAG(TAG)
350# --------------
351# Declare that the language TAG will be used in this test.
352# Skips the test if the compiler is apparently not functional.
353m4_define([LT_AT_TAG],
354[AT_KEYWORDS([$1])
355AT_CHECK([{ test -n "[$]$1" && test "X[$]$1" != Xno; } || (exit 77)])
356m4_case([$1],
357  [CXX],
358  [AT_CHECK([test g++ != "$CXX" || (g++ -v >/dev/null 2>&1) || (exit 77)])],
359  [FC],
360  [# Autoconf will accept f77 or similar as a valid FC, but often f77
361   # will not compile fortran90 code; in that case skip the FC checks.
362   AT_DATA([fc_test.f90],
363[[	program main
364
365	end
366]])
367   AT_CHECK([$FC $FCFLAGS fc_test.f90 || exit 77], [], [ignore], [ignore])],
368  [GCJ],
369  [# There are just too many broken gcj installations out there, either missing
370   # libgcj.spec or unable to find it.  Skip the test for them.
371   AT_DATA([gcj_test.java],
372[[public class gcj_test {
373    public static void main(String[] argv) { }
374  }
375]])
376   AT_CHECK([$GCJ $GCJFLAGS -c gcj_test.java || exit 77],
377	    [], [ignore], [ignore])])
378])
379
380
381# LT_AT_EXEC_TAG([TAG])
382# ---------------------
383# Declare that the language TAG will be used and compiled programs may be run.
384# Skips the test if the compiler is apparently not functional.
385m4_define([LT_AT_EXEC_TAG],
386[LT_AT_TAG([$1])
387m4_case([$1],
388  [GCJ],
389  [AT_CHECK([$GCJ $GCJFLAGS --main=gcj_test -o gcj_test$EXEEXT gcj_test.java ]dnl
390	    [|| exit 77], [], [ignore], [ignore])
391   AT_CHECK([./gcj_test$EXEEXT || exit 77], [], [ignore], [ignore])])
392])
393
394
395# LT_AT_MVDIR(SRC, DEST)
396# ----------------------
397# Move contents of a directory recursively.
398# Avoid 'mv DIR ...' due to issues with non-deletable shared libraries
399# on AIX on NFS mounts.  We cannot use slibclean as non-superuser.
400m4_define([LT_AT_MVDIR],
401[$mkdir_p $2
402(cd $1 && find . -type d) | (cd $2 && xargs $mkdir_p)
403for file in `cd $1 && find . -type f -print -o -type l -print`
404do
405  mv $1/$file $2/$file
406done
407rm -rf $1
408])
409
410## ------------------------------- ##
411## Files for a small ltdl project. ##
412## ------------------------------- ##
413
414# _LTDL_PROJECT_FILES([LTDL-DIR])
415# -------------------------------
416# LTDL-DIR is needed to generate a correct Makefile.  If the argument
417# is omitted, then no Makefile is created.
418m4_define([_LTDL_PROJECT_FILES],
419[AT_DATA([module.c],
420[[#ifdef __cplusplus
421extern "C"
422#endif
423const char *
424hello (void)
425{
426  return "Hello!";
427}
428]])
429
430AT_DATA([main.c],
431[[#include <stdio.h>
432#include "ltdl.h"
433
434int
435main ()
436{
437  lt_dlhandle module;
438  const char *(*func) (void) = 0;
439  int status = 1;
440
441  LTDL_SET_PRELOADED_SYMBOLS();
442  if (lt_dlinit() != 0) {
443    fprintf (stderr, "error during initialisation: %s\n", lt_dlerror());
444    return 1;
445  }
446
447  module = lt_dlopen("./module.la");
448  if (!module) {
449    fprintf (stderr, "error dlopening ./module.la: %s\n", lt_dlerror());
450    goto finish;
451  }
452
453  func = (const char *(*)(void)) lt_dlsym (module, "hello");
454  if (!func) {
455    fprintf (stderr, "error fetching func: %s\n", lt_dlerror());
456    goto finish;
457  }
458
459  printf ("%s\n", (*func) ());
460  status = 0;
461
462finish:
463  if (lt_dlexit() != 0) {
464    fprintf (stderr, "error during finalisation: %s\n", lt_dlerror());
465    status = 1;
466  }
467
468  return status;
469}
470]])
471
472m4_pushdef([_ARG_DIR], m4_bpatsubst([$1], [/*$]))
473m4_ifval([$1],
474[AT_DATA([Makefile],
475[[top_builddir	= .
476LIBTOOL		= ./]_ARG_DIR[/libtool
477INCLUDES	= -I./]_ARG_DIR[
478MODFLAGS	= -module -avoid-version -no-undefined
479
480LTCOMPILE = $(LIBTOOL) --tag=CC $(LIBTOOLFLAGS) --mode=compile \
481        $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
482LTLINK    = $(LIBTOOL) --tag=CC $(LIBTOOLFLAGS) --mode=link \
483        $(CC) $(CFLAGS) $(LDFLAGS)
484
485TARGETS		= ]_ARG_DIR[/libltdlc.la module.la ltdldemo$(EXEEXT)
486
487all: $(TARGETS)
488
489]_ARG_DIR[/libltdlc.la: $(LIBTOOL) ]_ARG_DIR[/Makefile
490	MAKE='$(MAKE)'; test -n "$$MAKE" || MAKE=make; \
491	cd ]_ARG_DIR[ && $$MAKE CC="$(CC)" LIBTOOLFLAGS="$(LIBTOOLFLAGS)" \
492	  CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
493          CONFIGURE_OPTIONS="$(CONFIGURE_OPTIONS)"
494
495$(LIBTOOL): ]_ARG_DIR[/Makefile
496
497]_ARG_DIR[/Makefile:
498	cd ]_ARG_DIR[ && CONFIG_SHELL="$(SHELL)" $(SHELL) ./configure $(CONFIGURE_OPTIONS)
499
500ltdldemo$(EXEEXT): $(LIBTOOL) module.la ]_ARG_DIR[/libltdlc.la main.lo
501	$(LTLINK) -o ltdldemo$(EXEEXT) main.lo -dlopen module.la ./]_ARG_DIR[/libltdlc.la
502
503main.lo: $(LIBTOOL) main.c
504	$(LTCOMPILE) -c main.c
505
506module.la: $(LIBTOOL) module.lo
507	$(LTLINK) -o module.la module.lo $(MODFLAGS) -rpath /dev/null
508
509module.lo: $(LIBTOOL) module.c
510	$(LTCOMPILE) -c module.c
511]])
512cat >> Makefile <<EOF
513SHELL = $SHELL
514EOF
515])
516m4_popdef([_ARG_DIR])
517])# _LTDL_PROJECT_FILES
518
519
520# We use 'dnl' in zillions of places...
521m4_pattern_allow([^dnl$])
522
523# We exercise these tools.
524dnl AT_TESTED([grep autoreconf autom4te automake])
525
526# Enable colored output if available.
527m4_ifdef([AT_COLOR_TESTS], [AT_COLOR_TESTS])
528
529AT_INIT
530
531## ----------- ##
532## The suite.  ##
533## ----------- ##
534
535# Tests will be appended here by the Makefile rule.
536