Fix Changelog
[libtool.git] / libtoolize.m4sh
blobb59c7b0edd91f778af7b7b7996d2a3f15c5ba48d
1 m4_define([_m4_divert(SCRIPT)], 100)
2 m4_divert_push([SCRIPT])#! /bin/sh
3 # @configure_input@
5 # libtoolize (GNU @PACKAGE@@TIMESTAMP@) @VERSION@
6 # Written by Gary V. Vaughan <gary@gnu.org>, 2003
8 # Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
9 # This is free software; see the source for copying conditions.  There is NO
10 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # Libtoolize is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # Libtoolize is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with libtoolize; see the file COPYING.  If not, a copy
24 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
25 # or obtained by writing to the Free Software Foundation, Inc.,
26 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 # Usage: $progname [OPTION]...
30 # Prepare a package to use libtool.
32 # -c, --copy            copy files rather than symlinking them
33 #     --debug           enable verbose shell tracing
34 # -n, --dry-run         print commands rather than running them
35 # -f, --force           replace existing files
36 # -i, --install         copy missing auxiliary files
37 #     --ltdl[=DIR]      install libltdl sources [default: libltdl]
38 #     --nonrecursive    prepare ltdl for non-recursive make
39 # -q, --quiet           work silently
40 #     --recursive       prepare ltdl for recursive make
41 #     --subproject      prepare ltdl to configure and build independently
42 # -v, --verbose         verbosely report processing
43 #     --version         print version information and exit
44 # -h, --help            print short or long help message
46 # You must `cd' to the top directory of your package before you run
47 # `$progname'.
49 # When reporting a bug, please describe a test case to reproduce it and
50 # include the following information:
52 #       host-triplet:   @host_triplet@
53 #       $progname:      (GNU @PACKAGE@@TIMESTAMP@) @VERSION@
54 #       automake:               $automake_version
55 #       autoconf:               $autoconf_version
57 # Report bugs to <bug-libtool@gnu.org>.
59 : ${TAR=tar}
61 PROGRAM=libtoolize
63 AS_SHELL_SANITIZE
64 $as_unset CDPATH
66 m4_include([getopt.m4sh])
68 M4SH_VERBATIM([[
69 # test EBCDIC or ASCII
70 case `echo X|tr X '\101'` in
71  A) # ASCII based system
72     # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
73   SP2NL='tr \040 \012'
74   NL2SP='tr \015\012 \040\040'
75   ;;
76  *) # EBCDIC based system
77   SP2NL='tr \100 \n'
78   NL2SP='tr \r\n \100\100'
79   ;;
80 esac
83 # Command line options:
84 opt_debug=:
85 opt_force=false
86 opt_install=false
87 opt_link=:
88 opt_ltdl=false
90 seen_autoconf=false
91 seen_libtool=false
92 seen_ltdl=false
94 # ltdl can be installed to be self-contained (subproject, the default);
95 # or to be configured by a parent project, either with a recursive or
96 # nonrecursive automake driven make:
97 ltdl_mode=
99 # Locations for important files:
100 prefix=@prefix@
101 datadir=@datadir@
102 pkgdatadir=@pkgdatadir@
103 pkgltdldir=@pkgdatadir@
104 aclocaldir=@aclocaldir@
105 auxdir=
106 m4dir=
107 ltdldir=
108 configure_ac=configure.in
111 # Parse options once, thoroughly.  This comes as soon as possible in
112 # the script to make things like `libtoolize --version' happen quickly.
114   # sed scripts:
115   my_sed_single_opt='1s/^\(..\).*$/\1/;q'
116   my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
117   my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
118   my_sed_long_arg='1s/^--[^=]*=//'
120   while test "$#" -gt 0; do
121     opt="$1"
122     shift
123     case $opt in
124       --copy|-c)        opt_link=false ;;
126       --debug)          func_echo "enabling shell trace mode"
127                         opt_debug='set -x'
128                         $opt_debug
129                         ;;
131       --dry-run|-n)     if $opt_dry_run; then :; else
132                           opt_dry_run=:
133                           RM="$ECHO $RM"
134                           test -n "$LN_S" && LN_S="$ECHO $LN_S"
135                           CP="$ECHO $CP"
136                           MKDIR="$ECHO $MKDIR"
137                           TAR="$ECHO $TAR"
138                         fi
139                         ;;
141       --force|-f)       opt_force=: ;;
143       --install|-i)     opt_install=: ;;
145       --ltdl)           opt_ltdl=:
146                         if test "$#" -gt 0; then
147                           case $1 in
148                             -*) ;;
149                             *)  ltdldir=`$ECHO "X$1" | $Xsed -e 's,/*$,,'`
150                                 shift
151                                 ;;
152                           esac
153                         fi
154                         ;;
156       --nonrecursive|--non-recursive)
157                         ltdl_mode=nonrecursive
158                         ;;
160       --quiet|--automake|-q) # --automake is for 1.5 compatibility
161                         opt_quiet=:
162                         ;;
164       --recursive)      ltdl_mode=recursive ;;
166       --subproject)     ltdl_mode=subproject ;;
168       --verbose|-v)     opt_verbose=: ;;
170       # Separate optargs to long options:
171       --*=*)
172                         arg=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_arg"`
173                         opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_opt"`
174                         set dummy "$opt" "$arg" ${1+"$@"}
175                         shift
176                         ;;
178       # Separate optargs to short options:
179       #-X*)
180       #                 arg=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_rest"`
181       #                 opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_opt"`
182       #                 set dummy "$opt" "$arg" ${1+"$@"}
183       #                 shift
184       #                 ;;
186       # Separate non-argument short options:
187       -c*|-f*|-i*|-n*|-q*|-v*)
188                         rest=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_rest"`
189                         opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_opt"`
190                         set dummy "$opt" "-$rest" ${1+"$@"}
191                         shift
192                         ;;
194       -\?|-h)           func_usage                                      ;;
195       --help)           func_help                                       ;;
196       --version)        func_version                                    ;;
197       --)               break                                           ;;
198       -*)               func_fatal_help "unrecognized option \`$opt'"   ;;
199       *)                func_fatal_help "too many arguments"            ;;
200     esac
201   done
205 # func_copy srcfile destfile
206 # A wrapper for func_copy_cb that accepts arguments in the same order
207 # as the cp(1) shell command.
208 func_copy ()
210     $opt_debug
212     test -f "$1" || \
213       { func_error "\`$1' not copied:  not a regular file"; return 1; }
215     my_f1=`$ECHO "X$1" | $Xsed -e "$basename"`
217     if test -d "$2"; then
219       func_copy_cb "$my_f1" \
220         `$ECHO "X$1" | $Xsed -e "$dirname"` "$2"
222     else
224       # Supporting this would mean changing the timestamp:
225       test "X$my_f1" = X`$ECHO "X$2" | $Xsed -e "$basename"` \
226         || func_fatal_error "func_copy() cannot change filename on copy"
228       func_copy_cb "$my_f1" \
229         `$ECHO "X$1" | $Xsed -e "$dirname"` \
230         `$ECHO "X$2" | $Xsed -e "$dirname"`
232     fi
234     return $copy_return_status # set in func_copy_cb
238 # func_copy_cb filename srcdir destdir
239 # If option `--copy' was specified, or soft-linking SRCFILE to DESTFILE fails,
240 # then try to copy SRCFILE to DESTFILE (without changing the timestamp if
241 # possible).
242 func_copy_cb ()
244     $opt_debug
245     my_file="$1"
246     my_srcdir="$2"
247     my_destdir="$3"
248     copy_return_status=1
250     # Libtool is probably misinstalled if this happens:
251     test -f "$my_srcdir/$my_file" || 
252         func_fatal_error "\`$my_file' not found in \`$my_srcdir'"
254     case $opt_verbose in
255       false) my_copy_msg="file \`$my_destdir/$my_file'"     ;;
256       *)     my_copy_msg="file from \`$my_srcdir/$my_file'" ;;
257     esac
258     func_mkdir_p `$ECHO "X$my_destdir/$my_file" | $Xsed -e "$dirname"`
260     $RM "$my_destdir/$my_file"
261     if $opt_link; then
262       if test "$my_file" = "aclocal.m4"; then
263         if { ( cd "$my_srcdir" && $TAR chf - "$my_file" ) 2>/dev/null \
264              | ( umask 0 && cd "$my_destdir" && $TAR xf - ) >/dev/null 2>&1 ; }
265         then
266           $opt_quiet || func_echo "copying $my_copy_msg"
267           copy_return_status=0
268         fi
269       else
270         if $LN_S "$my_srcdir/$my_file" "$my_destdir/$my_file"; then
271           $opt_quiet || func_echo "linking $my_copy_msg"
272           copy_return_status=0
273         fi
274       fi
275     else
276       if { ( cd "$my_srcdir" && $TAR chf - "$my_file" ) 2>/dev/null \
277            | ( umask 0 && cd "$my_destdir" && $TAR xf - ) >/dev/null 2>&1; } \
278          && touch "$my_destdir/$my_file"; then
279         $opt_quiet || func_echo "copying $my_copy_msg"
280         copy_return_status=0
281       fi
282     fi
283     if test "$copy_return_status" != 0; then
284       func_error "can not copy \`$my_srcdir/$my_file' to \`$my_destdir/'"
285       exit_status=$EXIT_FAILURE
286     fi
290 # func_copy_some_files srcfile_spec srcdir destdir [copy_cb=func_copy_cb]
291 # Call COPY_CB for each regular file in SRCDIR named by the ':' delimited
292 # names in SRCFILE_SPEC.  The odd calling convention is needed to allow
293 # spaces in file and directory names.
294 func_copy_some_files ()
296     $opt_debug
297     my_srcfile_spec="$1"
298     my_srcdir="$2"
299     my_destdir="$3"
300     my_copy_cb="${4-func_copy_cb}"
302     my_save_IFS="$IFS"
303     IFS=:
304     for my_filename in $my_srcfile_spec; do
305       IFS="$my_save_IFS"
306       if test -f "$my_srcdir/$my_filename"; then
307         if test "X$my_copy_cb" = Xfunc_copy_cb; then
308           $opt_force || if test -f "$my_destdir/$my_filename"; then
309             $opt_quiet \
310               || func_error "\`$my_destdir/$my_filename' exists: use \`--force' to overwrite"
311             continue
312           fi
313         fi
314       else
315         func_fatal_error "\`$my_filename' not found in \`$my_srcdir'"
316       fi
318       $my_copy_cb "$my_filename" "$my_srcdir" "$my_destdir"
319     done
320     IFS="$my_save_IFS"
323 # func_fixup_Makefile srcfile srcdir destdir
324 func_fixup_Makefile ()
326     my_filename="$1"
327     my_srcdir="$2"
328     my_destdir="$3"
329     my_fixup_non_subpackage_script="\
330       s,libltdl/configure.ac,,
331       s,libltdl/configure,,
332       s,libltdl/aclocal.m4,,
333       s,libltdl/config-h.in,,
334       s,libltdl/Makefile.am,,
335       s,libltdl/Makefile.in,,
336       /^[        ]*\\\\\$/d"
337     case $my_filename in
338       Makefile.am)
339         my_fixup_non_subpackage_script=`echo "$my_fixup_non_subpackage_script" | \
340                 sed 's,libltdl/,,'`
341         my_fixup_inc_paths_script= ;;
342       Makefile.inc)
343         repl=$ltdldir
344         repl_uscore=`$ECHO "X$repl" | $Xsed -e 's,[/.+-],_,g'`
345         my_fixup_inc_paths_script="\
346           s,libltdl_,@repl_uscore@_,
347           s,libltdl/,@repl@/,
348           s,: libltdl/,: @repl@/,
349           s, -Ilibltdl , -I@repl@ ,
350           s,\\\$(libltdl_,\$(@repl_uscore@_,
351           s,)/libltdl ,)/@repl@ ,
352           s,@repl_uscore@,${repl_uscore},g
353           s,@repl@,${repl},g"
354         ;;
355     esac
357     $RM "$my_destdir/$my_filename" 2>/dev/null
358     $opt_quiet || func_echo "creating file \`$my_destdir/$my_filename'"
359     if $opt_dry_run; then :;
360     else
361       $SED "$my_fixup_non_subpackage_script
362             $my_fixup_inc_paths_script" \
363         < "$my_srcdir/$my_filename" > "$my_destdir/$my_filename" ||
364         func_fatal_error "cannot create $my_destdir/$my_filename"
365     fi
368 # func_scan_files
369 # Scan configure.(ac|in) and aclocal.m4 (if present) for use of libltdl
370 # and libtool.  Possibly running some of these tools if necessary.
371 # Libtoolize affects the contents of aclocal.m4, and should be run before
372 # aclocal, so we can't use configure --trace which relies on a consistent
373 # configure.(ac|in) and aclocal.m4.
374 func_scan_files ()
376     $opt_debug
377     # Prefer configure.ac to configure.in
378     test -f configure.ac && configure_ac=configure.ac
379     test -f "$configure_ac" || configure_ac=
381     # Set local variables to reflect contents of configure.ac
382     my_sed_scan_configure_ac='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
383         /AC_INIT/ {
384             s,^.*$,seen_autoconf=:,
385             p
386         }
387         d'
388     test -z "$configure_ac" \
389         || eval `$SED "$my_sed_scan_configure_ac" "$configure_ac"`
391     $seen_autoconf || {
392         my_configure_ac=
393         test -n "$configure_ac" && my_configure_ac="$configure_ac: "
394         func_verbose "${my_configure_ac}not using Autoconf"
396         # Make sure ltdldir is set, even though we return early here:
397         test -n "$ltdldir" || ltdldir=libltdl
398         return
399     }
401     # ---------------------------------------------------- #
402     # Probe macro usage in configure.ac and/or aclocal.m4. #
403     # ---------------------------------------------------- #
405     my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,
406         s,^.*AC_REQUIRE(.*$,,; s,^.*m4_require(.*$,,; s,^.*m4_define(.*$,,
407         s,^.*A[CU]_DEFUN(.*$,,; s,^.*m4_defun(.*$,,
408         /AC_CONFIG_AUX_DIR(/ {
409             s,^.*AC_CONFIG_AUX_DIR([[   ]*\([^])]*\).*$,auxdir=\1,
410             p
411         }
412         /AC_CONFIG_MACRO_DIR(/ {
413             s,^.*AC_CONFIG_MACRO_DIR([[         ]*\([^])]*\).*$,macrodir=\1,
414             p
415         }
416         /_LT_CONFIG_LTDL_DIR(/d
417         /LT_CONFIG_LTDL_DIR(/ {
418             s/^.*LT_CONFIG_LTDL_DIR([[   ]*\([^]),]*\)[^,]*/ac_ltdldir=\1%%/
419             s/%%[[,     ]*\([^])]*\).*$/ ac_ltdl_mode=\1%%/
420             s/%%.*$//
421             p
422         }
423         /A[CM]_PROG_LIBTOOL/ {
424             s,^.*$,seen_libtool=:,
425             p
426         }
427         /LT_INIT/            {
428             s,^.*$,seen_libtool=:,
429             p
430         }
431         /LTDL_INIT/          {
432             s,^.*$,seen_ltdl=:,
433             p
434         }
435         /LT_WITH_LTDL/       {
436             s,^.*$,seen_ltdl=:,
437             p
438         }
439         /AC_LIB_LTDL/        {
440             s,^.*$,seen_ltdl=:,
441             p
442         }
443         /AC_WITH_LTDL/       {
444             s,^.*$,seen_ltdl=:,
445             p
446         }
447         d'
448     eval `cat aclocal.m4 "$configure_ac" 2>/dev/null | $SED "$my_sed_traces"`
451     # ----------------- #
452     # Validate ltdldir. #
453     # ----------------- #
455     ac_ltdldir=`$ECHO "X$ac_ltdldir" | $Xsed -e 's,/*$,,'`
457     # If $configure_ac contains AC_CONFIG_LTDL_DIR, check that its
458     # arguments were not given in terms of a shell variable!
459     case "$ac_ltdldir$ac_ltdl_mode" in
460       *\$*)
461         func_fatal_error "can not handle variables in LT_CONFIG_LTDL_DIR"
462         ;;
463     esac
465     # If neither --ltdl nor LT_CONFIG_LTDL_DIR are specified, default to
466     # `libltdl'.  If both are specified, they must be the same.  Otherwise,
467     # take the one that is given! (If LT_CONFIG_LTDL_DIR is not specified
468     # we suggest adding it later in this code.)
469     case x$ac_ltdldir,x$ltdldir in
470       x,x)      ltdldir=libltdl         ;;
471       x*,x)     ltdldir=$ac_ltdldir     ;;
472       x,x*)     ltdldir=$ltdldir        ;;
473       *)
474         test x"$ac_ltdldir" = x"$ltdldir" || \
475             func_fatal_error "--ltdl='$ltdldir' does not match LT_CONFIG_LTDL_DIR($ac_ltdldir)"
476         ;;
477     esac
480     # ------------------- #
481     # Validate ltdl_mode. #
482     # ------------------- #
484     test -n "$ac_ltdl_mode" && seen_ltdl=:
486     # If neither --ltdl nor LT_CONFIG_LTDL_DIR are specified, default to
487     # `subproject'.  If both are specified, they must be the same.  Otherwise,
488     # take the one that is given!
489     case x$ac_ltdl_mode,x$ltdl_mode in
490       x,x)      ltdl_mode=subproject    ;;
491       x*,x)     ltdl_mode=$ac_ltdl_mode ;;
492       x,x*)     ltdl_mode=$ltdl_mode    ;;
493       *)
494         test x"$ac_ltdl_mode" = x"$ltdl_mode" || \
495             func_fatal_error "--$ltdl_mode does not match LT_CONFIG_LTDL_DIR($ac_ltdldir, $ac_ltdl_mode)"
496         ;;
497     esac
500     # ---------------- #
501     # Validate auxdir. #
502     # ---------------- #
504     if test -n "$auxdir"; then
505       # If $configure_ac contains AC_CONFIG_AUX_DIR, check that it was
506       # not given in terms of a shell variable!
507       case "$auxdir" in
508       *\$*)
509         func_fatal_error "can not handle variables in AC_CONFIG_AUX_DIR"
510         ;;
511       *);;
512       esac
513     else
514       # Try to discover auxdir the same way it is discovered by configure.
515       # Note that we default to the current directory.
516       for dir in . .. ../..; do
517         if test -f "$dir/install-sh"; then
518           auxdir=$dir
519           break
520         elif test -f "$dir/install.sh"; then
521           auxdir="$dir"
522           break
523         fi
524       done
525     fi
527     # Just use the current directory if all else fails.
528     test -n "$auxdir" || auxdir=.
531     # ------------------------------ #
532     # Find local m4 macro directory. #
533     # ------------------------------ #
535     # If AC_CONFIG_MACRO_DIR turned nothing up, we hunt for ACLOCAL_AMFLAGS
536     # in `Makefile.am' for a `-I' argument.
538     my_sed_aclocal_flags='
539         /^[     ]*ACLOCAL_[A-Z_]*FLAGS[         ]*=/ {
540             s,^[^=]*=[  ]*\(.*\), \1,
541             q
542         }
543         d'
544     m4dir="$macrodir"
545     if test ! -n "$m4dir" && test -f Makefile.am; then
546       my_m4dir_is_next=false
547       for arg in `$SED "$my_sed_aclocal_flags" Makefile.am`; do
548         if $my_m4dir_is_next; then
549           m4dir="$arg"
550           break
551         else
552           if test "X$arg" = "X-I"; then
553             my_m4dir_is_next=:
554           else
555             my_m4dir_is_next=false
556           fi
557         fi
558       done
559     fi
562 # func_included_files searchfile
563 # Output INCLUDEFILE if SEARCHFILE m4_includes it, else output SEARCHFILE.
564 func_included_files ()
566     $opt_debug
567     my_searchfile="$1"
569     my_include_regex=
570     my_sed_include='
571         /^m4_include(\[.*\])$/ {
572             s,^m4_include(\[\(.*\)\])$,\1,
573             p
574         }
575         d'
577     if test -f "$my_searchfile"; then
578       $ECHO "X$my_searchfile" | $Xsed
580       # Only recurse when we don't care if all the variables we use get
581       # trashed, since they are in global scope.
582       for my_filename in `$SED "$my_sed_include" "$my_searchfile"`; do
583         func_included_files $my_filename
584       done
585     fi
589 # func_serial filename [macro_regex]
590 # Output the value of the serial number comment in FILENAME, where the
591 # comment line must also match MACRO_REGEX, if given.
592 func_serial ()
594     $opt_debug
595     my_filename="$1"
596     my_macro_regex="$2"
597     my_sed_serial='
598         /^# serial [1-9][0-9.]*[        ]*'"$my_macro_regex"'[  ]*$/ {
599             s,^# serial \([1-9][0-9.]*\).*$,\1,
600             q
601         }
602         d'
604     # Search FILENAME and all the files it m4_includes for a serial number
605     # in the file that AC_DEFUNs MACRO_REGEX.
606     my_serial=
607     for my_file in `func_included_files "$my_filename"`; do
608       if test -z "$my_macro_regex" ||
609          test "$my_filename" = aclocal.m4 ||
610          test "$my_macro_regex" = `echo "$my_filename" | $SED "$basename"` ||
611          func_grep '^AC_DEFUN(\@<:@'"$my_macro_regex" "$my_file"
612       then
613         my_serial=`$SED -e "$my_sed_serial" "$my_file"`
614         break
615       fi
616     done
618     # If the file has no serial number, we assume it's ancient.
619     test -n "$my_serial" || my_serial=0
621     $ECHO $my_serial
625 # func_serial_max serial1 serial2
626 # Compare (possibly multi-part, '.' delimited) serial numbers, and
627 # return the largest in $func_serial_max_result.  If they are the
628 # same, func_serial_max_result will be empty.
629 func_serial_max ()
631     $opt_debug
632     my_serial1="$1"
633     my_serial2="$2"
635     my_sed_dot='s/\..*$//g'
636     my_sed_rest='s/^[0-9][1-9]*\.*//'
637     my_sed_digits='s/[^0-9.]//g'
639     # Incase they turn out to be the same, we'll set it to empty
640     func_serial_max_result=
642     test "X$1$2" = X`$ECHO "X$1$2" | $Xsed -e "$my_sed_digits"` || {
643       func_error "serial numbers \`$1' or \`$2' contain non-digit chars"
644       return
645     }
647     while test -n "$my_serial1$my_serial2"; do
648       my_serial1_part=`$ECHO "X$my_serial1" | $Xsed -e "$my_sed_dot"`
649       my_serial2_part=`$ECHO "X$my_serial2" | $Xsed -e "$my_sed_dot"`
651       test -z "$my_serial1_part$my_serial2_part" \
652         && break
654       test -z "$my_serial1_part" \
655         && { func_serial_max_result="$2"; break; }
657       test -z "$my_serial2_part" \
658         && { func_serial_max_result="$1"; break; }
660       test "$my_serial1_part" -gt "$my_serial2_part" \
661         && { func_serial_max_result="$1"; break; }
663       test "$my_serial2_part" -gt "$my_serial1_part" \
664         && { func_serial_max_result="$2"; break; }
666       my_serial1=`$ECHO "X$my_serial1" | $Xsed -e "$my_sed_rest"`
667       my_serial2=`$ECHO "X$my_serial2" | $Xsed -e "$my_sed_rest"`
668     done
672 # func_serial_update_check srcfile src_serial destfile dest_serial
673 # Unless SRC_SERIAL is newer than DEST_SERIAL set $func_serial_update_check
674 # to 'false'.
675 func_serial_update_check ()
677     $opt_debug
678     my_srcfile="$1"
679     my_src_serial="$2"
680     my_destfile="$3"
681     my_dest_serial="$4"
682     my_update_p=:
684     if test -f "$my_destfile"; then
685       test "X$my_src_serial" = "X0" && {
686         func_error "warning: no serial number on \`$my_srcfile', not copying."
687         return
688       }
690       # Determine whether the destination has an older serial.
691       func_serial_max "$my_src_serial" "$my_dest_serial"
692       test "X$my_src_serial" = "X$func_serial_max_result" || my_update_p=false
694       test "X$my_src_serial" = "X$func_serial_max_result" \
695         && func_verbose "\`$my_srcfile' is serial $my_src_serial, greater than $my_dest_serial in \`$my_destfile'"
697       if test "X$my_dest_serial" = "X$func_serial_max_result"; then
698         func_verbose "\`$my_srcfile' is serial $my_src_serial, less than $my_dest_serial in \`$my_destfile'"
699         $opt_force \
700           || func_error "\`$my_destfile' is newer: use \`--force' to overwrite"
701       fi
702     fi
704     func_serial_update_check_result="$my_update_p"
708 # func_serial_update filename srcdir destdir [macro_regex] [old_macro_regex]
709 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
710 # has a newer serial number, or DESTFILE does not yet exist, or the user
711 # specified `--force' at the command line.  If given, MACRO_REGEX or
712 # OLD_MACRO_REGEX must match any text after "# serial N" in both files.
713 func_serial_update ()
715     $opt_debug
716     my_filename="$1"
717     my_srcdir="$2"
718     my_destdir="$3"
719     my_macro_regex="$4"
720     my_old_macro_regex="$5"
722     my_serial_update_p=:
723     my_return_status=1
724     my_srcfile="$my_srcdir/$my_filename"
725     my_destfile="$my_destdir/$my_filename"
727     test -f "$my_srcfile" || func_fatal_error "\`$my_srcfile' does not exist."
729     if test -f "$my_destfile"; then
730       my_src_serial=`func_serial "$my_srcfile" "$my_macro_regex"`
731       my_dest_serial=`func_serial "$my_destfile" "$my_macro_regex"`
733       # Strictly, this libtoolize ought not to have to deal with ancient
734       # serial formats, but we accept them here to be complete:
735       test "X$my_src_serial" = "X0" &&
736         my_src_serial=`func_serial "$my_srcfile" "$my_old_macro_regex"`
738       test "X$my_dest_serial" = "X0" &&
739         my_dest_serial=`func_serial "$my_destfile" "$my_old_macro_regex"`
741       func_serial_update_check \
742         "$my_srcfile" "$my_src_serial" "$my_destfile" "$my_dest_serial"
743       my_serial_update_p="$func_serial_update_check_result"
744     fi
746     if $my_serial_update_p || $opt_force; then
747       func_copy "$my_srcfile" "$my_destfile"
748       my_return_status=$?
749     elif test "X$my_dest_serial" = "X$my_src_serial"; then
750       $opt_quiet \
751         || func_echo "\`$my_destfile' is already up to date."
752     fi
754     # Do this after the copy for hand maintained `aclocal.m4', incase
755     # it has `m4_include([DESTFILE])', so the copy effectively already
756     # updated `aclocal.m4'.
757     my_included_files=`func_included_files aclocal.m4`
758     case `echo " $my_included_files " | $NL2SP` in
760       # Skip included files:
761       *" $my_destfile "*) ;;
763       # Otherwise compare to aclocal.m4 serial number (func_serial
764       # returns 0 for older macro serial numbers before we provided
765       # serial tags, so the update message will be correctly given
766       # if aclocal.m4 contains an untagged --i.e older-- macro file):
767       *)
768         if test -f aclocal.m4; then
769           func_serial_max \
770               "$my_src_serial" `func_serial aclocal.m4 "$my_macro_regex"`
771           test "X$my_src_serial" = "X$func_serial_max_result" \
772               && func_echo "You should add the contents of \`$my_destfile' to \`aclocal.m4'."
773         fi
774         ;;
775     esac
776     return $my_return_status
780 # func_keyword_update filename srcdir destdir sed_script
781 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
782 # has a newer revision according to the serial number extracted by
783 # SED_SCRIPT, or DESTFILE does not yet exist, or the user specified
784 # `--force' at the command line.
785 func_keyword_update ()
787     $opt_debug
788     my_filename="$1"
789     my_srcdir="$2"
790     my_destdir="$3"
791     my_sed_script="$4"
793     my_srcfile="$my_srcdir/$my_filename"
794     my_destfile="$my_destdir/$my_filename"
796     my_keyword_update_p=:
798     test -f "$my_srcfile" || func_fatal_error "\`$my_srcfile' does not exist."
800     if test -f "$my_destfile"; then
801       my_src_serial=`$SED -e "$my_sed_script" "$my_srcfile"`
802       test -z "$my_src_serial" && {
803         func_error "warning: no serial number in \`$my_srcfile', not copying."
804         return
805       }
807       my_dest_serial=`$SED -e "$my_sed_script" "$my_destfile"`
808       test -n "$my_dest_serial" || my_dest_serial=0
810       func_serial_update_check \
811          "$my_srcfile" "$my_src_serial" "$my_destfile" "$my_dest_serial"
812       my_keyword_update_p="$func_serial_update_check_result"
813     fi
815     if $my_keyword_update_p || $opt_force; then
816       func_copy "$my_srcfile" "$my_destfile"
817     elif test "X$my_dest_serial" = "X$my_src_serial"; then
818       $opt_quiet \
819         || func_echo "\`$my_destfile' is already up to date."
820     fi
824 # func_ltmain_update filename srcdir destdir
825 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
826 # has a newer revision, or DESTFILE does not yet exist, or the user
827 # specified `--force' at the command line.
828 func_ltmain_update ()
830     $opt_debug
831     my_sed_ltmain='
832         /^package_revision='\''*[0-9][1-9.]*'\''*/ {
833             s,^package_revision='\''*\([0-9.]*\)'\''*[  ]*$,\1,
834             p
835         }
836         d'
838     func_keyword_update "$1" "$2" "$3" "$my_sed_ltmain"
840     return $my_return_status
844 # func_config_update filename srcdir destdir
845 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
846 # has a newer timestamp, or DESTFILE does not yet exist, or the user
847 # specified `--force' at the command line.
848 func_config_update ()
850     $opt_debug
851     my_sed_config='
852         /^timestamp='\''*[0-9][1-9-]*'\''*/ {
853             s,^timestamp='\''*\([0-9-]*\)'\''*,\1,
854             s/-/./g
855             p
856         }
857         d'
859     func_keyword_update "$1" "$2" "$3" "$my_sed_config"
861     return $my_return_status
865 # func_install_update filename srcdir destdir
866 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
867 # has a newer timestamp, or DESTFILE does not yet exist, or the user
868 # specified `--force' at the command line.
869 func_install_update ()
871     $opt_debug
872     my_sed_install='
873         /^scriptversion='\''*[0-9][1-9.-]*'\''*/ {
874             s,^scriptversion='\''*\([0-9.-]*\)'\''*,\1,
875             s/-/./g
876             p
877         }
878         d'
880     func_keyword_update "$1" "$2" "$3" "$my_sed_install"
882     return $my_return_status
886 # func_check_macros
887 # Sanity check macros from aclocal.m4 against installed versions.
888 func_check_macros ()
890     $opt_debug
891     ac_config_macro_dir_advised=false
893     $seen_autoconf || return
895     # Suggest modern idioms for storing autoconf macros:
896     if test -z "$macrodir$ltdldir"; then
897       if test x"$m4dir" = x.; then
898         func_echo "Consider adding \`AC_CONFIG_MACRO_DIR([m4])' to $configure_ac and rerunning"
899         func_echo " libtoolize, to keep the correct libtool macros in-tree."
900       else
901         func_echo "Consider adding \`AC_CONFIG_MACRO_DIR([$m4dir])'to $configure.ac,"
902         func_echo "and rerunning libtoolize."
903       fi
904     elif test -z "$m4dir"; then
905       if $opt_ltdl && test "${ltdlprefix}m4" != "$m4dir"; then
906         acmacrodir="${ltdlprefix}m4"
907       else
908         acmacrodir="$aclocaldir"
909       fi
911       func_echo "You should add the contents of the following files to \`aclocal.m4':"
912       for need in libtool.m4 ltoptions.m4 ltversion.m4 ltsugar.m4 lt~obsolete.m4; do
913         func_echo "  \`$acmacrodir/$need'"
914       done
915       if $seen_ltdl || $opt_ltdl; then
916         for need in argz.m4 ltdl.m4; do
917           func_echo "  \`$acmacrodir/$need'"
918         done
919       fi
920       if test "$acmacrodir" != "$aclocaldir"; then
921         func_echo "or else add \`AC_CONFIG_MACRO_DIR([$acmacrodir])' to $configure_ac."
922         ac_config_macro_dir_advised=:
923       fi
924     fi
926     $seen_libtool ||
927       func_echo "Remember to add \`LT_INIT' to $configure_ac."
929     if $opt_ltdl; then
931       # Suggest using LT_WITH_LTDL if appropriate:
932       $seen_ltdl ||
933         func_echo "Consider adding \`LT_WITH_LTDL' to $configure_ac"
935       # Remind the user to call LT_CONFIG_LTDL_DIR:
936       test -n "$ac_ltdldir" ||
937         func_echo "Remember to add \`LT_CONFIG_LTDL_DIR([$ltdldir])' to \`$configure_ac'."
939       # Offer some suggestions for avoiding duplicate files in a project
940       # that uses libltdl:
941       test "${ltdlprefix}config" = "$auxdir" ||
942         func_echo "Consider using \`AC_CONFIG_AUX_DIR([${ltdlprefix}config])' in $configure_ac."
943       $ac_config_macro_dir_advised || test "${ltdlprefix}m4" = "$m4dir" ||
944         func_echo "Consider using \`AC_CONFIG_MACRO_DIR([${ltdlprefix}m4])' in $configure_ac."
945     else
946       # Don't trace for this, we're just checking the user didn't invoke it
947       # directly from configure.ac.
948       $SED 's,dnl .*$,,; s,# .*$,,' "$configure_ac" | grep AC_PROG_RANLIB &&
949         func_echo "\`AC_PROG_RANLIB' is rendered obsolete by \`LT_INIT'"
950     fi
952     # FIXME: Ensure ltmain.sh, libtool.m4 and ltdl.m4 are from the same release
956 # func_massage_aclocal_DATA [glob_exclude]
957 # @aclocal_DATA\@ is substituted as per its value in Makefile.am;
958 # this function massages it into a suitable format for func_copy_some_files.
959 func_massage_aclocal_DATA ()
961     pkgmacro_files=     # GLOBAL VAR
963     my_glob_exclude="$1"
965     # Massage a value for pkgmacro_files from the value used in Makefile.am.
966     for my_filename in @aclocal_DATA@; do
967       my_filename=`$ECHO "X$my_filename" | $Xsed -e "$basename"`
969       # ignore excluded filenames
970       if test -n "$my_glob_exclude"; then
971         my_cont=false
972         eval 'case $my_filename in '$my_glob_exclude') my_cont=: ;; esac'
973         $my_cont && continue
974       fi
976       pkgmacro_files="$pkgmacro_files:$my_filename"
977     done
979     # strip spurious leading `:'
980     pkgmacro_files=`$ECHO "X$pkgmacro_files" | $Xsed -e 's,^:*,,'`
984 # func_massage_pkgltdl_files [glob_exclude]
985 # @pkgltdl_files\@ is substituted as per its value in Makefile.am; this
986 # function massages it into a suitable format for func_copy_some_files.
987 func_massage_pkgltdl_files ()
989     pkgltdl_files=      # GLOBAL VAR
991     my_glob_exclude="$1"
993     # Massage a value for pkgltdl_files from the value used in Makefile.am
994     for my_filename in @pkgltdl_files@; do
996       # Strip surplus leading 'libltdl/':
997       my_filename=`expr "X$my_filename" : 'Xlibltdl/\(.*\)'`
999       # ignore excluded filenames
1000       if test -n "$my_glob_exclude"; then
1001         my_cont=false
1002         eval 'case $my_filename in '$my_glob_exclude') my_cont=: ;; esac'
1003         $my_cont && continue
1004       fi
1006       # ignore duplicates
1007       case :$pkgltdl_files: in
1008         *:$my_filename:*) ;;
1009         *) pkgltdl_files="$pkgltdl_files:$my_filename" ;;
1010       esac
1011     done
1013     # strip spurious leading `:'
1014     pkgltdl_files=`$ECHO "X$pkgltdl_files" | $Xsed -e 's,^:*,,'`
1018 # func_massage_pkgconfig_files [glob_exclude]
1019 # @pkgconfig_files\@ is substituted as per its value in Makefile.am; this
1020 # function massages it into a suitable format for func_copy_some_files.
1021 func_massage_pkgconfig_files ()
1023     pkgconfig_files=    # GLOBAL VAR
1025     my_glob_exclude="$1"
1027     # Massage a value for pkgconfig_files from the value used in Makefile.am
1028     for my_filename in @pkgconfig_files@; do
1030       # ignore excluded filenames
1031       if test -n "$my_glob_exclude"; then
1032         my_cont=false
1033         eval 'case $my_filename in '$my_glob_exclude') my_cont=: ;; esac'
1034         $my_cont && continue
1035       fi
1037       # ignore duplicates
1038       case :$pkgconfig_files: in
1039         *:$my_filename:*) ;;
1040         *) pkgconfig_files="$pkgconfig_files:$my_filename" ;;
1041       esac
1042     done
1044     # strip spurious leading `:'
1045     pkgconfig_files=`$ECHO "X$pkgconfig_files" | $Xsed -e 's,^:*,,'`
1049 # func_nonemptydir_p dirvar
1050 # DIRVAR is the name of a variable to evaluate.  Unless DIRVAR names
1051 # a directory that exists and is non-empty abort with a diagnostic.
1052 func_nonemptydir_p ()
1054     $opt_debug
1055     my_dirvar="$1"
1056     my_dir=`eval echo "\\\$$my_dirvar"`
1058     # Is it a directory at all?
1059     test -d "$my_dir" \
1060       || func_fatal_error "\$$my_dirvar not a directory: \`$my_dir'"
1062     # check that the directories contents can be ls'ed
1063     test -n "`{ cd $my_dir && ls; } 2>/dev/null`" \
1064         || func_fatal_error "can not list files: \`$my_dir'"
1068 ## ----------- ##
1069 ##    Main.    ##
1070 ## ----------- ##
1073   rerun_aclocal=false
1075   # Allow the user to override the master libtoolize repository:
1076   if test -n "$_lt_pkgdatadir"; then
1077     pkgltdldir="$_lt_pkgdatadir"
1078     pkgdatadir="$_lt_pkgdatadir/libltdl"
1079     aclocaldir="$_lt_pkgdatadir/libltdl/m4"
1080   fi
1081   func_nonemptydir_p pkgltdldir
1082   func_nonemptydir_p pkgdatadir
1083   func_nonemptydir_p aclocaldir
1085   func_scan_files
1087   case $ltdldir in
1088   .) ltdlprefix= ;;
1089   *) ltdlprefix=$ltdldir/ ;;
1090   esac
1092   # Unless we share CONFIG_AUX_DIR with the libltdl subproject, then
1093   # if they are newer, copy all the installed utility files to the
1094   # auxiliary directory if `--install' was passed, or else copy just
1095   # ltmain.sh.
1096   if test -n "$auxdir"; then
1097     if test "${ltdlprefix}config" != "$auxdir"; then
1098       $opt_quiet || if test "$auxdir" != .; then
1099         func_echo "putting files in AC_CONFIG_AUX_DIR, \`$auxdir'."
1100       fi
1101       if $opt_install; then
1102         func_config_update config.guess "$pkgdatadir/config" "$auxdir"
1103         func_config_update config.sub   "$pkgdatadir/config" "$auxdir"
1104         func_install_update install-sh  "$pkgdatadir/config" "$auxdir"
1105       fi
1106       func_ltmain_update ltmain.sh "$pkgdatadir/config" "$auxdir"
1107     fi
1108   else
1109     func_verbose "AC_CONFIG_AUX_DIR not defined, not copying libtool auxiliary files."
1110   fi
1112   # argz.m4, libtool.m4 and ltdl.m4 were handled specially above
1113   func_massage_aclocal_DATA 'argz.m4|libtool.m4|ltdl.m4'
1115   # Copy libtool's m4 macros to the macro directory, if they are newer
1116   # (keep these in alphabetical order to maintain sanity in testsuite):
1117   if test -n "$m4dir"; then
1118     $opt_quiet || func_echo "putting macros in AC_CONFIG_MACRO_DIR, \`$m4dir'."
1120     if $seen_ltdl; then
1121       func_serial_update argz.m4 "$aclocaldir" "$m4dir" argz.m4
1122     else
1123       func_verbose "Not copying \`$m4dir/argz.m4', libltdl not used."
1124     fi
1126     func_serial_update  libtool.m4 "$aclocaldir" "$m4dir" \
1127       LT_INIT 'A[CM]_PROG_LIBTOOL'
1129     if $seen_ltdl; then
1130       func_serial_update ltdl.m4 "$aclocaldir" "$m4dir" 'LTDL_INIT'
1131     else
1132       func_verbose "Not copying \`$m4dir/ltdl.m4', libltdl not used."
1133     fi
1135     my_save_IFS="$IFS"
1136     IFS=:
1137     for file in $pkgmacro_files; do
1138       IFS="$my_save_IFS"
1139       func_serial_update $file "$aclocaldir" "$m4dir" "$file"
1140     done
1141     IFS="$my_save_IFS"
1142   fi
1144   # These files are handled specially, depending on ltdl_mode:
1145   case $ltdl_mode in
1146     *recursive)
1147       glob_exclude_pkgltdl_files='Makefile.am|Makefile.in*|aclocal.m4|config*'
1148       ;;
1149     *)
1150       glob_exclude_pkgltdl_files='Makefile.inc'
1151       ;;
1152   esac
1154   func_massage_pkgltdl_files "$glob_exclude_pkgltdl_files"
1155   func_massage_pkgconfig_files
1157   # Copy all the files from installed libltdl to this project, if the
1158   # user specified `--ltdl'.
1159   if $opt_ltdl; then
1161     # Unless we share CONFIG_MACRO_DIR with our parent project,
1162     # copy macros here.
1163     if test "${ltdlprefix}m4" != "$m4dir"; then
1164       func_copy_some_files "argz.m4:libtool.m4:ltdl.m4:$pkgmacro_files" \
1165         "$aclocaldir" "${ltdlprefix}m4"
1166     fi
1168     func_copy_some_files "$pkgltdl_files" "$pkgltdldir/libltdl" "$ltdldir"
1170     # For recursive ltdl modes, copy a suitable Makefile.{am,inc}:
1171     case $ltdl_mode in
1172       recursive)    func_fixup_Makefile "Makefile.am" "$pkgltdldir/libltdl" "$ltdldir" ;;
1173       nonrecursive) func_fixup_Makefile "Makefile.inc" "$pkgltdldir/libltdl" "$ltdldir" ;;
1174     esac
1176     # Copy config aux files into libltdl.
1177     func_copy_some_files "$pkgconfig_files" "$pkgdatadir" "$ltdldir"
1178   fi
1180   $opt_quiet || func_check_macros
1183 exit $exit_status
1185 # Local Variables:
1186 # mode:shell-script
1187 # sh-indentation:2
1188 # End: