Commit 2155815234808373a00fcba67a59e40f40c564ee

Authored by Jay Berkenbilt
1 parent f562d494

configure: determine wordsize automatically

Based on sizeof(size_t). Assumes 64 if not 32.
README-maintainer
... ... @@ -90,6 +90,9 @@ RELEASE PREPARATION
90 90 * Test with clang. Pass `CC=clang CXX=clang++` to `./configure`. Test
91 91 with newer version of gcc if available.
92 92  
  93 +* Test 32-bit. Pass `CC=i686-linux-gnu-gcc CXX=i686-linux-gnu-g++` to
  94 + `./configure`.
  95 +
93 96 * Test build on a mac.
94 97  
95 98 * Test with address sanitizer as described above.
... ...
autoconf.mk.in
... ... @@ -41,6 +41,7 @@ OSS_FUZZ=@OSS_FUZZ@
41 41 QPDF_SKIP_TEST_COMPARE_IMAGES=@QPDF_SKIP_TEST_COMPARE_IMAGES@
42 42 BUILDRULES=@BUILDRULES@
43 43 HAVE_LD_VERSION_SCRIPT=@HAVE_LD_VERSION_SCRIPT@
  44 +IS_32BIT=@IS_32BIT@
44 45 WINDOWS_WORDSIZE=@WINDOWS_WORDSIZE@
45 46 WINDOWS_WMAIN_COMPILE=@WINDOWS_WMAIN_COMPILE@
46 47 WINDOWS_WMAIN_LINK=@WINDOWS_WMAIN_LINK@
... ...
autofiles.sums
1   -d6ab690ff0a692fae861cf77ede19245aa2e60bff561846085473ad7060df157 configure.ac
  1 +585322e3ca6c33acd1d8e3eb3da767c964e93f6fbeb0cf0d2c0cd11bb0b0a445 configure.ac
2 2 35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4
3 3 37f8897d5f68d7d484e5457832a8f190ddb7507fa2a467cb7ee2be40a4364643 m4/libtool.m4
4 4 e77ebba8361b36f14b4d0927173a034b98c5d05049697a9ded84d85eb99a7990 m4/ltoptions.m4
... ...
azure-pipelines/build-windows
... ... @@ -27,7 +27,7 @@ PATH=$cwd/libqpdf/build:$PATH
27 27  
28 28 installdir=install-$tool$wordsize
29 29 rm -rf $installdir
30   -./config-$tool --with-windows-wordsize=$wordsize --enable-show-failed-test-output
  30 +./config-$tool --enable-show-failed-test-output
31 31 make -j$(nproc) -k
32 32 make -k check
33 33 make install
... ...
config-mingw
... ... @@ -6,4 +6,4 @@ if echo $PATH | grep -q /mingw64; then
6 6 else
7 7 wordsize=32
8 8 fi
9   -./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-windows-wordsize=$wordsize --with-buildrules=mingw ${1+"$@"}
  9 +./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-buildrules=mingw ${1+"$@"}
... ...
config-msvc
... ... @@ -6,4 +6,4 @@ if echo $PATH | grep -q /mingw64; then
6 6 else
7 7 wordsize=32
8 8 fi
9   -CC=cl CXX="cl -TP -GR" ./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-windows-wordsize=$wordsize --with-buildrules=msvc ${1+"$@"}
  9 +CC=cl CXX="cl -TP -GR" ./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-buildrules=msvc ${1+"$@"}
... ...
configure
... ... @@ -651,6 +651,7 @@ QPDF_LARGE_FILE_TEST_PATH
651 651 WINDOWS_WMAIN_LINK
652 652 WINDOWS_WMAIN_COMPILE
653 653 WINDOWS_WORDSIZE
  654 +IS_32BIT
