Merge branch 'nasm-2.13.xx'
[nasm.git] / configure.ac
blob8db7c7265986452055b5014b1953370f32924fa0
1 dnl Process this file with autoconf 2.63 or later to produce
2 dnl a configure script.
3 AC_PREREQ(2.63)
4 AC_INIT(config/config.h.in)
5 AC_CONFIG_HEADERS(config/config.h)
7 AC_PREFIX_PROGRAM(nasm)
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 dnl If the user did not specify a CFLAGS default, change default -O2
28 dnl to either -O3 (normal) or -O0 (for debugging)
29 PA_ARG_DISABLED([optimization],
30  [compile without optimization (-O0) to help debugging],
31  [pa_optimize=-O0], [pa_optimize=-O3])
32 AS_IF([test x"$pa_init_cflags" = x],
33       [CFLAGS=`echo "$CFLAGS" | sed -e "s/-O2/$pa_optimize/"`])
35 dnl Check for library extension
36 PA_LIBEXT
38 dnl Checks for typedefs, structures, and compiler characteristics.
39 AC_C_CONST
40 AC_C_INLINE
41 AC_C_RESTRICT
42 AC_TYPE_SIZE_T
43 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
44 AH_TEMPLATE(WORDS_BIGENDIAN,
45 [Define to 1 if your processor stores words with the most significant
46 byte first (like Motorola and SPARC, unlike Intel and VAX).])
47 AH_TEMPLATE(WORDS_LITTLEENDIAN,
48 [Define to 1 if your processor stores words with the least significant
49 byte first (like Intel and VAX, unlike Motorola and SPARC).])
51 dnl Force gcc and gcc-compatible compilers treat signed integers
52 dnl as 2's complement
53 PA_ADD_CFLAGS([-fwrapv])
55 dnl Some environments abuse __STRICT_ANSI__ to disable some
56 dnl function declarations
57 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
59 dnl Don't put things in common if we can avoid it.  We don't want to
60 dnl assume all compilers support common, and this will help find those
61 dnl problems.  This also works around an OSX linker problem.
62 PA_ADD_CFLAGS([-fno-common])
64 dnl Look for programs...
65 AC_CHECK_PROGS(NROFF,    nroff,    false)
66 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
67 AC_CHECK_PROGS(XMLTO,    xmlto,    false)
69 dnl Check for progs needed for manpage generation
70 AS_IF([test $ASCIIDOC = false],
71   [AC_MSG_WARN([No asciidoc package found])]
73 AS_IF([test $XMLTO = false],
74   [AC_MSG_WARN([No xmlto package found])]
77 dnl Check for host compiler tools
78 AC_CHECK_TOOL(AR, ar)
79 AC_CHECK_TOOL(RANLIB, ranlib, :)
80 AC_CHECK_TOOL(STRIP, strip)
82 dnl Checks for header files.
83 AC_HEADER_STDC
84 AC_CHECK_HEADERS(inttypes.h)
85 AC_CHECK_HEADERS(strings.h)
86 AC_HEADER_STDBOOL
87 AC_CHECK_HEADERS(stdnoreturn.h)
88 AC_CHECK_HEADERS(io.h)
89 AC_CHECK_HEADERS(fcntl.h)
90 AC_CHECK_HEADERS(unistd.h)
91 AC_CHECK_HEADERS(endian.h sys/endian.h machine/endian.h)
92 AC_CHECK_HEADERS(sys/mman.h)
93 AC_CHECK_HEADERS(sys/types.h)
94 AC_CHECK_HEADERS(sys/stat.h)
96 dnl Checks for library functions.
97 AC_CHECK_FUNCS(strcasecmp stricmp)
98 AC_CHECK_FUNCS(strncasecmp strnicmp)
99 AC_CHECK_FUNCS(strsep)
100 AC_CHECK_FUNCS(strnlen)
102 AC_CHECK_FUNCS(getuid)
103 AC_CHECK_FUNCS(getgid)
105 AC_CHECK_FUNCS(realpath)
106 AC_CHECK_FUNCS(canonicalize_file_name)
107 AC_CHECK_FUNCS(_fullpath)
108 AC_CHECK_FUNCS(pathconf)
110 AC_FUNC_FSEEKO
111 AC_CHECK_FUNCS([_fseeki64])
112 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
113 AC_CHECK_FUNCS([fileno _fileno])
115 AC_CHECK_FUNCS(_filelengthi64)
116 AC_FUNC_MMAP
117 AC_CHECK_FUNCS(getpagesize)
118 AC_CHECK_FUNCS(sysconf)
120 AC_CHECK_FUNCS([access _access faccessat])
122 PA_HAVE_FUNC(__builtin_expect, (1,1))
124 dnl ilog2() building blocks
125 PA_ADD_HEADERS(intrin.h)
126 PA_HAVE_FUNC(__builtin_clz, (0U))
127 PA_HAVE_FUNC(__builtin_clzl, (0UL))
128 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
129 PA_HAVE_FUNC(_BitScanReverse, (0))
130 PA_HAVE_FUNC(_BitScanReverse64, (0))
132 dnl Functions for which we have replacements available in lib/
133 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
134 AC_CHECK_FUNCS([snprintf _snprintf])
135 AC_CHECK_FUNCS([strlcpy])
137 dnl These types are POSIX-specific, and Windows does it differently...
138 AC_CHECK_TYPES([struct _stati64])
139 AC_CHECK_TYPES([struct stat])
140 AC_CHECK_FUNCS([stat _stati64])
141 AC_CHECK_FUNCS([fstat _fstati64])
143 dnl Check for functions that might not be declared in the headers for
144 dnl various idiotic reasons (mostly because of library authors
145 dnl abusing the meaning of __STRICT_ANSI__)
146 AC_CHECK_DECLS(strcasecmp)
147 AC_CHECK_DECLS(stricmp)
148 AC_CHECK_DECLS(strncasecmp)
149 AC_CHECK_DECLS(strnicmp)
150 AC_CHECK_DECLS(strsep)
151 AC_CHECK_DECLS(strlcpy)
152 AC_CHECK_DECLS(strnlen)
154 dnl Check for missing types
155 AC_TYPE_UINTPTR_T
157 dnl Documentation: should we generate an uncompressed PDF?  It is
158 dnl about twice as big, but it can be externally compressed (e.g. with xz)
159 dnl and becomes significantly smaller than the original.
160 PA_ARG_DISABLED([pdf-compression],
161   [generate an uncompressed documentation PDF],
162   [PDFOPT='-nocompress'])
163 AC_SUBST([PDFOPT])
166 dnl Look for byte-swapping support...
168 PA_HAVE_FUNC(cpu_to_le16, (0))
169 PA_HAVE_FUNC(cpu_to_le32, (0))
170 PA_HAVE_FUNC(cpu_to_le64, (0))
171 PA_HAVE_FUNC(__cpu_to_le16, (0))
172 PA_HAVE_FUNC(__cpu_to_le32, (0))
173 PA_HAVE_FUNC(__cpu_to_le64, (0))
174 PA_HAVE_FUNC(htole16, (0))
175 PA_HAVE_FUNC(htole32, (0))
176 PA_HAVE_FUNC(htole64, (0))
177 PA_HAVE_FUNC(__bswap_16, (0))
178 PA_HAVE_FUNC(__bswap_32, (0))
179 PA_HAVE_FUNC(__bswap_64, (0))
180 PA_HAVE_FUNC(__builtin_bswap16, (0))
181 PA_HAVE_FUNC(__builtin_bswap32, (0))
182 PA_HAVE_FUNC(__builtin_bswap64, (0))
183 PA_HAVE_FUNC(_byteswap_ushort, (0))
184 PA_HAVE_FUNC(_byteswap_ulong, (0))
185 PA_HAVE_FUNC(_byteswap_uint64, (0))
188 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
189 dnl support these, but don't define __GNUC__ as they don't support
190 dnl some other features of gcc.
192 PA_ADD_CFLAGS([-Werror=attributes])
193 PA_FUNC_ATTRIBUTE(noreturn)
194 PA_FUNC_ATTRIBUTE(returns_nonnull)
195 PA_FUNC_ATTRIBUTE(malloc)
196 PA_FUNC_ATTRIBUTE(alloc_size, (1))
197 PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
198 PA_FUNC_ATTRIBUTE(const)
199 PA_FUNC_ATTRIBUTE(pure)
200 PA_FUNC_ATTRIBUTE_ERROR
203 dnl support function sections
205 PA_ARG_ENABLED([sections],
206  [compile with function/data section support],
207  [PA_ADD_CLDFLAGS([-ffunction-sections])
208   PA_ADD_CLDFLAGS([-fdata-sections])
209   PA_ADD_CLDFLAGS([-Wl,--gc-sections])],
210  [])
212 dnl support LTO
214 PA_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"], [])
225 dnl If we have gcc, add appropriate code cleanliness options
226 PA_ADD_CFLAGS([-W])
227 PA_ADD_CFLAGS([-Wall])
228 PA_ADD_CFLAGS([-pedantic])
229 dnl LLVM doesn't error out on invalid -W options unless this option is
230 dnl specified first.  Enable this so this script can actually discover
231 dnl which -W options are possible for this compiler.
232 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
233 dnl Suppress format warning on Windows targets due to their <inttypes.h>
234 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
235 PA_ADD_CFLAGS([-Wc90-c99-compat])
236 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
237 dnl PA_ADD_CFLAGS([-Wwrite-strings])
238 PA_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])]
254 dnl support ccache
256 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
258 AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
259 AC_OUTPUT(Makefile doc/Makefile)