H. Peter Anvin | cae5d06 | 2017-11-08 10:22:10 -0800 | [diff] [blame] | 1 | dnl Process this file with autoconf 2.69 or later to produce |
H. Peter Anvin | 1170eb6 | 2002-05-19 02:26:38 +0000 | [diff] [blame] | 2 | dnl a configure script. |
H. Peter Anvin | cae5d06 | 2017-11-08 10:22:10 -0800 | [diff] [blame] | 3 | AC_PREREQ(2.69) |
H. Peter Anvin | 97ea4ad | 2019-10-03 21:32:08 -0700 | [diff] [blame] | 4 | AC_INIT([config/config.h.in]) |
| 5 | AC_CONFIG_HEADERS([config/config.h]) |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 6 | AC_PREFIX_PROGRAM(nasm) |
H. Peter Anvin | 0bddd0f | 2019-02-22 01:13:52 -0800 | [diff] [blame] | 7 | AC_CONFIG_AUX_DIR(autoconf/helpers) |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 8 | |
H. Peter Anvin (Intel) | e204029 | 2020-07-06 11:10:30 -0700 | [diff] [blame] | 9 | dnl Mark where in config.h.in macros auto-generated by the configuration |
| 10 | dnl start; this is used to generate config/unconfig.h. |
| 11 | AH_BOTTOM([ |
| 12 | /* Begin unconfig.h */]) |
| 13 | |
H. Peter Anvin | 2d89477 | 2017-03-01 12:57:46 -0800 | [diff] [blame] | 14 | dnl Save initial CFLAGS, to see if -g -O2 came from configure or not |
| 15 | pa_init_cflags="$CFLAGS" |
| 16 | |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 17 | dnl This prevents us from running Wine and thinking we are not |
| 18 | dnl cross-compiling when in fact we are; running Wine here is at |
| 19 | dnl the best very slow and doesn't buy us a single thing at all. |
| 20 | WINELOADER=/dev/null |
| 21 | export WINELOADER |
| 22 | |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 23 | dnl Get the canonical target system name |
| 24 | AC_CANONICAL_HOST |
| 25 | |
H. Peter Anvin (Intel) | e8d6bba | 2020-07-09 19:12:25 -0700 | [diff] [blame^] | 26 | dnl Enable any available C extensions |
H. Peter Anvin | 2f0f9ea | 2008-06-08 20:53:29 -0700 | [diff] [blame] | 27 | AC_USE_SYSTEM_EXTENSIONS |
H. Peter Anvin | b423c02 | 2016-02-18 11:57:53 -0800 | [diff] [blame] | 28 | AC_SYS_LARGEFILE |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 29 | AC_PROG_CC |
H. Peter Anvin | d338b37 | 2016-02-18 00:54:30 -0800 | [diff] [blame] | 30 | AC_PROG_CC_STDC |
H. Peter Anvin (Intel) | e8d6bba | 2020-07-09 19:12:25 -0700 | [diff] [blame^] | 31 | PA_ADD_CFLAGS([-std=c11]) |
H. Peter Anvin | 48fd154 | 2018-06-14 19:19:09 -0700 | [diff] [blame] | 32 | |
| 33 | dnl If the user did not specify a CFLAGS default, change default |
| 34 | dnl to -O0 for debugging |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 35 | PA_ARG_DISABLED([optimization], |
| 36 | [compile without optimization (-O0) to help debugging], |
H. Peter Anvin | 48fd154 | 2018-06-14 19:19:09 -0700 | [diff] [blame] | 37 | [pa_no_optimize=true]) |
H. Peter Anvin | 9b935a0 | 2017-02-28 19:02:51 -0800 | [diff] [blame] | 38 | |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 39 | dnl Other programs |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 40 | pa_no_optimize=false |
| 41 | |
Cyrill Gorcunov | fdbf701 | 2017-07-29 16:05:36 +0300 | [diff] [blame] | 42 | dnl Compile and link with dwarf debug |
| 43 | PA_ARG_ENABLED([gdb], |
| 44 | [disable optimization and compile with extra debug information for GDB debugger], |
H. Peter Anvin | 48fd154 | 2018-06-14 19:19:09 -0700 | [diff] [blame] | 45 | [PA_ADD_CFLAGS([-ggdb3]) |
| 46 | pa_no_optimize=true]) |
H. Peter Anvin | 53259e8 | 2017-10-11 16:47:59 -0700 | [diff] [blame] | 47 | |
H. Peter Anvin | 48fd154 | 2018-06-14 19:19:09 -0700 | [diff] [blame] | 48 | AS_IF([$pa_no_optimize], |
| 49 | [PA_ADD_CFLAGS([-O0]) |
| 50 | PA_ADD_CFLAGS([-fno-omit-frame-pointer])]) |
Cyrill Gorcunov | fdbf701 | 2017-07-29 16:05:36 +0300 | [diff] [blame] | 51 | |
H. Peter Anvin | efee3ea | 2019-02-25 21:00:43 -0800 | [diff] [blame] | 52 | dnl Profiling |
| 53 | PA_ARG_ENABLED([profiling], |
| 54 | [compile with profiling (-pg option)], |
| 55 | [PA_ADD_CFLAGS([-pg])]) |
| 56 | |
H. Peter Anvin | dcbaf67 | 2017-12-20 12:06:54 -0800 | [diff] [blame] | 57 | dnl Abort on panic |
| 58 | PA_ARG_ENABLED([panic-abort], |
| 59 | [call abort() on panic to trap in the debugger], |
| 60 | [AC_DEFINE(ABORT_ON_PANIC)]) |
| 61 | AH_TEMPLATE(ABORT_ON_PANIC, |
| 62 | [Define to 1 to call abort() on panics (internal errors), for debugging.]) |
| 63 | |
Cyrill Gorcunov | 7729edf | 2014-12-20 11:35:51 +0300 | [diff] [blame] | 64 | dnl Checks for typedefs, structures, and compiler characteristics. |
Cyrill Gorcunov | 7729edf | 2014-12-20 11:35:51 +0300 | [diff] [blame] | 65 | AC_TYPE_SIZE_T |
H. Peter Anvin | ef63588 | 2016-03-01 21:53:09 -0800 | [diff] [blame] | 66 | AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,) |
Cyrill Gorcunov | 7729edf | 2014-12-20 11:35:51 +0300 | [diff] [blame] | 67 | AH_TEMPLATE(WORDS_BIGENDIAN, |
| 68 | [Define to 1 if your processor stores words with the most significant |
| 69 | byte first (like Motorola and SPARC, unlike Intel and VAX).]) |
| 70 | AH_TEMPLATE(WORDS_LITTLEENDIAN, |
| 71 | [Define to 1 if your processor stores words with the least significant |
| 72 | byte first (like Intel and VAX, unlike Motorola and SPARC).]) |
| 73 | |
H. Peter Anvin (Intel) | 0da8a88 | 2020-07-06 10:15:11 -0700 | [diff] [blame] | 74 | dnl LLVM doesn't error out on invalid -W options unless this option is |
| 75 | dnl specified first. Enable this so this script can actually discover |
| 76 | dnl which -W options are possible for this compiler. |
| 77 | PA_ADD_CFLAGS([-Werror=unknown-warning-option]) |
| 78 | |
H. Peter Anvin | b9c1ca7 | 2016-03-01 21:51:40 -0800 | [diff] [blame] | 79 | dnl Force gcc and gcc-compatible compilers treat signed integers |
| 80 | dnl as 2's complement |
H. Peter Anvin | 8d9f591 | 2016-02-27 00:15:13 -0800 | [diff] [blame] | 81 | PA_ADD_CFLAGS([-fwrapv]) |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 82 | |
H. Peter Anvin (Intel) | 0da8a88 | 2020-07-06 10:15:11 -0700 | [diff] [blame] | 83 | dnl Force clang to behave in a predictable manner, in order to make bugs |
| 84 | dnl possible to track down. gcc appears to have this behavior by default. |
H. Peter Anvin (Intel) | 0da8a88 | 2020-07-06 10:15:11 -0700 | [diff] [blame] | 85 | PA_ADD_CFLAGS([-ftrivial-auto-var-init=zero]) |
| 86 | |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 87 | dnl Some environments abuse __STRICT_ANSI__ to disable some |
| 88 | dnl function declarations |
| 89 | PA_ADD_CFLAGS([-U__STRICT_ANSI__]) |
| 90 | |
H. Peter Anvin | 43e0262 | 2016-08-02 09:28:22 -0700 | [diff] [blame] | 91 | dnl Don't put things in common if we can avoid it. We don't want to |
| 92 | dnl assume all compilers support common, and this will help find those |
| 93 | dnl problems. This also works around an OSX linker problem. |
| 94 | PA_ADD_CFLAGS([-fno-common]) |
| 95 | |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 96 | dnl Check for library extension |
| 97 | PA_LIBEXT |
H. Peter Anvin (Intel) | 30844a4 | 2020-07-06 12:39:14 -0700 | [diff] [blame] | 98 | |
H. Peter Anvin | eec3b52 | 2008-06-19 11:39:23 -0700 | [diff] [blame] | 99 | dnl Look for programs... |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 100 | AC_PROG_LN_S |
| 101 | AC_PROG_MAKE_SET |
| 102 | AC_PROG_INSTALL |
| 103 | AC_PROG_MKDIR_P |
| 104 | |
H. Peter Anvin | a939783 | 2013-05-17 12:02:49 -0700 | [diff] [blame] | 105 | AC_CHECK_PROGS(NROFF, nroff, false) |
H. Peter Anvin | d089c22 | 2013-10-24 13:22:19 +0100 | [diff] [blame] | 106 | AC_CHECK_PROGS(ASCIIDOC, asciidoc, false) |
| 107 | AC_CHECK_PROGS(XMLTO, xmlto, false) |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 108 | AC_CHECK_PROGS(XZ, xz, false) |
H. Peter Anvin | 620515a | 2002-04-30 20:57:38 +0000 | [diff] [blame] | 109 | |
H. Peter Anvin | d089c22 | 2013-10-24 13:22:19 +0100 | [diff] [blame] | 110 | dnl Check for progs needed for manpage generation |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 111 | MANPAGES=manpages |
| 112 | AS_IF([test x$ASCIIDOC = xfalse], |
| 113 | [AC_MSG_WARN([No asciidoc package found, cannot build man pages]) |
| 114 | MANPAGES=''] |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 115 | ) |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 116 | AS_IF([test x"$XMLTO" = xfalse], |
| 117 | [AC_MSG_WARN([No xmlto package found, cannot build man pages]) |
| 118 | MANPAGES=''] |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 119 | ) |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 120 | AC_SUBST([MANPAGES]) |
| 121 | |
| 122 | dnl Don't create .pdf.xz if there is no xz |
| 123 | AS_IF([test x"$XZ" = xfalse], |
| 124 | [], |
| 125 | [XZFILES=xzfiles]) |
| 126 | AC_SUBST([XZFILES]) |
| 127 | |
| 128 | dnl Can't create NSIS package if there is no makensis |
| 129 | dnl ... but it only applies to a Windows target ... |
| 130 | dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain" |
| 131 | dnl version of the program name, but it doesn't seem to. |
| 132 | AC_ARG_WITH([nsis], |
| 133 | [AS_HELP_STRING([[--with-nsis[=makensis]]], |
| 134 | [build an install .exe using NSIS on Windows hosts])], |
| 135 | [], [with_nsis=yes]) |
| 136 | AS_IF([test x"$MAKENSIS" = x], [], |
| 137 | [AS_IF([test x"$with_nsis" = xno], [] |
| 138 | [with_nsis="$MAKENSIS"])]) |
| 139 | |
| 140 | MAKENSIS=false |
| 141 | |
| 142 | AS_CASE([$host], |
| 143 | [*-win* | *-mingw*], |
| 144 | [AS_IF([test x"$with_nsis" = xno], [], |
| 145 | [NSIS=nsis |
| 146 | AS_IF([test x"$with_nsis" = xyes], |
| 147 | [AC_CHECK_TOOL(MAKENSIS_TOOL, makensis, false) |
| 148 | MAKENSIS="$MAKENSIS_TOOL" |
| 149 | AS_IF([test x"$MAKENSIS" = xfalse], |
| 150 | [AC_CHECK_PROGS(MAKENSIS_PLAIN, makensis, false) |
| 151 | MAKENSIS="$MAKENSIS_PLAIN"]) |
| 152 | AS_IF([test x"$MAKENSIS" = xfalse], |
| 153 | [AC_MSG_WARN([no makensis found, cannot build installer]) |
| 154 | NSIS=''])], |
| 155 | [MAKENSIS="$with_nsis"])])]) |
| 156 | AC_SUBST([MAKENSIS]) |
| 157 | AC_SUBST([NSIS]) |
H. Peter Anvin | d089c22 | 2013-10-24 13:22:19 +0100 | [diff] [blame] | 158 | |
H. Peter Anvin | cc147f7 | 2016-03-08 02:06:39 -0800 | [diff] [blame] | 159 | dnl Check for host compiler tools |
| 160 | AC_CHECK_TOOL(AR, ar) |
| 161 | AC_CHECK_TOOL(RANLIB, ranlib, :) |
| 162 | AC_CHECK_TOOL(STRIP, strip) |
| 163 | |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 164 | dnl |
| 165 | dnl NOTE: the tests for header files and library functions use constructs |
| 166 | dnl that create warnings on modern compilers, due to lack of prototypes, |
| 167 | dnl etc. Therefore, do not add the -Werror options before this. |
| 168 | dnl |
| 169 | |
| 170 | dnl Tests which may trigger warnings on some compilers |
| 171 | AC_C_CONST |
| 172 | AC_C_INLINE |
| 173 | AC_C_RESTRICT |
| 174 | |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 175 | dnl Checks for header files. |
| 176 | AC_HEADER_STDC |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 177 | PA_ADD_HEADERS(string.h) |
| 178 | PA_ADD_HEADERS(stdarg.h) |
H. Peter Anvin | 3ef4f00 | 2016-03-08 12:14:55 -0800 | [diff] [blame] | 179 | AC_CHECK_HEADERS(inttypes.h) |
H. Peter Anvin | fe50195 | 2007-10-02 21:53:51 -0700 | [diff] [blame] | 180 | AC_CHECK_HEADERS(strings.h) |
H. Peter Anvin | d338b37 | 2016-02-18 00:54:30 -0800 | [diff] [blame] | 181 | AC_HEADER_STDBOOL |
H. Peter Anvin | abd28c9 | 2016-12-20 02:29:58 -0800 | [diff] [blame] | 182 | AC_CHECK_HEADERS(stdnoreturn.h) |
H. Peter Anvin | e65e81b | 2016-02-18 14:24:40 -0800 | [diff] [blame] | 183 | AC_CHECK_HEADERS(io.h) |
H. Peter Anvin | d81a235 | 2016-09-21 14:03:18 -0700 | [diff] [blame] | 184 | AC_CHECK_HEADERS(fcntl.h) |
H. Peter Anvin | 4627e69 | 2016-01-26 12:01:34 -0800 | [diff] [blame] | 185 | AC_CHECK_HEADERS(unistd.h) |
H. Peter Anvin | d81a235 | 2016-09-21 14:03:18 -0700 | [diff] [blame] | 186 | AC_CHECK_HEADERS(sys/mman.h) |
H. Peter Anvin | 4c9132e | 2016-10-19 13:13:38 -0700 | [diff] [blame] | 187 | AC_CHECK_HEADERS(sys/types.h) |
H. Peter Anvin | 675e7b7 | 2017-04-05 21:19:03 -0700 | [diff] [blame] | 188 | AC_CHECK_HEADERS(sys/stat.h) |
H. Peter Anvin (Intel) | 5b4de52 | 2020-06-01 13:10:46 -0700 | [diff] [blame] | 189 | AC_CHECK_HEADERS(sys/resource.h) |
H. Peter Anvin | 4627e69 | 2016-01-26 12:01:34 -0800 | [diff] [blame] | 190 | |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 191 | dnl Checks for library functions. |
H. Peter Anvin | fe50195 | 2007-10-02 21:53:51 -0700 | [diff] [blame] | 192 | AC_CHECK_FUNCS(strcasecmp stricmp) |
| 193 | AC_CHECK_FUNCS(strncasecmp strnicmp) |
H. Peter Anvin | 73b22f5 | 2016-02-18 14:40:37 -0800 | [diff] [blame] | 194 | AC_CHECK_FUNCS(strsep) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 195 | AC_CHECK_FUNCS(strnlen) |
H. Peter Anvin | 81b62b9 | 2017-12-20 13:33:49 -0800 | [diff] [blame] | 196 | AC_CHECK_FUNCS(strrchrnul) |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 197 | AC_CHECK_FUNCS(iscntrl) |
| 198 | AC_CHECK_FUNCS(isascii) |
H. Peter Anvin | 06f72bb | 2018-12-26 06:22:47 -0800 | [diff] [blame] | 199 | AC_CHECK_FUNCS(mempcpy) |
H. Peter Anvin | fe50195 | 2007-10-02 21:53:51 -0700 | [diff] [blame] | 200 | |
H. Peter Anvin | 038d861 | 2007-04-12 16:54:50 +0000 | [diff] [blame] | 201 | AC_CHECK_FUNCS(getuid) |
| 202 | AC_CHECK_FUNCS(getgid) |
H. Peter Anvin (Intel) | 5b4de52 | 2020-06-01 13:10:46 -0700 | [diff] [blame] | 203 | AC_CHECK_FUNCS(getrlimit) |
H. Peter Anvin | 038d861 | 2007-04-12 16:54:50 +0000 | [diff] [blame] | 204 | |
H. Peter Anvin | 4627e69 | 2016-01-26 12:01:34 -0800 | [diff] [blame] | 205 | AC_CHECK_FUNCS(realpath) |
| 206 | AC_CHECK_FUNCS(canonicalize_file_name) |
| 207 | AC_CHECK_FUNCS(_fullpath) |
| 208 | AC_CHECK_FUNCS(pathconf) |
| 209 | |
H. Peter Anvin | e65e81b | 2016-02-18 14:24:40 -0800 | [diff] [blame] | 210 | AC_FUNC_FSEEKO |
H. Peter Anvin | ec82d7a | 2016-02-21 21:20:45 -0800 | [diff] [blame] | 211 | AC_CHECK_FUNCS([_fseeki64]) |
H. Peter Anvin | e65e81b | 2016-02-18 14:24:40 -0800 | [diff] [blame] | 212 | AC_CHECK_FUNCS([ftruncate _chsize _chsize_s]) |
H. Peter Anvin | 397c169 | 2016-10-04 17:01:59 -0700 | [diff] [blame] | 213 | AC_CHECK_FUNCS([fileno _fileno]) |
H. Peter Anvin | e65e81b | 2016-02-18 14:24:40 -0800 | [diff] [blame] | 214 | |
H. Peter Anvin | 895a66c | 2017-02-23 20:34:38 -0800 | [diff] [blame] | 215 | AC_FUNC_MMAP |
H. Peter Anvin | d81a235 | 2016-09-21 14:03:18 -0700 | [diff] [blame] | 216 | AC_CHECK_FUNCS(getpagesize) |
| 217 | AC_CHECK_FUNCS(sysconf) |
| 218 | |
H. Peter Anvin | 397c169 | 2016-10-04 17:01:59 -0700 | [diff] [blame] | 219 | AC_CHECK_FUNCS([access _access faccessat]) |
H. Peter Anvin | d81a235 | 2016-09-21 14:03:18 -0700 | [diff] [blame] | 220 | |
H. Peter Anvin | e558dfd | 2017-04-18 16:05:22 -0700 | [diff] [blame] | 221 | PA_HAVE_FUNC(__builtin_expect, (1,1)) |
| 222 | |
| 223 | dnl ilog2() building blocks |
| 224 | PA_ADD_HEADERS(intrin.h) |
H. Peter Anvin | 8d4fb26 | 2016-11-15 14:23:54 -0800 | [diff] [blame] | 225 | PA_HAVE_FUNC(__builtin_clz, (0U)) |
| 226 | PA_HAVE_FUNC(__builtin_clzl, (0UL)) |
| 227 | PA_HAVE_FUNC(__builtin_clzll, (0ULL)) |
H. Peter Anvin | e558dfd | 2017-04-18 16:05:22 -0700 | [diff] [blame] | 228 | PA_HAVE_FUNC(_BitScanReverse, (0)) |
| 229 | PA_HAVE_FUNC(_BitScanReverse64, (0)) |
H. Peter Anvin | d338b37 | 2016-02-18 00:54:30 -0800 | [diff] [blame] | 230 | |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 231 | PA_FUNC_SNPRINTF |
| 232 | PA_FUNC_VSNPRINTF |
H. Peter Anvin | cc147f7 | 2016-03-08 02:06:39 -0800 | [diff] [blame] | 233 | AC_CHECK_FUNCS([strlcpy]) |
H. Peter Anvin | 81b62b9 | 2017-12-20 13:33:49 -0800 | [diff] [blame] | 234 | AC_CHECK_FUNCS([strrchrnul]) |
H. Peter Anvin | d338b37 | 2016-02-18 00:54:30 -0800 | [diff] [blame] | 235 | |
H. Peter Anvin | 3118429 | 2017-04-06 15:30:56 -0700 | [diff] [blame] | 236 | dnl These types are POSIX-specific, and Windows does it differently... |
| 237 | AC_CHECK_TYPES([struct _stati64]) |
| 238 | AC_CHECK_TYPES([struct stat]) |
| 239 | AC_CHECK_FUNCS([stat _stati64]) |
| 240 | AC_CHECK_FUNCS([fstat _fstati64]) |
H. Peter Anvin (Intel) | 471120f | 2019-05-15 13:07:21 -0700 | [diff] [blame] | 241 | AC_CHECK_FUNCS([S_ISREG]) |
H. Peter Anvin | 3118429 | 2017-04-06 15:30:56 -0700 | [diff] [blame] | 242 | |
H. Peter Anvin | c13d31a | 2007-10-26 18:49:29 -0700 | [diff] [blame] | 243 | dnl Check for functions that might not be declared in the headers for |
| 244 | dnl various idiotic reasons (mostly because of library authors |
| 245 | dnl abusing the meaning of __STRICT_ANSI__) |
| 246 | AC_CHECK_DECLS(strcasecmp) |
| 247 | AC_CHECK_DECLS(stricmp) |
| 248 | AC_CHECK_DECLS(strncasecmp) |
| 249 | AC_CHECK_DECLS(strnicmp) |
| 250 | AC_CHECK_DECLS(strsep) |
H. Peter Anvin | eaa68f1 | 2009-08-10 15:56:52 -0700 | [diff] [blame] | 251 | AC_CHECK_DECLS(strlcpy) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 252 | AC_CHECK_DECLS(strnlen) |
H. Peter Anvin | 81b62b9 | 2017-12-20 13:33:49 -0800 | [diff] [blame] | 253 | AC_CHECK_DECLS(strrchrnul) |
H. Peter Anvin | c13d31a | 2007-10-26 18:49:29 -0700 | [diff] [blame] | 254 | |
H. Peter Anvin | d81a235 | 2016-09-21 14:03:18 -0700 | [diff] [blame] | 255 | dnl Check for missing types |
| 256 | AC_TYPE_UINTPTR_T |
| 257 | |
H. Peter Anvin | f13effe | 2017-04-10 16:10:28 -0700 | [diff] [blame] | 258 | dnl Documentation: should we generate an uncompressed PDF? It is |
| 259 | dnl about twice as big, but it can be externally compressed (e.g. with xz) |
| 260 | dnl and becomes significantly smaller than the original. |
| 261 | PA_ARG_DISABLED([pdf-compression], |
| 262 | [generate an uncompressed documentation PDF], |
| 263 | [PDFOPT='-nocompress']) |
| 264 | AC_SUBST([PDFOPT]) |
| 265 | |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 266 | dnl |
H. Peter Anvin | 5eb528b | 2017-04-18 15:49:25 -0700 | [diff] [blame] | 267 | dnl Look for byte-swapping support... |
| 268 | dnl |
H. Peter Anvin | e5033df | 2017-11-29 16:04:05 -0800 | [diff] [blame] | 269 | PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h) |
H. Peter Anvin | 5eb528b | 2017-04-18 15:49:25 -0700 | [diff] [blame] | 270 | PA_HAVE_FUNC(cpu_to_le16, (0)) |
| 271 | PA_HAVE_FUNC(cpu_to_le32, (0)) |
| 272 | PA_HAVE_FUNC(cpu_to_le64, (0)) |
| 273 | PA_HAVE_FUNC(__cpu_to_le16, (0)) |
| 274 | PA_HAVE_FUNC(__cpu_to_le32, (0)) |
| 275 | PA_HAVE_FUNC(__cpu_to_le64, (0)) |
| 276 | PA_HAVE_FUNC(htole16, (0)) |
| 277 | PA_HAVE_FUNC(htole32, (0)) |
| 278 | PA_HAVE_FUNC(htole64, (0)) |
| 279 | PA_HAVE_FUNC(__bswap_16, (0)) |
| 280 | PA_HAVE_FUNC(__bswap_32, (0)) |
| 281 | PA_HAVE_FUNC(__bswap_64, (0)) |
| 282 | PA_HAVE_FUNC(__builtin_bswap16, (0)) |
| 283 | PA_HAVE_FUNC(__builtin_bswap32, (0)) |
| 284 | PA_HAVE_FUNC(__builtin_bswap64, (0)) |
H. Peter Anvin | e558dfd | 2017-04-18 16:05:22 -0700 | [diff] [blame] | 285 | PA_HAVE_FUNC(_byteswap_ushort, (0)) |
| 286 | PA_HAVE_FUNC(_byteswap_ulong, (0)) |
| 287 | PA_HAVE_FUNC(_byteswap_uint64, (0)) |
H. Peter Anvin | 5eb528b | 2017-04-18 15:49:25 -0700 | [diff] [blame] | 288 | |
| 289 | dnl |
H. Peter Anvin (Intel) | b7f24e7 | 2018-12-14 14:21:16 -0800 | [diff] [blame] | 290 | dnl Some rather useful gcc extensions... |
H. Peter Anvin | e5033df | 2017-11-29 16:04:05 -0800 | [diff] [blame] | 291 | dnl |
| 292 | PA_HAVE_FUNC(__builtin_constant_p, (0)) |
H. Peter Anvin (Intel) | b7f24e7 | 2018-12-14 14:21:16 -0800 | [diff] [blame] | 293 | PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2)) |
H. Peter Anvin | e5033df | 2017-11-29 16:04:05 -0800 | [diff] [blame] | 294 | |
| 295 | dnl |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 296 | dnl Check for supported gcc attributes; some compilers (e.g. Sun CC) |
| 297 | dnl support these, but don't define __GNUC__ as they don't support |
| 298 | dnl some other features of gcc. |
| 299 | dnl |
H. Peter Anvin | bc18af1 | 2017-02-23 19:22:27 -0800 | [diff] [blame] | 300 | PA_ADD_CFLAGS([-Werror=attributes]) |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 301 | PA_FUNC_ATTRIBUTE(noreturn) |
H. Peter Anvin (Intel) | 8b6e6bf | 2019-08-16 00:08:27 -0700 | [diff] [blame] | 302 | PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null) |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 303 | PA_FUNC_ATTRIBUTE(malloc) |
H. Peter Anvin (Intel) | 8b6e6bf | 2019-08-16 00:08:27 -0700 | [diff] [blame] | 304 | PA_FUNC_ATTRIBUTE(alloc_size,[1]) |
| 305 | PA_FUNC_ATTRIBUTE(alloc_size,[1,2]) |
| 306 | PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null) |
| 307 | PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1]) |
H. Peter Anvin | 8b19083 | 2016-11-15 14:01:37 -0800 | [diff] [blame] | 308 | PA_FUNC_ATTRIBUTE(const) |
| 309 | PA_FUNC_ATTRIBUTE(pure) |
H. Peter Anvin (Intel) | 8b6e6bf | 2019-08-16 00:08:27 -0700 | [diff] [blame] | 310 | PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func) |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 311 | PA_FUNC_ATTRIBUTE(unused) |
H. Peter Anvin | abd28c9 | 2016-12-20 02:29:58 -0800 | [diff] [blame] | 312 | PA_FUNC_ATTRIBUTE_ERROR |
H. Peter Anvin | 87bc619 | 2002-04-30 20:53:16 +0000 | [diff] [blame] | 313 | |
Cyrill Gorcunov | 325768e | 2010-11-11 11:18:44 +0300 | [diff] [blame] | 314 | dnl |
H. Peter Anvin | 53259e8 | 2017-10-11 16:47:59 -0700 | [diff] [blame] | 315 | dnl support function sections (if available) |
Cyrill Gorcunov | 325768e | 2010-11-11 11:18:44 +0300 | [diff] [blame] | 316 | dnl |
H. Peter Anvin (Intel) | 7dc5b23 | 2018-12-13 22:51:22 -0800 | [diff] [blame] | 317 | PA_ARG_DISABLED([sections], |
Cyrill Gorcunov | 8274623 | 2018-12-23 17:15:41 +0300 | [diff] [blame] | 318 | [do not try to compile with function/data section support], |
H. Peter Anvin (Intel) | 7dc5b23 | 2018-12-13 22:51:22 -0800 | [diff] [blame] | 319 | [], |
H. Peter Anvin | b0121dc | 2018-12-22 18:17:16 -0800 | [diff] [blame] | 320 | [PA_ADD_CFLAGS([-ffunction-sections]) |
| 321 | PA_ADD_CFLAGS([-fdata-sections]) |
| 322 | PA_ADD_LDFLAGS([-Wl,--gc-sections])] |
H. Peter Anvin (Intel) | 7dc5b23 | 2018-12-13 22:51:22 -0800 | [diff] [blame] | 323 | ) |
H. Peter Anvin | 53259e8 | 2017-10-11 16:47:59 -0700 | [diff] [blame] | 324 | |
H. Peter Anvin | 5fe847e | 2017-02-28 18:48:01 -0800 | [diff] [blame] | 325 | dnl |
| 326 | dnl support LTO |
| 327 | dnl |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 328 | PA_ARG_ENABLED([lto], |
| 329 | [compile with gcc-style link time optimization], |
H. Peter Anvin | b0121dc | 2018-12-22 18:17:16 -0800 | [diff] [blame] | 330 | [PA_ADD_CFLAGS([-flto]) |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 331 | dnl Note: we use _PROG rather than _TOOL since we are prepending the full |
| 332 | dnl CC name which ought to already contain the host triplet if needed |
| 333 | ccbase=`echo "$CC" | awk '{ print $1; }'` |
| 334 | AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR]) |
| 335 | AR="$CC_AR" |
| 336 | AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB]) |
| 337 | RANLIB="$CC_RANLIB"], []) |
H. Peter Anvin | 5fe847e | 2017-02-28 18:48:01 -0800 | [diff] [blame] | 338 | |
H. Peter Anvin | 53259e8 | 2017-10-11 16:47:59 -0700 | [diff] [blame] | 339 | dnl |
| 340 | dnl support sanitizers (if available) |
| 341 | dnl |
| 342 | PA_ARG_ENABLED([sanitizer], |
| 343 | [compile with sanitizers enabled], |
| 344 | [PA_ADD_CFLAGS([-fno-omit-frame-pointer]) |
H. Peter Anvin | b0121dc | 2018-12-22 18:17:16 -0800 | [diff] [blame] | 345 | PA_ADD_CFLAGS([-fsanitize=address]) |
| 346 | PA_ADD_CFLAGS([-fsanitize=undefined])]) |
H. Peter Anvin | 53259e8 | 2017-10-11 16:47:59 -0700 | [diff] [blame] | 347 | |
H. Peter Anvin | 7310d0b | 2018-05-30 11:48:00 -0700 | [diff] [blame] | 348 | dnl |
| 349 | dnl Don't make symbols visible, there is no point and it just |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 350 | dnl makes the code slower. This mainly affects ELF. |
H. Peter Anvin | 7310d0b | 2018-05-30 11:48:00 -0700 | [diff] [blame] | 351 | dnl |
H. Peter Anvin | b0121dc | 2018-12-22 18:17:16 -0800 | [diff] [blame] | 352 | PA_ADD_CFLAGS([-fvisibility=hidden]) |
H. Peter Anvin | 7310d0b | 2018-05-30 11:48:00 -0700 | [diff] [blame] | 353 | |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 354 | dnl |
| 355 | dnl If we have gcc, add appropriate code cleanliness options. Do this |
| 356 | dnl here at the end, because configure relies on being able to use |
| 357 | dnl some very, very old C constructs. |
| 358 | dnl |
H. Peter Anvin | d338b37 | 2016-02-18 00:54:30 -0800 | [diff] [blame] | 359 | PA_ADD_CFLAGS([-Wall]) |
H. Peter Anvin (Intel) | 480d5e2 | 2019-08-16 00:52:26 -0700 | [diff] [blame] | 360 | PA_ARG_DISABLED([pedantic], |
| 361 | [disable some extra paranoid compiler warnings], |
| 362 | [], |
| 363 | [PA_ADD_CFLAGS([-W]) |
| 364 | PA_ADD_CFLAGS([-pedantic]) |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 365 | PA_ADD_CFLAGS([-Wc90-c99-compat]) |
| 366 | PA_ADD_CFLAGS([-Wc99-compat]) |
| 367 | PA_ADD_CFLAGS([-Wc99-extensions]) |
| 368 | ]) |
H. Peter Anvin | 25da6ea | 2016-03-01 22:20:10 -0800 | [diff] [blame] | 369 | dnl Suppress format warning on Windows targets due to their <inttypes.h> |
| 370 | PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format]) |
H. Peter Anvin | 25da6ea | 2016-03-01 22:20:10 -0800 | [diff] [blame] | 371 | PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long]) |
H. Peter Anvin | c4e16f7 | 2018-06-02 23:46:21 -0700 | [diff] [blame] | 372 | dnl This is needed because we intentionally expect strncpy() to fill |
| 373 | dnl in a zero-padded (not zero-terminated) buffer in several backends |
| 374 | PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation]) |
H. Peter Anvin (Intel) | 64b56ea | 2018-12-12 15:56:28 -0800 | [diff] [blame] | 375 | dnl This is needed because we assume 2's-completement signed arithmetic; |
| 376 | dnl on compilers with gcc-like command line syntax we pass the -fwrapv |
| 377 | dnl option for exactly that reason. |
| 378 | PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value]) |
| 379 | |
H. Peter Anvin (Intel) | 65ab3ab | 2020-06-30 10:14:21 -0700 | [diff] [blame] | 380 | dnl Want to turn this on at some point... |
H. Peter Anvin | cfd56eb | 2016-03-06 21:44:14 -0800 | [diff] [blame] | 381 | dnl PA_ADD_CFLAGS([-Wwrite-strings]) |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 382 | PA_ARG_ENABLED([werror], |
| 383 | [compile with -Werror to error out on any warning], |
| 384 | [PA_ADD_CFLAGS([-Werror])], |
| 385 | [PA_ADD_CFLAGS([-Werror=implicit]) |
| 386 | PA_ADD_CFLAGS([-Werror=missing-braces]) |
| 387 | PA_ADD_CFLAGS([-Werror=return-type]) |
| 388 | PA_ADD_CFLAGS([-Werror=trigraphs]) |
| 389 | PA_ADD_CFLAGS([-Werror=pointer-arith]) |
| 390 | PA_ADD_CFLAGS([-Werror=strict-prototypes]) |
| 391 | PA_ADD_CFLAGS([-Werror=missing-prototypes]) |
| 392 | PA_ADD_CFLAGS([-Werror=missing-declarations]) |
| 393 | PA_ADD_CFLAGS([-Werror=comment]) |
| 394 | PA_ADD_CFLAGS([-Werror=vla])] |
| 395 | ) |
Ozkan Sezer | ec3d426 | 2016-02-12 23:49:49 -0800 | [diff] [blame] | 396 | |
H. Peter Anvin | 0c36965 | 2017-02-28 19:34:36 -0800 | [diff] [blame] | 397 | dnl |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 398 | dnl Test compiler features. On some compilers, this can be affected |
| 399 | dnl by -Werror options, so run this *after* those options are added. |
H. Peter Anvin | 99d45c8 | 2018-02-20 12:34:17 -0800 | [diff] [blame] | 400 | dnl |
| 401 | PA_CHECK_BAD_STDC_INLINE |
H. Peter Anvin (Intel) | abcdf83 | 2020-07-09 19:04:28 -0700 | [diff] [blame] | 402 | PA_C_TYPEOF |
H. Peter Anvin | 99d45c8 | 2018-02-20 12:34:17 -0800 | [diff] [blame] | 403 | |
| 404 | dnl |
H. Peter Anvin | 0c36965 | 2017-02-28 19:34:36 -0800 | [diff] [blame] | 405 | dnl support ccache |
| 406 | dnl |
H. Peter Anvin | 0da1549 | 2017-04-06 15:24:58 -0700 | [diff] [blame] | 407 | PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], []) |
H. Peter Anvin | 0c36965 | 2017-02-28 19:34:36 -0800 | [diff] [blame] | 408 | |
H. Peter Anvin (Intel) | 941c75a | 2020-05-26 14:13:31 -0700 | [diff] [blame] | 409 | AC_CONFIG_FILES([Makefile doc/Makefile]) |
| 410 | AC_OUTPUT |