654 655 RANDOM_DEVICE
655 656 LT_SONAME
656 657 LT_AGE
... ... @@ -761,7 +762,6 @@ enable_os_secure_random
761 762 with_random
762 763 enable_avoid_windows_handle
763 764 enable_external_libs
764   -with_windows_wordsize
765 765 with_large_file_test_path
766 766 enable_largefile
767 767 enable_ld_version_script
... ... @@ -1468,9 +1468,6 @@ Optional Packages:
1468 1468 --with-sysroot[=DIR] Search for dependent libraries within DIR (or the
1469 1469 compiler's sysroot if not specified).
1470 1470 --with-random=FILE Use FILE as random number seed [auto-detected]
1471   - --with-windows-wordsize={32,64}
1472   - Windows only: whether this is a 32-bit or 64-bit
1473   - build; required if external-libs are enabled
1474 1471 --with-large-file-test-path=path
1475 1472 To enable testing of files > 4GB, give the path to a
1476 1473 directory with at least 11 GB free. The test suite
... ... @@ -1960,6 +1957,189 @@ fi
1960 1957  
1961 1958 } # ac_fn_cxx_try_link
1962 1959  
  1960 +# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
  1961 +# --------------------------------------------
  1962 +# Tries to find the compile-time value of EXPR in a program that includes
  1963 +# INCLUDES, setting VAR accordingly. Returns whether the value could be
  1964 +# computed
  1965 +ac_fn_c_compute_int ()
  1966 +{
  1967 + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  1968 + if test "$cross_compiling" = yes; then
  1969 + # Depending upon the size, compute the lo and hi bounds.
  1970 +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  1971 +/* end confdefs.h. */
  1972 +$4
  1973 +int
  1974 +main ()
  1975 +{
  1976 +static int test_array [1 - 2 * !(($2) >= 0)];
  1977 +test_array [0] = 0;
  1978 +return test_array [0];
  1979 +
  1980 + ;
  1981 + return 0;
  1982 +}
  1983 +_ACEOF
  1984 +if ac_fn_c_try_compile "$LINENO"; then :
  1985 + ac_lo=0 ac_mid=0
  1986 + while :; do
  1987 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  1988 +/* end confdefs.h. */
  1989 +$4
  1990 +int
  1991 +main ()
  1992 +{
  1993 +static int test_array [1 - 2 * !(($2) <= $ac_mid)];
  1994 +test_array [0] = 0;
  1995 +return test_array [0];
  1996 +
  1997 + ;
  1998 + return 0;
  1999 +}
  2000 +_ACEOF
  2001 +if ac_fn_c_try_compile "$LINENO"; then :
  2002 + ac_hi=$ac_mid; break
  2003 +else
  2004 + as_fn_arith $ac_mid + 1 && ac_lo=$as_val
  2005 + if test $ac_lo -le $ac_mid; then
  2006 + ac_lo= ac_hi=
  2007 + break
  2008 + fi
  2009 + as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val
  2010 +fi
  2011 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  2012 + done
  2013 +else
  2014 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  2015 +/* end confdefs.h. */
  2016 +$4
  2017 +int
  2018 +main ()
  2019 +{
  2020 +static int test_array [1 - 2 * !(($2) < 0)];
  2021 +test_array [0] = 0;
  2022 +return test_array [0];
  2023 +
  2024 + ;
  2025 + return 0;
  2026 +}
  2027 +_ACEOF
  2028 +if ac_fn_c_try_compile "$LINENO"; then :
  2029 + ac_hi=-1 ac_mid=-1
  2030 + while :; do
  2031 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  2032 +/* end confdefs.h. */
  2033 +$4
  2034 +int
  2035 +main ()
  2036 +{
  2037 +static int test_array [1 - 2 * !(($2) >= $ac_mid)];
  2038 +test_array [0] = 0;
  2039 +return test_array [0];
  2040 +
  2041 + ;
  2042 + return 0;
  2043 +}
  2044 +_ACEOF
  2045 +if ac_fn_c_try_compile "$LINENO"; then :
  2046 + ac_lo=$ac_mid; break
  2047 +else
  2048 + as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val
  2049 + if test $ac_mid -le $ac_hi; then
  2050 + ac_lo= ac_hi=
  2051 + break
  2052 + fi
  2053 + as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val
  2054 +fi
  2055 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  2056 + done
  2057 +else
  2058 + ac_lo= ac_hi=
  2059 +fi
  2060 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  2061 +fi
  2062 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  2063 +# Binary search between lo and hi bounds.
  2064 +while test "x$ac_lo" != "x$ac_hi"; do
  2065 + as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val
  2066 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  2067 +/* end confdefs.h. */
  2068 +$4
  2069 +int
  2070 +main ()
  2071 +{
  2072 +static int test_array [1 - 2 * !(($2) <= $ac_mid)];
  2073 +test_array [0] = 0;
  2074 +return test_array [0];
  2075 +
  2076 + ;
  2077 + return 0;
  2078 +}
  2079 +_ACEOF
  2080 +if ac_fn_c_try_compile "$LINENO"; then :
  2081 + ac_hi=$ac_mid
  2082 +else
  2083 + as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val
  2084 +fi
  2085 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  2086 +done
  2087 +case $ac_lo in #((
  2088 +?*) eval "$3=\$ac_lo"; ac_retval=0 ;;
  2089 +'') ac_retval=1 ;;
  2090 +esac
  2091 + else
  2092 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  2093 +/* end confdefs.h. */
  2094 +$4
  2095 +static long int longval () { return $2; }
  2096 +static unsigned long int ulongval () { return $2; }
  2097 +#include <stdio.h>
  2098 +#include <stdlib.h>
  2099 +int
  2100 +main ()
  2101 +{
  2102 +
  2103 + FILE *f = fopen ("conftest.val", "w");
  2104 + if (! f)
  2105 + return 1;
  2106 + if (($2) < 0)
  2107 + {
  2108 + long int i = longval ();
  2109 + if (i != ($2))
  2110 + return 1;
  2111 + fprintf (f, "%ld", i);
  2112 + }
  2113 + else
  2114 + {
  2115 + unsigned long int i = ulongval ();
  2116 + if (i != ($2))
  2117 + return 1;
  2118 + fprintf (f, "%lu", i);
  2119 + }
  2120 + /* Do not output a trailing newline, as this causes \r\n confusion
  2121 + on some platforms. */
  2122 + return ferror (f) || fclose (f) != 0;
  2123 +
  2124 + ;
  2125 + return 0;
  2126 +}
  2127 +_ACEOF
  2128 +if ac_fn_c_try_run "$LINENO"; then :
  2129 + echo >>conftest.val; read $3 <conftest.val; ac_retval=0
  2130 +else
  2131 + ac_retval=1
  2132 +fi
  2133 +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  2134 + conftest.$ac_objext conftest.beam conftest.$ac_ext
  2135 +rm -f conftest.val
  2136 +
  2137 + fi
  2138 + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2139 + as_fn_set_status $ac_retval
  2140 +
  2141 +} # ac_fn_c_compute_int
  2142 +
