lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | #-------------------------------------------------------------------------- |
| 4 | # die prints argument string to stdout and exits this shell script. |
| 5 | # |
| 6 | die(){ |
| 7 | echo "buildconf: $@" |
| 8 | exit 1 |
| 9 | } |
| 10 | |
| 11 | #-------------------------------------------------------------------------- |
| 12 | # findtool works as 'which' but we use a different name to make it more |
| 13 | # obvious we aren't using 'which'! ;-) |
| 14 | # |
| 15 | findtool(){ |
| 16 | file="$1" |
| 17 | |
| 18 | if { echo "$file" | grep "/" >/dev/null 2>&1; } then |
| 19 | # when file is given with a path check it first |
| 20 | if test -f "$file"; then |
| 21 | echo "$file" |
| 22 | return |
| 23 | fi |
| 24 | fi |
| 25 | |
| 26 | old_IFS=$IFS; IFS=':' |
| 27 | for path in $PATH |
| 28 | do |
| 29 | IFS=$old_IFS |
| 30 | # echo "checks for $file in $path" >&2 |
| 31 | if test -f "$path/$file"; then |
| 32 | echo "$path/$file" |
| 33 | return |
| 34 | fi |
| 35 | done |
| 36 | IFS=$old_IFS |
| 37 | } |
| 38 | |
| 39 | #-------------------------------------------------------------------------- |
| 40 | # removethis() removes all files and subdirectories with the given name, |
| 41 | # inside and below the current subdirectory at invocation time. |
| 42 | # |
| 43 | removethis(){ |
| 44 | if test "$#" = "1"; then |
| 45 | find . -depth -name $1 -print > buildconf.tmp.$$ |
| 46 | while read fdname |
| 47 | do |
| 48 | if test -f "$fdname"; then |
| 49 | rm -f "$fdname" |
| 50 | elif test -d "$fdname"; then |
| 51 | rm -f -r "$fdname" |
| 52 | fi |
| 53 | done < buildconf.tmp.$$ |
| 54 | rm -f buildconf.tmp.$$ |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | #-------------------------------------------------------------------------- |
| 59 | # Ensure that buildconf runs from the subdirectory where configure.ac lives |
| 60 | # |
| 61 | if test ! -f configure.ac || |
| 62 | test ! -f ares_init.c || |
| 63 | test ! -f m4/cares-functions.m4; then |
| 64 | echo "Can not run buildconf from outside of c-ares source subdirectory!" |
| 65 | echo "Change to the subdirectory where buildconf is found, and try again." |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | #-------------------------------------------------------------------------- |
| 70 | # GNU libtool preliminary check |
| 71 | # |
| 72 | want_lt_major=1 |
| 73 | want_lt_minor=4 |
| 74 | want_lt_patch=2 |
| 75 | want_lt_version=1.4.2 |
| 76 | |
| 77 | # This approach that tries 'glibtoolize first is intended for systems that |
| 78 | # have GNU libtool named as 'glibtoolize' and libtoolize not being GNU's. |
| 79 | |
| 80 | libtoolize=`findtool glibtoolize 2>/dev/null` |
| 81 | if test ! -x "$libtoolize"; then |
| 82 | libtoolize=`findtool ${LIBTOOLIZE:-libtoolize}` |
| 83 | fi |
| 84 | if test -z "$libtoolize"; then |
| 85 | echo "buildconf: libtoolize not found." |
| 86 | echo " You need GNU libtoolize $want_lt_version or newer installed." |
| 87 | exit 1 |
| 88 | fi |
| 89 | |
| 90 | lt_pver=`$libtoolize --version 2>/dev/null|head -n 1` |
| 91 | lt_qver=`echo $lt_pver|sed -e "s/([^)]*)//g" -e "s/^[^0-9]*//g"` |
| 92 | lt_version=`echo $lt_qver|sed -e "s/[- ].*//" -e "s/\([a-z]*\)$//"` |
| 93 | if test -z "$lt_version"; then |
| 94 | echo "buildconf: libtoolize not found." |
| 95 | echo " You need GNU libtoolize $want_lt_version or newer installed." |
| 96 | exit 1 |
| 97 | fi |
| 98 | old_IFS=$IFS; IFS='.'; set $lt_version; IFS=$old_IFS |
| 99 | lt_major=$1 |
| 100 | lt_minor=$2 |
| 101 | lt_patch=$3 |
| 102 | |
| 103 | if test -z "$lt_major"; then |
| 104 | lt_status="bad" |
| 105 | elif test "$lt_major" -gt "$want_lt_major"; then |
| 106 | lt_status="good" |
| 107 | elif test "$lt_major" -lt "$want_lt_major"; then |
| 108 | lt_status="bad" |
| 109 | elif test -z "$lt_minor"; then |
| 110 | lt_status="bad" |
| 111 | elif test "$lt_minor" -gt "$want_lt_minor"; then |
| 112 | lt_status="good" |
| 113 | elif test "$lt_minor" -lt "$want_lt_minor"; then |
| 114 | lt_status="bad" |
| 115 | elif test -z "$lt_patch"; then |
| 116 | lt_status="bad" |
| 117 | elif test "$lt_patch" -gt "$want_lt_patch"; then |
| 118 | lt_status="good" |
| 119 | elif test "$lt_patch" -lt "$want_lt_patch"; then |
| 120 | lt_status="bad" |
| 121 | else |
| 122 | lt_status="good" |
| 123 | fi |
| 124 | if test "$lt_status" != "good"; then |
| 125 | echo "buildconf: libtoolize version $lt_version found." |
| 126 | echo " You need GNU libtoolize $want_lt_version or newer installed." |
| 127 | exit 1 |
| 128 | fi |
| 129 | |
| 130 | #-------------------------------------------------------------------------- |
| 131 | # perl check |
| 132 | # |
| 133 | PERL=`findtool ${PERL:-perl}` |
| 134 | if test -z "$PERL"; then |
| 135 | echo "buildconf: perl not found" |
| 136 | exit 1 |
| 137 | fi |
| 138 | |
| 139 | #-------------------------------------------------------------------------- |
| 140 | # Remove files generated on previous buildconf/configure run. |
| 141 | # |
| 142 | for fname in .deps \ |
| 143 | .libs \ |
| 144 | *.la \ |
| 145 | *.lo \ |
| 146 | *.a \ |
| 147 | *.o \ |
| 148 | Makefile \ |
| 149 | Makefile.in \ |
| 150 | aclocal.m4 \ |
| 151 | aclocal.m4.bak \ |
| 152 | ares_build.h \ |
| 153 | ares_config.h \ |
| 154 | ares_config.h.in \ |
| 155 | autom4te.cache \ |
| 156 | compile \ |
| 157 | config.guess \ |
| 158 | config.log \ |
| 159 | config.lt \ |
| 160 | config.status \ |
| 161 | config.sub \ |
| 162 | configure \ |
| 163 | depcomp \ |
| 164 | libcares.pc \ |
| 165 | libtool \ |
| 166 | libtool.m4 \ |
| 167 | libtool.m4.tmp \ |
| 168 | ltmain.sh \ |
| 169 | ltoptions.m4 \ |
| 170 | ltsugar.m4 \ |
| 171 | ltversion.m4 \ |
| 172 | lt~obsolete.m4 \ |
| 173 | missing \ |
| 174 | stamp-h1 \ |
| 175 | stamp-h2 ; do |
| 176 | removethis "$fname" |
| 177 | done |
| 178 | |
| 179 | #-------------------------------------------------------------------------- |
| 180 | # run the correct scripts now |
| 181 | # |
| 182 | |
| 183 | echo "buildconf: running libtoolize" |
| 184 | ${libtoolize} --copy --automake --force || die "libtoolize command failed" |
| 185 | |
| 186 | # When using libtool 1.5.X (X < 26) we copy libtool.m4 to our local m4 |
| 187 | # subdirectory and this local copy is patched to fix some warnings that |
| 188 | # are triggered when running aclocal and using autoconf 2.62 or later. |
| 189 | |
| 190 | if test "$lt_major" = "1" && test "$lt_minor" = "5"; then |
| 191 | if test -z "$lt_patch" || test "$lt_patch" -lt "26"; then |
| 192 | echo "buildconf: copying libtool.m4 to local m4 subdir" |
| 193 | ac_dir=`${ACLOCAL:-aclocal} --print-ac-dir` |
| 194 | if test -f $ac_dir/libtool.m4; then |
| 195 | cp -f $ac_dir/libtool.m4 m4/libtool.m4 |
| 196 | else |
| 197 | echo "buildconf: $ac_dir/libtool.m4 not found" |
| 198 | fi |
| 199 | if test -f m4/libtool.m4; then |
| 200 | echo "buildconf: renaming some variables in local m4/libtool.m4" |
| 201 | $PERL -i.tmp -pe \ |
| 202 | 's/lt_prog_compiler_pic_works/lt_cv_prog_compiler_pic_works/g; \ |
| 203 | s/lt_prog_compiler_static_works/lt_cv_prog_compiler_static_works/g;' \ |
| 204 | m4/libtool.m4 |
| 205 | rm -f m4/libtool.m4.tmp |
| 206 | fi |
| 207 | fi |
| 208 | fi |
| 209 | |
| 210 | if test -f m4/libtool.m4; then |
| 211 | echo "buildconf: converting all mv to mv -f in local m4/libtool.m4" |
| 212 | $PERL -i.tmp -pe 's/\bmv +([^-\s])/mv -f $1/g' m4/libtool.m4 |
| 213 | rm -f m4/libtool.m4.tmp |
| 214 | fi |
| 215 | |
| 216 | echo "buildconf: running aclocal" |
| 217 | ${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS || die "aclocal command failed" |
| 218 | |
| 219 | echo "buildconf: converting all mv to mv -f in local aclocal.m4" |
| 220 | $PERL -i.bak -pe 's/\bmv +([^-\s])/mv -f $1/g' aclocal.m4 |
| 221 | |
| 222 | echo "buildconf: running autoheader" |
| 223 | ${AUTOHEADER:-autoheader} || die "autoheader command failed" |
| 224 | |
| 225 | echo "buildconf: running autoconf" |
| 226 | ${AUTOCONF:-autoconf} || die "autoconf command failed" |
| 227 | |
| 228 | echo "buildconf: running automake" |
| 229 | ${AUTOMAKE:-automake} --add-missing --copy || die "automake command failed" |
| 230 | |
| 231 | #-------------------------------------------------------------------------- |
| 232 | # GNU libtool complementary check |
| 233 | # |
| 234 | # Depending on the libtool and automake versions being used, config.guess |
| 235 | # might not be installed in the subdirectory until automake has finished. |
| 236 | # So we can not attempt to use it until this very last buildconf stage. |
| 237 | # |
| 238 | if test ! -f ./config.guess; then |
| 239 | echo "buildconf: config.guess not found" |
| 240 | else |
| 241 | buildhost=`./config.guess 2>/dev/null|head -n 1` |
| 242 | case $buildhost in |
| 243 | *-*-darwin*) |
| 244 | need_lt_major=1 |
| 245 | need_lt_minor=5 |
| 246 | need_lt_patch=26 |
| 247 | need_lt_check="yes" |
| 248 | ;; |
| 249 | *-*-hpux*) |
| 250 | need_lt_major=1 |
| 251 | need_lt_minor=5 |
| 252 | need_lt_patch=24 |
| 253 | need_lt_check="yes" |
| 254 | ;; |
| 255 | esac |
| 256 | if test ! -z "$need_lt_check"; then |
| 257 | if test -z "$lt_major"; then |
| 258 | lt_status="bad" |
| 259 | elif test "$lt_major" -gt "$need_lt_major"; then |
| 260 | lt_status="good" |
| 261 | elif test "$lt_major" -lt "$need_lt_major"; then |
| 262 | lt_status="bad" |
| 263 | elif test -z "$lt_minor"; then |
| 264 | lt_status="bad" |
| 265 | elif test "$lt_minor" -gt "$need_lt_minor"; then |
| 266 | lt_status="good" |
| 267 | elif test "$lt_minor" -lt "$need_lt_minor"; then |
| 268 | lt_status="bad" |
| 269 | elif test -z "$lt_patch"; then |
| 270 | lt_status="bad" |
| 271 | elif test "$lt_patch" -gt "$need_lt_patch"; then |
| 272 | lt_status="good" |
| 273 | elif test "$lt_patch" -lt "$need_lt_patch"; then |
| 274 | lt_status="bad" |
| 275 | else |
| 276 | lt_status="good" |
| 277 | fi |
| 278 | if test "$lt_status" != "good"; then |
| 279 | need_lt_version="$need_lt_major.$need_lt_minor.$need_lt_patch" |
| 280 | echo "buildconf: libtool version $lt_version found." |
| 281 | echo " $buildhost requires GNU libtool $need_lt_version or newer installed." |
| 282 | rm -f configure |
| 283 | exit 1 |
| 284 | fi |
| 285 | fi |
| 286 | fi |
| 287 | |
| 288 | #-------------------------------------------------------------------------- |
| 289 | # Finished successfully. |
| 290 | # |
| 291 | echo "buildconf: OK" |
| 292 | |
| 293 | if test -f "test/buildconf"; then |
| 294 | cd test && ./buildconf |
| 295 | fi |
| 296 | |
| 297 | exit 0 |