gnulib: import ffs
[binutils-gdb.git] / gnulib / update-gnulib.sh
1 #! /bin/sh
2
3 # Copyright (C) 2011-2021 Free Software Foundation, Inc.
4 #
5 # This file is part of GDB.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 # Usage: update-gnulib.sh <path-to-gnulib-repository>
21 # Update our import of gnulib in the GDB source tree.
22 #
23 # This script assumes that it is being called from the gdb/gnulib
24 # subdirectory, and will verify this before proceeding.
25 #
26 # This script will also make a number of other verifications:
27 # . The gnulib version (it should match $GNULIB_COMMIT_SHA1).
28 # . The correct versions of the auto-tools that are used to
29 # regenerate the various scripts and Makefiles are on the PATH.
30
31 # The list of gnulib modules we are importing in GDB.
32 IMPORTED_GNULIB_MODULES="\
33 alloca \
34 canonicalize-lgpl \
35 count-one-bits \
36 dirent \
37 dirfd \
38 errno \
39 ffs \
40 fnmatch-gnu \
41 frexpl \
42 gendocs \
43 getcwd \
44 getline \
45 gettimeofday \
46 gitlog-to-changelog \
47 glob \
48 inet_ntop
49 inttypes \
50 lstat \
51 limits-h \
52 memchr \
53 memmem \
54 mkdir \
55 mkdtemp \
56 mkostemp \
57 pathmax \
58 rawmemchr \
59 readlink \
60 rename \
61 setenv \
62 signal-h \
63 strchrnul \
64 strerror_r-posix \
65 strstr \
66 strtok_r \
67 sys_stat \
68 time_r \
69 unistd \
70 unsetenv \
71 update-copyright \
72 wchar \
73 wctype-h \
74 "
75
76 # The gnulib commit ID to use for the update.
77 GNULIB_COMMIT_SHA1="776af40e09b476a41073131a90022572f448c189"
78
79 # The expected version number for the various auto tools we will
80 # use after the import.
81 AUTOCONF_VERSION="2.69"
82 AUTOMAKE_VERSION="1.15.1"
83 ACLOCAL_VERSION="$AUTOMAKE_VERSION"
84
85 if [ $# -ne 1 ]; then
86 echo "Error: Path to gnulib repository missing. Aborting."
87 echo "Usage: update-gnulib.sh <path-to-gnulib-repository>"
88 exit 1
89 fi
90 gnulib_prefix=$1
91
92 gnulib_tool="$gnulib_prefix/gnulib-tool"
93
94 # Verify that the gnulib directory does exist...
95 if [ ! -f "$gnulib_tool" ]; then
96 echo "Error: Invalid gnulib directory. Cannot find gnulib tool"
97 echo " ($gnulib_tool)."
98 echo "Aborting."
99 exit 1
100 fi
101
102 # Verify that we have the right version of gnulib...
103 gnulib_head_sha1=`cd $gnulib_prefix && git rev-parse HEAD`
104 if [ "$gnulib_head_sha1" != "$GNULIB_COMMIT_SHA1" ]; then
105 echo "Error: Wrong version of gnulib: $gnulib_head_sha1"
106 echo " (we expected it to be $GNULIB_COMMIT_SHA1)"
107 echo "Aborting."
108 exit 1
109 fi
110
111 # Verify that we are in the correct directory.
112 if [ ! -f ../gdb/main.c -o ! -d import ]; then
113 echo "Error: This script should be called from the gnulib subdirectory."
114 echo "Aborting."
115 exit 1
116 fi
117
118 # Verify that we have the correct version of autoconf.
119 ver=`autoconf --version 2>&1 | head -1 | sed 's/.*) //'`
120 if [ "$ver" != "$AUTOCONF_VERSION" ]; then
121 echo "Error: Wrong autoconf version ($ver), we need $AUTOCONF_VERSION."
122 echo "Aborting."
123 exit 1
124 fi
125
126 # Verify that we have the correct version of automake.
127 ver=`automake --version 2>&1 | head -1 | sed 's/.*) //'`
128 if [ "$ver" != "$AUTOMAKE_VERSION" ]; then
129 echo "Error: Wrong automake version ($ver), we need $AUTOMAKE_VERSION."
130 echo "Aborting."
131 exit 1
132 fi
133
134 # Verify that we have the correct version of aclocal.
135 #
136 # The grep below is needed because Perl >= 5.16 dumps a "called too
137 # early to check prototype" warning when running aclocal 1.11.1. This
138 # causes trouble below, because the warning is the first line output
139 # by aclocal, resulting in:
140 #
141 # $ sh ./update-gnulib.sh ~/src/gnulib/src/
142 # Error: Wrong aclocal version: called too early to check prototype at /opt/automake-1.11.1/bin/aclocal line 617.. Aborting.
143 #
144 # Some distros carry an automake patch for that:
145 # https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=aclocal-function-prototypes.debdiff;att=1;bug=752784
146 #
147 # But since we prefer pristine FSF versions of autotools, work around
148 # the issue here. This can be removed later when we bump the required
149 # automake version.
150 #
151 ver=`aclocal --version 2>&1 | grep -v "called too early to check prototype" | head -1 | sed 's/.*) //'`
152 if [ "$ver" != "$ACLOCAL_VERSION" ]; then
153 echo "Error: Wrong aclocal version ($ver), we need $ACLOCAL_VERSION."
154 echo "Aborting."
155 exit 1
156 fi
157
158 # Update our gnulib import.
159 $gnulib_prefix/gnulib-tool --import --dir=. --lib=libgnu \
160 --source-base=import --m4-base=import/m4 --doc-base=doc \
161 --tests-base=tests --aux-dir=import/extra \
162 --no-conditional-dependencies --no-libtool --macro-prefix=gl \
163 --no-vc-files \
164 $IMPORTED_GNULIB_MODULES
165 if [ $? -ne 0 ]; then
166 echo "Error: gnulib import failed. Aborting."
167 exit 1
168 fi
169
170 # Apply our local patches.
171 apply_patches ()
172 {
173 patch -p2 -f -i "$1"
174 if [ $? -ne 0 ]; then
175 echo "Failed to apply some patches. Aborting."
176 exit 1
177 fi
178 }
179
180 apply_patches "patches/0001-use-windows-stat"
181
182 # Regenerate all necessary files...
183 aclocal &&
184 autoconf &&
185 autoheader &&
186 automake
187 if [ $? -ne 0 ]; then
188 echo "Error: Failed to regenerate Makefiles and configure scripts."
189 exit 1
190 fi