blob: 663798579f5ed478c579004e5a6f571c0d6a7f00 [file] [log] [blame]
H. Peter Anvind338b372016-02-18 00:54:30 -08001dnl Process this file with autoconf 2.63 or later to produce
H. Peter Anvin1170eb62002-05-19 02:26:38 +00002dnl a configure script.
H. Peter Anvind338b372016-02-18 00:54:30 -08003AC_PREREQ(2.63)
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
12dnl Checks for programs and enable necessary CC extensions
H. Peter Anvin2f0f9ea2008-06-08 20:53:29 -070013AC_USE_SYSTEM_EXTENSIONS
H. Peter Anvinb423c022016-02-18 11:57:53 -080014AC_SYS_LARGEFILE
H. Peter Anvin87bc6192002-04-30 20:53:16 +000015AC_PROG_CC
H. Peter Anvind338b372016-02-18 00:54:30 -080016AC_PROG_CC_STDC
H. Peter Anvin87bc6192002-04-30 20:53:16 +000017AC_PROG_LN_S
18AC_PROG_MAKE_SET
H. Peter Anvin87bc6192002-04-30 20:53:16 +000019AC_PROG_INSTALL
20
H. Peter Anvin2d894772017-03-01 12:57:46 -080021dnl If the user did not specify a CFLAGS default, change default -O2 to -O3
22if test x"$pa_init_cflags" = x; then
23 CFLAGS=`echo "$CFLAGS" | sed -e 's/-O2/-O3/'`
24fi
H. Peter Anvin9b935a02017-02-28 19:02:51 -080025
H. Peter Anvin89c17702016-03-09 14:11:40 -080026dnl Check for library extension
27PA_LIBEXT
28
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030029dnl Checks for typedefs, structures, and compiler characteristics.
30AC_C_CONST
H. Peter Anvin03f229c2015-11-04 11:29:09 -080031AC_C_INLINE
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030032AC_C_RESTRICT
33AC_TYPE_SIZE_T
H. Peter Anvinef635882016-03-01 21:53:09 -080034AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030035AH_TEMPLATE(WORDS_BIGENDIAN,
36[Define to 1 if your processor stores words with the most significant
37byte first (like Motorola and SPARC, unlike Intel and VAX).])
38AH_TEMPLATE(WORDS_LITTLEENDIAN,
39[Define to 1 if your processor stores words with the least significant
40byte first (like Intel and VAX, unlike Motorola and SPARC).])
41
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -080042dnl Force gcc and gcc-compatible compilers treat signed integers
43dnl as 2's complement
H. Peter Anvin8d9f5912016-02-27 00:15:13 -080044PA_ADD_CFLAGS([-fwrapv])
H. Peter Anvin87bc6192002-04-30 20:53:16 +000045
H. Peter Anvin8b190832016-11-15 14:01:37 -080046dnl Some environments abuse __STRICT_ANSI__ to disable some
47dnl function declarations
48PA_ADD_CFLAGS([-U__STRICT_ANSI__])
49
H. Peter Anvin43e02622016-08-02 09:28:22 -070050dnl Don't put things in common if we can avoid it. We don't want to
51dnl assume all compilers support common, and this will help find those
52dnl problems. This also works around an OSX linker problem.
53PA_ADD_CFLAGS([-fno-common])
54
H. Peter Anvineec3b522008-06-19 11:39:23 -070055dnl Look for programs...
H. Peter Anvina9397832013-05-17 12:02:49 -070056AC_CHECK_PROGS(NROFF, nroff, false)
H. Peter Anvind089c222013-10-24 13:22:19 +010057AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
58AC_CHECK_PROGS(XMLTO, xmlto, false)
H. Peter Anvineec3b522008-06-19 11:39:23 -070059AC_CHECK_PROGS(ACRODIST, acrodist, false)
60AC_CHECK_PROGS(PS2PDF, ps2pdf, false)
61AC_CHECK_PROGS(PSTOPDF, pstopdf, false)
H. Peter Anvin620515a2002-04-30 20:57:38 +000062
H. Peter Anvind089c222013-10-24 13:22:19 +010063dnl Check for progs needed for manpage generation
64if test $ASCIIDOC = false; then
H. Peter Anvincc147f72016-03-08 02:06:39 -080065 AC_MSG_WARN([No asciidoc package found])
H. Peter Anvind089c222013-10-24 13:22:19 +010066fi
67if test $XMLTO = false; then
68 AC_MSG_WARN([No xmlto package found])
69fi
70
H. Peter Anvincc147f72016-03-08 02:06:39 -080071dnl Check for host compiler tools
72AC_CHECK_TOOL(AR, ar)
73AC_CHECK_TOOL(RANLIB, ranlib, :)
74AC_CHECK_TOOL(STRIP, strip)
75
H. Peter Anvin87bc6192002-04-30 20:53:16 +000076dnl Checks for header files.
77AC_HEADER_STDC
H. Peter Anvin3ef4f002016-03-08 12:14:55 -080078AC_CHECK_HEADERS(inttypes.h)
H. Peter Anvinfe501952007-10-02 21:53:51 -070079AC_CHECK_HEADERS(strings.h)
H. Peter Anvind338b372016-02-18 00:54:30 -080080AC_HEADER_STDBOOL
H. Peter Anvinabd28c92016-12-20 02:29:58 -080081AC_CHECK_HEADERS(stdnoreturn.h)
H. Peter Anvine65e81b2016-02-18 14:24:40 -080082AC_CHECK_HEADERS(io.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -070083AC_CHECK_HEADERS(fcntl.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -080084AC_CHECK_HEADERS(unistd.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -080085AC_CHECK_HEADERS(sys/param.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -070086AC_CHECK_HEADERS(sys/mman.h)
87AC_CHECK_HEADERS(sys/stat.h)
H. Peter Anvin4c9132e2016-10-19 13:13:38 -070088AC_CHECK_HEADERS(sys/types.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -080089
H. Peter Anvin87bc6192002-04-30 20:53:16 +000090dnl Checks for library functions.
H. Peter Anvinfe501952007-10-02 21:53:51 -070091AC_CHECK_FUNCS(strcasecmp stricmp)
92AC_CHECK_FUNCS(strncasecmp strnicmp)
H. Peter Anvin73b22f52016-02-18 14:40:37 -080093AC_CHECK_FUNCS(strsep)
H. Peter Anvin22538e22016-05-25 05:42:47 -070094AC_CHECK_FUNCS(strnlen)
H. Peter Anvinfe501952007-10-02 21:53:51 -070095
H. Peter Anvin038d8612007-04-12 16:54:50 +000096AC_CHECK_FUNCS(getuid)
97AC_CHECK_FUNCS(getgid)
98
H. Peter Anvin4627e692016-01-26 12:01:34 -080099AC_CHECK_FUNCS(realpath)
100AC_CHECK_FUNCS(canonicalize_file_name)
101AC_CHECK_FUNCS(_fullpath)
102AC_CHECK_FUNCS(pathconf)
103
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800104AC_FUNC_FSEEKO
H. Peter Anvinec82d7a2016-02-21 21:20:45 -0800105AC_CHECK_FUNCS([_fseeki64])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800106AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
H. Peter Anvin397c1692016-10-04 17:01:59 -0700107AC_CHECK_FUNCS([fileno _fileno])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800108
H. Peter Anvin397c1692016-10-04 17:01:59 -0700109AC_CHECK_FUNCS(_filelengthi64)
110AC_CHECK_FUNCS([stat _stati64])
H. Peter Anvind81a2352016-09-21 14:03:18 -0700111AC_CHECK_FUNCS(fstat)
H. Peter Anvin895a66c2017-02-23 20:34:38 -0800112AC_FUNC_MMAP
H. Peter Anvind81a2352016-09-21 14:03:18 -0700113AC_CHECK_FUNCS(getpagesize)
114AC_CHECK_FUNCS(sysconf)
115
H. Peter Anvin397c1692016-10-04 17:01:59 -0700116AC_CHECK_FUNCS([access _access faccessat])
H. Peter Anvind81a2352016-09-21 14:03:18 -0700117
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700118PA_HAVE_FUNC(__builtin_expect, (1,1))
119
120dnl ilog2() building blocks
121PA_ADD_HEADERS(intrin.h)
H. Peter Anvin8d4fb262016-11-15 14:23:54 -0800122PA_HAVE_FUNC(__builtin_clz, (0U))
123PA_HAVE_FUNC(__builtin_clzl, (0UL))
124PA_HAVE_FUNC(__builtin_clzll, (0ULL))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700125PA_HAVE_FUNC(_BitScanReverse, (0))
126PA_HAVE_FUNC(_BitScanReverse64, (0))
H. Peter Anvind338b372016-02-18 00:54:30 -0800127
128dnl Functions for which we have replacements available in lib/
H. Peter Anvincc147f72016-03-08 02:06:39 -0800129AC_CHECK_FUNCS([vsnprintf _vsnprintf])
130AC_CHECK_FUNCS([snprintf _snprintf])
131AC_CHECK_FUNCS([strlcpy])
H. Peter Anvind338b372016-02-18 00:54:30 -0800132
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700133dnl Check for functions that might not be declared in the headers for
134dnl various idiotic reasons (mostly because of library authors
135dnl abusing the meaning of __STRICT_ANSI__)
136AC_CHECK_DECLS(strcasecmp)
137AC_CHECK_DECLS(stricmp)
138AC_CHECK_DECLS(strncasecmp)
139AC_CHECK_DECLS(strnicmp)
140AC_CHECK_DECLS(strsep)
H. Peter Anvineaa68f12009-08-10 15:56:52 -0700141AC_CHECK_DECLS(strlcpy)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700142AC_CHECK_DECLS(strnlen)
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700143
H. Peter Anvind81a2352016-09-21 14:03:18 -0700144dnl Check for missing types
145AC_TYPE_UINTPTR_T
146
H. Peter Anvin8b190832016-11-15 14:01:37 -0800147dnl
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700148dnl Look for byte-swapping support...
149dnl
150PA_ADD_HEADERS(endian.h asm/byteorder.h)
151PA_HAVE_FUNC(__cpu_to_le16, (0))
152PA_HAVE_FUNC(__cpu_to_le32, (0))
153PA_HAVE_FUNC(__cpu_to_le64, (0))
154PA_HAVE_FUNC(cpu_to_le16, (0))
155PA_HAVE_FUNC(cpu_to_le32, (0))
156PA_HAVE_FUNC(cpu_to_le64, (0))
157PA_HAVE_FUNC(__cpu_to_le16, (0))
158PA_HAVE_FUNC(__cpu_to_le32, (0))
159PA_HAVE_FUNC(__cpu_to_le64, (0))
160PA_HAVE_FUNC(htole16, (0))
161PA_HAVE_FUNC(htole32, (0))
162PA_HAVE_FUNC(htole64, (0))
163PA_HAVE_FUNC(__bswap_16, (0))
164PA_HAVE_FUNC(__bswap_32, (0))
165PA_HAVE_FUNC(__bswap_64, (0))
166PA_HAVE_FUNC(__builtin_bswap16, (0))
167PA_HAVE_FUNC(__builtin_bswap32, (0))
168PA_HAVE_FUNC(__builtin_bswap64, (0))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700169PA_HAVE_FUNC(_byteswap_ushort, (0))
170PA_HAVE_FUNC(_byteswap_ulong, (0))
171PA_HAVE_FUNC(_byteswap_uint64, (0))
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700172
173dnl
H. Peter Anvin8b190832016-11-15 14:01:37 -0800174dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
175dnl support these, but don't define __GNUC__ as they don't support
176dnl some other features of gcc.
177dnl
H. Peter Anvinbc18af12017-02-23 19:22:27 -0800178PA_ADD_CFLAGS([-Werror=attributes])
H. Peter Anvin8b190832016-11-15 14:01:37 -0800179PA_FUNC_ATTRIBUTE(noreturn)
180PA_FUNC_ATTRIBUTE(returns_nonnull)
181PA_FUNC_ATTRIBUTE(malloc)
182PA_FUNC_ATTRIBUTE(alloc_size, (1))
183PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
184PA_FUNC_ATTRIBUTE(const)
185PA_FUNC_ATTRIBUTE(pure)
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800186PA_FUNC_ATTRIBUTE_ERROR
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000187
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300188dnl
H. Peter Anvin0c369652017-02-28 19:34:36 -0800189dnl support function sections
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300190dnl
H. Peter Anvin0c369652017-02-28 19:34:36 -0800191AC_ARG_ENABLE([sections],
192[AC_HELP_STRING([--enable-sections], [compile with function/data section support])],
193[PA_ADD_CFLAGS([-ffunction-sections]),
194PA_ADD_CFLAGS([-fdata-sections])],
H. Peter Anvin44a609b2016-02-18 12:09:31 -0800195[])
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300196
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800197dnl
198dnl support LTO
199dnl
200AC_ARG_ENABLE([lto],
201[AC_HELP_STRING([--enable-lto], [compile with gcc link time optimization])],
202[PA_ADD_CLDFLAGS([-flto])
203dnl Note: we use _PROG rather than _TOOL since we are prepending the full
204dnl CC name which ought to already contain the host triplet if needed
205ccbase=`echo "$CC" | awk '{ print $1; }'`
206AC_CHECK_PROG(CC_AR, [${ccbase}-ar], [${ccbase}-ar], [$ac_cv_prog_AR])
207AR="$CC_AR"
208AC_CHECK_PROG(CC_RANLIB, [${ccbase}-ranlib], [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
209RANLIB="$CC_RANLIB"
210], [])
211
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -0800212dnl If we have gcc, add appropriate code cleanliness options
H. Peter Anvind338b372016-02-18 00:54:30 -0800213PA_ADD_CFLAGS([-W])
214PA_ADD_CFLAGS([-Wall])
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800215PA_ADD_CFLAGS([-pedantic])
H. Peter Anvinc9fd7b22016-05-16 21:35:48 -0700216dnl LLVM doesn't error out on invalid -W options unless this option is
217dnl specified first. Enable this so this script can actually discover
218dnl which -W options are possible for this compiler.
219PA_ADD_CFLAGS([-Werror=unknown-warning-option])
H. Peter Anvin25da6ea2016-03-01 22:20:10 -0800220dnl Suppress format warning on Windows targets due to their <inttypes.h>
221PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
222PA_ADD_CFLAGS([-Wc90-c99-compat])
223PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
H. Peter Anvincfd56eb2016-03-06 21:44:14 -0800224dnl PA_ADD_CFLAGS([-Wwrite-strings])
H. Peter Anvin44a609b2016-02-18 12:09:31 -0800225AC_ARG_ENABLE([werror],
226[AC_HELP_STRING([--enable-werror],
227[compile with -Werror to error out on any warning])],
H. Peter Anvinfdf0d072016-03-03 12:39:02 -0800228[], [enable_werror=no])
229AS_IF([test x"$enable_werror" != xno],
H. Peter Anvin44a609b2016-02-18 12:09:31 -0800230[PA_ADD_CFLAGS([-Werror])],
231[PA_ADD_CFLAGS([-Werror=implicit])
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800232PA_ADD_CFLAGS([-Werror=missing-braces])
233PA_ADD_CFLAGS([-Werror=return-type])
234PA_ADD_CFLAGS([-Werror=trigraphs])
235PA_ADD_CFLAGS([-Werror=pointer-arith])
236PA_ADD_CFLAGS([-Werror=strict-prototypes])
237PA_ADD_CFLAGS([-Werror=missing-prototypes])
238PA_ADD_CFLAGS([-Werror=missing-declarations])
239PA_ADD_CFLAGS([-Werror=comment])
H. Peter Anvin44a609b2016-02-18 12:09:31 -0800240PA_ADD_CFLAGS([-Werror=vla])])
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800241
H. Peter Anvin0c369652017-02-28 19:34:36 -0800242dnl
243dnl support ccache
244dnl
245AC_ARG_ENABLE([ccache],
246[AC_HELP_STRING([--enable-ccache], [compile with ccache])],
247[CC="ccache $CC"],
248[])
249
H. Peter Anvin397c1692016-10-04 17:01:59 -0700250AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm])
H. Peter Anvin0fcdade2002-05-19 01:57:54 +0000251AC_OUTPUT(Makefile rdoff/Makefile doc/Makefile)