1963 2143 # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
1964 2144 # -------------------------------------------------------
1965 2145 # Tests whether HEADER exists, giving a warning if it cannot be compiled using
... ... @@ -15836,25 +16016,48 @@ else
15836 16016 $as_echo "yes" >&6; }
15837 16017 fi
15838 16018  
15839   -WINDOWS_WORDSIZE=
15840   -
  16019 +# The cast to long int works around a bug in the HP C Compiler
  16020 +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
  16021 +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
  16022 +# This bug is HP SR number 8606223364.
  16023 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5
  16024 +$as_echo_n "checking size of size_t... " >&6; }
  16025 +if ${ac_cv_sizeof_size_t+:} false; then :
  16026 + $as_echo_n "(cached) " >&6
  16027 +else
  16028 + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default"; then :
15841 16029  
15842   -# Check whether --with-windows-wordsize was given.
15843   -if test "${with_windows_wordsize+set}" = set; then :
15844   - withval=$with_windows_wordsize; WINDOWS_WORDSIZE=$withval
15845 16030 else
15846   - WINDOWS_WORDSIZE=none
  16031 + if test "$ac_cv_type_size_t" = yes; then
  16032 + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  16033 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  16034 +as_fn_error 77 "cannot compute sizeof (size_t)
  16035 +See \`config.log' for more details" "$LINENO" 5; }
  16036 + else
  16037 + ac_cv_sizeof_size_t=0
  16038 + fi
15847 16039 fi
15848 16040  
15849   -if test "$USE_EXTERNAL_LIBS" = "1"; then
15850   - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for windows wordsize" >&5
15851   -$as_echo_n "checking for windows wordsize... " >&6; }
15852   - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WINDOWS_WORDSIZE" >&5
15853   -$as_echo "$WINDOWS_WORDSIZE" >&6; }
15854   - if ! test "$WINDOWS_WORDSIZE" = "32" -o "$WINDOWS_WORDSIZE" = "64"; then
15855   - as_fn_error $? "Windows wordsize of 32 or 64 must be specified if external libs are being used." "$LINENO" 5
15856   - fi
15857 16041 fi
  16042 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5
  16043 +$as_echo "$ac_cv_sizeof_size_t" >&6; }
  16044 +
  16045 +
  16046 +
  16047 +cat >>confdefs.h <<_ACEOF
  16048 +#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t
  16049 +_ACEOF
  16050 +
  16051 +
  16052 +if test "$ac_cv_sizeof_size_t" = "4"; then
  16053 + IS_32BIT=1
  16054 + WINDOWS_WORDSIZE=32
  16055 +else
  16056 + IS_32BIT=0
  16057 + WINDOWS_WORDSIZE=64
  16058 +fi
  16059 +
  16060 +
15858 16061  
15859 16062 if test "$BUILD_INTERNAL_LIBS" = "0"; then
15860 16063 ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default"
... ...
configure.ac
... ... @@ -123,20 +123,16 @@ else
123 123 AC_MSG_RESULT(yes)
124 124 fi
125 125  
126   -WINDOWS_WORDSIZE=
127   -AC_SUBST(WINDOWS_WORDSIZE)
128   -AC_ARG_WITH(windows-wordsize,
129   - AS_HELP_STRING([--with-windows-wordsize={32,64}],
130   - [Windows only: whether this is a 32-bit or 64-bit build; required if external-libs are enabled]),
131   - [WINDOWS_WORDSIZE=$withval],
132   - [WINDOWS_WORDSIZE=none])
133   -if test "$USE_EXTERNAL_LIBS" = "1"; then
134   - AC_MSG_CHECKING(for windows wordsize)
135   - AC_MSG_RESULT($WINDOWS_WORDSIZE)
136   - if ! test "$WINDOWS_WORDSIZE" = "32" -o "$WINDOWS_WORDSIZE" = "64"; then
137   - AC_MSG_ERROR(Windows wordsize of 32 or 64 must be specified if external libs are being used.)
138   - fi
  126 +AC_CHECK_SIZEOF([size_t])
  127 +if test "$ac_cv_sizeof_size_t" = "4"; then
  128 + IS_32BIT=1
  129 + WINDOWS_WORDSIZE=32
  130 +else
  131 + IS_32BIT=0
  132 + WINDOWS_WORDSIZE=64
139 133 fi
  134 +AC_SUBST(IS_32BIT)
  135 +AC_SUBST(WINDOWS_WORDSIZE)
140 136  
141 137 if test "$BUILD_INTERNAL_LIBS" = "0"; then
142 138 AC_CHECK_HEADER(zlib.h,,[MISSING_ZLIB_H=1; MISSING_ANY=1])
... ...
libqpdf/qpdf/qpdf-config.h.in
... ... @@ -69,6 +69,9 @@
69 69 /* Define to the filename of the random device (and set HAVE_RANDOM_DEVICE) */
70 70 #undef RANDOM_DEVICE
71 71  
  72 +/* The size of `size_t', as computed by sizeof. */
  73 +#undef SIZEOF_SIZE_T
  74 +
72 75 /* Whether to suppres use of OS-provided secure random numbers */
73 76 #undef SKIP_OS_SECURE_RANDOM
74 77  
... ...