preproc: Fix nil dereference on error paths
[nasm.git] / configure.ac
blob83943d623c9e566c4160fb823ac33a77c8b2caf9
1 dnl Process this file with autoconf 2.69 or later to produce
2 dnl a configure script.
3 AC_PREREQ(2.69)
4 AC_INIT(config/config.h.in)
5 AC_CONFIG_HEADERS(config/config.h)
6 AC_PREFIX_PROGRAM(nasm)
7 AC_CONFIG_AUX_DIR(autoconf/helpers)
9 dnl Save initial CFLAGS, to see if -g -O2 came from configure or not
10 pa_init_cflags="$CFLAGS"
12 dnl This prevents us from running Wine and thinking we are not
13 dnl cross-compiling when in fact we are; running Wine here is at
14 dnl the best very slow and doesn't buy us a single thing at all.
15 WINELOADER=/dev/null
16 export WINELOADER
18 dnl Checks for programs and enable necessary CC extensions
19 AC_USE_SYSTEM_EXTENSIONS
20 AC_SYS_LARGEFILE
21 AC_PROG_CC
22 AC_PROG_CC_STDC
23 AC_PROG_LN_S
24 AC_PROG_MAKE_SET
25 AC_PROG_INSTALL
27 pa_no_optimize=false
29 dnl If the user did not specify a CFLAGS default, change default
30 dnl to -O0 for debugging
31 PA_ARG_DISABLED([optimization],
32  [compile without optimization (-O0) to help debugging],
33  [pa_no_optimize=true])
35 dnl Compile and link with dwarf debug
36 PA_ARG_ENABLED([gdb],
37  [disable optimization and compile with extra debug information for GDB debugger],
38  [PA_ADD_CFLAGS([-ggdb3])
39   pa_no_optimize=true])
41 AS_IF([$pa_no_optimize],
42       [PA_ADD_CFLAGS([-O0])
43        PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
45 dnl Abort on panic
46 PA_ARG_ENABLED([panic-abort],
47  [call abort() on panic to trap in the debugger],
48  [AC_DEFINE(ABORT_ON_PANIC)])
49 AH_TEMPLATE(ABORT_ON_PANIC,
50 [Define to 1 to call abort() on panics (internal errors), for debugging.])
52 dnl Check for library extension
53 PA_LIBEXT
55 dnl Checks for typedefs, structures, and compiler characteristics.
56 AC_C_CONST
57 AC_C_INLINE
58 AC_C_RESTRICT
59 AC_TYPE_SIZE_T
60 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
61 AH_TEMPLATE(WORDS_BIGENDIAN,
62 [Define to 1 if your processor stores words with the most significant
63 byte first (like Motorola and SPARC, unlike Intel and VAX).])
64 AH_TEMPLATE(WORDS_LITTLEENDIAN,
65 [Define to 1 if your processor stores words with the least significant
66 byte first (like Intel and VAX, unlike Motorola and SPARC).])
68 dnl Force gcc and gcc-compatible compilers treat signed integers
69 dnl as 2's complement
70 PA_ADD_CFLAGS([-fwrapv])
72 dnl Some environments abuse __STRICT_ANSI__ to disable some
73 dnl function declarations
74 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
76 dnl Don't put things in common if we can avoid it.  We don't want to
77 dnl assume all compilers support common, and this will help find those
78 dnl problems.  This also works around an OSX linker problem.
79 PA_ADD_CFLAGS([-fno-common])
81 dnl Look for programs...
82 AC_CHECK_PROGS(NROFF,    nroff,    false)
83 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
84 AC_CHECK_PROGS(XMLTO,    xmlto,    false)
86 dnl Check for progs needed for manpage generation
87 AS_IF([test $ASCIIDOC = false],
88   [AC_MSG_WARN([No asciidoc package found])]
90 AS_IF([test $XMLTO = false],
91   [AC_MSG_WARN([No xmlto package found])]
94 dnl Check for host compiler tools
95 AC_CHECK_TOOL(AR, ar)
96 AC_CHECK_TOOL(RANLIB, ranlib, :)
97 AC_CHECK_TOOL(STRIP, strip)
99 dnl Checks for header files.
100 AC_HEADER_STDC
101 AC_CHECK_HEADERS(inttypes.h)
102 AC_CHECK_HEADERS(strings.h)
103 AC_HEADER_STDBOOL
104 AC_CHECK_HEADERS(stdnoreturn.h)
105 AC_CHECK_HEADERS(io.h)
106 AC_CHECK_HEADERS(fcntl.h)
107 AC_CHECK_HEADERS(unistd.h)
108 AC_CHECK_HEADERS(sys/mman.h)
109 AC_CHECK_HEADERS(sys/types.h)
110 AC_CHECK_HEADERS(sys/stat.h)
112 dnl Checks for library functions.
113 AC_CHECK_FUNCS(strcasecmp stricmp)
114 AC_CHECK_FUNCS(strncasecmp strnicmp)
115 AC_CHECK_FUNCS(strsep)
116 AC_CHECK_FUNCS(strnlen)
117 AC_CHECK_FUNCS(strrchrnul)
118 AC_CHECK_FUNCS(iscntrl)
119 AC_CHECK_FUNCS(isascii)
120 AC_CHECK_FUNCS(mempcpy)
122 AC_CHECK_FUNCS(getuid)
123 AC_CHECK_FUNCS(getgid)
125 AC_CHECK_FUNCS(realpath)
126 AC_CHECK_FUNCS(canonicalize_file_name)
127 AC_CHECK_FUNCS(_fullpath)
128 AC_CHECK_FUNCS(pathconf)
130 AC_FUNC_FSEEKO
131 AC_CHECK_FUNCS([_fseeki64])
132 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
133 AC_CHECK_FUNCS([fileno _fileno])
135 AC_CHECK_FUNCS(_filelengthi64)
136 AC_FUNC_MMAP
137 AC_CHECK_FUNCS(getpagesize)
138 AC_CHECK_FUNCS(sysconf)
140 AC_CHECK_FUNCS([access _access faccessat])
142 PA_HAVE_FUNC(__builtin_expect, (1,1))
144 dnl ilog2() building blocks
145 PA_ADD_HEADERS(intrin.h)
146 PA_HAVE_FUNC(__builtin_clz, (0U))
147 PA_HAVE_FUNC(__builtin_clzl, (0UL))
148 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
149 PA_HAVE_FUNC(_BitScanReverse, (0))
150 PA_HAVE_FUNC(_BitScanReverse64, (0))
152 dnl Functions for which we have replacements available in stdlib/
153 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
154 AC_CHECK_FUNCS([snprintf _snprintf])
155 AC_CHECK_FUNCS([strlcpy])
156 AC_CHECK_FUNCS([strrchrnul])
158 dnl These types are POSIX-specific, and Windows does it differently...
159 AC_CHECK_TYPES([struct _stati64])
160 AC_CHECK_TYPES([struct stat])
161 AC_CHECK_FUNCS([stat _stati64])
162 AC_CHECK_FUNCS([fstat _fstati64])
164 dnl Check for functions that might not be declared in the headers for
165 dnl various idiotic reasons (mostly because of library authors
166 dnl abusing the meaning of __STRICT_ANSI__)
167 AC_CHECK_DECLS(strcasecmp)
168 AC_CHECK_DECLS(stricmp)
169 AC_CHECK_DECLS(strncasecmp)
170 AC_CHECK_DECLS(strnicmp)
171 AC_CHECK_DECLS(strsep)
172 AC_CHECK_DECLS(strlcpy)
173 AC_CHECK_DECLS(strnlen)
174 AC_CHECK_DECLS(strrchrnul)
176 dnl Check for missing types
177 AC_TYPE_UINTPTR_T
179 dnl Documentation: should we generate an uncompressed PDF?  It is
180 dnl about twice as big, but it can be externally compressed (e.g. with xz)
181 dnl and becomes significantly smaller than the original.
182 PA_ARG_DISABLED([pdf-compression],
183   [generate an uncompressed documentation PDF],
184   [PDFOPT='-nocompress'])
185 AC_SUBST([PDFOPT])
188 dnl Look for byte-swapping support...
190 PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
191 PA_HAVE_FUNC(cpu_to_le16, (0))
192 PA_HAVE_FUNC(cpu_to_le32, (0))
193 PA_HAVE_FUNC(cpu_to_le64, (0))
194 PA_HAVE_FUNC(__cpu_to_le16, (0))
195 PA_HAVE_FUNC(__cpu_to_le32, (0))
196 PA_HAVE_FUNC(__cpu_to_le64, (0))
197 PA_HAVE_FUNC(htole16, (0))
198 PA_HAVE_FUNC(htole32, (0))
199 PA_HAVE_FUNC(htole64, (0))
200 PA_HAVE_FUNC(__bswap_16, (0))
201 PA_HAVE_FUNC(__bswap_32, (0))
202 PA_HAVE_FUNC(__bswap_64, (0))
203 PA_HAVE_FUNC(__builtin_bswap16, (0))
204 PA_HAVE_FUNC(__builtin_bswap32, (0))
205 PA_HAVE_FUNC(__builtin_bswap64, (0))
206 PA_HAVE_FUNC(_byteswap_ushort, (0))
207 PA_HAVE_FUNC(_byteswap_ulong, (0))
208 PA_HAVE_FUNC(_byteswap_uint64, (0))
211 dnl Some rather useful gcc extensions...
213 PA_HAVE_FUNC(__builtin_constant_p, (0))
214 PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
217 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
218 dnl support these, but don't define __GNUC__ as they don't support
219 dnl some other features of gcc.
221 PA_ADD_CFLAGS([-Werror=attributes])
222 PA_FUNC_ATTRIBUTE(noreturn)
223 PA_FUNC_ATTRIBUTE(returns_nonnull)
224 PA_FUNC_ATTRIBUTE(malloc)
225 PA_FUNC_ATTRIBUTE(alloc_size, (1))
226 PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL])
227 PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
228 PA_FUNC_ATTRIBUTE(const)
229 PA_FUNC_ATTRIBUTE(pure)
230 PA_FUNC_ATTRIBUTE(cold)
231 PA_FUNC_ATTRIBUTE_ERROR
234 dnl support function sections (if available)
236 PA_ARG_DISABLED([sections],
237  [do not try to compile with function/data section support],
238  [],
239  [PA_ADD_CFLAGS([-ffunction-sections])
240   PA_ADD_CFLAGS([-fdata-sections])
241   PA_ADD_LDFLAGS([-Wl,--gc-sections])]
245 dnl support LTO
247 PA_ARG_ENABLED([lto],
248  [compile with gcc-style link time optimization],
249  [PA_ADD_CFLAGS([-flto])
250   dnl Note: we use _PROG rather than _TOOL since we are prepending the full
251   dnl CC name which ought to already contain the host triplet if needed
252   ccbase=`echo "$CC" | awk '{ print $1; }'`
253   AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
254   AR="$CC_AR"
255   AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
256   RANLIB="$CC_RANLIB"], [])
259 dnl support sanitizers (if available)
261 PA_ARG_ENABLED([sanitizer],
262  [compile with sanitizers enabled],
263  [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
264   PA_ADD_CFLAGS([-fsanitize=address])
265   PA_ADD_CFLAGS([-fsanitize=undefined])])
268 dnl Don't make symbols visible, there is no point and it just
269 dnl makes the code slower.
271 PA_ADD_CFLAGS([-fvisibility=hidden])
273 dnl If we have gcc, add appropriate code cleanliness options
274 PA_ADD_CFLAGS([-W])
275 PA_ADD_CFLAGS([-Wall])
276 PA_ADD_CFLAGS([-pedantic])
277 dnl LLVM doesn't error out on invalid -W options unless this option is
278 dnl specified first.  Enable this so this script can actually discover
279 dnl which -W options are possible for this compiler.
280 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
281 dnl Suppress format warning on Windows targets due to their <inttypes.h>
282 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
283 PA_ADD_CFLAGS([-Wc90-c99-compat])
284 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
285 dnl This is needed because we intentionally expect strncpy() to fill
286 dnl in a zero-padded (not zero-terminated) buffer in several backends
287 PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
288 dnl This is needed because we assume 2's-completement signed arithmetic;
289 dnl on compilers with gcc-like command line syntax we pass the -fwrapv
290 dnl option for exactly that reason.
291 PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
293 dnl PA_ADD_CFLAGS([-Wwrite-strings])
294 PA_ARG_ENABLED([werror],
295  [compile with -Werror to error out on any warning],
296  [PA_ADD_CFLAGS([-Werror])],
297  [PA_ADD_CFLAGS([-Werror=implicit])
298   PA_ADD_CFLAGS([-Werror=missing-braces])
299   PA_ADD_CFLAGS([-Werror=return-type])
300   PA_ADD_CFLAGS([-Werror=trigraphs])
301   PA_ADD_CFLAGS([-Werror=pointer-arith])
302   PA_ADD_CFLAGS([-Werror=strict-prototypes])
303   PA_ADD_CFLAGS([-Werror=missing-prototypes])
304   PA_ADD_CFLAGS([-Werror=missing-declarations])
305   PA_ADD_CFLAGS([-Werror=comment])
306   PA_ADD_CFLAGS([-Werror=vla])]
310 dnl On some versions of gcc, -Werror=missing-prototypes causes problems
311 dnl with C99-style external inlines.  Test this *after* adding the -Werror
312 dnl options.
314 PA_CHECK_BAD_STDC_INLINE
317 dnl support ccache
319 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
321 AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
322 AC_OUTPUT(Makefile doc/Makefile)