Bump to 2.4.7
[platform/upstream/libtool.git] / libtoolize.in
1 #! /usr/bin/env sh
2
3 # Prepare a package to use libtool.
4 # Written by Gary V. Vaughan <gary@gnu.org>, 2003
5
6 # Copyright (C) 2003-2019, 2021-2022 Free Software Foundation, Inc.
7 # This is free software; see the source for copying conditions.  There is NO
8 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
10 # Libtoolize is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # Libtoolize is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23
24 ## ------ ##
25 ## Usage. ##
26 ## ------ ##
27
28 # Run './libtoolize --help' for help with using this script from the
29 # command line.
30
31
32 ## ------------------------------- ##
33 ## User overridable command paths. ##
34 ## ------------------------------- ##
35
36 # After configure completes, it has a better idea of some of the
37 # shell tools we need than the defaults used by the functions shared
38 # with bootstrap, so set those here where they can still be over-
39 # ridden by the user, but otherwise take precedence.
40
41 : ${AUTOCONF="autoconf"}
42 : ${AUTOMAKE="automake"}
43 : ${EGREP="@EGREP@"}
44 : ${FGREP="@FGREP@"}
45 : ${GREP="@GREP@"}
46 : ${LN_S="@LN_S@"}
47 : ${SED="@SED@"}
48
49
50 ## -------------------------- ##
51 ## Source external libraries. ##
52 ## -------------------------- ##
53
54 # Much of our low-level functionality needs to be sourced from external
55 # libraries, which are installed to $pkgauxdir under normal use, though
56 # we also need to be able to find them in $srcdir during testing, or if
57 # executed directly from the build tree.
58
59 . "@auxscriptsdir@/funclib.sh"
60 . "@auxscriptsdir@/options-parser"
61 . "@auxscriptsdir@/extract-trace"
62
63 # Set a version string.
64 scriptversion='(GNU @PACKAGE@) @VERSION@'
65
66
67 ## ---------------- ##
68 ## Options parsing. ##
69 ## ---------------- ##
70
71 # Hook in the functions to make sure our own options are parsed during
72 # the option parsing loop.
73
74 usage='$progpath [OPTION]...'
75
76 # Short help message in response to '-h'.
77 usage_message="Options:
78    -c, --copy          copy files rather than symlinking them
79        --debug         enable verbose shell tracing
80    -n, --dry-run       print commands rather than running them
81    -f, --force         replace existing files
82    -i, --install       copy missing auxiliary files
83        --ltdl[=DIR]    install libltdl sources [default: libltdl]
84        --no-warnings   equivalent to '-Wnone'
85        --nonrecursive  prepare ltdl for non-recursive make
86    -q, --quiet         work silently
87        --recursive     prepare ltdl for recursive make
88        --subproject    prepare ltdl to configure and build independently
89    -v, --verbose       verbosely report processing
90        --version       print version information and exit
91    -W, --warnings=CATEGORY
92                        report the warnings falling in CATEGORY [all]
93    -h, --help          print short or long help message
94 "
95
96 # Additional text appended to 'usage_message' in response to '--help'.
97 func_help ()
98 {
99     $debug_cmd
100
101     func_usage_message
102     $ECHO "$long_help_message
103        'environment'   show warnings about LIBTOOLIZE_OPTIONS content
104        'file'          show warnings about file copying and linking
105
106 The following space or comma delimited options can be passed to $progname
107 via the environment variable LIBTOOLIZE_OPTIONS, unknown environment
108 options are ignored:
109
110        --debug         enable verbose shell tracing
111        --no-warnings   don't display warning messages
112        --quiet         work silently
113        --verbose       verbosely report processing
114
115 You must 'cd' to the top directory of your package before you run
116 '$progname'.
117
118 When reporting a bug, please describe a test case to reproduce it and
119 include the following information:
120
121        host-triplet:   @host_triplet@
122        version:        $progname (GNU @PACKAGE@) @VERSION@
123        automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
124        autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
125
126 Report bugs to <@PACKAGE_BUGREPORT@>.
127 GNU @PACKAGE@ home page: <@PACKAGE_URL@>.
128 General help using GNU software: <http://www.gnu.org/gethelp/>."
129     exit 0
130 }
131
132 warning_categories='environment file'
133
134
135 # libtoolize_environment_options [ARG]...
136 # ---------------------------------------
137 # Parse environment options.
138 libtoolize_environment_options ()
139 {
140     $debug_mode
141
142     my_sed_env_opt='1s/^\([^,:; ]*\).*$/\1/;q'
143     my_sed_env_rest='1s/^[^,:; ]*[,:; ]*\(.*\)$/\1/;q'
144
145     while test -n "$LIBTOOLIZE_OPTIONS"; do
146       opt=`echo "$LIBTOOLIZE_OPTIONS" | $SED "$my_sed_env_opt"`
147       LIBTOOLIZE_OPTIONS=`echo "$LIBTOOLIZE_OPTIONS" | $SED "$my_sed_env_rest"`
148
149       case $opt in
150         --debug|--no-warn|--no-warning|--no-warnings|--quiet|--verbose)
151                 envopts="${envopts+$envopts }$opt"                        ;;
152         --*)    env_warning="${env_warning+$env_warning
153 }unrecognized environment option '$opt'"                                  ;;
154         *)      func_fatal_help "garbled LIBTOOLIZE_OPTIONS near '$opt'"  ;;
155       esac
156     done
157
158     # Pass back the updated list of options.
159     if test -n "$envopts"; then
160       func_quote eval "$envopts" ${1+"$@"}
161     else
162       func_quote eval ${1+"$@"}
163     fi
164     libtoolize_environment_options_result=$func_quote_result
165 }
166 func_add_hook func_options_prep libtoolize_environment_options
167
168
169 # libtoolize_options_prep [ARG]...
170 # --------------------------------
171 # Preparation for options parsed by libtoolize.
172 libtoolize_options_prep ()
173 {
174     $debug_cmd
175
176     # Option defaults:
177     opt_copy=false
178     opt_dry_run=false
179     opt_force=false
180     opt_install=false
181     opt_ltdl=false
182     opt_nonrecursive=false
183     opt_quiet=false
184     opt_recursive=false
185     opt_subproject=false
186
187     ltdl_mode=
188 }
189 func_add_hook func_options_prep libtoolize_options_prep
190
191
192 # libtoolize_parse_options [ARG]...
193 # ---------------------------------
194 # Provide handling for libtoolize specific options.
195 libtoolize_parse_options ()
196 {
197     $debug_cmd
198
199     # Perform our own loop to consume as many options as possible in
200     # each iteration.
201     while test $# -gt 0; do
202       _G_opt=$1
203       shift
204       case $_G_opt in
205         --copy|-c)      opt_copy=: ;;
206
207         --dry-run|--dryrun|-n)
208                         $opt_dry_run || {
209                           opt_dry_run=:
210                           CP="func_echo_all $CP"
211                           test -n "$LN_S" && LN_S="func_echo_all $LN_S"
212                           MKDIR="func_echo_all $MKDIR"
213                           RM="func_echo_all $RM"
214                         }
215                         ;;
216
217         --force|-f)     opt_force=: ;;
218
219         --install|-i)   opt_install=: ;;
220
221         --ltdl)         opt_ltdl=:
222                         if test 0 -lt $#; then
223                           case $1 in
224                             -*) ;;
225                             *)  ltdl_dir=`$ECHO "$1" | $SED 's|/*$||'`
226                                 shift
227                                 ;;
228                           esac
229                         fi
230                         ;;
231
232         --nonrecursive|--non-recursive)
233                         opt_nonrecursive=:
234                         ;;
235
236         --quiet|--automake|-q) # --automake is for 1.5 compatibility
237                         opt_quiet=: ;;
238
239         --recursive)    opt_recursive=: ;;
240
241         --subproject)   opt_subproject=: ;;
242
243         # Separate non-argument short options:
244         -c*|-f*|-i*|-n*|-q*)
245                         func_split_short_opt "$_G_opt"
246                         set dummy "$func_split_short_opt_name" \
247                             "-$func_split_short_opt_arg" ${1+"$@"}
248                         shift
249                         ;;
250
251         # An option not handled by this hook function:
252         *)              set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
253       esac
254     done
255
256     # save modified positional parameters for caller
257     func_quote eval ${1+"$@"}
258     libtoolize_parse_options_result=$func_quote_result
259 }
260 func_add_hook func_parse_options libtoolize_parse_options
261
262
263 # libtoolize_validate_options [ARG]...
264 # ------------------------------------
265 # Perform any sanity checks on option settings and/or unconsumed
266 # arguments.
267 libtoolize_validate_options ()
268 {
269     # show any warnings saved by LIBTOOLIZE_OPTIONS parsing
270     test -n "$env_warning" && func_warning environment "$env_warning"
271
272     # validate $opt_nonrecursive, $opt_recursive and $opt_subproject
273     if $opt_nonrecursive; then
274       if $opt_recursive || $opt_subproject; then
275         func_error "you can have at most one of --non-recursive, --recursive and --subproject"
276       fi
277       ltdl_mode=nonrecursive
278     elif $opt_recursive; then
279       $opt_subproject &&
280         func_error "you can have at most one of --non-recursive, --recursive and --subproject"
281       ltdl_mode=recursive
282     elif $opt_subproject; then
283       ltdl_mode=subproject
284     fi
285
286     # any remaining arguments are an error
287     test 0 -lt $# &&
288       func_fatal_help "unknown additional arguments: '${1+$@}'"
289
290     # Pass back the empty argument list
291     func_quote eval ${1+"$@"}
292     libtoolize_validate_options_result=$func_quote_result
293 }
294 func_add_hook func_validate_options libtoolize_validate_options
295
296
297 # Process options as early as possible so that --help and --version
298 # can return quickly.
299 func_options ${1+"$@"}
300 eval set dummy "$func_options_result"; shift
301
302
303 # func_notquiet_once MSG_VAR
304 # --------------------------
305 # Call func_notquiet with the value of MSG_VAR, and then set MSG_VAR='' so
306 # that subsequent calls will have no effect.
307 func_notquiet_once ()
308 {
309     $debug_cmd
310
311     if test -n "$1"; then
312       eval my_msg=\$$1
313
314       if test -n "$my_msg"; then
315         func_notquiet "$my_msg"
316         eval $1=
317       fi
318     fi
319 }
320
321
322 # func_notquiet_hdr MSG_VAR ARG...
323 # --------------------------------
324 # With at least 1 non-empty ARG, call func_notquiet_once with MSG_VAR,
325 # and then func_notquiet with the remaining arguments.
326 func_notquiet_hdr ()
327 {
328     $debug_cmd
329
330     my_msg_var=$1; shift
331     test -n "$*" || return
332
333     func_notquiet_once "$my_msg_var"
334     func_notquiet "$*"
335 }
336
337
338 # func_notquiet_error_hdr MSG_VAR ARG...
339 # --------------------------------------
340 # Much the same as func_notquiet_header, but for (non-fatal) error
341 # messages.
342 func_notquiet_error_hdr ()
343 {
344     $debug_cmd
345
346     my_msg_var=$1; shift
347     test -n "$*" || return
348
349     func_notquiet_once "$my_msg_var"
350     func_error "$*"
351
352     exit_status=$EXIT_FAILURE
353 }
354
355
356 # func_copy FILENAME SRCDIR DESTDIR [MSG_VAR [FILTER]]
357 # ----------------------------------------------------
358 # If option '--copy' was specified, or soft-linking SRCFILE to DESTFILE
359 # fails, then try to copy SRCFILE to DESTFILE (making sure to update the
360 # timestamp so that a series of files with dependencies can be copied
361 # in the right order that their timestamps won't trigger rebuilds). If
362 # FILTER is non-empty, it is a sed script to apply to SRCFILE as it is
363 # copied.  MSG_VAR names a variable for use with func_notquiet_hdr.
364 func_copy ()
365 {
366     $debug_cmd
367
368     my_filename=$1
369     my_srcdir=$2
370     my_destdir=$3
371     my_msg_var=$4
372     my_filter=$5
373
374     my_srcfile=$my_srcdir/$my_filename
375     my_destfile=$my_destdir/$my_filename
376
377     # Libtool is probably misinstalled if this happens:
378     test -f "$my_srcfile" || {
379       func_notquiet_error_hdr "$my_msg_var" "'$my_srcfile' not found"
380       return 1
381     }
382
383     # Require --force to remove existing $my_destfile.
384     $opt_force && $RM "$my_destfile"
385     test -f "$my_destfile" && {
386       func_notquiet_error_hdr "$my_msg_var" \
387         "'$my_destfile' exists: use '--force' to overwrite"
388       return 1
389     }
390
391     # Be careful to support 'func_copy dir/target srcbase destbase'.
392     func_dirname "$my_destfile"
393     func_mkdir_p "$func_dirname_result"
394
395     # Filters always take priority.
396     if test -n "$my_filter"; then
397       if $opt_dry_run || $SED -e "$my_filter" "$my_srcfile" > "$my_destfile" 2>/dev/null
398       then
399         func_notquiet_once "$my_msg_var"
400         if $opt_verbose; then
401           func_notquiet "$SED -e '$my_filter' $my_srcfile > $my_destfile"
402          else
403           func_notquiet "creating file '$my_destfile'"
404          fi
405       else
406         func_notquiet_error_hdr "$my_msg_var" "creating '$my_destfile' from '$my_srcfile' failed"
407         return 1
408       fi
409       return 0
410     fi
411
412     # Otherwise copy or link according to '--copy' option.
413     if $opt_copy; then
414       my_copycmd=$CP
415       my_copy_type=copying
416     else
417       my_copycmd=$LN_S
418       my_copy_type=linking
419     fi
420     my_copy_msg="$my_copy_type file '$my_destfile'"
421     $opt_verbose && my_copy_msg="$my_copycmd $my_srcfile $my_destdir"
422
423     if $opt_dry_run || $my_copycmd "$my_srcfile" "$my_destfile" 2>/dev/null
424     then
425       func_notquiet_hdr "$my_msg_var" "$my_copy_msg"
426     else
427       func_notquiet_error_hdr "$my_msg_var" \
428         "$my_copy_type '$my_srcdir/$my_filename' to '$my_destdir/' failed"
429       return 1
430     fi
431 }
432
433
434 # func_included_files SEARCHFILE
435 # ------------------------------
436 # Output INCLUDEFILE if SEARCHFILE m4_includes it, else output SEARCHFILE.
437 func_included_files ()
438 {
439     $debug_cmd
440
441     my_searchfile=$1
442
443     my_include_regex=
444     my_sed_include='
445         /^m4_include(\[.*\])$/ {
446             s|^m4_include(\[\(.*\)\])$|\1|
447             p
448         }
449         d'
450
451     if test -f "$my_searchfile"; then
452       $ECHO "$my_searchfile"
453
454       # Only recurse when we don't care if all the variables we use get
455       # trashed, since they are in global scope.
456       for my_filename in `$SED "$my_sed_include" "$my_searchfile"`; do
457         func_included_files $my_filename
458       done
459     fi
460 }
461
462
463 # func_serial FILENAME [MACRO_REGEX]
464 # ----------------------------------
465 # Output the value of the serial number comment in FILENAME, where the
466 # comment line must also match MACRO_REGEX, if given.
467 func_serial ()
468 {
469     $debug_cmd
470
471     my_filename=$1
472     my_macro_regex=$2
473     my_sed_serial='
474         /^# serial [1-9][0-9.]*[         ]*'"$my_macro_regex"'[  ]*$/ {
475             s|^# serial \([1-9][0-9.]*\).*$|\1|
476             q
477         }
478         d'
479
480     # Search FILENAME and all the files it m4_includes for a serial number
481     # in the file that AC_DEFUNs MACRO_REGEX.
482     my_serial=
483     func_dirname_and_basename "$my_filename"
484     my_filebase=$func_basename_result
485     for my_file in `func_included_files "$my_filename"`; do
486       if test -z "$my_macro_regex" ||
487          test aclocal.m4 = "$my_filename" ||
488          test "X$my_macro_regex" = "X$my_filebase" ||
489          func_grep '^AC_DEFUN(\['"$my_macro_regex" "$my_file"
490       then
491         my_serial=`$SED -e "$my_sed_serial" "$my_file"`
492         break
493       fi
494     done
495
496     # If the file has no serial number, we assume it's ancient.
497     test -n "$my_serial" || my_serial=0
498
499     $ECHO "$my_serial"
500 }
501
502
503 # func_serial_max SERIAL1 SERIAL2
504 # -------------------------------
505 # Compare (possibly multi-part, '.' delimited) serial numbers, and
506 # return the largest in $func_serial_max_result.  If they are the
507 # same, func_serial_max_result will be empty.
508 func_serial_max ()
509 {
510     $debug_cmd
511
512     my_serial1=$1
513     my_serial2=$2
514
515     my_sed_dot='s/\..*$//g'
516     my_sed_rest='s/^[0-9][1-9]*\.*//'
517     my_sed_digits='s/[^0-9.]//g'
518
519     # Incase they turn out to be the same, we'll set it to empty
520     func_serial_max_result=
521
522     test "X$1$2" = X`$ECHO "$1$2" | $SED "$my_sed_digits"` || {
523       func_error "serial numbers '$1' or '$2' contain non-digit chars"
524       return
525     }
526
527     while test -n "$my_serial1$my_serial2"; do
528       my_serial1_part=`$ECHO "$my_serial1" | $SED "$my_sed_dot"`
529       my_serial2_part=`$ECHO "$my_serial2" | $SED "$my_sed_dot"`
530
531       test -z "$my_serial1_part$my_serial2_part" \
532         && break
533
534       test -z "$my_serial1_part" \
535         && { func_serial_max_result=$2; break; }
536
537       test -z "$my_serial2_part" \
538         && { func_serial_max_result=$1; break; }
539
540       test "$my_serial1_part" -gt "$my_serial2_part" \
541         && { func_serial_max_result=$1; break; }
542
543       test "$my_serial2_part" -gt "$my_serial1_part" \
544         && { func_serial_max_result=$2; break; }
545
546       my_serial1=`$ECHO "$my_serial1" | $SED "$my_sed_rest"`
547       my_serial2=`$ECHO "$my_serial2" | $SED "$my_sed_rest"`
548     done
549 }
550
551
552 # func_serial_update_check SRCFILE SRC_SERIAL DESTFILE DEST_SERIAL
553 # ----------------------------------------------------------------
554 # Unless SRC_SERIAL is newer than DEST_SERIAL set $func_serial_update_check
555 # to 'false'.
556 func_serial_update_check ()
557 {
558     $debug_cmd
559
560     $require_ac_ltdl_dir
561     $require_ac_macro_dir
562
563     my_srcfile=$1
564     my_src_serial=$2
565     my_destfile=$3
566     my_dest_serial=$4
567     my_update_p=:
568
569     if test -f "$my_destfile"; then
570       test 0 = "$my_src_serial" && {
571         func_warning file "no serial number on '$my_srcfile', not copying."
572         return
573       }
574
575       # Determine whether the destination has an older serial.
576       func_serial_max "$my_src_serial" "$my_dest_serial"
577       test "X$my_src_serial" = "X$func_serial_max_result" || my_update_p=false
578
579       test "X$my_src_serial" = "X$func_serial_max_result" \
580         && func_verbose "'$my_srcfile' is serial $my_src_serial, greater than $my_dest_serial in '$my_destfile'"
581
582       if test "X$my_dest_serial" = "X$func_serial_max_result"; then
583         func_verbose "'$my_srcfile' is serial $my_src_serial, less than $my_dest_serial in '$my_destfile'"
584         $opt_force || if test -n "$ac_macro_dir$ac_ltdl_dir"; then
585            func_error "'$my_destfile' is newer: use '--force' to overwrite"
586         fi
587       fi
588     fi
589
590     func_serial_update_check_result=$my_update_p
591 }
592
593
594 # func_aclocal_update_check FILENAME
595 # ----------------------------------
596 # Unless serial number of FILENAME is newer than the matching serial number
597 # in aclocal.m4, set $func_aclocal_update_check to 'false'.
598 func_aclocal_update_check ()
599 {
600     $debug_cmd
601
602     my_filename=$1
603
604     my_srcfile=$aclocaldir/$1
605     my_destfile=aclocal.m4
606
607     case $my_filename in
608       libtool.m4)
609         my_src_serial=`func_serial "$my_srcfile" LT_INIT`
610         my_dest_serial=`func_serial "$my_destfile" LT_INIT`
611
612         # Strictly, this libtoolize ought not to have to deal with ancient
613         # serial formats, but we accept them here to be complete:
614         test 0 = "$my_src_serial" &&
615           my_src_serial=`func_serial "$my_srcfile" 'A[CM]_PROG_LIBTOOL'`
616         test 0 = "$my_dest_serial" &&
617           my_dest_serial=`func_serial "$my_destfile" 'A[CM]_PROG_LIBTOOL'`
618         ;;
619       ltdl.m4)
620         my_src_serial=`func_serial "$my_srcfile" LTDL_INIT`
621         my_dest_serial=`func_serial "$my_destfile" LTDL_INIT`
622         ;;
623       *)
624         my_src_serial=`func_serial "$my_srcfile" "$my_filename"`
625         my_dest_serial=`func_serial "$my_destfile" "$my_filename"`
626         ;;
627     esac
628
629     func_serial_update_check \
630       "$my_srcfile" "$my_src_serial" "$my_destfile" "$my_dest_serial"
631
632     func_aclocal_update_check_result=$func_serial_update_check_result
633 }
634
635
636 # func_serial_update FILENAME SRCDIR DESTDIR [MSG_VAR] [MACRO_RE] [OLD_MACRO_RE]
637 # ------------------------------------------------------------------------------
638 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
639 # has a newer serial number, or DESTFILE does not yet exist, or the user
640 # specified '--force' at the command line.  If given, MACRO_REGEX or
641 # OLD_MACRO_REGEX must match any text after "# serial N" in both files.
642 func_serial_update ()
643 {
644     $debug_cmd
645
646     my_filename=$1
647     my_srcdir=$2
648     my_destdir=$3
649     my_msg_var=$4
650     my_macro_regex=$5
651     my_old_macro_regex=$6
652
653     my_serial_update_p=:
654     my_return_status=1
655     my_srcfile=$my_srcdir/$my_filename
656     my_destfile=$my_destdir/$my_filename
657
658     test -f "$my_srcfile" || func_fatal_error "'$my_srcfile' does not exist."
659
660     if test -f "$my_destfile"; then
661       my_src_serial=`func_serial "$my_srcfile" "$my_macro_regex"`
662       my_dest_serial=`func_serial "$my_destfile" "$my_macro_regex"`
663
664       # Strictly, this libtoolize ought not to have to deal with ancient
665       # serial formats, but we accept them here to be complete:
666       test 0 = "$my_src_serial" &&
667         my_src_serial=`func_serial "$my_srcfile" "$my_old_macro_regex"`
668
669       test 0 = "$my_dest_serial" &&
670         my_dest_serial=`func_serial "$my_destfile" "$my_old_macro_regex"`
671
672       func_serial_update_check \
673         "$my_srcfile" "$my_src_serial" "$my_destfile" "$my_dest_serial"
674       my_serial_update_p=$func_serial_update_check_result
675     fi
676
677     if $my_serial_update_p || $opt_force; then
678       $RM "$my_destfile"
679       func_copy "$my_filename" "$my_srcdir" "$my_destdir" "$my_msg_var"
680       my_return_status=$?
681     elif $opt_force && test "X$my_dest_serial" = "X$my_src_serial"; then
682       func_notquiet_hdr "$my_msg_var" "'$my_destfile' is already up to date."
683     fi
684
685     # Do this after the copy for hand maintained 'aclocal.m4', incase
686     # it has 'm4_include([DESTFILE])', so the copy effectively already
687     # updated 'aclocal.m4'.
688     my_included_files=`func_included_files aclocal.m4`
689     case `echo " "$my_included_files" "` in
690
691       # Skip included files:
692       *" $my_destfile "*) ;;
693
694       # Otherwise compare to aclocal.m4 serial number (func_serial
695       # returns 0 for older macro serial numbers before we provided
696       # serial tags, so the update message will be correctly given
697       # if aclocal.m4 contains an untagged --i.e older-- macro file):
698       *)
699         if test -f aclocal.m4; then
700           func_serial_max \
701               "$my_src_serial" `func_serial aclocal.m4 "$my_macro_regex"`
702           if test "X$my_src_serial" = "X$func_serial_max_result"; then
703               func_notquiet_hdr "$my_msg_var" \
704                 "You should add the contents of '$my_destfile' to 'aclocal.m4'."
705           fi
706         fi
707         ;;
708     esac
709     return $my_return_status
710 }
711
712
713 # func_keyword_update FILENAME SRCDIR DESTDIR SED_SCRIPT [MSG_VAR]
714 # ----------------------------------------------------------------
715 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
716 # has a newer revision according to the serial number extracted by
717 # SED_SCRIPT, or DESTFILE does not yet exist, or the user specified
718 # '--force' at the command line.
719 func_keyword_update ()
720 {
721     $debug_cmd
722
723     my_filename=$1
724     my_srcdir=$2
725     my_destdir=$3
726     my_sed_script=$4
727     my_msg_var=$5
728
729     my_srcfile=$my_srcdir/$my_filename
730     my_destfile=$my_destdir/$my_filename
731
732     my_keyword_update_p=:
733
734     test -f "$my_srcfile" || func_fatal_error "'$my_srcfile' does not exist."
735
736     if test -f "$my_destfile"; then
737       my_src_serial=`$SED -e "$my_sed_script" "$my_srcfile"`
738       test -z "$my_src_serial" && {
739         func_warning file "no serial number in '$my_srcfile', not copying."
740         return
741       }
742
743       my_dest_serial=`$SED -e "$my_sed_script" "$my_destfile"`
744       test -n "$my_dest_serial" || my_dest_serial=0
745
746       func_serial_update_check \
747          "$my_srcfile" "$my_src_serial" "$my_destfile" "$my_dest_serial"
748       my_keyword_update_p=$func_serial_update_check_result
749     fi
750
751     if $my_keyword_update_p || $opt_force; then
752       $RM "$my_destfile"
753       func_copy "$my_filename" "$my_srcdir" "$my_destdir" "$my_msg_var"
754     elif $opt_verbose || $opt_force && test "X$my_dest_serial" = "X$my_src_serial"; then
755       func_notquiet_hdr "$my_msg_var" "'$my_destfile' is already up to date."
756     fi
757 }
758
759
760 # func_ltmain_update FILENAME SRCDIR DESTDIR [MSG_VAR]
761 # ----------------------------------------------------
762 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
763 # has a newer revision, or DESTFILE does not yet exist, or the user
764 # specified '--force' at the command line.
765 func_ltmain_update ()
766 {
767     $debug_cmd
768
769     my_sed_ltmain='
770         /^package_revision='\''*[0-9][1-9.]*'\''*/ {
771             s|^package_revision='\''*\([0-9.]*\)'\''*[   ]*$|\1|
772             p
773         }
774         d'
775
776     func_keyword_update "$1" "$2" "$3" "$my_sed_ltmain" "$4"
777
778     return $my_return_status
779 }
780
781
782 # func_config_update FILENAME SRCDIR DESTDIR [MSG_VAR]
783 # ----------------------------------------------------
784 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
785 # has a newer timestamp, or DESTFILE does not yet exist, or the user
786 # specified '--force' at the command line.
787 func_config_update ()
788 {
789     $debug_cmd
790
791     my_sed_config='
792         /^timestamp='\''*[0-9][1-9-]*'\''*/ {
793             s|^timestamp='\''*\([0-9-]*\)'\''*|\1|
794             s|-|.|g
795             p
796         }
797         d'
798
799     func_keyword_update "$1" "$2" "$3" "$my_sed_config" "$4"
800
801     return $my_return_status
802 }
803
804
805 # func_install_update FILENAME SRCDIR DESTDIR [MSG_VAR]
806 # -----------------------------------------------------
807 # Copy the FILENAME from a SRCDIR to DESTDIR provided that either FILENAME
808 # has a newer timestamp, or DESTFILE does not yet exist, or the user
809 # specified '--force' at the command line.
810 func_install_update ()
811 {
812     $debug_cmd
813
814     my_sed_install='
815         /^scriptversion='\''*[0-9][1-9.-]*'\''*/ {
816             s|[#;].*||
817             s|^scriptversion='\''*\([0-9.-]*\)'\''*|\1|
818             s|-|.|g
819             p
820         }
821         d'
822
823     func_keyword_update "$1" "$2" "$3" "$my_sed_install" "$4"
824
825     return $my_return_status
826 }
827
828
829 # func_install_pkgmacro_files
830 # ---------------------------
831 # Install copies of the libtool and libltdl m4 macros into this package.
832 func_install_pkgmacro_files ()
833 {
834     $debug_cmd
835
836     $require_ac_macro_dir
837     $require_am_macro_dir
838     $require_ltdl_mode
839     $require_macro_dir
840
841     $opt_ltdl || test -n "$ac_macro_dir$am_macro_dir" || return
842
843     # Remove any lingering files that my have been installed by some
844     # previous libtoolize release:
845     $opt_force && for file in $all_pkgmacro_files; do
846       test -f "$macro_dir/$file" && func_verbose "rm -f '$macro_dir/$file'"
847       rm -f "$macro_dir/$file"
848     done
849
850     # Install the libltdl autoconf macros to this project's source tree.
851     $opt_quiet || if test -n "$ac_macro_dir"; then
852       my_pkgmacro_header="putting macros in AC_CONFIG_MACRO_DIRS, '$ac_macro_dir'."
853     else
854       my_pkgmacro_header="putting macros in '$macro_dir'."
855     fi
856
857     for file in $pkgmacro_files; do
858       case $file in
859         libtool.m4)
860           func_serial_update "$file" "$aclocaldir" "$macro_dir" \
861             my_pkgmacro_header LT_INIT 'A[CM]_PROG_LIBTOOL'
862           ;;
863         ltdl.m4)
864           if $opt_ltdl; then
865             func_serial_update "$file" "$aclocaldir" "$macro_dir" \
866               my_pkgmacro_header 'LTDL_INIT'
867           else
868             func_verbose "Not copying '$macro_dir/$file', libltdl not used."
869           fi
870           ;;
871         ltoptions.m4|ltsugar.m4|ltversion.m4|lt~obsolete.m4)
872           func_serial_update "$file" "$aclocaldir" "$macro_dir" \
873             my_pkgmacro_header "$file"
874           ;;
875         *)
876           if $opt_ltdl; then
877             func_serial_update "$file" "$aclocaldir" "$macro_dir" \
878               my_pkgmacro_header "$file"
879           else
880             func_verbose "Not copying '$macro_dir/$file', libltdl not used."
881           fi
882           ;;
883       esac
884     done
885 }
886
887
888 # func_install_pkgltdl_files
889 # --------------------------
890 # Install copies of the libltdl files into this package.  Any auxiliary
891 # or m4 macro files needed in the libltdl tree will also be copied by
892 # func_install_pkgaux_files and func_install_pkgmacro_files resp.
893 func_install_pkgltdl_files ()
894 {
895     $debug_cmd
896
897     $opt_ltdl || return
898
899     $require_ac_ltdl_dir
900     $require_ltdl_dir
901     $require_ltdl_mode
902
903     # Remove any lingering files that my have been installed by some
904     # previous libtoolize release:
905     $opt_force && for file in $all_pkgltdl_files; do
906       test -f "$ltdl_dir/$file" && func_verbose "rm -f '$ltdl_dir/$file'"
907       rm -f "$ltdl_dir/$file"
908     done
909
910     # Copy all the files from installed libltdl to this project, if the
911     # user specified '--ltdl'.
912     $opt_quiet || if test -n "$ac_ltdl_dir"; then
913       pkgltdl_header="putting libltdl files in LT_CONFIG_LTDL_DIR, '$ac_ltdl_dir'."
914     else
915       pkgltdl_header="putting libltdl files in '$ltdl_dir'."
916     fi
917
918     $require_filter_Makefile_am
919     $require_filter_ltdl_mk
920
921     # Copy ltdl sources appropriate to the requested ltdl_mode.
922     for file in $pkgltdl_files; do
923       my_copy_filter=
924       case $file in
925         Makefile.am|Makefile.in)
926           test nonrecursive = "$ltdl_mode" && continue
927           my_copy_filter=$filter_Makefile_am
928           ;;
929
930         ltdl.mk)
931           test nonrecursive = "$ltdl_mode" || continue
932           my_copy_filter=$filter_ltdl_mk
933           ;;
934
935         aclocal.m4)
936           test subproject = "$ltdl_mode" && {
937             $require_filter_aclocal_m4
938
939             # Always copy aclocal.m4, otherwise regenerating it can
940             # overwrite the destination if it is symlinked.
941             ( opt_copy=:
942               func_copy "$file" "$pkgltdldir" "$ltdl_dir" \
943                 pkgltdl_header "$filter_aclocal_m4"
944             )
945           }
946           continue
947           ;;
948
949         config-h.in)
950           test subproject = "$ltdl_mode" || continue
951           ;;
952
953         configure)
954           test subproject = "$ltdl_mode" && {
955             $require_filter_configure_ac
956
957             # Always copy configure, otherwise regenerating it can
958             # overwrite the destination if it is symlinked.
959             ( opt_copy=:
960               func_copy "$file" "$pkgltdldir" "$ltdl_dir" \
961                 pkgltdl_header "$filter_configure_ac"
962             )
963           }
964           continue
965           ;;
966
967         configure.ac)
968           test subproject = "$ltdl_mode" || continue
969           $require_filter_configure_ac
970           my_copy_filter=$filter_configure_ac
971           ;;
972       esac
973
974       # Still here?  Copy the file then, with selected filters.
975       func_copy "$file" "$pkgltdldir" "$ltdl_dir" \
976         pkgltdl_header "$my_copy_filter"
977
978       # FIXME: Remove in 2013
979       #        (along with deprecation warning in func_check_macros)
980       test ltdl.mk = "$file" \
981         && func_grep "^-\?include $ltdl_dir/Makefile.inc\$" Makefile.am \
982         && mv "$ltdl_dir/$file" "$ltdl_dir/Makefile.inc" \
983         && func_notquiet "renaming file '$ltdl_dir/Makefile.inc'"
984     done
985 }
986
987
988 # func_install_pkgaux_files
989 # -------------------------
990 # Install copies of the auxiliary files into this package according to
991 # the whether libltdl is included as a subproject, and whether the parent
992 # shares the AC_CONFIG_AUX_DIR setting.
993 func_install_pkgaux_files ()
994 {
995     $debug_cmd
996
997     $require_ac_aux_dir
998     $require_aux_dir
999     $require_configure_ac
1000     $require_ltdl_mode
1001
1002     # Remove any lingering files that my have been installed by some
1003     # previous libtoolize release:
1004     $opt_force && for file in $all_pkgaux_files; do
1005       test -f "$aux_dir/$file" && func_verbose "rm -f '$aux_dir/$file'"
1006       rm -f "$aux_dir/$file"
1007     done
1008
1009     if test -n "$ac_aux_dir"; then
1010       pkgaux_header="putting auxiliary files in AC_CONFIG_AUX_DIR, '$ac_aux_dir'."
1011     else
1012       pkgaux_header="putting auxiliary files in '$aux_dir'."
1013     fi
1014
1015     for file in $pkgaux_files; do
1016       case $file in
1017         config.guess|config.sub)
1018           $opt_install || test subproject = "$ltdl_mode" || continue
1019           func_config_update "$file" "$pkgauxdir" "$aux_dir" pkgaux_header
1020           ;;
1021         install-sh)
1022           $opt_install || test subproject = "$ltdl_mode" || continue
1023           func_install_update "$file" "$pkgauxdir" "$aux_dir" pkgaux_header
1024           ;;
1025         ltmain.sh)
1026           func_ltmain_update "$file" "$pkgauxdir" "$aux_dir" pkgaux_header
1027           ;;
1028         *)
1029           test subproject = "$ltdl_mode" || continue
1030           func_copy "$file" "$pkgauxdir" "$aux_dir" pkgaux_header
1031           ;;
1032       esac
1033     done
1034
1035     # If the parent project is using Autoconf and linking with Libtool,
1036     # even if subproject libltdl already has a copy, the parent project
1037     # will still need to build libtool for its own purposes, and might
1038     # need another copy of ltmain.sh if the parent didn't declare an
1039     # AC_CONFIG_AUX_DIR.
1040     pkgaux_hdr="putting another copy of auxiliary files in '.'"
1041     test -f "$configure_ac" \
1042       && test -z "$ac_aux_dir" \
1043       && test subproject = "$ltdl_mode" \
1044       && test "$aux_dir" = "$ltdl_dir" \
1045       && func_ltmain_update "$file" "$pkgauxdir" . pkgaux_hdr
1046
1047     # FIXME: Remove in 2013.
1048     # Very old parent projects using 'libtoolize --install --ltdl', and
1049     # a top-level $configure_ac to build the ltdl subproject, but not
1050     # using Automake themselves, might still be relying on the old
1051     # behaviour of libtoolize to put a second copy of some 'Auxiliary
1052     # Programs' needed by the top-level configure (instead of using
1053     # the recommended method: 'automake --add-missing').
1054     test -f "$configure_ac" \
1055       && test subproject = "$ltdl_mode" \
1056       && test "$aux_dir" = "$ltdl_dir" \
1057       && func_config_update config.guess "$pkgauxdir" . pkgaux_hdr \
1058       && func_config_update config.sub "$pkgauxdir" . pkgaux_hdr \
1059       && func_install_update install-sh "$pkgauxdir" . pkgaux_hdr
1060 }
1061
1062
1063 # func_nonemptydir_p DIRVAR
1064 # -------------------------
1065 # DIRVAR is the name of a variable to evaluate.  Unless DIRVAR names
1066 # a directory that exists and is non-empty abort with a diagnostic.
1067 func_nonemptydir_p ()
1068 {
1069     $debug_cmd
1070
1071     my_dirvar=$1
1072     my_dir=`eval echo "\\\$$my_dirvar"`
1073
1074     # Is it a directory at all?
1075     test -d "$my_dir" \
1076       || func_fatal_error "\$$my_dirvar is not a directory: '$my_dir'"
1077
1078     # check that the directories contents can be ls'ed
1079     test -n "`{ cd $my_dir && ls; } 2>/dev/null`" \
1080         || func_fatal_error "cannot list files: '$my_dir'"
1081 }
1082
1083
1084 # func_check_macros
1085 # -----------------
1086 # Sanity check macros from aclocal.m4 against installed versions.
1087 func_check_macros ()
1088 {
1089     $debug_cmd
1090
1091     $require_ac_ltdl_dir
1092     $require_ac_macro_dir
1093     $require_am_macro_dir
1094     $require_aux_dir
1095     $require_configure_ac
1096     $require_ltdl_dir
1097     $require_ltdl_mode
1098     $require_macro_dir
1099     $require_seen_ltdl
1100     $require_seen_libtool
1101
1102     $opt_quiet && return
1103     test -n "$configure_ac" || return
1104
1105     ac_config_macro_dir_advised=false
1106
1107     if test -z "$ac_macro_dir$am_macro_dir"; then
1108       my_missing=
1109       for file in $pkgmacro_files; do
1110         case $file in
1111           ltargz.m4|ltdl.m4) $opt_ltdl || continue ;;
1112         esac
1113         if test -f "aclocal.m4"; then
1114           func_aclocal_update_check $file
1115           $func_aclocal_update_check_result || continue
1116         fi
1117         my_missing="$my_missing $file"
1118       done
1119
1120       if test -n "$my_missing"; then
1121         func_echo "You should add the contents of the following files to 'aclocal.m4':"
1122         for need in $my_missing; do
1123           func_echo "  '$aclocaldir/$need'"
1124         done
1125       fi
1126     fi
1127
1128     ## ---------------------------------------------------------- ##
1129     ## Since we return early here when --no-warn was given:       ##
1130     ## DO NOT PUT ANYTHING BUT UPGRADE ADVICE MESSAGES BELOW HERE ##
1131     ## ---------------------------------------------------------- ##
1132
1133     test " none" = "$opt_warning_types" && return
1134
1135     $seen_libtool ||
1136       func_echo "Remember to add 'LT_INIT' to $configure_ac."
1137
1138     # Suggest using LTDL_INIT if appropriate:
1139     $opt_ltdl && if test : != "$seen_ltdl"; then
1140       case $ltdl_mode in
1141         subproject) ltdl_init_args=                 ;;
1142         *)          ltdl_init_args="([$ltdl_mode])" ;;
1143       esac
1144       func_echo "Remember to add 'LTDL_INIT$ltdl_init_args' to $configure_ac."
1145     fi
1146
1147     if $opt_ltdl; then
1148       # Remind the user to call LT_CONFIG_LTDL_DIR:
1149       test -n "$ac_ltdl_dir" ||
1150         func_echo "Remember to add 'LT_CONFIG_LTDL_DIR([$ltdl_dir])' to '$configure_ac'."
1151
1152       # For nonrecursive mode, warn about continued use of Makefile.inc:
1153       # FIXME: Remove in 2013
1154       #        (along with last minute rename in func_install_pkgltdl_files)
1155       if test nonrecursive = "$ltdl_mode"; then
1156         if func_grep "^-\?include $ltdl_dir/Makefile.inc\$" Makefile.am;
1157         then
1158           func_error "Use of 'include $ltdl_dir/Makefile.inc' is deprecated!"
1159           func_echo "Consider updating to use of 'include $ltdl_dir/ltdl.mk' in Makefile.am."
1160         fi
1161       fi
1162     fi
1163
1164     # Suggest modern idioms for storing autoconf macros:
1165     $ac_config_macro_dir_advised || if test -z "$macro_dir" || test . = "$macro_dir"; then
1166       func_echo "Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to $configure_ac and"
1167       func_echo "rerunning $progname, to keep the correct libtool macros in-tree."
1168       ac_config_macro_dir_advised=:
1169
1170     elif test -z "$ac_macro_dir"; then
1171       func_echo "Consider adding 'AC_CONFIG_MACRO_DIRS([$macro_dir])' to $configure_ac,"
1172       func_echo "and rerunning $progname and aclocal."
1173       ac_config_macro_dir_advised=:
1174     fi
1175
1176     if test -z "$am_macro_dir$ac_macro_dir"; then
1177       func_echo "Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am."
1178
1179     elif test -z "$am_macro_dir"; then
1180       func_echo "Consider adding '-I $macro_dir' to ACLOCAL_AMFLAGS in Makefile.am."
1181     fi
1182
1183     # Don't trace for this, we're just checking the user didn't invoke it
1184     # directly from configure.ac.
1185     $SED 's|dnl .*$||; s|# .*$||' "$configure_ac" | $GREP AC_PROG_RANLIB >/dev/null &&
1186       func_echo "'AC_PROG_RANLIB' is rendered obsolete by 'LT_INIT'"
1187
1188     # FIXME: Ensure ltmain.sh, libtool.m4 and ltdl.m4 are from the same release
1189 }
1190
1191
1192
1193 ## ------------------##
1194 ## Helper functions. ##
1195 ## ------------------##
1196
1197 # This section contains the helper functions used by the rest of
1198 # this script.
1199
1200
1201 # func_autoconf_configure MAYBE-CONFIGURE-FILE
1202 # --------------------------------------------
1203 # Ensure that MAYBE-CONFIGURE-FILE is the name of a file in the current
1204 # directory that contains an uncommented call to AC_INIT.
1205 func_autoconf_configure ()
1206 {
1207     $debug_cmd
1208
1209     _G_sed_no_comment='s|#.*$||; s|^dnl .*$||; s| dnl .*$||;'
1210     _G_ac_init=
1211
1212     # If we were passed a genuine file, make sure it calls AC_INIT.
1213     test -f "$1" \
1214       && _G_ac_init=`$SED "$_G_sed_no_comment" "$1" |$GREP AC_INIT`
1215
1216     # Otherwise it is not a genuine Autoconf input file.
1217     test -n "$_G_ac_init"
1218     _G_status=$?
1219
1220     test 0 -ne "$_G_status" \
1221       && func_verbose "'$1' not using Autoconf"
1222
1223     (exit $_G_status)
1224 }
1225
1226
1227 # func_make_relative_dir_filter CURRDIR SRCDIR DESTDIR [PREFIX [SUFFIX]]
1228 # ----------------------------------------------------------------------
1229 # Make a sed script suitable for appending to a copy filter, which will
1230 # replace occurrences of CURRDIR with the relative path from SRCDIR to
1231 # DESTDIR if they are different, otherwise the result is the empty
1232 # string:
1233 #
1234 #    func_make_relative_dir_filter ltdl config ../build-aux
1235 #      => 's|\.\./build-aux|../config|g'
1236 #    func_make_relative_dir_filter ltdl ltdl/m4 ../m4
1237 #      => 's|\.\./m4|m4|g'
1238 #    func_make_relative_dir_filter libltdl build-aux ../build-aux
1239 #      => ''
1240 #
1241 # If PREFIX (and SUFFIX) are passed they are prepended (and appended)
1242 # to the match and replacement expressions literally:
1243 #
1244 #    func_make_relative_dir_filter ltdl ltdl/m4 ../m4 '-I ' ' '
1245 #      => 's|-I \.\./m4 |-I m4 |g'
1246 func_make_relative_dir_filter ()
1247 {
1248     $debug_cmd
1249
1250     my_currdir=$1
1251     my_srcdir=$2
1252     my_destdir=$3
1253
1254     func_relative_path "$my_srcdir" "$my_destdir"
1255
1256     if test "$my_currdir" = "$func_relative_path_result"; then
1257       func_make_relative_dir_filter_result=
1258     else
1259       my_match_currdir=`$ECHO "$my_currdir" |$SED "$sed_make_literal_regex"`
1260
1261       # Avoid substituting with 'dir/./file' when current dir is '.'.
1262       if test . = "$my_currdir"; then
1263         func_make_relative_dir_filter_result="
1264           s|$4$my_match_currdir/$5|$4$5|g"
1265       else
1266         func_make_relative_dir_filter_result="
1267           s|$4$my_match_currdir$5|$4$func_relative_path_result$5|g"
1268       fi
1269     fi
1270 }
1271
1272 # func_make_relative_ltdl_filter CURRDIR DESTDIR [PREFIX [SUFFIX]]
1273 # ----------------------------------------------------------------
1274 # As 'func_make_relative_dir_filter' optimised for the common case where
1275 # SRCDIR is '$ltdl_dir'.
1276 func_make_relative_ltdl_filter ()
1277 {
1278     $debug_cmd
1279
1280     $require_ltdl_dir
1281
1282     func_make_relative_dir_filter "$1" "$ltdl_dir" "$2" "$3" "$4"
1283     func_make_relative_ltdl_filter_result=$func_make_relative_dir_filter_result
1284 }
1285
1286
1287 ## -------------------- ##
1288 ## Resource management. ##
1289 ## -------------------- ##
1290
1291 # This section contains definitions for functions that each ensure a
1292 # particular resource (a file, or a non-empty configuration variable for
1293 # example) is available, and if appropriate to extract default values
1294 # from pertinent package files.  Where a variable already has a non-
1295 # empty value (as set by the package's 'bootstrap.conf'), that value is
1296 # used in preference to deriving the default. Call them using their
1297 # associated 'require_*' variable to ensure that they are executed, at
1298 # most, once.
1299 #
1300 # Some of the require functions are very similar, so we generate those
1301 # as this file is sourced. They look complicated, but they are the same
1302 # as normal function declarations wrapped in "eval '<definition>'", so
1303 # that embedded single quotes need to be escaped, and wherever a symbol
1304 # is generated, we drop out of the single quotes and expand a variable
1305 # that holds the symbol.
1306 #
1307 # After that, the rest appear in asciibetical order.
1308
1309 for base in '' ltdl_; do
1310   if test ltdl_ = "$base"; then p='$pkgltdldir/'; else p=; fi
1311
1312   # require_Makefile_am
1313   # require_ltdl_Makefile_am
1314   # ------------------------
1315   # If not already set, set Makefile_am to 'Makefile.am' if that file is
1316   # present in the current directory, and similarly for
1317   # '$pkgltdldir/Makefile.am'.
1318   r=${base}Makefile_am
1319   v=require_$r
1320   f=func_$v
1321   eval $v'='$f'
1322   '$f' ()
1323   {
1324     $debug_cmd
1325
1326     test -n "$'$r'" || '$r'='$p'Makefile.am
1327
1328     if test -f "$'$r'"; then
1329       func_verbose "found '\'\$$r\''"
1330     else
1331       '$r'=
1332     fi
1333
1334     '$v'=:
1335   }'
1336   o=$r
1337
1338
1339   # require_aclocal_amflags
1340   # require_ltdl_aclocal_amflags
1341   # ----------------------------
1342   # Extract '$aclocal_amflags' from 'Makefile.am' if present, and
1343   # similarly for 'libltdl/Makefile.am'.
1344   r=${base}aclocal_amflags
1345   v=require_$r
1346   f=func_$v
1347   eval $v'='$f'
1348   '$f' ()
1349   {
1350     $debug_cmd
1351
1352     $require_'$o'
1353
1354     test -n "$'$o'" && {
1355       _G_sed_extract_aclocal_amflags='\''s|#.*$||
1356         /^[      ]*ACLOCAL_AMFLAGS[      ]*=/ {
1357             s|^.*=[      ]*\(.*\)|'$r'="\1"|
1358             p
1359         }'\''
1360
1361       _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
1362           "$'$o'"`
1363       eval "$_G_aclocal_flags_cmd"
1364
1365       test -n "$'$r'" && func_verbose "'$r'='\$$r\''"
1366     }
1367
1368     '$v'=:
1369   }'
1370   o=$r
1371
1372
1373   # require_am_macro_dir
1374   # require_ltdl_am_macro_dir
1375   # -------------------------
1376   # Set am_macro_dir to the first directory specified in
1377   # ACLOCAL_AMFLAGS from 'Makefile.am', and similarly for
1378   # 'libltdl/Makefile.am'.
1379   r=${base}am_macro_dir
1380   v=require_$r
1381   f=func_$v
1382   eval $v'='$f'
1383   '$f' ()
1384   {
1385     $debug_cmd
1386
1387     $require_'$o'
1388
1389     _G_minus_I_seen=false
1390     for _G_arg in $'$o'; do
1391       case $_G_minus_I_seen,$_G_arg in
1392         :,*)   '$r'=$_G_arg; break ;;
1393         *,-I)  _G_minus_I_seen=: ;;
1394         *,-I*) '$r'=`expr x$_G_arg : '\''x-I\(.*\)$'\''`; break ;;
1395       esac
1396     done
1397
1398     test -n "$'$r'" && func_verbose "'$r'='\'\$$r\''"
1399
1400     '$v'=:
1401   }'
1402   o=$r
1403
1404 done
1405
1406
1407 # require_ac_aux_dir
1408 # ------------------
1409 # Extract ac_aux_dir from AC_CONFIG_AUX_DIR.
1410 require_ac_aux_dir=func_require_ac_aux_dir
1411 func_require_ac_aux_dir ()
1412 {
1413     $debug_cmd
1414
1415     $require_configure_ac
1416
1417     test -n "$configure_ac" && {
1418       func_extract_trace_first AC_CONFIG_AUX_DIR
1419       ac_aux_dir=$func_extract_trace_first_result
1420
1421       case $ac_aux_dir in
1422         *\$*)
1423           func_fatal_error "\
1424 cannot expand unknown variable in AC_CONFIG_AUX_DIR argument."
1425           ;;
1426       esac
1427     }
1428
1429     test -n "$ac_aux_dir" && func_verbose "ac_aux_dir='$ac_aux_dir'"
1430
1431     require_ac_aux_dir=:
1432 }
1433
1434
1435 # require_ac_ltdl_dir
1436 # -------------------
1437 # Extract ac_ltdl_dir from LT_CONFIG_LTDL_DIR.
1438 require_ac_ltdl_dir=func_require_ac_ltdl_dir
1439 func_require_ac_ltdl_dir ()
1440 {
1441     $debug_cmd
1442
1443     $require_configure_ac
1444
1445     if test -n "$configure_ac"; then
1446       func_extract_trace_first LT_CONFIG_LTDL_DIR
1447       ac_ltdl_dir=$func_extract_trace_first_result
1448
1449       case $ac_ltdl_dir in
1450         *\$*)
1451           func_fatal_error "\
1452 cannot expand unknown variable in LT_CONFIG_LTDL_DIR argument."
1453           ;;
1454       esac
1455     fi
1456
1457     # Strip trailing slashes.
1458     ac_ltdl_dir=`echo "$ac_ltdl_dir" |$SED 's|/*$||'`
1459
1460     require_ac_ltdl_dir=:
1461 }
1462
1463
1464 # require_ac_ltdl_mode
1465 # --------------------
1466 # Extract mode name from LTDL_INIT options.
1467 require_ac_ltdl_mode=func_require_ac_ltdl_mode
1468 func_require_ac_ltdl_mode ()
1469 {
1470     $debug_cmd
1471
1472     $require_ac_ltdl_options
1473
1474     case " $ac_ltdl_options " in
1475       *" nonrecursive "*) ac_ltdl_mode=nonrecursive ;;
1476       *" recursive "*)    ac_ltdl_mode=recursive    ;;
1477       *" subproject "*)   ac_ltdl_mode=subproject   ;;
1478     esac
1479
1480     require_ac_ltdl_mode=:
1481 }
1482
1483
1484 # require_ac_ltdl_options
1485 # -----------------------
1486 # Extract ac_ltdl_options from LTDL_INIT.
1487 require_ac_ltdl_options=func_require_ac_ltdl_options
1488 func_require_ac_ltdl_options ()
1489 {
1490     $debug_cmd
1491
1492     $require_configure_ac
1493
1494     if test -n "$configure_ac"; then
1495       func_extract_trace_first LTDL_INIT
1496       ac_ltdl_options=$func_extract_trace_first_result
1497
1498       case $ac_ltdl_options in
1499         *\$*)
1500           func_fatal_error "\
1501 cannot expand unknown variable in LTDL_INIT argument."
1502           ;;
1503       esac
1504     fi
1505
1506     require_ac_ltdl_mode=:
1507 }
1508
1509
1510 # require_ac_macro_dir
1511 # --------------------
1512 # Extract ac_macro_dir from AC_CONFIG_MACRO_DIRS.
1513 require_ac_macro_dir=func_require_ac_macro_dir
1514 func_require_ac_macro_dir ()
1515 {
1516     $debug_cmd
1517
1518     $require_configure_ac
1519
1520     if test -n "$configure_ac"; then
1521       func_extract_trace_first AC_CONFIG_MACRO_DIRS
1522       ac_macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^    ]*\)'`
1523
1524       test -n "$ac_macro_dir" || {
1525         func_extract_trace_first AC_CONFIG_MACRO_DIR
1526         ac_macro_dir=$func_extract_trace_first_result
1527       }
1528     fi
1529
1530     require_ac_macro_dir=:
1531 }
1532
1533
1534 # require_aux_dir
1535 # ---------------
1536 # Set aux_dir according to AC_CONFIG_AUX_DIR or else use the same
1537 # heuristics as Autoconf to intuit an appropriate setting.
1538 require_aux_dir=func_require_aux_dir
1539 func_require_aux_dir ()
1540 {
1541     $debug_cmd
1542
1543     $require_ac_aux_dir
1544
1545     test -z "$aux_dir" && aux_dir=$ac_aux_dir
1546
1547     # Subproject ltdl without $configure_ac keeps pkgauxfiles in
1548     # specified --ltdl optarg directory.
1549     test -z "$aux_dir" && $opt_ltdl && {
1550       $require_configure_ac
1551
1552       test -n "$configure_ac" || {
1553         $require_ltdl_dir
1554         $require_ltdl_mode
1555
1556         test subproject = "$ltdl_mode" && aux_dir=$ltdl_dir
1557       }
1558     }
1559
1560     test -z "$aux_dir" && {
1561       # Try to intuit aux_dir using the same heuristic as Autoconf.
1562       for _G_dir in . .. ../..; do
1563         if test -f "$_G_dir/install-sh" || test -f "$_G_dir/install.sh"
1564         then
1565           aux_dir=$_G_dir
1566           break
1567         fi
1568       done
1569     }
1570
1571     # Use the current directory if all else fails.
1572     test -z "$aux_dir" && aux_dir=.
1573
1574     require_aux_dir=:
1575 }
1576
1577
1578 # require_configure_ac
1579 # --------------------
1580 # Ensure that there is a 'configure.ac' or 'configure.in' file in this
1581 # directory, and that '$configure_ac' contains its name.
1582 require_configure_ac=func_require_configure_ac
1583 func_require_configure_ac ()
1584 {
1585     $debug_cmd
1586
1587     test -z "$configure_ac" \
1588       && func_autoconf_configure configure.ac && configure_ac=configure.ac
1589     test -z "$configure_ac" \
1590       && func_autoconf_configure configure.in && configure_ac=configure.in
1591     test -z "$configure_ac" \
1592       || func_verbose "found '$configure_ac'"
1593
1594     require_configure_ac=:
1595 }
1596
1597
1598 # require_filter_Makefile_am
1599 # --------------------------
1600 # Set 'filter_Makefile_am' ready for passing to func_copy when libltdl's
1601 # stock Makefile.am contents need to be filtered to work in recursive
1602 # mode.
1603 require_filter_Makefile_am=func_require_filter_Makefile_am
1604 func_require_filter_Makefile_am ()
1605 {
1606     $debug_cmd
1607
1608     $require_ltdl_mode
1609
1610     case $ltdl_mode in
1611       recursive)
1612         filter_Makefile_am='
1613             /^[^#]/{
1614               s|(LIBOBJS)|(ltdl_LIBOBJS)|g
1615               s|(LTLIBOBJS)|(ltdl_LTLIBOBJS)|g
1616             }'
1617         ;;
1618
1619       subproject)
1620         # Adjust default relative macro_dir paths.
1621         $require_ltdl_am_macro_dir
1622
1623         func_make_relative_ltdl_filter "$ltdl_am_macro_dir" "$macro_dir" '-I '
1624         test -z "$func_make_relative_ltdl_filter_result" || {
1625           func_append filter_Makefile_am "
1626               /^ACLOCAL_AMFLAGS = /{
1627                 $func_make_relative_ltdl_filter_result
1628               }"
1629         }
1630         func_make_relative_ltdl_filter "$ltdl_am_macro_dir" "$macro_dir" 'dir)'
1631         func_append filter_Makefile_am "$func_make_relative_ltdl_filter_result"
1632
1633         # Adjust default relative aux_dir paths.
1634         $require_ltdl_ac_aux_dir
1635         func_make_relative_ltdl_filter "$ltdl_ac_aux_dir" "$aux_dir"
1636         func_append filter_Makefile_am "$func_make_relative_ltdl_filter_result"
1637         ;;
1638     esac
1639
1640     require_filter_Makefile_am=:
1641 }
1642
1643
1644 # require_filter_aclocal_m4
1645 # -------------------------
1646 # Set 'filter_aclocal_m4' ready for passing to func_copy when libltdl's
1647 # stock aclocal.m4 contents need to be filtered to work in recursive
1648 # mode.
1649 require_filter_aclocal_m4=func_require_filter_aclocal_m4
1650 func_require_filter_aclocal_m4 ()
1651 {
1652     $debug_cmd
1653
1654     $require_ltdl_am_macro_dir
1655
1656     func_make_relative_ltdl_filter "$ltdl_am_macro_dir" "$macro_dir"
1657
1658     test -z "$func_make_relative_ltdl_filter_result" || {
1659       func_append filter_aclocal_m4 "
1660           /^[m]4_include(/{
1661             $func_make_relative_ltdl_filter_result
1662           }"
1663     }
1664
1665     require_filter_aclocal_m4=:
1666 }
1667
1668
1669 # require_filter_configure_ac
1670 # ---------------------------
1671 # Set 'filter_configure_ac' ready for passing to func_copy when
1672 # libltdl's stock configure.ac contents need to be filtered to work in
1673 # subproject mode.
1674 require_filter_configure_ac=func_require_filter_configure_ac
1675 func_require_filter_configure_ac ()
1676 {
1677     $debug_cmd
1678
1679     $require_ltdl_ac_aux_dir
1680
1681     func_make_relative_ltdl_filter "$ltdl_ac_aux_dir" "$aux_dir"
1682     func_append filter_configure_ac "$func_make_relative_ltdl_filter_result"
1683
1684     require_filter_configure_ac=:
1685 }
1686
1687
1688 # require_filter_ltdl_mk
1689 # ----------------------
1690 # Set 'filter_ltdl_mk' ready for passing to func_copy in order for the
1691 # contents of ltdl.mk to match the nonrecursive libltdl directory into
1692 # which it is copied.
1693 require_filter_ltdl_mk=func_require_filter_ltdl_mk
1694 func_require_filter_ltdl_mk ()
1695 {
1696     $debug_cmd
1697
1698     $require_ltdl_dir
1699
1700     # Note that we strip comments right here, rather than rely on
1701     # using a $SED that allows comments.
1702     my_uscore=`$ECHO "$ltdl_dir" | $SED 's|[/.+-]|_|g'`
1703     filter_ltdl_mk=`$ECHO '
1704       /^[^#]/{
1705
1706         # Use only libltdl conditional objects.
1707         s|(LIBOBJS)|(ltdl_LIBOBJS)|g
1708         s|(LTLIBOBJS)|(ltdl_LTLIBOBJS)|g
1709
1710         # Convert libltdl path and variable sections to $ltdl_dir.
1711         s|libltdl_|@my_uscore@_|
1712         s|libltdl/|@ltdl_dir@/|
1713         s|: libltdl/|: @ltdl_dir@/|
1714         s| -Ilibltdl | -I@ltdl_dir@ |
1715         s|\$(libltdl_|\$(@my_uscore@_|
1716         s|)/libltdl |)/@ltdl_dir@ |
1717         s|@my_uscore@|'"$my_uscore"'|g
1718         s|@ltdl_dir@|'"$ltdl_dir"'|g
1719
1720       }' | $SED '/^[     ]*#/d;/^$/d'`
1721
1722     require_filter_ltdl_mk=:
1723 }
1724
1725
1726 # require_ltdl_ac_aux_dir
1727 # -----------------------
1728 # This needs to work in subproject mode, when GNU M4 may not be
1729 # available and hence extract-trace can't be used.  But since we
1730 # installed libltdl/configure.ac, then we already know what value
1731 # we used.
1732 require_ltdl_ac_aux_dir=func_require_ltdl_ac_aux_dir
1733 func_require_ltdl_ac_aux_dir ()
1734 {
1735     $debug_cmd
1736
1737     ltdl_ac_aux_dir="@ltdl_ac_aux_dir@"
1738     func_verbose "ltdl_ac_aux_dir='$ltdl_ac_aux_dir'"
1739
1740     require_ltdl_ac_aux_dir=:
1741 }
1742
1743
1744 # require_ltdl_dir
1745 # ----------------
1746 # If both are specified, ensure both --ltdl=LTDL_DIR and
1747 # LT_CONFIG_LTDL_DIR agree, and set ltdl_dir to the value of either.
1748 require_ltdl_dir=func_require_ltdl_dir
1749 func_require_ltdl_dir ()
1750 {
1751     $debug_cmd
1752
1753     $require_ac_ltdl_dir
1754
1755     test -z "$ltdl_dir" && ltdl_dir=$ac_ltdl_dir
1756     test -z "$ltdl_dir" && $opt_ltdl && ltdl_dir=libltdl
1757
1758     if test -n "$ac_ltdl_dir"; then
1759       test "$ac_ltdl_dir" = "$ltdl_dir" || func_fatal_error "\
1760 --ltdl='$ltdl_dir' does not match LT_CONFIG_LTDL_DIR($ac_ltdl_dir)"
1761     fi
1762
1763     require_ltdl_dir=:
1764 }
1765
1766
1767 # require_ltdl_mode
1768 # -----------------
1769 # If both are specified, ensure both command line setting and LTDL_INIT
1770 # option agree, and set ltdl_mode to the value of either.
1771 require_ltdl_mode=func_require_ltdl_mode
1772 func_require_ltdl_mode ()
1773 {
1774     $debug_cmd
1775
1776     $require_ac_ltdl_mode
1777
1778     test -z "$ltdl_mode" && ltdl_mode=$ac_ltdl_mode
1779     test -z "$ltdl_mode" && {
1780       $require_ltdl_dir
1781
1782       test -n "$ltdl_dir" && ltdl_mode=subproject
1783     }
1784
1785     if test -n "$ac_ltdl_mode"; then
1786       test "$ac_ltdl_mode" = "$ltdl_mode" || func_fatal_error "\
1787 --$ltdl_mode does not match LTDL_INIT($ac_ltdl_mode)"
1788     fi
1789
1790     func_verbose "ltdl mode='$ltdl_mode'"
1791
1792     require_ltdl_mode=:
1793 }
1794
1795
1796 # require_macro_dir
1797 # -----------------
1798 # If both are specified, ensure both ACLOCAL_AMFLAGS and
1799 # AC_CONFIG_MACRO_DIRS agree, and set macro_dir to the value of either.
1800 require_macro_dir=func_require_macro_dir
1801 func_require_macro_dir ()
1802 {
1803     $debug_cmd
1804
1805     $require_ac_macro_dir
1806     $require_am_macro_dir
1807
1808     # AC_CONFIG_MACRO_DIRS takes precedence.
1809     macro_dir=$ac_macro_dir
1810
1811     # Followed by first -I optarg from ACLOCAL_AMFLAGS.
1812     test -z "$macro_dir" && macro_dir=$am_macro_dir
1813
1814     # Subproject ltdl without either of the above keeps macros in
1815     # specified --ltdl optarg subdirectory.
1816     test -z "$macro_dir" && $opt_ltdl && {
1817       $require_ltdl_dir
1818       $require_ltdl_mode
1819
1820       test subproject = "$ltdl_mode" && macro_dir=$ltdl_dir/m4
1821     }
1822
1823     # Use ./m4 as the last resort.
1824     test -z "$macro_dir" && macro_dir=m4
1825
1826     # Diagnose conflicts.
1827     if test -n "$ac_macro_dir" && test -n "$am_macro_dir"; then
1828       test "$ac_macro_dir" = "$am_macro_dir" || func_fatal_error "\
1829 AC_CONFIG_MACRO_DIRS([$ac_macro_dir]) conflicts with ACLOCAL_AMFLAGS=-I $am_macro_dir."
1830     fi
1831
1832     require_macro_dir=:
1833 }
1834
1835
1836 # require_seen_ltdl
1837 # -----------------
1838 # Determine from contents of $configure_ac whether this project contains
1839 # libltdl.
1840 require_seen_ltdl=func_require_seen_ltdl
1841 func_require_seen_ltdl ()
1842 {
1843     $debug_cmd
1844
1845     $require_configure_ac
1846
1847     if test -n "$configure_ac"; then
1848       func_extract_trace AC_LIB_LTDL,AC_WITH_LTDL,LT_WITH_LTDL,LTDL_INIT
1849       test -n "$func_extract_trace_result" && seen_ltdl=:
1850     fi
1851     test -n "$seen_ltdl" || seen_ltdl=false
1852
1853     $seen_ltdl && func_verbose "found LTDL_INIT invocation"
1854
1855     require_seen_ltdl=:
1856 }
1857
1858
1859 # require_seen_libtool
1860 # --------------------
1861 # Determine from contents of $configure_ac whether this project is using
1862 # Libtool to compile (some of) its objects.
1863 require_seen_libtool=func_require_seen_libtool
1864 func_require_seen_libtool ()
1865 {
1866     $debug_cmd
1867
1868     $require_configure_ac
1869
1870     if test -n "$configure_ac"; then
1871       func_extract_trace AM_PROG_LIBTOOL,AC_PROG_LIBTOOL,LT_INIT
1872       test -n "$func_extract_trace_result" && seen_libtool=:
1873     fi
1874     test -n "$seen_libtool" || seen_libtool=false
1875
1876     $seen_libtool && func_verbose "found LT_INIT invocation"
1877
1878     require_seen_libtool=:
1879 }
1880
1881
1882
1883 ## ----------- ##
1884 ##    Main.    ##
1885 ## ----------- ##
1886
1887 {
1888   # Lists of all files libtoolize has ever installed.  These are removed
1889   # before installing the latest files when --force was passed to help
1890   # ensure a clean upgrade.
1891   # Do not remove config.guess, config.sub or install-sh, we don't
1892   # install them without --install, and the project may not be using
1893   # Automake.  Similarly, do not remove Gnulib files.
1894   all_pkgaux_files="compile depcomp missing ltmain.sh"
1895   all_pkgmacro_files="libtool.m4 ltargz.m4 ltdl.m4 ltoptions.m4 ltsugar.m4 ltversion.in ltversion.m4 lt~obsolete.m4"
1896   all_pkgltdl_files="COPYING.LIB Makefile Makefile.in Makefile.inc Makefile.am README acinclude.m4 aclocal.m4 argz_.h argz.c config.h.in config-h.in configure configure.ac configure.in libltdl/lt__alloc.h libltdl/lt__argz.h libltdl/lt__dirent.h libltdl/lt__glibc.h libltdl/lt__private.h libltdl/lt__strl.h libltdl/lt_dlloader.h libltdl/lt_error.h libltdl/lt_system.h libltdl/slist.h loaders/dld_link.c loaders/dlopen.c loaders/dyld.c loaders/load_add_on.c loaders/loadlibrary.c loaders/preopen.c loaders/shl_load.c lt__alloc.c lt__argz.c lt__dirent.c lt__strl.c lt_dlloader.c lt_error.c ltdl.c ltdl.h ltdl.mk slist.c"
1897
1898   # Files installed by func_install_*, some files are missing from these
1899   # lists deliberately because their respective func_install has to handle
1900   # the missing filenames specially.
1901   pkgaux_files="@pkgaux_files@"
1902   pkgltdl_files="@pkgltdl_files@"
1903   pkgmacro_files="@pkgmacro_files@"
1904
1905   # Locations for important files:
1906   prefix="@prefix@"
1907   datadir="@datadir@"
1908   pkgauxdir="@pkgauxdir@"
1909   pkgltdldir="@pkgdatadir@"
1910   aclocaldir="@aclocaldir@"
1911
1912   # Allow the user to override the master libtoolize repository:
1913   if test -n "$_lt_pkgdatadir"; then
1914     pkgauxdir=$_lt_pkgdatadir/build-aux
1915     pkgltdldir=$_lt_pkgdatadir/libltdl
1916     aclocaldir=$_lt_pkgdatadir/m4
1917   fi
1918   func_nonemptydir_p pkgauxdir
1919   func_nonemptydir_p pkgltdldir
1920   func_nonemptydir_p aclocaldir
1921
1922   extract_trace=$pkgauxdir/extract-trace
1923
1924   # :::BE CAREFUL HERE:::
1925   # func_check_macros needs to check whether --ltdl was specified when
1926   # LTDL_INIT was not seen, so we can't just use one variable for both
1927   # conditions, or that check will be impossible.   No need to clutter the
1928   # rest of the code with '$opt_ltdl || $seen_ltdl' though, because we CAN
1929   # safely set opt_ltdl to true if LTDL_INIT was seen:
1930   $require_seen_ltdl
1931   $seen_ltdl && opt_ltdl=:
1932
1933   func_install_pkgaux_files
1934   func_install_pkgmacro_files
1935   func_install_pkgltdl_files
1936
1937   func_check_macros
1938 }
1939
1940 exit $exit_status
1941
1942 # Local Variables:
1943 # mode:shell-script
1944 # sh-indentation:2
1945 # End: