blob: 8db7c7265986452055b5014b1953370f32924fa0 [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
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])
32AS_IF([test x"$pa_init_cflags" = x],
33 [CFLAGS=`echo "$CFLAGS" | sed -e "s/-O2/$pa_optimize/"`])
H. Peter Anvin9b935a02017-02-28 19:02:51 -080034
H. Peter Anvin89c17702016-03-09 14:11:40 -080035dnl Check for library extension
36PA_LIBEXT
37
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030038dnl Checks for typedefs, structures, and compiler characteristics.
39AC_C_CONST
H. Peter Anvin03f229c2015-11-04 11:29:09 -080040AC_C_INLINE
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030041AC_C_RESTRICT
42AC_TYPE_SIZE_T
H. Peter Anvinef635882016-03-01 21:53:09 -080043AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
Cyrill Gorcunov7729edf2014-12-20 11:35:51 +030044AH_TEMPLATE(WORDS_BIGENDIAN,
45[Define to 1 if your processor stores words with the most significant
46byte first (like Motorola and SPARC, unlike Intel and VAX).])
47AH_TEMPLATE(WORDS_LITTLEENDIAN,
48[Define to 1 if your processor stores words with the least significant
49byte first (like Intel and VAX, unlike Motorola and SPARC).])
50
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -080051dnl Force gcc and gcc-compatible compilers treat signed integers
52dnl as 2's complement
H. Peter Anvin8d9f5912016-02-27 00:15:13 -080053PA_ADD_CFLAGS([-fwrapv])
H. Peter Anvin87bc6192002-04-30 20:53:16 +000054
H. Peter Anvin8b190832016-11-15 14:01:37 -080055dnl Some environments abuse __STRICT_ANSI__ to disable some
56dnl function declarations
57PA_ADD_CFLAGS([-U__STRICT_ANSI__])
58
H. Peter Anvin43e02622016-08-02 09:28:22 -070059dnl Don't put things in common if we can avoid it. We don't want to
60dnl assume all compilers support common, and this will help find those
61dnl problems. This also works around an OSX linker problem.
62PA_ADD_CFLAGS([-fno-common])
63
H. Peter Anvineec3b522008-06-19 11:39:23 -070064dnl Look for programs...
H. Peter Anvina9397832013-05-17 12:02:49 -070065AC_CHECK_PROGS(NROFF, nroff, false)
H. Peter Anvind089c222013-10-24 13:22:19 +010066AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
67AC_CHECK_PROGS(XMLTO, xmlto, false)
H. Peter Anvin620515a2002-04-30 20:57:38 +000068
H. Peter Anvind089c222013-10-24 13:22:19 +010069dnl Check for progs needed for manpage generation
H. Peter Anvin0da15492017-04-06 15:24:58 -070070AS_IF([test $ASCIIDOC = false],
71 [AC_MSG_WARN([No asciidoc package found])]
72)
73AS_IF([test $XMLTO = false],
74 [AC_MSG_WARN([No xmlto package found])]
75)
H. Peter Anvind089c222013-10-24 13:22:19 +010076
H. Peter Anvincc147f72016-03-08 02:06:39 -080077dnl Check for host compiler tools
78AC_CHECK_TOOL(AR, ar)
79AC_CHECK_TOOL(RANLIB, ranlib, :)
80AC_CHECK_TOOL(STRIP, strip)
81
H. Peter Anvin87bc6192002-04-30 20:53:16 +000082dnl Checks for header files.
83AC_HEADER_STDC
H. Peter Anvin3ef4f002016-03-08 12:14:55 -080084AC_CHECK_HEADERS(inttypes.h)
H. Peter Anvinfe501952007-10-02 21:53:51 -070085AC_CHECK_HEADERS(strings.h)
H. Peter Anvind338b372016-02-18 00:54:30 -080086AC_HEADER_STDBOOL
H. Peter Anvinabd28c92016-12-20 02:29:58 -080087AC_CHECK_HEADERS(stdnoreturn.h)
H. Peter Anvine65e81b2016-02-18 14:24:40 -080088AC_CHECK_HEADERS(io.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -070089AC_CHECK_HEADERS(fcntl.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -080090AC_CHECK_HEADERS(unistd.h)
H. Peter Anvin573112e2017-04-24 13:28:14 -070091AC_CHECK_HEADERS(endian.h sys/endian.h machine/endian.h)
H. Peter Anvind81a2352016-09-21 14:03:18 -070092AC_CHECK_HEADERS(sys/mman.h)
H. Peter Anvin4c9132e2016-10-19 13:13:38 -070093AC_CHECK_HEADERS(sys/types.h)
H. Peter Anvin675e7b72017-04-05 21:19:03 -070094AC_CHECK_HEADERS(sys/stat.h)
H. Peter Anvin4627e692016-01-26 12:01:34 -080095
H. Peter Anvin87bc6192002-04-30 20:53:16 +000096dnl Checks for library functions.
H. Peter Anvinfe501952007-10-02 21:53:51 -070097AC_CHECK_FUNCS(strcasecmp stricmp)
98AC_CHECK_FUNCS(strncasecmp strnicmp)
H. Peter Anvin73b22f52016-02-18 14:40:37 -080099AC_CHECK_FUNCS(strsep)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700100AC_CHECK_FUNCS(strnlen)
H. Peter Anvinfe501952007-10-02 21:53:51 -0700101
H. Peter Anvin038d8612007-04-12 16:54:50 +0000102AC_CHECK_FUNCS(getuid)
103AC_CHECK_FUNCS(getgid)
104
H. Peter Anvin4627e692016-01-26 12:01:34 -0800105AC_CHECK_FUNCS(realpath)
106AC_CHECK_FUNCS(canonicalize_file_name)
107AC_CHECK_FUNCS(_fullpath)
108AC_CHECK_FUNCS(pathconf)
109
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800110AC_FUNC_FSEEKO
H. Peter Anvinec82d7a2016-02-21 21:20:45 -0800111AC_CHECK_FUNCS([_fseeki64])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800112AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
H. Peter Anvin397c1692016-10-04 17:01:59 -0700113AC_CHECK_FUNCS([fileno _fileno])
H. Peter Anvine65e81b2016-02-18 14:24:40 -0800114
H. Peter Anvin397c1692016-10-04 17:01:59 -0700115AC_CHECK_FUNCS(_filelengthi64)
H. Peter Anvin895a66c2017-02-23 20:34:38 -0800116AC_FUNC_MMAP
H. Peter Anvind81a2352016-09-21 14:03:18 -0700117AC_CHECK_FUNCS(getpagesize)
118AC_CHECK_FUNCS(sysconf)
119
H. Peter Anvin397c1692016-10-04 17:01:59 -0700120AC_CHECK_FUNCS([access _access faccessat])
H. Peter Anvind81a2352016-09-21 14:03:18 -0700121
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700122PA_HAVE_FUNC(__builtin_expect, (1,1))
123
124dnl ilog2() building blocks
125PA_ADD_HEADERS(intrin.h)
H. Peter Anvin8d4fb262016-11-15 14:23:54 -0800126PA_HAVE_FUNC(__builtin_clz, (0U))
127PA_HAVE_FUNC(__builtin_clzl, (0UL))
128PA_HAVE_FUNC(__builtin_clzll, (0ULL))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700129PA_HAVE_FUNC(_BitScanReverse, (0))
130PA_HAVE_FUNC(_BitScanReverse64, (0))
H. Peter Anvind338b372016-02-18 00:54:30 -0800131
132dnl Functions for which we have replacements available in lib/
H. Peter Anvincc147f72016-03-08 02:06:39 -0800133AC_CHECK_FUNCS([vsnprintf _vsnprintf])
134AC_CHECK_FUNCS([snprintf _snprintf])
135AC_CHECK_FUNCS([strlcpy])
H. Peter Anvind338b372016-02-18 00:54:30 -0800136
H. Peter Anvin31184292017-04-06 15:30:56 -0700137dnl These types are POSIX-specific, and Windows does it differently...
138AC_CHECK_TYPES([struct _stati64])
139AC_CHECK_TYPES([struct stat])
140AC_CHECK_FUNCS([stat _stati64])
141AC_CHECK_FUNCS([fstat _fstati64])
142
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700143dnl Check for functions that might not be declared in the headers for
144dnl various idiotic reasons (mostly because of library authors
145dnl abusing the meaning of __STRICT_ANSI__)
146AC_CHECK_DECLS(strcasecmp)
147AC_CHECK_DECLS(stricmp)
148AC_CHECK_DECLS(strncasecmp)
149AC_CHECK_DECLS(strnicmp)
150AC_CHECK_DECLS(strsep)
H. Peter Anvineaa68f12009-08-10 15:56:52 -0700151AC_CHECK_DECLS(strlcpy)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700152AC_CHECK_DECLS(strnlen)
H. Peter Anvinc13d31a2007-10-26 18:49:29 -0700153
H. Peter Anvind81a2352016-09-21 14:03:18 -0700154dnl Check for missing types
155AC_TYPE_UINTPTR_T
156
H. Peter Anvinf13effe2017-04-10 16:10:28 -0700157dnl Documentation: should we generate an uncompressed PDF? It is
158dnl about twice as big, but it can be externally compressed (e.g. with xz)
159dnl and becomes significantly smaller than the original.
160PA_ARG_DISABLED([pdf-compression],
161 [generate an uncompressed documentation PDF],
162 [PDFOPT='-nocompress'])
163AC_SUBST([PDFOPT])
164
H. Peter Anvin8b190832016-11-15 14:01:37 -0800165dnl
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700166dnl Look for byte-swapping support...
167dnl
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700168PA_HAVE_FUNC(cpu_to_le16, (0))
169PA_HAVE_FUNC(cpu_to_le32, (0))
170PA_HAVE_FUNC(cpu_to_le64, (0))
171PA_HAVE_FUNC(__cpu_to_le16, (0))
172PA_HAVE_FUNC(__cpu_to_le32, (0))
173PA_HAVE_FUNC(__cpu_to_le64, (0))
174PA_HAVE_FUNC(htole16, (0))
175PA_HAVE_FUNC(htole32, (0))
176PA_HAVE_FUNC(htole64, (0))
177PA_HAVE_FUNC(__bswap_16, (0))
178PA_HAVE_FUNC(__bswap_32, (0))
179PA_HAVE_FUNC(__bswap_64, (0))
180PA_HAVE_FUNC(__builtin_bswap16, (0))
181PA_HAVE_FUNC(__builtin_bswap32, (0))
182PA_HAVE_FUNC(__builtin_bswap64, (0))
H. Peter Anvine558dfd2017-04-18 16:05:22 -0700183PA_HAVE_FUNC(_byteswap_ushort, (0))
184PA_HAVE_FUNC(_byteswap_ulong, (0))
185PA_HAVE_FUNC(_byteswap_uint64, (0))
H. Peter Anvin5eb528b2017-04-18 15:49:25 -0700186
187dnl
H. Peter Anvin8b190832016-11-15 14:01:37 -0800188dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
189dnl support these, but don't define __GNUC__ as they don't support
190dnl some other features of gcc.
191dnl
H. Peter Anvinbc18af12017-02-23 19:22:27 -0800192PA_ADD_CFLAGS([-Werror=attributes])
H. Peter Anvin8b190832016-11-15 14:01:37 -0800193PA_FUNC_ATTRIBUTE(noreturn)
194PA_FUNC_ATTRIBUTE(returns_nonnull)
195PA_FUNC_ATTRIBUTE(malloc)
196PA_FUNC_ATTRIBUTE(alloc_size, (1))
197PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
198PA_FUNC_ATTRIBUTE(const)
199PA_FUNC_ATTRIBUTE(pure)
H. Peter Anvinabd28c92016-12-20 02:29:58 -0800200PA_FUNC_ATTRIBUTE_ERROR
H. Peter Anvin87bc6192002-04-30 20:53:16 +0000201
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300202dnl
H. Peter Anvin0c369652017-02-28 19:34:36 -0800203dnl support function sections
Cyrill Gorcunov325768e2010-11-11 11:18:44 +0300204dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700205PA_ARG_ENABLED([sections],
206 [compile with function/data section support],
H. Peter Anvin26fad142017-04-23 21:42:31 -0700207 [PA_ADD_CLDFLAGS([-ffunction-sections])
208 PA_ADD_CLDFLAGS([-fdata-sections])
209 PA_ADD_CLDFLAGS([-Wl,--gc-sections])],
H. Peter Anvin0da15492017-04-06 15:24:58 -0700210 [])
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800211dnl
212dnl support LTO
213dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700214PA_ARG_ENABLED([lto],
215 [compile with gcc-style link time optimization],
216 [PA_ADD_CLDFLAGS([-flto])
217 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
218 dnl CC name which ought to already contain the host triplet if needed
219 ccbase=`echo "$CC" | awk '{ print $1; }'`
220 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
221 AR="$CC_AR"
222 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
223 RANLIB="$CC_RANLIB"], [])
H. Peter Anvin5fe847e2017-02-28 18:48:01 -0800224
H. Peter Anvinb9c1ca72016-03-01 21:51:40 -0800225dnl If we have gcc, add appropriate code cleanliness options
H. Peter Anvind338b372016-02-18 00:54:30 -0800226PA_ADD_CFLAGS([-W])
227PA_ADD_CFLAGS([-Wall])
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800228PA_ADD_CFLAGS([-pedantic])
H. Peter Anvinc9fd7b22016-05-16 21:35:48 -0700229dnl LLVM doesn't error out on invalid -W options unless this option is
230dnl specified first. Enable this so this script can actually discover
231dnl which -W options are possible for this compiler.
232PA_ADD_CFLAGS([-Werror=unknown-warning-option])
H. Peter Anvin25da6ea2016-03-01 22:20:10 -0800233dnl Suppress format warning on Windows targets due to their <inttypes.h>
234PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
235PA_ADD_CFLAGS([-Wc90-c99-compat])
236PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
H. Peter Anvincfd56eb2016-03-06 21:44:14 -0800237dnl PA_ADD_CFLAGS([-Wwrite-strings])
H. Peter Anvin0da15492017-04-06 15:24:58 -0700238PA_ARG_ENABLED([werror],
239 [compile with -Werror to error out on any warning],
240 [PA_ADD_CFLAGS([-Werror])],
241 [PA_ADD_CFLAGS([-Werror=implicit])
242 PA_ADD_CFLAGS([-Werror=missing-braces])
243 PA_ADD_CFLAGS([-Werror=return-type])
244 PA_ADD_CFLAGS([-Werror=trigraphs])
245 PA_ADD_CFLAGS([-Werror=pointer-arith])
246 PA_ADD_CFLAGS([-Werror=strict-prototypes])
247 PA_ADD_CFLAGS([-Werror=missing-prototypes])
248 PA_ADD_CFLAGS([-Werror=missing-declarations])
249 PA_ADD_CFLAGS([-Werror=comment])
250 PA_ADD_CFLAGS([-Werror=vla])]
251)
Ozkan Sezerec3d4262016-02-12 23:49:49 -0800252
H. Peter Anvin0c369652017-02-28 19:34:36 -0800253dnl
254dnl support ccache
255dnl
H. Peter Anvin0da15492017-04-06 15:24:58 -0700256PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
H. Peter Anvin0c369652017-02-28 19:34:36 -0800257
Ed Beroset74fa0a72017-04-14 17:08:15 -0400258AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
H. Peter Anvin9a714c92017-04-06 17:24:03 -0700259AC_OUTPUT(Makefile doc/Makefile)