blob: 44c9e1791c8ecb159318660b71e65f01b1e63cf1 [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 Anvin397c1692016-10-04 17:01:59 -07004AC_INIT(config/config.h.in)
5AC_CONFIG_HEADERS(config/config.h)
H. Peter Anvin87bc6192002-04-30 20:53:16 +00006
H. Peter Anvin87bc6192002-04-30 20:53:16 +00007AC_PREFIX_PROGRAM(nasm)
8
H. Peter Anvin2d894772017-03-01 12:57:46 -08009dnl Save initial CFLAGS, to see if -g -O2 came from configure or not
10pa_init_cflags="$CFLAGS"
11
H. Peter Anvin0da15492017-04-06 15:24:58 -070012dnl This prevents us from running Wine and thinking we are not
13dnl cross-compiling when in fact we are; running Wine here is at
14dnl the best very slow and doesn't buy us a single thing at all.
15WINELOADER=/dev/null
16export WINELOADER
17
H. Peter Anvin2d894772017-03-01 12:57:46 -080018dnl Checks for programs and enable necessary CC extensions
H. Peter Anvin2f0f9ea2008-06-08 20:53:29 -070019AC_USE_SYSTEM_EXTENSIONS
H. Peter Anvinb423c022016-02-18 11:57:53 -080020AC_SYS_LARGEFILE
H. Peter Anvin87bc6192002-04-30 20:53:16 +000021AC_PROG_CC
H. Peter Anvind338b372016-02-18 00:54:30 -080022AC_PROG_CC_STDC
H. Peter Anvin87bc6192002-04-30 20:53:16 +000023AC_PROG_LN_S
24AC_PROG_MAKE_SET
H. Peter Anvin87bc6192002-04-30 20:53:16 +000025AC_PROG_INSTALL
26
H. Peter Anvin0da15492017-04-06 15:24:58 -070027dnl If the user did not specify a CFLAGS default, change default -O2
28dnl to either -O3 (normal) or -O0 (for debugging)
29PA_ARG_DISABLED([optimization],
30 [compile without optimization (-O0) to help debugging],
31 [pa_optimize=-O0], [pa_optimize=-O3])
H. Peter Anvin9b935a02017-02-28 19:02:51 -080032
Cyrill Gorcunovfdbf7012017-07-29 16:05:36 +030033dnl Compile and link with dwarf debug
34PA_ARG_ENABLED([gdb],
35 [disable optimization and compile with extra debug information for GDB debugger],
H. Peter Anvin53259e82017-10-11 16:47:59 -070036 [pa_optimize='-O0'
37 PA_ADD_CFLAGS([-ggdb3])
38 ])
39
40AS_IF([test x"$pa_init_cflags" = x],
41 [CFLAGS=`echo "$CFLAGS" | sed -e "s/-O2/$pa_optimize/"`])
42
43AS_IF([test x"$pa_optimize" = "x-O0"],
44 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
Cyrill Gorcunovfdbf7012017-07-29 16:05:36 +030045
H. Peter Anvindcbaf672017-12-20 12:06:54 -080046dnl Abort on panic
47PA_ARG_ENABLED([panic-abort],
48 [call abort() on panic to trap in the debugger],
49 [AC_DEFINE(ABORT_ON_PANIC)])
50AH_TEMPLATE(ABORT_ON_PANIC,
51[Define to 1 to call abort() on panics (internal errors), for debugging.])
52
H. Peter Anvin89c17702016-03-09 14:11:40 -080053dnl Check for library extension
54PA_LIBEXT
55
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030056dnl Checks for typedefs, structures, and compiler characteristics.
57AC_C_CONST
H. Peter Anvin03f229c2015-11-04 11:29:09 -080058AC_C_INLINE
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030059AC_C_RESTRICT
60AC_TYPE_SIZE_T
H. Peter Anvinef635882016-03-01 21:53:09 -080061AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030062AH_TEMPLATE(WORDS_BIGENDIAN,
63[Define to 1 if your processor stores words with the most significant
64byte first (like Motorola and SPARC, unlike Intel and VAX).])
65AH_TEMPLATE(WORDS_LITTLEENDIAN,
66[Define to 1 if your processor stores words with the least significant
67byte first (like Intel and VAX, unlike Motorola and SPARC).])
68
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -080069dnl Force gcc and gcc-compatible compilers treat signed integers
70dnl as 2's complement
H. Peter Anvin8d9f5912016-02-27 00:15:13 -080071PA_ADD_CFLAGS([-fwrapv])
H. Peter Anvin87bc6192002-04-30 20:53:16 +000072
H. Peter Anvin8b190832016-11-15 14:01:37 -080073dnl Some environments abuse __STRICT_ANSI__ to disable some
74dnl function declarations
75PA_ADD_CFLAGS([-U__STRICT_ANSI__])
76
H. Peter Anvin43e02622016-08-02 09:28:22 -070077dnl Don't put things in common if we can avoid it. We don't want to
78dnl assume all compilers support common, and this will help find those
79dnl problems. This also works around an OSX linker problem.
80PA_ADD_CFLAGS([-fno-common])
81
H. Peter Anvineec3b522008-06-19 11:39:23 -070082dnl Look for programs...
H. Peter Anvina9397832013-05-17 12:02:49 -070083AC_CHECK_PROGS(NROFF, nroff, false)
H. Peter Anvind089c222013-10-24 13:22:19 +010084AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
85AC_CHECK_PROGS(XMLTO, xmlto, false)
H. Peter Anvin620515a2002-04-30 20:57:38 +000086
H. Peter Anvind089c222013-10-24 13:22:19 +010087dnl Check for progs needed for manpage generation
H. Peter Anvin0da15492017-04-06 15:24:58 -070088AS_IF([test $ASCIIDOC = false],
89 [AC_MSG_WARN([No asciidoc package found])]
90)
91AS_IF([test $XMLTO = false],
92 [AC_MSG_WARN([No xmlto package found])]
93)
H. Peter Anvind089c222013-10-24 13:22:19 +010094
H. Peter Anvincc147f72016-03-08 02:06:39 -080095dnl Check for host compiler tools
96AC_CHECK_TOOL(AR, ar)
97AC_CHECK_TOOL(RANLIB, ranlib, :)
98AC_CHECK_TOOL(STRIP, strip)
99
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000100dnl Checks for header files.
101AC_HEADER_STDC
H. Peter Anvin3ef4f002016-03-08 12:14:55 -0800102AC_CHECK_HEADERS(inttypes.h)
H. Peter Anvinfe501952007-10-02 21:53:51 -0700103AC_CHECK_HEADERS(strings.h)
H. Peter Anvind338b372016-02-18 00:54:30 -0800104AC_HEADER_STDBOOL
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800105AC_CHECK_HEADERS(stdnoreturn.h)
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800106AC_CHECK_HEADERS(io.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -0700107AC_CHECK_HEADERS(fcntl.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -0800108AC_CHECK_HEADERS(unistd.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -0700109AC_CHECK_HEADERS(sys/mman.h)
H. Peter Anvin4c9132e2016-10-19 13:13:38 -0700110AC_CHECK_HEADERS(sys/types.h)
H. Peter Anvin675e7b72017-04-05 21:19:03 -0700111AC_CHECK_HEADERS(sys/stat.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -0800112
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000113dnl Checks for library functions.
H. Peter Anvinfe501952007-10-02 21:53:51 -0700114AC_CHECK_FUNCS(strcasecmp stricmp)
115AC_CHECK_FUNCS(strncasecmp strnicmp)
H. Peter Anvin73b22f52016-02-18 14:40:37 -0800116AC_CHECK_FUNCS(strsep)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700117AC_CHECK_FUNCS(strnlen)
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800118AC_CHECK_FUNCS(strrchrnul)
H. Peter Anvinfe501952007-10-02 21:53:51 -0700119
H. Peter Anvin038d8612007-04-12 16:54:50 +0000120AC_CHECK_FUNCS(getuid)
121AC_CHECK_FUNCS(getgid)
122
H. Peter Anvin4627e692016-01-26 12:01:34 -0800123AC_CHECK_FUNCS(realpath)
124AC_CHECK_FUNCS(canonicalize_file_name)
125AC_CHECK_FUNCS(_fullpath)
126AC_CHECK_FUNCS(pathconf)
127
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800128AC_FUNC_FSEEKO
H. Peter Anvinec82d7a2016-02-21 21:20:45 -0800129AC_CHECK_FUNCS([_fseeki64])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800130AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
H. Peter Anvin397c1692016-10-04 17:01:59 -0700131AC_CHECK_FUNCS([fileno _fileno])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800132
H. Peter Anvin397c1692016-10-04 17:01:59 -0700133AC_CHECK_FUNCS(_filelengthi64)
H. Peter Anvin895a66c2017-02-23 20:34:38 -0800134AC_FUNC_MMAP
H. Peter Anvind81a2352016-09-21 14:03:18 -0700135AC_CHECK_FUNCS(getpagesize)
136AC_CHECK_FUNCS(sysconf)
137
H. Peter Anvin397c1692016-10-04 17:01:59 -0700138AC_CHECK_FUNCS([access _access faccessat])
H. Peter Anvind81a2352016-09-21 14:03:18 -0700139
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700140PA_HAVE_FUNC(__builtin_expect, (1,1))
141
142dnl ilog2() building blocks
143PA_ADD_HEADERS(intrin.h)
H. Peter Anvin8d4fb262016-11-15 14:23:54 -0800144PA_HAVE_FUNC(__builtin_clz, (0U))
145PA_HAVE_FUNC(__builtin_clzl, (0UL))
146PA_HAVE_FUNC(__builtin_clzll, (0ULL))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700147PA_HAVE_FUNC(_BitScanReverse, (0))
148PA_HAVE_FUNC(_BitScanReverse64, (0))
H. Peter Anvind338b372016-02-18 00:54:30 -0800149
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800150dnl Functions for which we have replacements available in stdlib/
H. Peter Anvincc147f72016-03-08 02:06:39 -0800151AC_CHECK_FUNCS([vsnprintf _vsnprintf])
152AC_CHECK_FUNCS([snprintf _snprintf])
153AC_CHECK_FUNCS([strlcpy])
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800154AC_CHECK_FUNCS([strrchrnul])
H. Peter Anvind338b372016-02-18 00:54:30 -0800155
H. Peter Anvin31184292017-04-06 15:30:56 -0700156dnl These types are POSIX-specific, and Windows does it differently...
157AC_CHECK_TYPES([struct _stati64])
158AC_CHECK_TYPES([struct stat])
159AC_CHECK_FUNCS([stat _stati64])
160AC_CHECK_FUNCS([fstat _fstati64])
161
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700162dnl Check for functions that might not be declared in the headers for
163dnl various idiotic reasons (mostly because of library authors
164dnl abusing the meaning of __STRICT_ANSI__)
165AC_CHECK_DECLS(strcasecmp)
166AC_CHECK_DECLS(stricmp)
167AC_CHECK_DECLS(strncasecmp)
168AC_CHECK_DECLS(strnicmp)
169AC_CHECK_DECLS(strsep)
H. Peter Anvineaa68f12009-08-10 15:56:52 -0700170AC_CHECK_DECLS(strlcpy)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700171AC_CHECK_DECLS(strnlen)
H. Peter Anvin81b62b92017-12-20 13:33:49 -0800172AC_CHECK_DECLS(strrchrnul)
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700173
H. Peter Anvind81a2352016-09-21 14:03:18 -0700174dnl Check for missing types
175AC_TYPE_UINTPTR_T
176
H. Peter Anvinf13effe2017-04-10 16:10:28 -0700177dnl Documentation: should we generate an uncompressed PDF? It is
178dnl about twice as big, but it can be externally compressed (e.g. with xz)
179dnl and becomes significantly smaller than the original.
180PA_ARG_DISABLED([pdf-compression],
181 [generate an uncompressed documentation PDF],
182 [PDFOPT='-nocompress'])
183AC_SUBST([PDFOPT])
184
H. Peter Anvin8b190832016-11-15 14:01:37 -0800185dnl
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700186dnl Look for byte-swapping support...
187dnl
H. Peter Anvine5033df2017-11-29 16:04:05 -0800188PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700189PA_HAVE_FUNC(cpu_to_le16, (0))
190PA_HAVE_FUNC(cpu_to_le32, (0))
191PA_HAVE_FUNC(cpu_to_le64, (0))
192PA_HAVE_FUNC(__cpu_to_le16, (0))
193PA_HAVE_FUNC(__cpu_to_le32, (0))
194PA_HAVE_FUNC(__cpu_to_le64, (0))
195PA_HAVE_FUNC(htole16, (0))
196PA_HAVE_FUNC(htole32, (0))
197PA_HAVE_FUNC(htole64, (0))
198PA_HAVE_FUNC(__bswap_16, (0))
199PA_HAVE_FUNC(__bswap_32, (0))
200PA_HAVE_FUNC(__bswap_64, (0))
201PA_HAVE_FUNC(__builtin_bswap16, (0))
202PA_HAVE_FUNC(__builtin_bswap32, (0))
203PA_HAVE_FUNC(__builtin_bswap64, (0))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700204PA_HAVE_FUNC(_byteswap_ushort, (0))
205PA_HAVE_FUNC(_byteswap_ulong, (0))
206PA_HAVE_FUNC(_byteswap_uint64, (0))
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700207
208dnl
H. Peter Anvine5033df2017-11-29 16:04:05 -0800209dnl Check for __builtin_constant_p()
210dnl
211PA_HAVE_FUNC(__builtin_constant_p, (0))
212
213dnl
H. Peter Anvin8b190832016-11-15 14:01:37 -0800214dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
215dnl support these, but don't define __GNUC__ as they don't support
216dnl some other features of gcc.
217dnl
H. Peter Anvinbc18af12017-02-23 19:22:27 -0800218PA_ADD_CFLAGS([-Werror=attributes])
H. Peter Anvin8b190832016-11-15 14:01:37 -0800219PA_FUNC_ATTRIBUTE(noreturn)
220PA_FUNC_ATTRIBUTE(returns_nonnull)
221PA_FUNC_ATTRIBUTE(malloc)
222PA_FUNC_ATTRIBUTE(alloc_size, (1))
223PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
224PA_FUNC_ATTRIBUTE(const)
225PA_FUNC_ATTRIBUTE(pure)
H. Peter Anvin6686fc62018-02-22 14:52:50 -0800226PA_FUNC_ATTRIBUTE(cold)
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800227PA_FUNC_ATTRIBUTE_ERROR
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000228
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300229dnl
H. Peter Anvin53259e82017-10-11 16:47:59 -0700230dnl support function sections (if available)
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300231dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700232PA_ARG_ENABLED([sections],
233 [compile with function/data section support],
H. Peter Anvin26fad142017-04-23 21:42:31 -0700234 [PA_ADD_CLDFLAGS([-ffunction-sections])
235 PA_ADD_CLDFLAGS([-fdata-sections])
236 PA_ADD_CLDFLAGS([-Wl,--gc-sections])],
H. Peter Anvin0da15492017-04-06 15:24:58 -0700237 [])
H. Peter Anvin53259e82017-10-11 16:47:59 -0700238
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800239dnl
240dnl support LTO
241dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700242PA_ARG_ENABLED([lto],
243 [compile with gcc-style link time optimization],
244 [PA_ADD_CLDFLAGS([-flto])
245 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
246 dnl CC name which ought to already contain the host triplet if needed
247 ccbase=`echo "$CC" | awk '{ print $1; }'`
248 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
249 AR="$CC_AR"
250 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
251 RANLIB="$CC_RANLIB"], [])
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800252
H. Peter Anvin53259e82017-10-11 16:47:59 -0700253dnl
254dnl support sanitizers (if available)
255dnl
256PA_ARG_ENABLED([sanitizer],
257 [compile with sanitizers enabled],
258 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
259 PA_ADD_CLDFLAGS([-fsanitize=address])
260 PA_ADD_CLDFLAGS([-fsanitize=undefined])])
261
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -0800262dnl If we have gcc, add appropriate code cleanliness options
H. Peter Anvind338b372016-02-18 00:54:30 -0800263PA_ADD_CFLAGS([-W])
264PA_ADD_CFLAGS([-Wall])
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800265PA_ADD_CFLAGS([-pedantic])
H. Peter Anvinc9fd7b22016-05-16 21:35:48 -0700266dnl LLVM doesn't error out on invalid -W options unless this option is
267dnl specified first. Enable this so this script can actually discover
268dnl which -W options are possible for this compiler.
269PA_ADD_CFLAGS([-Werror=unknown-warning-option])
H. Peter Anvin25da6ea2016-03-01 22:20:10 -0800270dnl Suppress format warning on Windows targets due to their <inttypes.h>
271PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
272PA_ADD_CFLAGS([-Wc90-c99-compat])
273PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
H. Peter Anvincfd56eb2016-03-06 21:44:14 -0800274dnl PA_ADD_CFLAGS([-Wwrite-strings])
H. Peter Anvin0da15492017-04-06 15:24:58 -0700275PA_ARG_ENABLED([werror],
276 [compile with -Werror to error out on any warning],
277 [PA_ADD_CFLAGS([-Werror])],
278 [PA_ADD_CFLAGS([-Werror=implicit])
279 PA_ADD_CFLAGS([-Werror=missing-braces])
280 PA_ADD_CFLAGS([-Werror=return-type])
281 PA_ADD_CFLAGS([-Werror=trigraphs])
282 PA_ADD_CFLAGS([-Werror=pointer-arith])
283 PA_ADD_CFLAGS([-Werror=strict-prototypes])
284 PA_ADD_CFLAGS([-Werror=missing-prototypes])
285 PA_ADD_CFLAGS([-Werror=missing-declarations])
286 PA_ADD_CFLAGS([-Werror=comment])
287 PA_ADD_CFLAGS([-Werror=vla])]
288)
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800289
H. Peter Anvin0c369652017-02-28 19:34:36 -0800290dnl
H. Peter Anvin99d45c82018-02-20 12:34:17 -0800291dnl On some versions of gcc, -Werror=missing-prototypes causes problems
292dnl with C99-style external inlines. Test this *after* adding the -Werror
293dnl options.
294dnl
295PA_CHECK_BAD_STDC_INLINE
296
297dnl
H. Peter Anvin0c369652017-02-28 19:34:36 -0800298dnl support ccache
299dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700300PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
H. Peter Anvin0c369652017-02-28 19:34:36 -0800301
Ed Beroset74fa0a72017-04-14 17:08:15 -0400302AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
H. Peter Anvin9a714c92017-04-06 17:24:03 -0700303AC_OUTPUT(Makefile doc/Makefile)