3 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
25 cvsdatestamp='$Date: 2003-01-01 14:51:23 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 AUTOCONF="${AUTOCONFPATH}autoconf"
39 AUTOHEADER="${AUTOCONFPATH}autoheader"
40 AUTOMAKE="${AUTOCONFPATH}automake-1.7"
44 # outputs to stdout the --help usage message.
48 Usage: gnulib-tool --list
49 gnulib-tool --import module1 ... moduleN
50 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
51 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
52 gnulib-tool --test --dir=directory module1 ... moduleN
53 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
54 gnulib-tool --extract-description module
55 gnulib-tool --extract-filelist module
56 gnulib-tool --extract-dependencies module
57 gnulib-tool --extract-autoconf-snippet module
58 gnulib-tool --extract-automake-snippet module
59 gnulib-tool --extract-include-directive module
62 --list print the available module names
63 --import import the given modules into the current package
64 --create-testdir create a scratch package with the given modules
65 --create-megatestdir create a mega scratch package with the given modules
66 one by one and all together
67 --test test the combination of the given modules
68 (recommended to use CC="gcc -Wall -Werror" here)
69 --megatest test the given modules one by one and all together
70 (recommended to use CC="gcc -Wall -Werror" here)
71 --extract-description extract the description
72 --extract-filelist extract the list of files
73 --extract-dependencies extract the dependencies
74 --extract-autoconf-snippet extract the snippet for configure.ac
75 --extract-automake-snippet extract the snippet for lib/Makefile.am
76 --extract-include-directive extract the #include directive
79 --dir=DIRECTORY specify the target directory
80 --lib=libRARY specify the library name
81 --no-changelog don't update or create ChangeLog files
83 Report bugs to <bug-gnulib@gnu.org>."
87 # outputs to stdout the --version message.
90 echo "$progname (GNU $package) $version"
91 echo "Copyright (C) 2002 Free Software Foundation, Inc.
92 This is free software; see the source for copying conditions. There is NO
93 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
94 echo "Written by" "Bruno Haible"
97 # func_fatal_error message
98 # outputs to stderr a fatal error message, and terminates the program.
101 echo "gnulib-tool: *** $1" 1>&2
102 echo "gnulib-tool: *** Stop." 1>&2
106 # Command-line option processing.
107 # Removes the OPTIONS from the arguments. Sets the variables:
108 # - mode list or import or create-testdir or create-megatestdir
109 # - destdir from --dir
110 # - libname from --lib
111 # - do_changelog false if --no-changelog was given, : otherwise
118 while test $# -gt 0; do
123 --import | --impor | --impo | --imp | --im | --i )
126 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
129 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
130 mode=create-megatestdir
132 --test | --tes | --te | --t )
135 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
139 mode=`echo "X$1" | sed -e 's/^X--//'`
144 func_fatal_error "missing argument for --dir"
149 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
154 func_fatal_error "missing argument for --lib"
159 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
161 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
164 --help | --hel | --he | --h )
167 --version | --versio | --versi | --vers | --ver | --ve | --v )
171 # Stop option prcessing
175 echo "gnulib-tool: unknown option $1" 1>&2
176 echo "Try 'gnulib-tool --help' for more information." 1>&2
185 /*) self_abspathname="$0" ;;
186 */*) self_abspathname=`pwd`/"$0" ;;
187 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
188 if test -x "$d/$0" && test ! -d "$d/$0"; then
189 self_abspathname="$d/$0"
193 if test -z "$self_abspathname"; then
194 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
198 while test -L "$self_abspathname"; do
199 # Resolve symbolic link.
200 sedexpr1='s, -> ,#%%#,'
201 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
202 linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
203 test -n "$linkval" || break
205 /* ) self_abspathname="$linkval" ;;
206 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
209 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
214 (cd "$gnulib_dir/modules" && ls -1) \
215 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^TEMPLATE$/d' \
220 # verifies a module name
221 func_verify_module ()
223 if test ! -f "$gnulib_dir/modules/$module" \
224 || test "CVS" = "$module" || test "ChangeLog" = "$module" || test "TEMPLATE" = "$module"; then
225 echo "gnulib-tool: module $1 doesn't exist" 1>&2
230 tags_regexp='\(Description\|Files\|Depends-on\|configure\.ac\|Makefile\.am\|Include\)'
231 sed_extract_prog=':[ ]*$/ {
234 s/^'"$tags_regexp"':[ ]*$//
241 # func_get_description module
242 func_get_description ()
244 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
247 # func_get_filelist module
250 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
252 echo m4/onceonly_2_57.m4
255 # func_get_dependencies module
256 func_get_dependencies ()
258 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
261 # func_get_autoconf_snippet module
262 func_get_autoconf_snippet ()
264 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
267 # func_get_automake_snippet module
268 func_get_automake_snippet ()
270 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
273 # func_get_include_directive module
274 func_get_include_directive ()
276 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
277 sed -e 's/^\(["<]\)/#include \1/'
280 # func_create_testdir testdir modules
281 func_create_testdir ()
285 modules=`for m in $modules; do echo $m; done | sort | uniq`
287 # Determine final module list.
290 for module in $modules; do
292 if test -n "$module"; then
293 xmodules="$xmodules $module "`func_get_dependencies $module`
296 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
297 if test "$xmodules" = "$modules"; then
302 echo "Module list with included dependencies:"
303 echo "$modules" | sed -e 's/^/ /'
305 # Determine final file list.
307 for module in $modules; do
309 if test -n "$module"; then
310 files="$files "`func_get_filelist $module`
313 files=`for f in $files; do echo $f; done | sort | uniq`
315 echo "$files" | sed -e 's/^/ /'
317 # Create directories.
318 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
319 mkdir -p "$testdir/$d"
324 ln "$gnulib_dir/$f" "$testdir/$f" 2>/dev/null ||
325 cp -p "$gnulib_dir/$f" "$testdir/$f"
328 # Create lib/Makefile.am.
329 mkdir -p "$testdir/lib"
330 (echo "## Process this file with automake to produce Makefile.in."
332 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
334 echo "noinst_LIBRARIES = $libname.a"
336 echo "$libname"'_a_SOURCES ='
337 echo "$libname"'_a_LIBADD = @LIBOBJS@'
338 echo '#'"$libname"'_la_LIBADD = @LTLIBOBJS@'
340 echo "BUILT_SOURCES ="
342 echo "MOSTLYCLEANFILES ="
344 echo "DISTCLEANFILES ="
345 echo "MAINTAINERCLEANFILES ="
346 for module in $modules; do
348 if test -n "$module"; then
349 func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,$libname"'_a_SOURCES,g'
350 if test "$module" = 'alloca'; then
351 echo "$libname"'_a_LIBADD += @ALLOCA@'
352 echo '#'"$libname"'_la_LIBADD += @LTALLOCA@'
356 ) > "$testdir/lib/Makefile.am"
358 # Create m4/Makefile.am.
359 mkdir -p "$testdir/m4"
360 (echo "## Process this file with automake to produce Makefile.in."
366 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
369 ) > "$testdir/m4/Makefile.am"
373 if test -f "$testdir"/m4/gettext.m4; then
374 # Avoid stupid error message from automake:
375 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
376 mkdir -p "$testdir/po"
377 (echo "## Process this file with automake to produce Makefile.in."
378 ) > "$testdir/po/Makefile.am"
379 subdirs="$subdirs po"
382 # Create Makefile.am.
383 (echo "## Process this file with automake to produce Makefile.in."
385 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
387 echo "SUBDIRS = $subdirs"
389 echo "ACLOCAL_AMFLAGS = -I m4"
390 ) > "$testdir/Makefile.am"
392 # Create configure.ac.
393 (echo "# Process this file with autoconf to produce a configure script."
394 echo "AC_INIT(dummy,0)"
395 echo "AM_INIT_AUTOMAKE"
397 echo "AM_CONFIG_HEADER(config.h)"
400 echo "AC_PROG_INSTALL"
401 echo "AC_PROG_MAKE_SET"
402 echo "AC_PROG_RANLIB"
404 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
408 for module in $modules; do
410 if test -n "$module"; then
411 func_get_autoconf_snippet "$module"
416 for d in $subdirs; do
417 makefiles="$makefiles $d/Makefile"
419 echo "AC_OUTPUT([$makefiles])"
420 ) > "$testdir/configure.ac"
422 # Create autogenerated files.
424 echo "executing ${ACLOCAL} -I m4"
426 echo "executing ${AUTOHEADER}"
428 echo "executing ${AUTOCONF}"
430 echo "executing ${AUTOMAKE} --add-missing --copy"
431 ${AUTOMAKE} --add-missing --copy
433 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
437 built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
438 if test -n "$built_sources"; then
447 # func_create_megatestdir megatestdir allmodules
448 func_create_megatestdir ()
452 if test -z "$allmodules"; then
453 allmodules=`func_all_modules`
457 # First, all modules one by one.
458 for onemodule in $allmodules; do
459 func_create_testdir "$megatestdir/$onemodule" $onemodule
460 megasubdirs="${megasubdirs}$onemodule "
462 # Then, all modules all together.
463 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
464 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
465 func_create_testdir "$megatestdir/ALL" "$allmodules"
466 megasubdirs="${megasubdirs}ALL"
468 # Create Makefile.am.
469 (echo "## Process this file with automake to produce Makefile.in."
471 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
473 echo "SUBDIRS = $megasubdirs"
474 ) > "$megatestdir/Makefile.am"
476 # Create configure.ac.
477 (echo "# Process this file with autoconf to produce a configure script."
478 echo "AC_INIT(dummy,0)"
479 echo "AM_INIT_AUTOMAKE"
481 echo "AC_PROG_MAKE_SET"
483 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
484 echo "AC_OUTPUT([Makefile])"
485 ) > "$megatestdir/configure.ac"
487 # Create autogenerated files.
489 echo "executing ${ACLOCAL}"
491 echo "executing ${AUTOCONF}"
493 echo "executing ${AUTOMAKE} --add-missing --copy Makefile"
494 ${AUTOMAKE} --add-missing --copy Makefile
500 func_fatal_error "no mode specified" ;;
507 func_fatal_error "NYI" ;;
510 if test -z "$destdir"; then
511 func_fatal_error "please specify --dir option"
515 || func_fatal_error "could not create destination directory"
516 func_create_testdir "$destdir" "$*"
520 if test -z "$destdir"; then
521 func_fatal_error "please specify --dir option"
523 mkdir "$destdir" || func_fatal_error "could not create destination directory"
524 func_create_megatestdir "$destdir" "$*"
528 test -n "$destdir" || destdir=testdir$$
529 mkdir "$destdir" || func_fatal_error "could not create destination directory"
530 func_create_testdir "$destdir" "$*"
538 remaining=`find . -type f -print`
539 if test -n "$remaining"; then
540 echo "Remaining files:" $remaining 1>&2
541 echo "gnulib-tool: *** Stop." 1>&2
550 test -n "$destdir" || destdir=testdir$$
551 mkdir "$destdir" || func_fatal_error "could not create destination directory"
552 func_create_megatestdir "$destdir" "$*"
560 remaining=`find . -type f -print`
561 if test -n "$remaining"; then
562 echo "Remaining files:" $remaining 1>&2
563 echo "gnulib-tool: *** Stop." 1>&2
571 extract-description )
575 if test -n "$module"; then
576 func_get_description "$module"
585 if test -n "$module"; then
586 func_get_filelist "$module"
591 extract-dependencies )
595 if test -n "$module"; then
596 func_get_dependencies "$module"
601 extract-autoconf-snippet )
605 if test -n "$module"; then
606 func_get_autoconf_snippet "$module"
611 extract-automake-snippet )
615 if test -n "$module"; then
616 func_get_automake_snippet "$module"
621 extract-include-directive )
625 if test -n "$module"; then
626 func_get_include_directive "$module"
632 func_fatal_error "unknown operation mode --$mode" ;;