blob: 7f0548989a14c1dfed0cd268a7cfcb5a7c99c294 [file] [log] [blame]
H. Peter Anvincae5d062017-11-08 10:22:10 -08001dnl Process this file with autoconf 2.69 or later to produce
H. Peter Anvin1170eb62002-05-19 02:26:38 +00002dnl a configure script.
H. Peter Anvincae5d062017-11-08 10:22:10 -08003AC_PREREQ(2.69)
H. Peter Anvin97ea4ad2019-10-03 21:32:08 -07004AC_INIT([config/config.h.in])
5AC_CONFIG_HEADERS([config/config.h])
H. Peter Anvin87bc6192002-04-30 20:53:16 +00006AC_PREFIX_PROGRAM(nasm)
H. Peter Anvin0bddd0f2019-02-22 01:13:52 -08007AC_CONFIG_AUX_DIR(autoconf/helpers)
H. Peter Anvin87bc6192002-04-30 20:53:16 +00008
H. Peter Anvin (Intel)e2040292020-07-06 11:10:30 -07009dnl Mark where in config.h.in macros auto-generated by the configuration
10dnl start; this is used to generate config/unconfig.h.
11AH_BOTTOM([
12/* Begin unconfig.h */])
13
H. Peter Anvin2d894772017-03-01 12:57:46 -080014dnl Save initial CFLAGS, to see if -g -O2 came from configure or not
15pa_init_cflags="$CFLAGS"
16
H. Peter Anvin0da15492017-04-06 15:24:58 -070017dnl This prevents us from running Wine and thinking we are not
18dnl cross-compiling when in fact we are; running Wine here is at
19dnl the best very slow and doesn't buy us a single thing at all.
20WINELOADER=/dev/null
21export WINELOADER
22
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -070023dnl Get the canonical target system name
24AC_CANONICAL_HOST
25
H. Peter Anvin (Intel)e8d6bba2020-07-09 19:12:25 -070026dnl Enable any available C extensions
H. Peter Anvin2f0f9ea2008-06-08 20:53:29 -070027AC_USE_SYSTEM_EXTENSIONS
H. Peter Anvinb423c022016-02-18 11:57:53 -080028AC_SYS_LARGEFILE
H. Peter Anvin87bc6192002-04-30 20:53:16 +000029AC_PROG_CC
H. Peter Anvind338b372016-02-18 00:54:30 -080030AC_PROG_CC_STDC
H. Peter Anvin (Intel)e8d6bba2020-07-09 19:12:25 -070031PA_ADD_CFLAGS([-std=c11])
H. Peter Anvin48fd1542018-06-14 19:19:09 -070032
33dnl If the user did not specify a CFLAGS default, change default
34dnl to -O0 for debugging
H. Peter Anvin0da15492017-04-06 15:24:58 -070035PA_ARG_DISABLED([optimization],
36 [compile without optimization (-O0) to help debugging],
H. Peter Anvin48fd1542018-06-14 19:19:09 -070037 [pa_no_optimize=true])
H. Peter Anvin9b935a02017-02-28 19:02:51 -080038
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -070039dnl Other programs
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -070040pa_no_optimize=false
41
Cyrill Gorcunovfdbf7012017-07-29 16:05:36 +030042dnl Compile and link with dwarf debug
43PA_ARG_ENABLED([gdb],
44 [disable optimization and compile with extra debug information for GDB debugger],
H. Peter Anvin48fd1542018-06-14 19:19:09 -070045 [PA_ADD_CFLAGS([-ggdb3])
46 pa_no_optimize=true])
H. Peter Anvin53259e82017-10-11 16:47:59 -070047
H. Peter Anvin48fd1542018-06-14 19:19:09 -070048AS_IF([$pa_no_optimize],
49 [PA_ADD_CFLAGS([-O0])
50 PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
Cyrill Gorcunovfdbf7012017-07-29 16:05:36 +030051
H. Peter Anvinefee3ea2019-02-25 21:00:43 -080052dnl Profiling
53PA_ARG_ENABLED([profiling],
54 [compile with profiling (-pg option)],
55 [PA_ADD_CFLAGS([-pg])])
56
H. Peter Anvindcbaf672017-12-20 12:06:54 -080057dnl Abort on panic
58PA_ARG_ENABLED([panic-abort],
59 [call abort() on panic to trap in the debugger],
60 [AC_DEFINE(ABORT_ON_PANIC)])
61AH_TEMPLATE(ABORT_ON_PANIC,
62[Define to 1 to call abort() on panics (internal errors), for debugging.])
63
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030064dnl Checks for typedefs, structures, and compiler characteristics.
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030065AC_TYPE_SIZE_T
H. Peter Anvinef635882016-03-01 21:53:09 -080066AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030067AH_TEMPLATE(WORDS_BIGENDIAN,
68[Define to 1 if your processor stores words with the most significant
69byte first (like Motorola and SPARC, unlike Intel and VAX).])
70AH_TEMPLATE(WORDS_LITTLEENDIAN,
71[Define to 1 if your processor stores words with the least significant
72byte first (like Intel and VAX, unlike Motorola and SPARC).])
73
H. Peter Anvin (Intel)0da8a882020-07-06 10:15:11 -070074dnl LLVM doesn't error out on invalid -W options unless this option is
75dnl specified first. Enable this so this script can actually discover
76dnl which -W options are possible for this compiler.
77PA_ADD_CFLAGS([-Werror=unknown-warning-option])
78
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -080079dnl Force gcc and gcc-compatible compilers treat signed integers
80dnl as 2's complement
H. Peter Anvin8d9f5912016-02-27 00:15:13 -080081PA_ADD_CFLAGS([-fwrapv])
H. Peter Anvin87bc6192002-04-30 20:53:16 +000082
H. Peter Anvin (Intel)0da8a882020-07-06 10:15:11 -070083dnl Force clang to behave in a predictable manner, in order to make bugs
84dnl possible to track down. gcc appears to have this behavior by default.
H. Peter Anvin (Intel)0da8a882020-07-06 10:15:11 -070085PA_ADD_CFLAGS([-ftrivial-auto-var-init=zero])
86
H. Peter Anvin8b190832016-11-15 14:01:37 -080087dnl Some environments abuse __STRICT_ANSI__ to disable some
88dnl function declarations
89PA_ADD_CFLAGS([-U__STRICT_ANSI__])
90
H. Peter Anvin43e02622016-08-02 09:28:22 -070091dnl Don't put things in common if we can avoid it. We don't want to
92dnl assume all compilers support common, and this will help find those
93dnl problems. This also works around an OSX linker problem.
94PA_ADD_CFLAGS([-fno-common])
95
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -070096dnl Check for library extension
97PA_LIBEXT
H. Peter Anvin (Intel)30844a42020-07-06 12:39:14 -070098
H. Peter Anvineec3b522008-06-19 11:39:23 -070099dnl Look for programs...
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700100AC_PROG_LN_S
101AC_PROG_MAKE_SET
102AC_PROG_INSTALL
103AC_PROG_MKDIR_P
104
H. Peter Anvina9397832013-05-17 12:02:49 -0700105AC_CHECK_PROGS(NROFF, nroff, false)
H. Peter Anvind089c222013-10-24 13:22:19 +0100106AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
107AC_CHECK_PROGS(XMLTO, xmlto, false)
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -0700108AC_CHECK_PROGS(XZ, xz, false)
H. Peter Anvin620515a2002-04-30 20:57:38 +0000109
H. Peter Anvind089c222013-10-24 13:22:19 +0100110dnl Check for progs needed for manpage generation
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -0700111MANPAGES=manpages
112AS_IF([test x$ASCIIDOC = xfalse],
113 [AC_MSG_WARN([No asciidoc package found, cannot build man pages])
114 MANPAGES='']
H. Peter Anvin0da15492017-04-06 15:24:58 -0700115)
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -0700116AS_IF([test x"$XMLTO" = xfalse],
117 [AC_MSG_WARN([No xmlto package found, cannot build man pages])
118 MANPAGES='']
H. Peter Anvin0da15492017-04-06 15:24:58 -0700119)
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -0700120AC_SUBST([MANPAGES])
121
122dnl Don't create .pdf.xz if there is no xz
123AS_IF([test x"$XZ" = xfalse],
124 [],
125 [XZFILES=xzfiles])
126AC_SUBST([XZFILES])
127
128dnl Can't create NSIS package if there is no makensis
129dnl ... but it only applies to a Windows target ...
130dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain"
131dnl version of the program name, but it doesn't seem to.
132AC_ARG_WITH([nsis],
133[AS_HELP_STRING([[--with-nsis[=makensis]]],
134 [build an install .exe using NSIS on Windows hosts])],
135 [], [with_nsis=yes])
136AS_IF([test x"$MAKENSIS" = x], [],
137 [AS_IF([test x"$with_nsis" = xno], []
138 [with_nsis="$MAKENSIS"])])
139
140MAKENSIS=false
141
142AS_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"])])])
156AC_SUBST([MAKENSIS])
157AC_SUBST([NSIS])
H. Peter Anvind089c222013-10-24 13:22:19 +0100158
H. Peter Anvincc147f72016-03-08 02:06:39 -0800159dnl Check for host compiler tools
160AC_CHECK_TOOL(AR, ar)
161AC_CHECK_TOOL(RANLIB, ranlib, :)
162AC_CHECK_TOOL(STRIP, strip)
163
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700164dnl
165dnl NOTE: the tests for header files and library functions use constructs
166dnl that create warnings on modern compilers, due to lack of prototypes,
167dnl etc. Therefore, do not add the -Werror options before this.
168dnl
169
170dnl Tests which may trigger warnings on some compilers
171AC_C_CONST
172AC_C_INLINE
173AC_C_RESTRICT
174
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000175dnl Checks for header files.
176AC_HEADER_STDC
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700177PA_ADD_HEADERS(string.h)
178PA_ADD_HEADERS(stdarg.h)
H. Peter Anvin3ef4f002016-03-08 12:14:55 -0800179AC_CHECK_HEADERS(inttypes.h)
H. Peter Anvinfe501952007-10-02 21:53:51 -0700180AC_CHECK_HEADERS(strings.h)
H. Peter Anvind338b372016-02-18 00:54:30 -0800181AC_HEADER_STDBOOL
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800182AC_CHECK_HEADERS(stdnoreturn.h)
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800183AC_CHECK_HEADERS(io.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -0700184AC_CHECK_HEADERS(fcntl.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -0800185AC_CHECK_HEADERS(unistd.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -0700186AC_CHECK_HEADERS(sys/mman.h)
H. Peter Anvin4c9132e2016-10-19 13:13:38 -0700187AC_CHECK_HEADERS(sys/types.h)
H. Peter Anvin675e7b72017-04-05 21:19:03 -0700188AC_CHECK_HEADERS(sys/stat.h)
H. Peter Anvin (Intel)5b4de522020-06-01 13:10:46 -0700189AC_CHECK_HEADERS(sys/resource.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -0800190
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000191dnl Checks for library functions.
H. Peter Anvinfe501952007-10-02 21:53:51 -0700192AC_CHECK_FUNCS(strcasecmp stricmp)
193AC_CHECK_FUNCS(strncasecmp strnicmp)
H. Peter Anvin73b22f52016-02-18 14:40:37 -0800194AC_CHECK_FUNCS(strsep)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700195AC_CHECK_FUNCS(strnlen)
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800196AC_CHECK_FUNCS(strrchrnul)
H. Peter Anvin13506202018-11-28 14:55:58 -0800197AC_CHECK_FUNCS(iscntrl)
198AC_CHECK_FUNCS(isascii)
H. Peter Anvin06f72bb2018-12-26 06:22:47 -0800199AC_CHECK_FUNCS(mempcpy)
H. Peter Anvinfe501952007-10-02 21:53:51 -0700200
H. Peter Anvin038d8612007-04-12 16:54:50 +0000201AC_CHECK_FUNCS(getuid)
202AC_CHECK_FUNCS(getgid)
H. Peter Anvin (Intel)5b4de522020-06-01 13:10:46 -0700203AC_CHECK_FUNCS(getrlimit)
H. Peter Anvin038d8612007-04-12 16:54:50 +0000204
H. Peter Anvin4627e692016-01-26 12:01:34 -0800205AC_CHECK_FUNCS(realpath)
206AC_CHECK_FUNCS(canonicalize_file_name)
207AC_CHECK_FUNCS(_fullpath)
208AC_CHECK_FUNCS(pathconf)
209
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800210AC_FUNC_FSEEKO
H. Peter Anvinec82d7a2016-02-21 21:20:45 -0800211AC_CHECK_FUNCS([_fseeki64])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800212AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
H. Peter Anvin397c1692016-10-04 17:01:59 -0700213AC_CHECK_FUNCS([fileno _fileno])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800214
H. Peter Anvin895a66c2017-02-23 20:34:38 -0800215AC_FUNC_MMAP
H. Peter Anvind81a2352016-09-21 14:03:18 -0700216AC_CHECK_FUNCS(getpagesize)
217AC_CHECK_FUNCS(sysconf)
218
H. Peter Anvin397c1692016-10-04 17:01:59 -0700219AC_CHECK_FUNCS([access _access faccessat])
H. Peter Anvind81a2352016-09-21 14:03:18 -0700220
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700221PA_HAVE_FUNC(__builtin_expect, (1,1))
222
223dnl ilog2() building blocks
224PA_ADD_HEADERS(intrin.h)
H. Peter Anvin8d4fb262016-11-15 14:23:54 -0800225PA_HAVE_FUNC(__builtin_clz, (0U))
226PA_HAVE_FUNC(__builtin_clzl, (0UL))
227PA_HAVE_FUNC(__builtin_clzll, (0ULL))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700228PA_HAVE_FUNC(_BitScanReverse, (0))
229PA_HAVE_FUNC(_BitScanReverse64, (0))
H. Peter Anvind338b372016-02-18 00:54:30 -0800230
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700231PA_FUNC_SNPRINTF
232PA_FUNC_VSNPRINTF
H. Peter Anvincc147f72016-03-08 02:06:39 -0800233AC_CHECK_FUNCS([strlcpy])
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800234AC_CHECK_FUNCS([strrchrnul])
H. Peter Anvind338b372016-02-18 00:54:30 -0800235
H. Peter Anvin31184292017-04-06 15:30:56 -0700236dnl These types are POSIX-specific, and Windows does it differently...
237AC_CHECK_TYPES([struct _stati64])
238AC_CHECK_TYPES([struct stat])
239AC_CHECK_FUNCS([stat _stati64])
240AC_CHECK_FUNCS([fstat _fstati64])
H. Peter Anvin (Intel)471120f2019-05-15 13:07:21 -0700241AC_CHECK_FUNCS([S_ISREG])
H. Peter Anvin31184292017-04-06 15:30:56 -0700242
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700243dnl Check for functions that might not be declared in the headers for
244dnl various idiotic reasons (mostly because of library authors
245dnl abusing the meaning of __STRICT_ANSI__)
246AC_CHECK_DECLS(strcasecmp)
247AC_CHECK_DECLS(stricmp)
248AC_CHECK_DECLS(strncasecmp)
249AC_CHECK_DECLS(strnicmp)
250AC_CHECK_DECLS(strsep)
H. Peter Anvineaa68f12009-08-10 15:56:52 -0700251AC_CHECK_DECLS(strlcpy)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700252AC_CHECK_DECLS(strnlen)
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800253AC_CHECK_DECLS(strrchrnul)
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700254
H. Peter Anvind81a2352016-09-21 14:03:18 -0700255dnl Check for missing types
256AC_TYPE_UINTPTR_T
257
H. Peter Anvinf13effe2017-04-10 16:10:28 -0700258dnl Documentation: should we generate an uncompressed PDF? It is
259dnl about twice as big, but it can be externally compressed (e.g. with xz)
260dnl and becomes significantly smaller than the original.
261PA_ARG_DISABLED([pdf-compression],
262 [generate an uncompressed documentation PDF],
263 [PDFOPT='-nocompress'])
264AC_SUBST([PDFOPT])
265
H. Peter Anvin8b190832016-11-15 14:01:37 -0800266dnl
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700267dnl Look for byte-swapping support...
268dnl
H. Peter Anvine5033df2017-11-29 16:04:05 -0800269PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700270PA_HAVE_FUNC(cpu_to_le16, (0))
271PA_HAVE_FUNC(cpu_to_le32, (0))
272PA_HAVE_FUNC(cpu_to_le64, (0))
273PA_HAVE_FUNC(__cpu_to_le16, (0))
274PA_HAVE_FUNC(__cpu_to_le32, (0))
275PA_HAVE_FUNC(__cpu_to_le64, (0))
276PA_HAVE_FUNC(htole16, (0))
277PA_HAVE_FUNC(htole32, (0))
278PA_HAVE_FUNC(htole64, (0))
279PA_HAVE_FUNC(__bswap_16, (0))
280PA_HAVE_FUNC(__bswap_32, (0))
281PA_HAVE_FUNC(__bswap_64, (0))
282PA_HAVE_FUNC(__builtin_bswap16, (0))
283PA_HAVE_FUNC(__builtin_bswap32, (0))
284PA_HAVE_FUNC(__builtin_bswap64, (0))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700285PA_HAVE_FUNC(_byteswap_ushort, (0))
286PA_HAVE_FUNC(_byteswap_ulong, (0))
287PA_HAVE_FUNC(_byteswap_uint64, (0))
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700288
289dnl
H. Peter Anvin (Intel)b7f24e72018-12-14 14:21:16 -0800290dnl Some rather useful gcc extensions...
H. Peter Anvine5033df2017-11-29 16:04:05 -0800291dnl
292PA_HAVE_FUNC(__builtin_constant_p, (0))
H. Peter Anvin (Intel)b7f24e72018-12-14 14:21:16 -0800293PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
H. Peter Anvine5033df2017-11-29 16:04:05 -0800294
295dnl
H. Peter Anvin8b190832016-11-15 14:01:37 -0800296dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
297dnl support these, but don't define __GNUC__ as they don't support
298dnl some other features of gcc.
299dnl
H. Peter Anvinbc18af12017-02-23 19:22:27 -0800300PA_ADD_CFLAGS([-Werror=attributes])
H. Peter Anvin8b190832016-11-15 14:01:37 -0800301PA_FUNC_ATTRIBUTE(noreturn)
H. Peter Anvin (Intel)8b6e6bf2019-08-16 00:08:27 -0700302PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null)
H. Peter Anvin8b190832016-11-15 14:01:37 -0800303PA_FUNC_ATTRIBUTE(malloc)
H. Peter Anvin (Intel)8b6e6bf2019-08-16 00:08:27 -0700304PA_FUNC_ATTRIBUTE(alloc_size,[1])
305PA_FUNC_ATTRIBUTE(alloc_size,[1,2])
306PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null)
307PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1])
H. Peter Anvin8b190832016-11-15 14:01:37 -0800308PA_FUNC_ATTRIBUTE(const)
309PA_FUNC_ATTRIBUTE(pure)
H. Peter Anvin (Intel)8b6e6bf2019-08-16 00:08:27 -0700310PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -0700311PA_FUNC_ATTRIBUTE(unused)
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800312PA_FUNC_ATTRIBUTE_ERROR
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000313
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300314dnl
H. Peter Anvin53259e82017-10-11 16:47:59 -0700315dnl support function sections (if available)
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300316dnl
H. Peter Anvin (Intel)7dc5b232018-12-13 22:51:22 -0800317PA_ARG_DISABLED([sections],
Cyrill Gorcunov82746232018-12-23 17:15:41 +0300318 [do not try to compile with function/data section support],
H. Peter Anvin (Intel)7dc5b232018-12-13 22:51:22 -0800319 [],
H. Peter Anvinb0121dc2018-12-22 18:17:16 -0800320 [PA_ADD_CFLAGS([-ffunction-sections])
321 PA_ADD_CFLAGS([-fdata-sections])
322 PA_ADD_LDFLAGS([-Wl,--gc-sections])]
H. Peter Anvin (Intel)7dc5b232018-12-13 22:51:22 -0800323 )
H. Peter Anvin53259e82017-10-11 16:47:59 -0700324
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800325dnl
326dnl support LTO
327dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700328PA_ARG_ENABLED([lto],
329 [compile with gcc-style link time optimization],
H. Peter Anvinb0121dc2018-12-22 18:17:16 -0800330 [PA_ADD_CFLAGS([-flto])
H. Peter Anvin0da15492017-04-06 15:24:58 -0700331 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 Anvin5fe847e2017-02-28 18:48:01 -0800338
H. Peter Anvin53259e82017-10-11 16:47:59 -0700339dnl
340dnl support sanitizers (if available)
341dnl
342PA_ARG_ENABLED([sanitizer],
343 [compile with sanitizers enabled],
344 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
H. Peter Anvinb0121dc2018-12-22 18:17:16 -0800345 PA_ADD_CFLAGS([-fsanitize=address])
346 PA_ADD_CFLAGS([-fsanitize=undefined])])
H. Peter Anvin53259e82017-10-11 16:47:59 -0700347
H. Peter Anvin7310d0b2018-05-30 11:48:00 -0700348dnl
349dnl Don't make symbols visible, there is no point and it just
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -0700350dnl makes the code slower. This mainly affects ELF.
H. Peter Anvin7310d0b2018-05-30 11:48:00 -0700351dnl
H. Peter Anvinb0121dc2018-12-22 18:17:16 -0800352PA_ADD_CFLAGS([-fvisibility=hidden])
H. Peter Anvin7310d0b2018-05-30 11:48:00 -0700353
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -0700354dnl
355dnl If we have gcc, add appropriate code cleanliness options. Do this
356dnl here at the end, because configure relies on being able to use
357dnl some very, very old C constructs.
358dnl
H. Peter Anvind338b372016-02-18 00:54:30 -0800359PA_ADD_CFLAGS([-Wall])
H. Peter Anvin (Intel)480d5e22019-08-16 00:52:26 -0700360PA_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)65ab3ab2020-06-30 10:14:21 -0700365 PA_ADD_CFLAGS([-Wc90-c99-compat])
366 PA_ADD_CFLAGS([-Wc99-compat])
367 PA_ADD_CFLAGS([-Wc99-extensions])
368])
H. Peter Anvin25da6ea2016-03-01 22:20:10 -0800369dnl Suppress format warning on Windows targets due to their <inttypes.h>
370PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
H. Peter Anvin25da6ea2016-03-01 22:20:10 -0800371PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
H. Peter Anvinc4e16f72018-06-02 23:46:21 -0700372dnl This is needed because we intentionally expect strncpy() to fill
373dnl in a zero-padded (not zero-terminated) buffer in several backends
374PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
H. Peter Anvin (Intel)64b56ea2018-12-12 15:56:28 -0800375dnl This is needed because we assume 2's-completement signed arithmetic;
376dnl on compilers with gcc-like command line syntax we pass the -fwrapv
377dnl option for exactly that reason.
378PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
379
H. Peter Anvin (Intel)65ab3ab2020-06-30 10:14:21 -0700380dnl Want to turn this on at some point...
H. Peter Anvincfd56eb2016-03-06 21:44:14 -0800381dnl PA_ADD_CFLAGS([-Wwrite-strings])
H. Peter Anvin0da15492017-04-06 15:24:58 -0700382PA_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 Sezerec3d4262016-02-12 23:49:49 -0800396
H. Peter Anvin0c369652017-02-28 19:34:36 -0800397dnl
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700398dnl Test compiler features. On some compilers, this can be affected
399dnl by -Werror options, so run this *after* those options are added.
H. Peter Anvin99d45c82018-02-20 12:34:17 -0800400dnl
401PA_CHECK_BAD_STDC_INLINE
H. Peter Anvin (Intel)abcdf832020-07-09 19:04:28 -0700402PA_C_TYPEOF
H. Peter Anvin99d45c82018-02-20 12:34:17 -0800403
404dnl
H. Peter Anvin0c369652017-02-28 19:34:36 -0800405dnl support ccache
406dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700407PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
H. Peter Anvin0c369652017-02-28 19:34:36 -0800408
H. Peter Anvin (Intel)941c75a2020-05-26 14:13:31 -0700409AC_CONFIG_FILES([Makefile doc/Makefile])
410AC_OUTPUT