1 dnl Process this file with autoconf 2.69 or later to produce
2 dnl a configure script.
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.
18 dnl Get the canonical target system name
21 dnl Checks for programs and enable necessary CC extensions
22 AC_USE_SYSTEM_EXTENSIONS
33 dnl If the user did not specify a CFLAGS default, change default
34 dnl to -O0 for debugging
35 PA_ARG_DISABLED([optimization],
36 [compile without optimization (-O0) to help debugging],
37 [pa_no_optimize=true])
39 dnl Compile and link with dwarf debug
41 [disable optimization and compile with extra debug information for GDB debugger],
42 [PA_ADD_CFLAGS([-ggdb3])
45 AS_IF([$pa_no_optimize],
47 PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
50 PA_ARG_ENABLED([profiling],
51 [compile with profiling (-pg option)],
52 [PA_ADD_CFLAGS([-pg])])
55 PA_ARG_ENABLED([panic-abort],
56 [call abort() on panic to trap in the debugger],
57 [AC_DEFINE(ABORT_ON_PANIC)])
58 AH_TEMPLATE(ABORT_ON_PANIC,
59 [Define to 1 to call abort() on panics (internal errors), for debugging.])
61 dnl Check for library extension
64 dnl Checks for typedefs, structures, and compiler characteristics.
69 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
70 AH_TEMPLATE(WORDS_BIGENDIAN,
71 [Define to 1 if your processor stores words with the most significant
72 byte first (like Motorola and SPARC, unlike Intel and VAX).])
73 AH_TEMPLATE(WORDS_LITTLEENDIAN,
74 [Define to 1 if your processor stores words with the least significant
75 byte first (like Intel and VAX, unlike Motorola and SPARC).])
77 dnl Force gcc and gcc-compatible compilers treat signed integers
79 PA_ADD_CFLAGS([-fwrapv])
81 dnl Some environments abuse __STRICT_ANSI__ to disable some
82 dnl function declarations
83 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
85 dnl Don't put things in common if we can avoid it. We don't want to
86 dnl assume all compilers support common, and this will help find those
87 dnl problems. This also works around an OSX linker problem.
88 PA_ADD_CFLAGS([-fno-common])
90 dnl Look for programs...
91 AC_CHECK_PROGS(NROFF, nroff, false)
92 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
93 AC_CHECK_PROGS(XMLTO, xmlto, false)
94 AC_CHECK_PROGS(XZ, xz, false)
96 dnl Check for progs needed for manpage generation
98 AS_IF([test x$ASCIIDOC = xfalse],
99 [AC_MSG_WARN([No asciidoc package found, cannot build man pages])
102 AS_IF([test x"$XMLTO" = xfalse],
103 [AC_MSG_WARN([No xmlto package found, cannot build man pages])
108 dnl Don't create .pdf.xz if there is no xz
109 AS_IF([test x"$XZ" = xfalse],
114 dnl Can't create NSIS package if there is no makensis
115 dnl ... but it only applies to a Windows target ...
116 dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain"
117 dnl version of the program name, but it doesn't seem to.
119 [AS_HELP_STRING([[--with-nsis[=makensis]]],
120 [build an install .exe using NSIS on Windows hosts])],
122 AS_IF([test x"$MAKENSIS" = x], [],
123 [AS_IF([test x"$with_nsis" = xno], []
124 [with_nsis="$MAKENSIS"])])
130 [AS_IF([test x"$with_nsis" = xno], [],
132 AS_IF([test x"$with_nsis" = xyes],
133 [AC_CHECK_TOOL(MAKENSIS_TOOL, makensis, false)
134 MAKENSIS="$MAKENSIS_TOOL"
135 AS_IF([test x"$MAKENSIS" = xfalse],
136 [AC_CHECK_PROGS(MAKENSIS_PLAIN, makensis, false)
137 MAKENSIS="$MAKENSIS_PLAIN"])
138 AS_IF([test x"$MAKENSIS" = xfalse],
139 [AC_MSG_WARN([no makensis found, cannot build installer])
141 [MAKENSIS="$with_nsis"])])])
145 dnl Check for host compiler tools
146 AC_CHECK_TOOL(AR, ar)
147 AC_CHECK_TOOL(RANLIB, ranlib, :)
148 AC_CHECK_TOOL(STRIP, strip)
150 dnl Checks for header files.
152 AC_CHECK_HEADERS(inttypes.h)
153 AC_CHECK_HEADERS(strings.h)
155 AC_CHECK_HEADERS(stdnoreturn.h)
156 AC_CHECK_HEADERS(io.h)
157 AC_CHECK_HEADERS(fcntl.h)
158 AC_CHECK_HEADERS(unistd.h)
159 AC_CHECK_HEADERS(sys/mman.h)
160 AC_CHECK_HEADERS(sys/types.h)
161 AC_CHECK_HEADERS(sys/stat.h)
162 AC_CHECK_HEADERS(sys/resource.h)
164 dnl Checks for library functions.
165 AC_CHECK_FUNCS(strcasecmp stricmp)
166 AC_CHECK_FUNCS(strncasecmp strnicmp)
167 AC_CHECK_FUNCS(strsep)
168 AC_CHECK_FUNCS(strnlen)
169 AC_CHECK_FUNCS(strrchrnul)
170 AC_CHECK_FUNCS(iscntrl)
171 AC_CHECK_FUNCS(isascii)
172 AC_CHECK_FUNCS(mempcpy)
174 AC_CHECK_FUNCS(getuid)
175 AC_CHECK_FUNCS(getgid)
176 AC_CHECK_FUNCS(getrlimit)
178 AC_CHECK_FUNCS(realpath)
179 AC_CHECK_FUNCS(canonicalize_file_name)
180 AC_CHECK_FUNCS(_fullpath)
181 AC_CHECK_FUNCS(pathconf)
184 AC_CHECK_FUNCS([_fseeki64])
185 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
186 AC_CHECK_FUNCS([fileno _fileno])
189 AC_CHECK_FUNCS(getpagesize)
190 AC_CHECK_FUNCS(sysconf)
192 AC_CHECK_FUNCS([access _access faccessat])
194 PA_HAVE_FUNC(__builtin_expect, (1,1))
196 dnl ilog2() building blocks
197 PA_ADD_HEADERS(intrin.h)
198 PA_HAVE_FUNC(__builtin_clz, (0U))
199 PA_HAVE_FUNC(__builtin_clzl, (0UL))
200 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
201 PA_HAVE_FUNC(_BitScanReverse, (0))
202 PA_HAVE_FUNC(_BitScanReverse64, (0))
204 dnl Functions for which we have replacements available in stdlib/
205 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
206 AC_CHECK_FUNCS([snprintf _snprintf])
207 AC_CHECK_FUNCS([strlcpy])
208 AC_CHECK_FUNCS([strrchrnul])
210 dnl These types are POSIX-specific, and Windows does it differently...
211 AC_CHECK_TYPES([struct _stati64])
212 AC_CHECK_TYPES([struct stat])
213 AC_CHECK_FUNCS([stat _stati64])
214 AC_CHECK_FUNCS([fstat _fstati64])
215 AC_CHECK_FUNCS([S_ISREG])
217 dnl Check for functions that might not be declared in the headers for
218 dnl various idiotic reasons (mostly because of library authors
219 dnl abusing the meaning of __STRICT_ANSI__)
220 AC_CHECK_DECLS(strcasecmp)
221 AC_CHECK_DECLS(stricmp)
222 AC_CHECK_DECLS(strncasecmp)
223 AC_CHECK_DECLS(strnicmp)
224 AC_CHECK_DECLS(strsep)
225 AC_CHECK_DECLS(strlcpy)
226 AC_CHECK_DECLS(strnlen)
227 AC_CHECK_DECLS(strrchrnul)
229 dnl Check for missing types
232 dnl Documentation: should we generate an uncompressed PDF? It is
233 dnl about twice as big, but it can be externally compressed (e.g. with xz)
234 dnl and becomes significantly smaller than the original.
235 PA_ARG_DISABLED([pdf-compression],
236 [generate an uncompressed documentation PDF],
237 [PDFOPT='-nocompress'])
241 dnl Look for byte-swapping support...
243 PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
244 PA_HAVE_FUNC(cpu_to_le16, (0))
245 PA_HAVE_FUNC(cpu_to_le32, (0))
246 PA_HAVE_FUNC(cpu_to_le64, (0))
247 PA_HAVE_FUNC(__cpu_to_le16, (0))
248 PA_HAVE_FUNC(__cpu_to_le32, (0))
249 PA_HAVE_FUNC(__cpu_to_le64, (0))
250 PA_HAVE_FUNC(htole16, (0))
251 PA_HAVE_FUNC(htole32, (0))
252 PA_HAVE_FUNC(htole64, (0))
253 PA_HAVE_FUNC(__bswap_16, (0))
254 PA_HAVE_FUNC(__bswap_32, (0))
255 PA_HAVE_FUNC(__bswap_64, (0))
256 PA_HAVE_FUNC(__builtin_bswap16, (0))
257 PA_HAVE_FUNC(__builtin_bswap32, (0))
258 PA_HAVE_FUNC(__builtin_bswap64, (0))
259 PA_HAVE_FUNC(_byteswap_ushort, (0))
260 PA_HAVE_FUNC(_byteswap_ulong, (0))
261 PA_HAVE_FUNC(_byteswap_uint64, (0))
264 dnl Some rather useful gcc extensions...
266 PA_HAVE_FUNC(__builtin_constant_p, (0))
267 PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
270 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
271 dnl support these, but don't define __GNUC__ as they don't support
272 dnl some other features of gcc.
274 PA_ADD_CFLAGS([-Werror=attributes])
275 PA_FUNC_ATTRIBUTE(noreturn)
276 PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null)
277 PA_FUNC_ATTRIBUTE(malloc)
278 PA_FUNC_ATTRIBUTE(alloc_size,[1])
279 PA_FUNC_ATTRIBUTE(alloc_size,[1,2])
280 PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null)
281 PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1])
282 PA_FUNC_ATTRIBUTE(const)
283 PA_FUNC_ATTRIBUTE(pure)
284 PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
285 PA_FUNC_ATTRIBUTE_ERROR
288 dnl support function sections (if available)
290 PA_ARG_DISABLED([sections],
291 [do not try to compile with function/data section support],
293 [PA_ADD_CFLAGS([-ffunction-sections])
294 PA_ADD_CFLAGS([-fdata-sections])
295 PA_ADD_LDFLAGS([-Wl,--gc-sections])]
301 PA_ARG_ENABLED([lto],
302 [compile with gcc-style link time optimization],
303 [PA_ADD_CFLAGS([-flto])
304 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
305 dnl CC name which ought to already contain the host triplet if needed
306 ccbase=`echo "$CC" | awk '{ print $1; }'`
307 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
309 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
310 RANLIB="$CC_RANLIB"], [])
313 dnl support sanitizers (if available)
315 PA_ARG_ENABLED([sanitizer],
316 [compile with sanitizers enabled],
317 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
318 PA_ADD_CFLAGS([-fsanitize=address])
319 PA_ADD_CFLAGS([-fsanitize=undefined])])
322 dnl Don't make symbols visible, there is no point and it just
323 dnl makes the code slower.
325 PA_ADD_CFLAGS([-fvisibility=hidden])
327 dnl If we have gcc, add appropriate code cleanliness options
328 PA_ADD_CFLAGS([-Wall])
329 PA_ARG_DISABLED([pedantic],
330 [disable some extra paranoid compiler warnings],
333 PA_ADD_CFLAGS([-pedantic])
334 PA_ADD_CFLAGS([-Wc90-c99-compat])])
335 dnl LLVM doesn't error out on invalid -W options unless this option is
336 dnl specified first. Enable this so this script can actually discover
337 dnl which -W options are possible for this compiler.
338 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
339 dnl Suppress format warning on Windows targets due to their <inttypes.h>
340 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
341 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
342 dnl This is needed because we intentionally expect strncpy() to fill
343 dnl in a zero-padded (not zero-terminated) buffer in several backends
344 PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
345 dnl This is needed because we assume 2's-completement signed arithmetic;
346 dnl on compilers with gcc-like command line syntax we pass the -fwrapv
347 dnl option for exactly that reason.
348 PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
350 dnl PA_ADD_CFLAGS([-Wwrite-strings])
351 PA_ARG_ENABLED([werror],
352 [compile with -Werror to error out on any warning],
353 [PA_ADD_CFLAGS([-Werror])],
354 [PA_ADD_CFLAGS([-Werror=implicit])
355 PA_ADD_CFLAGS([-Werror=missing-braces])
356 PA_ADD_CFLAGS([-Werror=return-type])
357 PA_ADD_CFLAGS([-Werror=trigraphs])
358 PA_ADD_CFLAGS([-Werror=pointer-arith])
359 PA_ADD_CFLAGS([-Werror=strict-prototypes])
360 PA_ADD_CFLAGS([-Werror=missing-prototypes])
361 PA_ADD_CFLAGS([-Werror=missing-declarations])
362 PA_ADD_CFLAGS([-Werror=comment])
363 PA_ADD_CFLAGS([-Werror=vla])]
367 dnl On some versions of gcc, -Werror=missing-prototypes causes problems
368 dnl with C99-style external inlines. Test this *after* adding the -Werror
371 PA_CHECK_BAD_STDC_INLINE
376 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
378 AC_CONFIG_FILES([Makefile doc/Makefile])