Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / defs.m4sh
1 AS_INIT[]m4_divert_push([HEADER-COPYRIGHT])
2 # defs -- Defines for Libtool testing environment.
3 #
4 #   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
5 #   Foundation, Inc.
6 #   Written by Gord Matzigkeit, 1996
7 #   Rewritten by Gary V. Vaughan, 2003
8 #
9 #   This file is part of GNU Libtool.
10 #
11 # GNU Libtool is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation; either version 2 of
14 # the License, or (at your option) any later version.
15 #
16 # GNU Libtool is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with GNU Libtool; see the file COPYING.  If not, a copy
23 # can be downloaded from  http://www.gnu.org/licenses/gpl.html,
24 # or obtained by writing to the Free Software Foundation, Inc.,
25 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 ####
27
28 m4_divert_pop
29 m4_include([general.m4sh])
30
31 M4SH_VERBATIM([[
32 : ${AUTOCONF="autoconf"}
33 : ${AUTORECONF="autoreconf"}
34 : ${LIBTOOL="./libtool"}
35
36 # Sed that helps us avoid accidentally triggering echo(1) options like -n.
37 Xsed="$SED -e 1s/^X//"
38
39 # Disable usage of config.site for autoconf, unless DJGPP is present.
40 # The DJGPP port of autoconf requires config.site, to work correctly.
41 if test -z "$DJGPP"; then
42     CONFIG_SITE=/nonexistent
43 fi
44
45 # How verbose should we be?  Default is test output in log file.
46 # Setting VERBOSE=debug puts the shell in debug mode.
47 opt_debug=:
48 case "$VERBOSE" in
49 DEBUG | debug )
50   opt_debug='set -x'
51   $opt_debug
52   ;;
53 esac
54
55 if test -z "$srcdir"; then
56   srcdir=`$ECHO "$0" | $SED "$dirname; s,/tests\$,,"`
57   test "$srcdir" = "$0" && srcdir=.
58 fi
59
60 # func_msg arg...
61 # Echo message with prefix.
62 func_msg ()
63 {
64     func_echo "=== " ${1+"$@"}
65 }
66
67 # func_skip arg...
68 # Echo message to standard error, and skip the rest of this test.
69 func_skip ()
70 {
71     func_error ${1+"$@"}
72     exit $EXIT_SKIP
73 }
74
75 # func_fail arg...
76 # Echo message to standard error, and fail this test.
77 func_fail ()
78 {
79     func_fatal_error ${1+"$@"}
80 }
81
82 # func_get_config varname_list src [failp] [regex]
83 func_get_config ()
84 {
85   $opt_debug
86   my_varname_list="$1"
87   my_src="$2"
88   my_failp="false";  test -z "$3" || my_failp=:
89   my_regex="$4"
90
91   my_exitp=false
92   if test -z "$my_regex"; then
93     my_regex="^("
94     my_build_regex=:
95   else
96     my_build_regex=false
97   fi
98   my_first=:
99
100   for my_varname in $my_varname_list; do
101     if $my_build_regex; then
102       $my_first || my_regex="$my_regex|"
103       my_first=false
104       my_regex="$my_regex$my_varname"
105     fi
106     eval $my_varname=NONE
107   done
108   $my_build_regex && my_regex="$my_regex)="
109   eval `eval "$my_src" | eval "$EGREP \"$my_regex\""`
110
111   for my_varname in $my_varname_list; do
112     if eval test x\"\$$my_varname\" = xNONE; then
113       func_error "$my_varname not set in \`$my_src'"
114       $my_failp && my_exitp=:
115     fi
116   done
117
118   $my_exitp && exit $EXIT_FAILURE
119 }
120
121
122 # Extract some variables from the libtool configuration.
123 func_get_config "objext
124 objdir
125 CC
126 host
127 host_os
128 host_alias
129 build
130 build_alias" "$LIBTOOL --config" ": fatal"
131
132
133 # func_mkprefixdir
134 func_mkprefixdir ()
135 {
136     $opt_debug
137     # An absolute path to a test installation directory.
138     func_mkdir_p "$prefix"
139     prefix=`cd $prefix && pwd`
140 }
141
142 # func_rmprefixdir
143 func_rmprefixdir ()
144 {
145     $opt_debug
146     test -d $prefix && rm -rf $prefix
147     prefix=NONE
148 }
149
150 # func_cd dir
151 # Make sure a directory exists, and then change to it.
152 func_cd ()
153 {
154     $opt_debug
155     my_dir="$1"
156
157     # Maybe we have a VPATH build, in which case, create a new subdir.
158     func_mkdir_p "$my_dir"
159
160     # Change to our build directory.
161     cd "$my_dir" || func_fatal_error "couldn't cd to \`$my_dir'"
162 }
163
164
165 # func_require prereq file [...]
166 # If FILE does not exist, give a fatal error regarding running PREREQ first.
167 func_require ()
168 {
169     $opt_debug
170     my_prereq="$1"; shift
171     my_files=${1+"$@"}
172
173     for my_file in $my_files; do
174       test -f "$my_file" \
175         || func_skip "You must run ${my_prereq}.test before running $0"
176     done
177 }
178
179 # func_configure_nofail [args ...]
180 # Configure the demonstration.
181 func_configure_nofail ()
182 {
183     $opt_debug
184     my_args=${1+"$@"}
185     func_dirname_and_basename "`pwd`"
186     my_dir=$func_basename_result
187     my_testdir="$srcdir/tests/$my_dir"
188     conf_status=$EXIT_FAILURE
189
190     test -n "$my_args" && my_args=" $my_args"
191     my_args="--srcdir="\""$my_testdir"\"" --prefix="\""$prefix"\""$my_args"
192     test -n "$host_alias" && my_args="$my_args --host=\"$host_alias\""
193     test -n "$build_alias" && my_args="$my_args --build=\"$build_alias\""
194
195     func_msg "Configuring in $my_dir"
196
197     test -f "$my_testdir/configure" || ${AUTORECONF} --force --install $my_testdir
198     if test -f "$my_testdir/configure"; then
199
200       eval func_msg $SHELL "$my_testdir/configure" $my_args
201       if eval $SHELL "$my_testdir/configure" $my_args; then
202         conf_status=$EXIT_SUCCESS
203       else
204         func_msg "FAILED: Configuring in $my_testdir"
205         ls -ltr $my_testdir
206       fi
207     fi
208 }
209
210 # func_configure [args ...]
211 # Configure the demonstration, fail on error.
212 func_configure ()
213 {
214     func_configure_nofail ${1+"$@"}
215     if test "$conf_status" -eq "$EXIT_FAILURE"; then
216       exit $EXIT_FAILURE
217     fi
218 }
219
220 # func_check_static_shared staticp sharedp
221 # Determine whether the generated libtool script is configured properly
222 # for the expected STATICP and SHAREDP library building
223 func_check_static_shared ()
224 {
225     $opt_debug
226     my_staticp="$1"
227     my_sharedp="$2"
228
229     if func_grep "^build_old_libs=$staticp" libtool &&
230        func_grep "^build_libtool_libs=$sharedp" libtool; then :
231     else
232       rm -f Makefile
233       exit $EXIT_FAIL
234     fi
235 }
236
237
238 # func_make [args ...]
239 # Do the actual build.
240 func_make ()
241 {
242     $opt_debug
243     my_args=${1+"$@"}
244     func_dirname_and_basename "`pwd`"
245     func_msg "Running \`$MAKE $my_args' in $func_basename_result"
246
247     eval $MAKE $my_args || exit $EXIT_FAIL
248 }
249
250
251 # func_distclean
252 # Possibly clean up the distribution.
253 func_make_distclean ()
254 {
255     $opt_debug
256     if test -f Makefile; then
257       func_make distclean
258     fi
259     rm -rf autom4te.cache config.cache
260 }
261
262
263 # func_make_uninstall
264 # See that there were no files leftover in $prefix.
265 # Ignore dotfiles, so that .nfsXXX files don't screw up the test.
266 func_make_uninstall ()
267 {
268     $opt_debug
269     func_make uninstall
270
271     leftovers=`find $prefix ! -type d ! -name '.*' -print`
272     if test -n "$leftovers"; then
273       func_msg "Leftover after make uninstall:"
274       ls -l $leftovers
275       exit 1
276     fi
277 }
278
279
280 # func_exec_init mode
281 func_exec_init ()
282 {
283     $opt_debug
284     func_dirname_and_basename "`pwd`"
285     func_msg "Executing $1 programs in $func_basename_result"
286
287     # Windows hosts search for dlls in the command path
288     PATH=$prefix/lib:$PATH
289
290     exec_status=$EXIT_SUCCESS
291 }
292
293 # func_exec_check program [msg ...]
294 # Check to see if PROGRAM was built. If not display MSG.
295 func_exec_check ()
296 {
297     $opt_debug
298     my_program="$1"
299
300     if test -f "$my_program"; then :
301     else
302       shift
303       func_error "$0: $my_program did not build ${1+$@}"
304       exec_status=$EXIT_FAILURE
305     fi
306 }
307
308 # func_exec program [exp_output] [msg ...]
309 # Check to see if PROGRAM really runs, and produces EXP_OUTPUT if given.
310 # If not display MSG.
311 func_exec ()
312 {
313     $opt_debug
314     my_program="$1"
315     my_exp_output="$2"
316     func_dirname_and_basename "`pwd`"
317     my_dir=$func_basename_result
318
319     test -n "$my_exp_output" \
320       && my_exp_output="| $EGREP -e "\""$my_exp_output"\"
321
322     if eval $my_program $my_exp_output; then :
323     else
324       shift
325       test "x$1" = x || shift
326       func_error "$0: cannot execute $my_program ${1+$@}"
327
328       if test "$build" != "$host"; then
329         func_msg "This may be ok since you seem to be cross-compiling."
330         exec_status=$EXIT_SKIP
331       else
332         # Simple check to see if they are superuser.
333         if test $exec_status = $EXIT_FAILURE || test -w /; then :
334         else
335           func_msg "You may need to run $0 as the superuser."
336         fi
337         exec_status=$EXIT_FAILURE
338       fi
339     fi
340 }
341
342 # Shared global variables for test scripts
343 prefix=./_inst-`echo "$0" | sed 's,.*/,,; s,-.*,,'`
344 srcdir=`cd $srcdir && pwd`
345 m4dir=$srcdir/libltdl/m4
346 auxdir=$srcdir/libltdl/config
347 scripts="$auxdir/ltmain.m4sh $srcdir/libtoolize.m4sh"
348
349 # Unset some MAKE... variables that may cause $MAKE to act like a
350 # recursively invoked sub-make.  Any $MAKE invocation in a test is
351 # conceptually an independent invocation.
352 unset MFLAGS MAKEFLAGS MAKELEVEL __MKLVL__ MAKE_JOBS_FIFO
353
354 # On AIX, shared libraries remain loaded in memory after use if they
355 # are world-readable, until root issues slibclean.  On NFS, this causes
356 # a testsuite rerun to fail to clean up test group directories.  Avoid
357 # this with a suitable umask.  Do not do this on other systems, for
358 # example HP-UX suffers unless shared libraries are mode 555.
359 case $host_os in
360 aix*) umask o-rwx ;;
361 esac
362
363 func_msg "Running $progname"
364
365 # Local Variables:
366 # mode:shell-script
367 # sh-indentation:2
368 # End:
369 ]])