Makefile: don't store dependency information in git
[nasm.git] / configure.ac
blob7268eaaf0a766af0b39a9a711449912d7fd5d97b
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])
33 dnl Compile and link with dwarf debug
34 PA_ARG_ENABLED([gdb],
35  [disable optimization and compile with extra debug information for GDB debugger],
36  [pa_optimize='-O0'
37   PA_ADD_CFLAGS([-ggdb3])
38  ])
40 AS_IF([test x"$pa_init_cflags" = x],
41       [CFLAGS=`echo "$CFLAGS" | sed -e "s/-O2/$pa_optimize/"`])
43 AS_IF([test x"$pa_optimize" = "x-O0"],
44       [PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
46 dnl Check for library extension
47 PA_LIBEXT
49 dnl Checks for typedefs, structures, and compiler characteristics.
50 AC_C_CONST
51 AC_C_INLINE
52 AC_C_RESTRICT
53 AC_TYPE_SIZE_T
54 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
55 AH_TEMPLATE(WORDS_BIGENDIAN,
56 [Define to 1 if your processor stores words with the most significant
57 byte first (like Motorola and SPARC, unlike Intel and VAX).])
58 AH_TEMPLATE(WORDS_LITTLEENDIAN,
59 [Define to 1 if your processor stores words with the least significant
60 byte first (like Intel and VAX, unlike Motorola and SPARC).])
62 dnl Force gcc and gcc-compatible compilers treat signed integers
63 dnl as 2's complement
64 PA_ADD_CFLAGS([-fwrapv])
66 dnl Some environments abuse __STRICT_ANSI__ to disable some
67 dnl function declarations
68 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
70 dnl Don't put things in common if we can avoid it.  We don't want to
71 dnl assume all compilers support common, and this will help find those
72 dnl problems.  This also works around an OSX linker problem.
73 PA_ADD_CFLAGS([-fno-common])
75 dnl Look for programs...
76 AC_CHECK_PROGS(NROFF,    nroff,    false)
77 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
78 AC_CHECK_PROGS(XMLTO,    xmlto,    false)
80 dnl Check for progs needed for manpage generation
81 AS_IF([test $ASCIIDOC = false],
82   [AC_MSG_WARN([No asciidoc package found])]
84 AS_IF([test $XMLTO = false],
85   [AC_MSG_WARN([No xmlto package found])]
88 dnl Check for host compiler tools
89 AC_CHECK_TOOL(AR, ar)
90 AC_CHECK_TOOL(RANLIB, ranlib, :)
91 AC_CHECK_TOOL(STRIP, strip)
93 dnl Checks for header files.
94 AC_HEADER_STDC
95 AC_CHECK_HEADERS(inttypes.h)
96 AC_CHECK_HEADERS(strings.h)
97 AC_HEADER_STDBOOL
98 AC_CHECK_HEADERS(stdnoreturn.h)
99 AC_CHECK_HEADERS(io.h)
100 AC_CHECK_HEADERS(fcntl.h)
101 AC_CHECK_HEADERS(unistd.h)
102 AC_CHECK_HEADERS(endian.h sys/endian.h machine/endian.h)
103 AC_CHECK_HEADERS(sys/mman.h)
104 AC_CHECK_HEADERS(sys/types.h)
105 AC_CHECK_HEADERS(sys/stat.h)
107 dnl Checks for library functions.
108 AC_CHECK_FUNCS(strcasecmp stricmp)
109 AC_CHECK_FUNCS(strncasecmp strnicmp)
110 AC_CHECK_FUNCS(strsep)
111 AC_CHECK_FUNCS(strnlen)
113 AC_CHECK_FUNCS(getuid)
114 AC_CHECK_FUNCS(getgid)
116 AC_CHECK_FUNCS(realpath)
117 AC_CHECK_FUNCS(canonicalize_file_name)
118 AC_CHECK_FUNCS(_fullpath)
119 AC_CHECK_FUNCS(pathconf)
121 AC_FUNC_FSEEKO
122 AC_CHECK_FUNCS([_fseeki64])
123 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
124 AC_CHECK_FUNCS([fileno _fileno])
126 AC_CHECK_FUNCS(_filelengthi64)
127 AC_FUNC_MMAP
128 AC_CHECK_FUNCS(getpagesize)
129 AC_CHECK_FUNCS(sysconf)
131 AC_CHECK_FUNCS([access _access faccessat])
133 PA_HAVE_FUNC(__builtin_expect, (1,1))
135 dnl ilog2() building blocks
136 PA_ADD_HEADERS(intrin.h)
137 PA_HAVE_FUNC(__builtin_clz, (0U))
138 PA_HAVE_FUNC(__builtin_clzl, (0UL))
139 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
140 PA_HAVE_FUNC(_BitScanReverse, (0))
141 PA_HAVE_FUNC(_BitScanReverse64, (0))
143 dnl Functions for which we have replacements available in lib/
144 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
145 AC_CHECK_FUNCS([snprintf _snprintf])
146 AC_CHECK_FUNCS([strlcpy])
148 dnl These types are POSIX-specific, and Windows does it differently...
149 AC_CHECK_TYPES([struct _stati64])
150 AC_CHECK_TYPES([struct stat])
151 AC_CHECK_FUNCS([stat _stati64])
152 AC_CHECK_FUNCS([fstat _fstati64])
154 dnl Check for functions that might not be declared in the headers for
155 dnl various idiotic reasons (mostly because of library authors
156 dnl abusing the meaning of __STRICT_ANSI__)
157 AC_CHECK_DECLS(strcasecmp)
158 AC_CHECK_DECLS(stricmp)
159 AC_CHECK_DECLS(strncasecmp)
160 AC_CHECK_DECLS(strnicmp)
161 AC_CHECK_DECLS(strsep)
162 AC_CHECK_DECLS(strlcpy)
163 AC_CHECK_DECLS(strnlen)
165 dnl Check for missing types
166 AC_TYPE_UINTPTR_T
168 dnl Documentation: should we generate an uncompressed PDF?  It is
169 dnl about twice as big, but it can be externally compressed (e.g. with xz)
170 dnl and becomes significantly smaller than the original.
171 PA_ARG_DISABLED([pdf-compression],
172   [generate an uncompressed documentation PDF],
173   [PDFOPT='-nocompress'])
174 AC_SUBST([PDFOPT])
177 dnl Look for byte-swapping support...
179 PA_HAVE_FUNC(cpu_to_le16, (0))
180 PA_HAVE_FUNC(cpu_to_le32, (0))
181 PA_HAVE_FUNC(cpu_to_le64, (0))
182 PA_HAVE_FUNC(__cpu_to_le16, (0))
183 PA_HAVE_FUNC(__cpu_to_le32, (0))
184 PA_HAVE_FUNC(__cpu_to_le64, (0))
185 PA_HAVE_FUNC(htole16, (0))
186 PA_HAVE_FUNC(htole32, (0))
187 PA_HAVE_FUNC(htole64, (0))
188 PA_HAVE_FUNC(__bswap_16, (0))
189 PA_HAVE_FUNC(__bswap_32, (0))
190 PA_HAVE_FUNC(__bswap_64, (0))
191 PA_HAVE_FUNC(__builtin_bswap16, (0))
192 PA_HAVE_FUNC(__builtin_bswap32, (0))
193 PA_HAVE_FUNC(__builtin_bswap64, (0))
194 PA_HAVE_FUNC(_byteswap_ushort, (0))
195 PA_HAVE_FUNC(_byteswap_ulong, (0))
196 PA_HAVE_FUNC(_byteswap_uint64, (0))
199 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
200 dnl support these, but don't define __GNUC__ as they don't support
201 dnl some other features of gcc.
203 PA_ADD_CFLAGS([-Werror=attributes])
204 PA_FUNC_ATTRIBUTE(noreturn)
205 PA_FUNC_ATTRIBUTE(returns_nonnull)
206 PA_FUNC_ATTRIBUTE(malloc)
207 PA_FUNC_ATTRIBUTE(alloc_size, (1))
208 PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
209 PA_FUNC_ATTRIBUTE(const)
210 PA_FUNC_ATTRIBUTE(pure)
211 PA_FUNC_ATTRIBUTE_ERROR
214 dnl support function sections (if available)
216 PA_ARG_ENABLED([sections],
217  [compile with function/data section support],
218  [PA_ADD_CLDFLAGS([-ffunction-sections])
219   PA_ADD_CLDFLAGS([-fdata-sections])
220   PA_ADD_CLDFLAGS([-Wl,--gc-sections])],
221  [])
224 dnl support LTO
226 PA_ARG_ENABLED([lto],
227  [compile with gcc-style link time optimization],
228  [PA_ADD_CLDFLAGS([-flto])
229   dnl Note: we use _PROG rather than _TOOL since we are prepending the full
230   dnl CC name which ought to already contain the host triplet if needed
231   ccbase=`echo "$CC" | awk '{ print $1; }'`
232   AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
233   AR="$CC_AR"
234   AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
235   RANLIB="$CC_RANLIB"], [])
238 dnl support sanitizers (if available)
240 PA_ARG_ENABLED([sanitizer],
241  [compile with sanitizers enabled],
242  [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
243   PA_ADD_CLDFLAGS([-fsanitize=address])
244   PA_ADD_CLDFLAGS([-fsanitize=undefined])])
246 dnl If we have gcc, add appropriate code cleanliness options
247 PA_ADD_CFLAGS([-W])
248 PA_ADD_CFLAGS([-Wall])
249 PA_ADD_CFLAGS([-pedantic])
250 dnl LLVM doesn't error out on invalid -W options unless this option is
251 dnl specified first.  Enable this so this script can actually discover
252 dnl which -W options are possible for this compiler.
253 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
254 dnl Suppress format warning on Windows targets due to their <inttypes.h>
255 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
256 PA_ADD_CFLAGS([-Wc90-c99-compat])
257 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
258 dnl PA_ADD_CFLAGS([-Wwrite-strings])
259 PA_ARG_ENABLED([werror],
260  [compile with -Werror to error out on any warning],
261  [PA_ADD_CFLAGS([-Werror])],
262  [PA_ADD_CFLAGS([-Werror=implicit])
263   PA_ADD_CFLAGS([-Werror=missing-braces])
264   PA_ADD_CFLAGS([-Werror=return-type])
265   PA_ADD_CFLAGS([-Werror=trigraphs])
266   PA_ADD_CFLAGS([-Werror=pointer-arith])
267   PA_ADD_CFLAGS([-Werror=strict-prototypes])
268   PA_ADD_CFLAGS([-Werror=missing-prototypes])
269   PA_ADD_CFLAGS([-Werror=missing-declarations])
270   PA_ADD_CFLAGS([-Werror=comment])
271   PA_ADD_CFLAGS([-Werror=vla])]
275 dnl support ccache
277 PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
279 AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
280 AC_OUTPUT(Makefile doc/Makefile)