xref: /freebsd/contrib/libpcap/autogen.sh (revision 187d8a3ce55a4e2d41fbe61465d5ff4ac0fc6bd5)
1#!/bin/sh -e
2
3: "${AUTORECONF:=autoreconf}"
4: "${BUILD_YEAR2038:=no}"
5
6AUTORECONFVERSION=`$AUTORECONF --version 2>&1 | grep "^autoreconf" | sed 's/.*) *//'`
7
8maj=`echo "$AUTORECONFVERSION" | cut -d. -f1`
9min=`echo "$AUTORECONFVERSION" | cut -d. -f2`
10# The minimum required version of autoconf is currently 2.69.
11if [ "$maj" = "" ] || [ "$min" = "" ] || \
12   [ "$maj" -lt 2 ] || { [ "$maj" -eq 2 ] && [ "$min" -lt 69 ]; }; then
13	cat >&2 <<-EOF
14	Please install the 'autoconf' package version 2.69 or later.
15	If version 2.69 or later is already installed and there is no
16	autoconf default, it may be necessary to set the AUTORECONF
17	environment variable to enable the one to use, like:
18	AUTORECONF=autoreconf-2.69 ./autogen.sh
19	or
20	AUTORECONF=autoreconf-2.71 ./autogen.sh
21	EOF
22	exit 1
23fi
24
25# On Linux, if Autoconf version >= 2.72 and GNU C Library version >= 2.34,
26# s/AC_SYS_LARGEFILE/AC_SYS_YEAR2038_RECOMMENDED/ to ensure time_t
27# is Y2038-safe.
28if [ "$BUILD_YEAR2038" = yes ] && [ "`uname -s`" = Linux ]; then
29	if [ "$maj" -gt 2 ] || { [ "$maj" -eq 2 ] && [ "$min" -ge 72 ]; }; then
30		GLIBC_VERSION=`ldd --version|head -1|grep GLIBC|sed 's/.* //'`
31		maj_glibc=`echo "$GLIBC_VERSION" | cut -d. -f1`
32		min_glibc=`echo "$GLIBC_VERSION" | cut -d. -f2`
33		echo "GNU C Library identification: $GLIBC_VERSION"
34		if [ "$maj_glibc" -gt 2 ] || { [ "$maj_glibc" -eq 2 ] && \
35		   [ "$min_glibc" -ge 34 ]; }; then
36			CONFIGURE_AC_NEW="configure.ac.new$$"
37			sed 's/^AC_SYS_LARGEFILE/AC_SYS_YEAR2038_RECOMMENDED/' \
38				<configure.ac >"$CONFIGURE_AC_NEW"
39			cmp -s configure.ac "$CONFIGURE_AC_NEW" || \
40			cat "$CONFIGURE_AC_NEW" >configure.ac
41			rm -f "$CONFIGURE_AC_NEW"
42			echo 'Setup to ensure time_t is Y2038-safe.'
43		fi
44	fi
45fi
46
47echo "$AUTORECONF identification: $AUTORECONFVERSION"
48
49# configure.ac is an Autoconf 2.69 file, but it works as expected even with
50# Autoconf 2.72.  However, in Autoconf versions 2.70 and later obsolete
51# construct warnings are enabled by default, which adds varying (depending on
52# the branch) amount of noise to the build matrix output, so provide a means
53# to silence that.
54env ${AUTOCONF_WARNINGS:+WARNINGS="$AUTOCONF_WARNINGS"} "$AUTORECONF" -f
55
56# Autoconf 2.71 adds a blank line after the final "exit 0" on Linux, but not
57# on OpenBSD.  Remove this difference to make it easier to compare the result
58# of "make releasetar" across different platforms.  From sed one-liners:
59# "delete all trailing blank lines at end of file (works on all seds)".  Don't
60# use mktemp(1) because AIX does not have it.
61CONFIGURE_NEW="configure.new$$"
62sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' <configure >"$CONFIGURE_NEW"
63cmp -s configure "$CONFIGURE_NEW" || cat "$CONFIGURE_NEW" >configure
64rm -f "$CONFIGURE_NEW"
65