comparison gnulib-tool @ 6181:95b89dc3f638

Read the previous cached settings. Remove files that become obsolete if gnulib-tool added them earlier.
author Bruno Haible <bruno@clisp.org>
date Wed, 31 Aug 2005 20:54:49 +0000
parents a0904de304e5
children 6ac925998337
comparison
equal deleted inserted replaced
6180:a0904de304e5 6181:95b89dc3f638
20 # This program is meant for authors or maintainers which want to import 20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages. 21 # modules from gnulib into their packages.
22 22
23 progname=$0 23 progname=$0
24 package=gnulib 24 package=gnulib
25 cvsdatestamp='$Date: 2005-08-31 20:53:42 $' 25 cvsdatestamp='$Date: 2005-08-31 20:54:49 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'` 26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'` 27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
28 28
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH. 29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
30 AUTOCONFPATH= 30 AUTOCONFPATH=
754 # - dry_run true if actions shall only be printed, blank otherwise 754 # - dry_run true if actions shall only be printed, blank otherwise
755 # - symbolic true if files should be symlinked, copied otherwise 755 # - symbolic true if files should be symlinked, copied otherwise
756 # - supplied_opts all options passed to gnulib-tool 756 # - supplied_opts all options passed to gnulib-tool
757 func_import () 757 func_import ()
758 { 758 {
759 modules="$1" 759 # Get the cached settings.
760 modules=`for m in $modules; do echo $m; done | sort | uniq` 760 cached_specified_modules=
761 specified_modules="$modules" 761 cached_avoidlist=
762 cached_sourcebase=
763 cached_m4base=
764 cached_libname=
765 cached_lgpl=
766 cached_libtool=
767 cached_macro_prefix=
768 cached_files=
769 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
770 my_sed_traces='
771 s,#.*$,,
772 s,^dnl .*$,,
773 s, dnl .*$,,
774 /gl_MODULES(/ {
775 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
776 }
777 /gl_AVOID(/ {
778 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
779 }
780 /gl_SOURCE_BASE(/ {
781 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
782 }
783 /gl_M4_BASE(/ {
784 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
785 }
786 /gl_LIB(/ {
787 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
788 }
789 /gl_LGPL/ {
790 s,^.*$,cached_lgpl=true,p
791 }
792 /gl_LIBTOOL/ {
793 s,^.*$,cached_libtool=true,p
794 }
795 /gl_MACRO_PREFIX(/ {
796 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
797 }'
798 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
799 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
800 my_sed_traces='
801 s,#.*$,,
802 s,^dnl .*$,,
803 s, dnl .*$,,
804 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
805 s,^.*$,cached_files=",p
806 n
807 ta
808 :a
809 s,^\]).*$,",
810 tb
811 p
812 n
813 ba
814 :b
815 p
816 }'
817 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
818 fi
819 fi
820
821 # Merge the cached settings with the specified ones.
822 # The m4base must be the same as expected from the pathname.
823 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
824 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
825 fi
826 # Append the cached and the specified module names. So that
827 # "gnulib-tool --import foo" means to add the module foo.
828 specified_modules="$cached_specified_modules $1"
829 # Append the cached and the specified avoidlist. This is probably better
830 # than dropping the cached one when --avoid is specified at least once.
831 avoidlist=`echo $cached_avoidlist $avoidlist`
832 # The sourcebase defaults to the cached one.
833 if test -z "$sourcebase"; then
834 sourcebase="$cached_sourcebase"
835 if test -z "$sourcebase"; then
836 func_fatal_error "missing --source-base option"
837 fi
838 fi
839 # The libname defaults to the cached one.
840 if test -z "$libname"; then
841 libname="$cached_libname"
842 if test -z "$libname"; then
843 func_fatal_error "missing --lib option"
844 fi
845 fi
846 # Require LGPL if specified either way.
847 if test -z "$lgpl"; then
848 lgpl="$cached_lgpl"
849 fi
850 # Use libtool if specified either way.
851 if test -z "$libtool"; then
852 libtool="$cached_libtool"
853 fi
854 # The macro_prefix defaults to the cached one.
855 if test -z "$macro_prefix"; then
856 macro_prefix="$cached_macro_prefix"
857 if test -z "$macro_prefix"; then
858 func_fatal_error "missing --macro-prefix option"
859 fi
860 fi
861
862 # Canonicalize the list of specified modules.
863 specified_modules=`for m in $specified_modules; do echo $m; done | sort | uniq`
762 864
763 # Determine final module list. 865 # Determine final module list.
866 modules="$specified_modules"
764 func_modules_transitive_closure 867 func_modules_transitive_closure
765 echo "Module list with included dependencies:" 868 echo "Module list with included dependencies:"
766 echo "$modules" | sed -e 's/^/ /' 869 echo "$modules" | sed -e 's/^/ /'
767 870
768 # If --lgpl, check the license of modules are compatible. 871 # If --lgpl, check the license of modules are compatible.
769 if test -n "$lgpl"; then 872 if test -n "$lgpl"; then
770 for module in $modules; do 873 for module in $modules; do
771 license=`func_get_license $module` 874 license=`func_get_license $module`
772 case $license in 875 case $license in
773 LGPL | 'public domain' | 'unlimited') ;; 876 LGPL | 'public domain' | 'unlimited') ;;
774 *) 877 *) func_fatal_error "incompatible license on module $module: $license" ;;
775 func_fatal_error \
776 "incompatible license on module \`$module\`: $license" ;;
777 esac 878 esac
778 done 879 done
779 fi 880 fi
780 881
781 # Determine final file list. 882 # Determine final file list.
784 echo "$files" | sed -e 's/^/ /' 885 echo "$files" | sed -e 's/^/ /'
785 886
786 test -n "$files" \ 887 test -n "$files" \
787 || func_fatal_error "refusing to do nothing" 888 || func_fatal_error "refusing to do nothing"
788 889
789 # Copy files or make symbolic links. 890 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
790 for f in $files m4/gnulib-tool.m4; do 891 new_files="$files m4/gnulib-tool.m4"
791 source= 892 old_files="$cached_files"
792 case "$f" in 893 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
793 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;; 894 old_files="$old_files m4/gnulib-tool.m4"
794 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"`; source=true ;; 895 fi
795 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;; 896
796 *) g="$f" ;; 897 # Copy files or make symbolic links. Remove obsolete files.
898 for f1 in $old_files; do
899 case "$f1" in
900 build-aux/*) g1=`echo "$f1" | sed -e "s,^build-aux/,$auxdir/,"` ;;
901 lib/*) g1=`echo "$f1" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
902 m4/*) g1=`echo "$f1" | sed -e "s,^m4/,$cached_m4base/,"` ;;
903 *) g1="$f1" ;;
797 esac 904 esac
798 if test -z "$symbolic"; then 905 still_present=
799 func_cp_if_changed "$gnulib_dir/$f" "$destdir/$g" 906 for f2 in $new_files; do
907 case "$f2" in
908 build-aux/*) g2=`echo "$f2" | sed -e "s,^build-aux/,$auxdir/,"` ;;
909 lib/*) g2=`echo "$f2" | sed -e "s,^lib/,$sourcebase/,"` ;;
910 m4/*) g2=`echo "$f2" | sed -e "s,^m4/,$m4base/,"` ;;
911 *) g2="$f2" ;;
912 esac
913 if test "$g2" = "$g1"; then
914 still_present=true
915 break
916 fi
917 done
918 if test -z "$still_present"; then
919 # Remove the file. Do nothing if the user already removed it.
920 if test -f "$destdir/$g1"; then
921 echo "Removing file $g1 (backup in ${g1}~)"
922 test -n "$dry_run" && dry=echo
923 $dry mv -f "$destdir/$g1" "$destdir/${g1}~" || func_fatal_error "failed"
924 fi
925 fi
926 done
927 for f2 in $new_files; do
928 case "$f2" in
929 build-aux/*) g2=`echo "$f2" | sed -e "s,^build-aux/,$auxdir/,"` ;;
930 lib/*) g2=`echo "$f2" | sed -e "s,^lib/,$sourcebase/,"` ;;
931 m4/*) g2=`echo "$f2" | sed -e "s,^m4/,$m4base/,"` ;;
932 *) g2="$f2" ;;
933 esac
934 already_present=
935 for f1 in $old_files; do
936 case "$f1" in
937 build-aux/*) g1=`echo "$f1" | sed -e "s,^build-aux/,$auxdir/,"` ;;
938 lib/*) g1=`echo "$f1" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
939 m4/*) g1=`echo "$f1" | sed -e "s,^m4/,$cached_m4base/,"` ;;
940 *) g1="$f1" ;;
941 esac
942 if test "$g1" = "$g2"; then
943 already_present=true
944 break
945 fi
946 done
947 cp "$gnulib_dir/$f2" "$destdir/$g2.tmp" || func_fatal_error "failed"
948 if test -n "$lgpl"; then
949 # Update license.
950 case "$f2" in
951 lib/*)
952 sed -e 's/GNU General/GNU Lesser General/g' \
953 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
954 < "$gnulib_dir/$f2" > "$destdir/$g2.tmp" || func_fatal_error "failed"
955 ;;
956 esac
957 fi
958 if test -f "$destdir/$g2"; then
959 # The file already exists.
960 if cmp "$destdir/$g2" "$destdir/$g2.tmp" > /dev/null; then
961 : # The file has not changed.
962 else
963 # Replace the file.
964 if test -n "$already_present"; then
965 echo "Updating file $g2 (backup in ${g2}~)"
966 else
967 echo "Replacing file $g2 (non-gnulib code backuped in ${g2}~) !!"
968 fi
969 test -n "$dry_run" && dry=echo
970 $dry mv -f "$destdir/$g2" "$destdir/${g2}~" || func_fatal_error "failed"
971 if test -z "$symbolic" && cmp "$gnulib_dir/$f2" "$destdir/$g2.tmp"; then
972 func_ln_if_changed "$gnulib_dir/$f2" "$destdir/$g2"
973 else
974 $dry mv -f "$destdir/$g2.tmp" "$destdir/${g2}" || func_fatal_error "failed"
975 fi
976 fi
800 else 977 else
801 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g" 978 # Install the file.
802 fi 979 # Don't protest if the file should be there but isn't: it happens
803 # Update license. 980 # frequently that developers don't put autogenerated files into CVS.
804 if test -z "$dry_run" && test -n "$lgpl" && test -n "$source"; then 981 echo "Copying file $g2"
805 perl -pi -e 's/GNU General/GNU Lesser General/g;' \ 982 test -n "$dry_run" && dry=echo
806 -e 's/version 2([ ,])/version 2.1\1/g' \ 983 if test -z "$symbolic" && cmp "$gnulib_dir/$f2" "$destdir/$g2.tmp"; then
807 "$destdir/$g" 984 func_ln_if_changed "$gnulib_dir/$f2" "$destdir/$g2"
985 else
986 $dry mv -f "$destdir/$g2.tmp" "$destdir/${g2}" || func_fatal_error "failed"
987 fi
808 fi 988 fi
809 done 989 done
810 990
811 # Commands printed in a comment in generated files. 991 # Command-line invocation printed in various files.
812 cmd="gnulib-tool $supplied_opts" 992 cmd="gnulib-tool $supplied_opts"
813 opt_libtool= 993
994 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
995 actioncmd="gnulib-tool --import"
996 actioncmd="$actioncmd --dir=$destdir"
997 actioncmd="$actioncmd --lib=$libname"
998 actioncmd="$actioncmd --source-base=$sourcebase"
999 actioncmd="$actioncmd --m4-base=$m4base"
1000 actioncmd="$actioncmd --aux-dir=$auxdir"
1001 for module in $avoidlist; do
1002 actioncmd="$actioncmd --avoid=$module"
1003 done
1004 if test -n "$lgpl"; then
1005 actioncmd="$actioncmd --lgpl"
1006 fi
814 if test -n "$libtool"; then 1007 if test -n "$libtool"; then
815 opt_libtool="--libtool" 1008 actioncmd="$actioncmd --libtool"
816 fi 1009 fi
817 opt_lgpl= 1010 actioncmd="$actioncmd -macro-prefix=$macro_prefix"
818 if test -n "$lgpl"; then 1011 actioncmd="$actioncmd `echo $specified_modules`"
819 opt_lgpl="--lgpl"
820 fi
821 actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base --aux-dir=$auxdir $opt_libtool $opt_lgpl `echo $specified_modules`"
822 1012
823 # Create lib/Makefile.am. 1013 # Create lib/Makefile.am.
824 echo "Creating $destdir/$sourcebase/Makefile.am..."
825 if test -z "$dry_run"; then 1014 if test -z "$dry_run"; then
826 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.new 1015 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1016 if test -f "$destdir"/$sourcebase/Makefile.am; then
1017 if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1018 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1019 else
1020 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1021 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1022 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1023 fi
1024 else
1025 echo "Creating $sourcebase/Makefile.am"
1026 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1027 fi
827 else 1028 else
1029 echo "Creating $sourcebase/Makefile.am..."
828 func_emit_lib_Makefile_am 1030 func_emit_lib_Makefile_am
829 fi 1031 fi
830 func_mv_if_changed "$destdir"/$sourcebase/Makefile.am.new \
831 "$destdir"/$sourcebase/Makefile.am
832 1032
833 # Create m4/gnulib-cache.m4. 1033 # Create m4/gnulib-cache.m4.
834 echo "Creating $destdir/$m4base/gnulib-cache.m4..."
835 ( 1034 (
836 if test -z "$dry_run"; then 1035 if test -z "$dry_run"; then
837 exec > "$destdir"/$m4base/gnulib-cache.m4.new 1036 exec > "$destdir"/$m4base/gnulib-cache.m4.tmp
838 else 1037 else
1038 echo "Creating $m4base/gnulib-cache.m4..."
839 echo "# $destdir/$m4base/gnulib-cache.m4" 1039 echo "# $destdir/$m4base/gnulib-cache.m4"
840 fi 1040 fi
841 echo "# Copyright (C) 2004 Free Software Foundation, Inc." 1041 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
842 echo "# This file is free software, distributed under the terms of the GNU" 1042 echo "# This file is free software, distributed under the terms of the GNU"
843 echo "# General Public License. As a special exception to the GNU General" 1043 echo "# General Public License. As a special exception to the GNU General"
855 echo 1055 echo
856 echo "# Specification in the form of a command-line invocation:" 1056 echo "# Specification in the form of a command-line invocation:"
857 echo "# $actioncmd" 1057 echo "# $actioncmd"
858 echo 1058 echo
859 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:" 1059 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
860 echo "gl_MODULES([$specified_modules])" 1060 echo "gl_MODULES(["`echo $specified_modules`"])"
861 echo "gl_AVOID([$avoidlist])" 1061 echo "gl_AVOID([$avoidlist])"
862 echo "gl_SOURCE_BASE([$sourcebase])" 1062 echo "gl_SOURCE_BASE([$sourcebase])"
863 echo "gl_M4_BASE([$m4base])" 1063 echo "gl_M4_BASE([$m4base])"
864 echo "gl_LIB([$libname])" 1064 echo "gl_LIB([$libname])"
865 test -z "$lgpl" || echo "gl_LGPL" 1065 test -z "$lgpl" || echo "gl_LGPL"
866 test -z "$libtool" || echo "gl_LIBTOOL" 1066 test -z "$libtool" || echo "gl_LIBTOOL"
867 echo "gl_MACRO_PREFIX([$macro_prefix])" 1067 echo "gl_MACRO_PREFIX([$macro_prefix])"
868 echo 1068 echo
869 echo "# gnulib-cache.m4 ends here" 1069 echo "# gnulib-cache.m4 ends here"
870 ) 1070 )
871 func_mv_if_changed "$destdir"/$m4base/gnulib-cache.m4.new "$destdir"/$m4base/gnulib-cache.m4 1071 if test -z "$dry_run"; then
1072 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1073 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1074 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1075 else
1076 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1077 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1078 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1079 fi
1080 else
1081 echo "Creating $m4base/gnulib-cache.m4"
1082 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1083 fi
1084 fi
872 1085
873 # Create m4/gnulib-comp.m4. 1086 # Create m4/gnulib-comp.m4.
874 echo "Creating $destdir/$m4base/gnulib-comp.m4..."
875 ( 1087 (
876 if test -z "$dry_run"; then 1088 if test -z "$dry_run"; then
877 exec > "$destdir"/$m4base/gnulib-comp.m4.new 1089 exec > "$destdir"/$m4base/gnulib-comp.m4.tmp
878 else 1090 else
1091 echo "Creating $m4base/gnulib-comp.m4..."
879 echo "# $destdir/$m4base/gnulib-comp.m4" 1092 echo "# $destdir/$m4base/gnulib-comp.m4"
880 fi 1093 fi
881 echo "# Copyright (C) 2004 Free Software Foundation, Inc." 1094 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
882 echo "# This file is free software, distributed under the terms of the GNU" 1095 echo "# This file is free software, distributed under the terms of the GNU"
883 echo "# General Public License. As a special exception to the GNU General" 1096 echo "# General Public License. As a special exception to the GNU General"
930 echo "$files" | sed -e 's,^, ,' 1143 echo "$files" | sed -e 's,^, ,'
931 echo "])" 1144 echo "])"
932 echo 1145 echo
933 echo "# gnulib-comp.m4 ends here" 1146 echo "# gnulib-comp.m4 ends here"
934 ) 1147 )
935 func_mv_if_changed "$destdir"/$m4base/gnulib-comp.m4.new "$destdir"/$m4base/gnulib-comp.m4 1148 if test -z "$dry_run"; then
1149 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1150 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1151 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1152 else
1153 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1154 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1155 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1156 fi
1157 else
1158 echo "Creating $m4base/gnulib-comp.m4"
1159 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1160 fi
1161 fi
1162
936 echo "Finished." 1163 echo "Finished."
937 echo 1164 echo
938 echo "You may need to add #include directives for the following .h files." 1165 echo "You may need to add #include directives for the following .h files."
939 for module in $modules; do 1166 for module in $modules; do
940 func_get_include_directive "$module" 1167 func_get_include_directive "$module"