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
27 dnl If the user did not specify a CFLAGS default, change default
28 dnl to -O0 for debugging
29 PA_ARG_DISABLED([optimization],
30 [compile without optimization (-O0) to help debugging],
31 [pa_no_optimize=true])
33 dnl LLVM doesn't error out on invalid -W options unless this option is
34 dnl specified first. Enable this so this script can actually discover
35 dnl which -W options are possible for this compiler.
36 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
46 dnl Compile and link with dwarf debug
48 [disable optimization and compile with extra debug information for GDB debugger],
49 [PA_ADD_CFLAGS([-ggdb3])
52 AS_IF([$pa_no_optimize],
54 PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
57 PA_ARG_ENABLED([profiling],
58 [compile with profiling (-pg option)],
59 [PA_ADD_CFLAGS([-pg])])
62 PA_ARG_ENABLED([panic-abort],
63 [call abort() on panic to trap in the debugger],
64 [AC_DEFINE(ABORT_ON_PANIC)])
65 AH_TEMPLATE(ABORT_ON_PANIC,
66 [Define to 1 to call abort() on panics (internal errors), for debugging.])
68 dnl Check for library extension
71 dnl Checks for typedefs, structures, and compiler characteristics.
76 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
77 AH_TEMPLATE(WORDS_BIGENDIAN,
78 [Define to 1 if your processor stores words with the most significant
79 byte first (like Motorola and SPARC, unlike Intel and VAX).])
80 AH_TEMPLATE(WORDS_LITTLEENDIAN,
81 [Define to 1 if your processor stores words with the least significant
82 byte first (like Intel and VAX, unlike Motorola and SPARC).])
84 dnl Force gcc and gcc-compatible compilers treat signed integers
86 PA_ADD_CFLAGS([-fwrapv])
88 dnl Some environments abuse __STRICT_ANSI__ to disable some
89 dnl function declarations
90 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
92 dnl Don't put things in common if we can avoid it. We don't want to
93 dnl assume all compilers support common, and this will help find those
94 dnl problems. This also works around an OSX linker problem.
95 PA_ADD_CFLAGS([-fno-common])
97 dnl Look for programs...
98 AC_CHECK_PROGS(NROFF, nroff, false)
99 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
100 AC_CHECK_PROGS(XMLTO, xmlto, false)
101 AC_CHECK_PROGS(XZ, xz, false)
103 dnl Check for progs needed for manpage generation
105 AS_IF([test x$ASCIIDOC = xfalse],
106 [AC_MSG_WARN([No asciidoc package found, cannot build man pages])
109 AS_IF([test x"$XMLTO" = xfalse],
110 [AC_MSG_WARN([No xmlto package found, cannot build man pages])
115 dnl Don't create .pdf.xz if there is no xz
116 AS_IF([test x"$XZ" = xfalse],
121 dnl Can't create NSIS package if there is no makensis
122 dnl ... but it only applies to a Windows target ...
123 dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain"
124 dnl version of the program name, but it doesn't seem to.
126 [AS_HELP_STRING([[--with-nsis[=makensis]]],
127 [build an install .exe using NSIS on Windows hosts])],
129 AS_IF([test x"$MAKENSIS" = x], [],
130 [AS_IF([test x"$with_nsis" = xno], []
131 [with_nsis="$MAKENSIS"])])
137 [AS_IF([test x"$with_nsis" = xno], [],
139 AS_IF([test x"$with_nsis" = xyes],
140 [AC_CHECK_TOOL(MAKENSIS_TOOL, makensis, false)
141 MAKENSIS="$MAKENSIS_TOOL"
142 AS_IF([test x"$MAKENSIS" = xfalse],
143 [AC_CHECK_PROGS(MAKENSIS_PLAIN, makensis, false)
144 MAKENSIS="$MAKENSIS_PLAIN"])
145 AS_IF([test x"$MAKENSIS" = xfalse],
146 [AC_MSG_WARN([no makensis found, cannot build installer])
148 [MAKENSIS="$with_nsis"])])])
152 dnl Check for host compiler tools
153 AC_CHECK_TOOL(AR, ar)
154 AC_CHECK_TOOL(RANLIB, ranlib, :)
155 AC_CHECK_TOOL(STRIP, strip)
157 dnl Checks for header files.
159 AC_CHECK_HEADERS(inttypes.h)
160 AC_CHECK_HEADERS(strings.h)
162 AC_CHECK_HEADERS(stdnoreturn.h)
163 AC_CHECK_HEADERS(io.h)
164 AC_CHECK_HEADERS(fcntl.h)
165 AC_CHECK_HEADERS(unistd.h)
166 AC_CHECK_HEADERS(sys/mman.h)
167 AC_CHECK_HEADERS(sys/types.h)
168 AC_CHECK_HEADERS(sys/stat.h)
169 AC_CHECK_HEADERS(sys/resource.h)
171 dnl Checks for library functions.
172 AC_CHECK_FUNCS(strcasecmp stricmp)
173 AC_CHECK_FUNCS(strncasecmp strnicmp)
174 AC_CHECK_FUNCS(strsep)
175 AC_CHECK_FUNCS(strnlen)
176 AC_CHECK_FUNCS(strrchrnul)
177 AC_CHECK_FUNCS(iscntrl)
178 AC_CHECK_FUNCS(isascii)
179 AC_CHECK_FUNCS(mempcpy)
181 AC_CHECK_FUNCS(getuid)
182 AC_CHECK_FUNCS(getgid)
183 AC_CHECK_FUNCS(getrlimit)
185 AC_CHECK_FUNCS(realpath)
186 AC_CHECK_FUNCS(canonicalize_file_name)
187 AC_CHECK_FUNCS(_fullpath)
188 AC_CHECK_FUNCS(pathconf)
191 AC_CHECK_FUNCS([_fseeki64])
192 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
193 AC_CHECK_FUNCS([fileno _fileno])
196 AC_CHECK_FUNCS(getpagesize)
197 AC_CHECK_FUNCS(sysconf)
199 AC_CHECK_FUNCS([access _access faccessat])
201 PA_HAVE_FUNC(__builtin_expect, (1,1))
203 dnl ilog2() building blocks
204 PA_ADD_HEADERS(intrin.h)
205 PA_HAVE_FUNC(__builtin_clz, (0U))
206 PA_HAVE_FUNC(__builtin_clzl, (0UL))
207 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
208 PA_HAVE_FUNC(_BitScanReverse, (0))
209 PA_HAVE_FUNC(_BitScanReverse64, (0))
211 dnl Functions for which we have replacements available in stdlib/
212 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
213 AC_CHECK_FUNCS([snprintf _snprintf])
214 AC_CHECK_FUNCS([strlcpy])
215 AC_CHECK_FUNCS([strrchrnul])
217 dnl These types are POSIX-specific, and Windows does it differently...
218 AC_CHECK_TYPES([struct _stati64])
219 AC_CHECK_TYPES([struct stat])
220 AC_CHECK_FUNCS([stat _stati64])
221 AC_CHECK_FUNCS([fstat _fstati64])
222 AC_CHECK_FUNCS([S_ISREG])
224 dnl Check for functions that might not be declared in the headers for
225 dnl various idiotic reasons (mostly because of library authors
226 dnl abusing the meaning of __STRICT_ANSI__)
227 AC_CHECK_DECLS(strcasecmp)
228 AC_CHECK_DECLS(stricmp)
229 AC_CHECK_DECLS(strncasecmp)
230 AC_CHECK_DECLS(strnicmp)
231 AC_CHECK_DECLS(strsep)
232 AC_CHECK_DECLS(strlcpy)
233 AC_CHECK_DECLS(strnlen)
234 AC_CHECK_DECLS(strrchrnul)
236 dnl Check for missing types
239 dnl Documentation: should we generate an uncompressed PDF? It is
240 dnl about twice as big, but it can be externally compressed (e.g. with xz)
241 dnl and becomes significantly smaller than the original.
242 PA_ARG_DISABLED([pdf-compression],
243 [generate an uncompressed documentation PDF],
244 [PDFOPT='-nocompress'])
248 dnl Look for byte-swapping support...
250 PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
251 PA_HAVE_FUNC(cpu_to_le16, (0))
252 PA_HAVE_FUNC(cpu_to_le32, (0))
253 PA_HAVE_FUNC(cpu_to_le64, (0))
254 PA_HAVE_FUNC(__cpu_to_le16, (0))
255 PA_HAVE_FUNC(__cpu_to_le32, (0))
256 PA_HAVE_FUNC(__cpu_to_le64, (0))
257 PA_HAVE_FUNC(htole16, (0))
258 PA_HAVE_FUNC(htole32, (0))
259 PA_HAVE_FUNC(htole64, (0))
260 PA_HAVE_FUNC(__bswap_16, (0))
261 PA_HAVE_FUNC(__bswap_32, (0))
262 PA_HAVE_FUNC(__bswap_64, (0))
263 PA_HAVE_FUNC(__builtin_bswap16, (0))
264 PA_HAVE_FUNC(__builtin_bswap32, (0))
265 PA_HAVE_FUNC(__builtin_bswap64, (0))
266 PA_HAVE_FUNC(_byteswap_ushort, (0))
267 PA_HAVE_FUNC(_byteswap_ulong, (0))
268 PA_HAVE_FUNC(_byteswap_uint64, (0))
271 dnl Some rather useful gcc extensions...
273 PA_HAVE_FUNC(__builtin_constant_p, (0))
274 PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
277 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
278 dnl support these, but don't define __GNUC__ as they don't support
279 dnl some other features of gcc.
281 PA_ADD_CFLAGS([-Werror=attributes])
282 PA_FUNC_ATTRIBUTE(noreturn)
283 PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null)
284 PA_FUNC_ATTRIBUTE(malloc)
285 PA_FUNC_ATTRIBUTE(alloc_size,[1])
286 PA_FUNC_ATTRIBUTE(alloc_size,[1,2])
287 PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null)
288 PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1])
289 PA_FUNC_ATTRIBUTE(const)
290 PA_FUNC_ATTRIBUTE(pure)
291 PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
292 PA_FUNC_ATTRIBUTE(unused)
293 PA_FUNC_ATTRIBUTE_ERROR
296 dnl support function sections (if available)
298 PA_ARG_DISABLED([sections],
299 [do not try to compile with function/data section support],
301 [PA_ADD_CFLAGS([-ffunction-sections])
302 PA_ADD_CFLAGS([-fdata-sections])
303 PA_ADD_LDFLAGS([-Wl,--gc-sections])]
309 PA_ARG_ENABLED([lto],
310 [compile with gcc-style link time optimization],
311 [PA_ADD_CFLAGS([-flto])
312 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
313 dnl CC name which ought to already contain the host triplet if needed
314 ccbase=`echo "$CC" | awk '{ print $1; }'`
315 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
317 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
318 RANLIB="$CC_RANLIB"], [])
321 dnl support sanitizers (if available)
323 PA_ARG_ENABLED([sanitizer],
324 [compile with sanitizers enabled],
325 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
326 PA_ADD_CFLAGS([-fsanitize=address])
327 PA_ADD_CFLAGS([-fsanitize=undefined])])
330 dnl Don't make symbols visible, there is no point and it just
331 dnl makes the code slower. This mainly affects ELF.
333 PA_ADD_CFLAGS([-fvisibility=hidden])
336 dnl If we have gcc, add appropriate code cleanliness options. Do this
337 dnl here at the end, because configure relies on being able to use
338 dnl some very, very old C constructs.
340 PA_ADD_CFLAGS([-Wall])
341 PA_ARG_DISABLED([pedantic],
342 [disable some extra paranoid compiler warnings],
345 PA_ADD_CFLAGS([-pedantic])
346 PA_ADD_CFLAGS([-Wc90-c99-compat])
347 PA_ADD_CFLAGS([-Wc99-compat])
348 PA_ADD_CFLAGS([-Wc99-extensions])
350 dnl Suppress format warning on Windows targets due to their <inttypes.h>
351 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
352 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
353 dnl This is needed because we intentionally expect strncpy() to fill
354 dnl in a zero-padded (not zero-terminated) buffer in several backends
355 PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
356 dnl This is needed because we assume 2's-completement signed arithmetic;
357 dnl on compilers with gcc-like command line syntax we pass the -fwrapv
358 dnl option for exactly that reason.
359 PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
361 dnl Want to turn this on at some point...
362 dnl PA_ADD_CFLAGS([-Wwrite-strings])
363 PA_ARG_ENABLED([werror],
364 [compile with -Werror to error out on any warning],
365 [PA_ADD_CFLAGS([-Werror])],
366 [PA_ADD_CFLAGS([-Werror=implicit])
367 PA_ADD_CFLAGS([-Werror=missing-braces])
368 PA_ADD_CFLAGS([-Werror=return-type])
369 PA_ADD_CFLAGS([-Werror=trigraphs])
370 PA_ADD_CFLAGS([-Werror=pointer-arith])
371 PA_ADD_CFLAGS([-Werror=strict-prototypes])
372 PA_ADD_CFLAGS([-Werror=missing-prototypes])
373 PA_ADD_CFLAGS([-Werror=missing-declarations])
374 PA_ADD_CFLAGS([-Werror=comment])
375 PA_ADD_CFLAGS([-Werror=vla])]
379 dnl On some versions of gcc, -Werror=missing-prototypes causes problems
380 dnl with C99-style external inlines. Test this *after* adding the -Werror
383 PA_CHECK_BAD_STDC_INLINE
388 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
390 AC_CONFIG_FILES([Makefile doc/Makefile])