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 Checks for programs and enable necessary CC extensions
19 AC_USE_SYSTEM_EXTENSIONS
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
37 [disable optimization and compile with extra debug information for GDB debugger],
38 [PA_ADD_CFLAGS([-ggdb3])
41 AS_IF([$pa_no_optimize],
43 PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
46 PA_ARG_ENABLED([profiling],
47 [compile with profiling (-pg option)],
48 [PA_ADD_CFLAGS([-pg])])
51 PA_ARG_ENABLED([panic-abort],
52 [call abort() on panic to trap in the debugger],
53 [AC_DEFINE(ABORT_ON_PANIC)])
54 AH_TEMPLATE(ABORT_ON_PANIC,
55 [Define to 1 to call abort() on panics (internal errors), for debugging.])
57 dnl Check for library extension
60 dnl Checks for typedefs, structures, and compiler characteristics.
65 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
66 AH_TEMPLATE(WORDS_BIGENDIAN,
67 [Define to 1 if your processor stores words with the most significant
68 byte first (like Motorola and SPARC, unlike Intel and VAX).])
69 AH_TEMPLATE(WORDS_LITTLEENDIAN,
70 [Define to 1 if your processor stores words with the least significant
71 byte first (like Intel and VAX, unlike Motorola and SPARC).])
73 dnl Force gcc and gcc-compatible compilers treat signed integers
75 PA_ADD_CFLAGS([-fwrapv])
77 dnl Some environments abuse __STRICT_ANSI__ to disable some
78 dnl function declarations
79 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
81 dnl Don't put things in common if we can avoid it. We don't want to
82 dnl assume all compilers support common, and this will help find those
83 dnl problems. This also works around an OSX linker problem.
84 PA_ADD_CFLAGS([-fno-common])
86 dnl Look for programs...
87 AC_CHECK_PROGS(NROFF, nroff, false)
88 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
89 AC_CHECK_PROGS(XMLTO, xmlto, false)
91 dnl Check for progs needed for manpage generation
92 AS_IF([test $ASCIIDOC = false],
93 [AC_MSG_WARN([No asciidoc package found])]
95 AS_IF([test $XMLTO = false],
96 [AC_MSG_WARN([No xmlto package found])]
99 dnl Check for host compiler tools
100 AC_CHECK_TOOL(AR, ar)
101 AC_CHECK_TOOL(RANLIB, ranlib, :)
102 AC_CHECK_TOOL(STRIP, strip)
104 dnl Checks for header files.
106 AC_CHECK_HEADERS(inttypes.h)
107 AC_CHECK_HEADERS(strings.h)
109 AC_CHECK_HEADERS(stdnoreturn.h)
110 AC_CHECK_HEADERS(io.h)
111 AC_CHECK_HEADERS(fcntl.h)
112 AC_CHECK_HEADERS(unistd.h)
113 AC_CHECK_HEADERS(sys/mman.h)
114 AC_CHECK_HEADERS(sys/types.h)
115 AC_CHECK_HEADERS(sys/stat.h)
117 dnl Checks for library functions.
118 AC_CHECK_FUNCS(strcasecmp stricmp)
119 AC_CHECK_FUNCS(strncasecmp strnicmp)
120 AC_CHECK_FUNCS(strsep)
121 AC_CHECK_FUNCS(strnlen)
122 AC_CHECK_FUNCS(strrchrnul)
123 AC_CHECK_FUNCS(iscntrl)
124 AC_CHECK_FUNCS(isascii)
125 AC_CHECK_FUNCS(mempcpy)
127 AC_CHECK_FUNCS(getuid)
128 AC_CHECK_FUNCS(getgid)
130 AC_CHECK_FUNCS(realpath)
131 AC_CHECK_FUNCS(canonicalize_file_name)
132 AC_CHECK_FUNCS(_fullpath)
133 AC_CHECK_FUNCS(pathconf)
136 AC_CHECK_FUNCS([_fseeki64])
137 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
138 AC_CHECK_FUNCS([fileno _fileno])
141 AC_CHECK_FUNCS(getpagesize)
142 AC_CHECK_FUNCS(sysconf)
144 AC_CHECK_FUNCS([access _access faccessat])
146 PA_HAVE_FUNC(__builtin_expect, (1,1))
148 dnl ilog2() building blocks
149 PA_ADD_HEADERS(intrin.h)
150 PA_HAVE_FUNC(__builtin_clz, (0U))
151 PA_HAVE_FUNC(__builtin_clzl, (0UL))
152 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
153 PA_HAVE_FUNC(_BitScanReverse, (0))
154 PA_HAVE_FUNC(_BitScanReverse64, (0))
156 dnl Functions for which we have replacements available in stdlib/
157 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
158 AC_CHECK_FUNCS([snprintf _snprintf])
159 AC_CHECK_FUNCS([strlcpy])
160 AC_CHECK_FUNCS([strrchrnul])
162 dnl These types are POSIX-specific, and Windows does it differently...
163 AC_CHECK_TYPES([struct _stati64])
164 AC_CHECK_TYPES([struct stat])
165 AC_CHECK_FUNCS([stat _stati64])
166 AC_CHECK_FUNCS([fstat _fstati64])
167 AC_CHECK_FUNCS([S_ISREG])
169 dnl Check for functions that might not be declared in the headers for
170 dnl various idiotic reasons (mostly because of library authors
171 dnl abusing the meaning of __STRICT_ANSI__)
172 AC_CHECK_DECLS(strcasecmp)
173 AC_CHECK_DECLS(stricmp)
174 AC_CHECK_DECLS(strncasecmp)
175 AC_CHECK_DECLS(strnicmp)
176 AC_CHECK_DECLS(strsep)
177 AC_CHECK_DECLS(strlcpy)
178 AC_CHECK_DECLS(strnlen)
179 AC_CHECK_DECLS(strrchrnul)
181 dnl Check for missing types
184 dnl Documentation: should we generate an uncompressed PDF? It is
185 dnl about twice as big, but it can be externally compressed (e.g. with xz)
186 dnl and becomes significantly smaller than the original.
187 PA_ARG_DISABLED([pdf-compression],
188 [generate an uncompressed documentation PDF],
189 [PDFOPT='-nocompress'])
193 dnl Look for byte-swapping support...
195 PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
196 PA_HAVE_FUNC(cpu_to_le16, (0))
197 PA_HAVE_FUNC(cpu_to_le32, (0))
198 PA_HAVE_FUNC(cpu_to_le64, (0))
199 PA_HAVE_FUNC(__cpu_to_le16, (0))
200 PA_HAVE_FUNC(__cpu_to_le32, (0))
201 PA_HAVE_FUNC(__cpu_to_le64, (0))
202 PA_HAVE_FUNC(htole16, (0))
203 PA_HAVE_FUNC(htole32, (0))
204 PA_HAVE_FUNC(htole64, (0))
205 PA_HAVE_FUNC(__bswap_16, (0))
206 PA_HAVE_FUNC(__bswap_32, (0))
207 PA_HAVE_FUNC(__bswap_64, (0))
208 PA_HAVE_FUNC(__builtin_bswap16, (0))
209 PA_HAVE_FUNC(__builtin_bswap32, (0))
210 PA_HAVE_FUNC(__builtin_bswap64, (0))
211 PA_HAVE_FUNC(_byteswap_ushort, (0))
212 PA_HAVE_FUNC(_byteswap_ulong, (0))
213 PA_HAVE_FUNC(_byteswap_uint64, (0))
216 dnl Some rather useful gcc extensions...
218 PA_HAVE_FUNC(__builtin_constant_p, (0))
219 PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
222 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
223 dnl support these, but don't define __GNUC__ as they don't support
224 dnl some other features of gcc.
226 PA_ADD_CFLAGS([-Werror=attributes])
227 PA_FUNC_ATTRIBUTE(noreturn)
228 PA_FUNC_ATTRIBUTE(returns_nonnull)
229 PA_FUNC_ATTRIBUTE(malloc)
230 PA_FUNC_ATTRIBUTE(alloc_size, (1))
231 PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL])
232 PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
233 PA_FUNC_ATTRIBUTE(const)
234 PA_FUNC_ATTRIBUTE(pure)
235 PA_FUNC_ATTRIBUTE(cold)
236 PA_FUNC_ATTRIBUTE_ERROR
239 dnl support function sections (if available)
241 PA_ARG_DISABLED([sections],
242 [do not try to compile with function/data section support],
244 [PA_ADD_CFLAGS([-ffunction-sections])
245 PA_ADD_CFLAGS([-fdata-sections])
246 PA_ADD_LDFLAGS([-Wl,--gc-sections])]
252 PA_ARG_ENABLED([lto],
253 [compile with gcc-style link time optimization],
254 [PA_ADD_CFLAGS([-flto])
255 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
256 dnl CC name which ought to already contain the host triplet if needed
257 ccbase=`echo "$CC" | awk '{ print $1; }'`
258 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
260 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
261 RANLIB="$CC_RANLIB"], [])
264 dnl support sanitizers (if available)
266 PA_ARG_ENABLED([sanitizer],
267 [compile with sanitizers enabled],
268 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
269 PA_ADD_CFLAGS([-fsanitize=address])
270 PA_ADD_CFLAGS([-fsanitize=undefined])])
273 dnl Don't make symbols visible, there is no point and it just
274 dnl makes the code slower.
276 PA_ADD_CFLAGS([-fvisibility=hidden])
278 dnl If we have gcc, add appropriate code cleanliness options
280 PA_ADD_CFLAGS([-Wall])
281 PA_ADD_CFLAGS([-pedantic])
282 dnl LLVM doesn't error out on invalid -W options unless this option is
283 dnl specified first. Enable this so this script can actually discover
284 dnl which -W options are possible for this compiler.
285 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
286 dnl Suppress format warning on Windows targets due to their <inttypes.h>
287 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
288 PA_ADD_CFLAGS([-Wc90-c99-compat])
289 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
290 dnl This is needed because we intentionally expect strncpy() to fill
291 dnl in a zero-padded (not zero-terminated) buffer in several backends
292 PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
293 dnl This is needed because we assume 2's-completement signed arithmetic;
294 dnl on compilers with gcc-like command line syntax we pass the -fwrapv
295 dnl option for exactly that reason.
296 PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
298 dnl PA_ADD_CFLAGS([-Wwrite-strings])
299 PA_ARG_ENABLED([werror],
300 [compile with -Werror to error out on any warning],
301 [PA_ADD_CFLAGS([-Werror])],
302 [PA_ADD_CFLAGS([-Werror=implicit])
303 PA_ADD_CFLAGS([-Werror=missing-braces])
304 PA_ADD_CFLAGS([-Werror=return-type])
305 PA_ADD_CFLAGS([-Werror=trigraphs])
306 PA_ADD_CFLAGS([-Werror=pointer-arith])
307 PA_ADD_CFLAGS([-Werror=strict-prototypes])
308 PA_ADD_CFLAGS([-Werror=missing-prototypes])
309 PA_ADD_CFLAGS([-Werror=missing-declarations])
310 PA_ADD_CFLAGS([-Werror=comment])
311 PA_ADD_CFLAGS([-Werror=vla])]
315 dnl On some versions of gcc, -Werror=missing-prototypes causes problems
316 dnl with C99-style external inlines. Test this *after* adding the -Werror
319 PA_CHECK_BAD_STDC_INLINE
324 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
326 AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
327 AC_OUTPUT(Makefile doc/Makefile)