configure.ac: make possible to compile with -ffunction/data-sections
[nasm.git] / configure.ac
blob16cbb37011a6b2b09e12d575331358d538c11f96
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 Checks for programs.
10 dnl Consider AC_USE_SYSTEM_EXTENSIONS if autoconf 2.61 is OK in the future
11 AC_USE_SYSTEM_EXTENSIONS
12 AC_SYS_LARGEFILE
13 AC_PROG_CC
14 AC_PROG_CC_STDC
15 AC_PROG_LN_S
16 AC_PROG_MAKE_SET
17 AC_PROG_INSTALL
19 dnl For gcc, at lest, use -O3
20 PA_ADD_CFLAGS([-O3])
22 dnl Check for library extension
23 PA_LIBEXT
25 dnl Checks for typedefs, structures, and compiler characteristics.
26 AC_C_CONST
27 AC_C_INLINE
28 AC_C_RESTRICT
29 AC_TYPE_SIZE_T
30 AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
31 AH_TEMPLATE(WORDS_BIGENDIAN,
32 [Define to 1 if your processor stores words with the most significant
33 byte first (like Motorola and SPARC, unlike Intel and VAX).])
34 AH_TEMPLATE(WORDS_LITTLEENDIAN,
35 [Define to 1 if your processor stores words with the least significant
36 byte first (like Intel and VAX, unlike Motorola and SPARC).])
38 dnl Force gcc and gcc-compatible compilers treat signed integers
39 dnl as 2's complement
40 PA_ADD_CFLAGS([-fwrapv])
42 dnl Some environments abuse __STRICT_ANSI__ to disable some
43 dnl function declarations
44 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
46 dnl Don't put things in common if we can avoid it.  We don't want to
47 dnl assume all compilers support common, and this will help find those
48 dnl problems.  This also works around an OSX linker problem.
49 PA_ADD_CFLAGS([-fno-common])
51 dnl Look for programs...
52 AC_CHECK_PROGS(NROFF,    nroff,    false)
53 AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
54 AC_CHECK_PROGS(XMLTO,    xmlto,    false)
55 AC_CHECK_PROGS(ACRODIST, acrodist, false)
56 AC_CHECK_PROGS(PS2PDF,   ps2pdf,   false)
57 AC_CHECK_PROGS(PSTOPDF,  pstopdf,  false)
59 dnl Check for progs needed for manpage generation
60 if test $ASCIIDOC = false; then
61   AC_MSG_WARN([No asciidoc package found])
63 if test $XMLTO = false; then
64   AC_MSG_WARN([No xmlto package found])
67 dnl Check for host compiler tools
68 AC_CHECK_TOOL(AR, ar)
69 AC_CHECK_TOOL(RANLIB, ranlib, :)
70 AC_CHECK_TOOL(STRIP, strip)
72 dnl Checks for header files.
73 AC_HEADER_STDC
74 AC_CHECK_HEADERS(inttypes.h)
75 AC_CHECK_HEADERS(strings.h)
76 AC_HEADER_STDBOOL
77 AC_CHECK_HEADERS(stdnoreturn.h)
78 AC_CHECK_HEADERS(io.h)
79 AC_CHECK_HEADERS(fcntl.h)
80 AC_CHECK_HEADERS(unistd.h)
81 AC_CHECK_HEADERS(sys/param.h)
82 AC_CHECK_HEADERS(sys/mman.h)
83 AC_CHECK_HEADERS(sys/stat.h)
84 AC_CHECK_HEADERS(sys/types.h)
86 dnl Checks for library functions.
87 AC_CHECK_FUNCS(strcasecmp stricmp)
88 AC_CHECK_FUNCS(strncasecmp strnicmp)
89 AC_CHECK_FUNCS(strsep)
90 AC_CHECK_FUNCS(strnlen)
92 AC_CHECK_FUNCS(getuid)
93 AC_CHECK_FUNCS(getgid)
95 AC_CHECK_FUNCS(realpath)
96 AC_CHECK_FUNCS(canonicalize_file_name)
97 AC_CHECK_FUNCS(_fullpath)
98 AC_CHECK_FUNCS(pathconf)
100 AC_FUNC_FSEEKO
101 AC_CHECK_FUNCS([_fseeki64])
102 AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
103 AC_CHECK_FUNCS([fileno _fileno])
105 AC_CHECK_FUNCS(_filelengthi64)
106 AC_CHECK_FUNCS([stat _stati64])
107 AC_CHECK_FUNCS(fstat)
108 AC_FUNC_MMAP
109 AC_CHECK_FUNCS(getpagesize)
110 AC_CHECK_FUNCS(sysconf)
112 AC_CHECK_FUNCS([access _access faccessat])
114 PA_HAVE_FUNC(__builtin_clz, (0U))
115 PA_HAVE_FUNC(__builtin_clzl, (0UL))
116 PA_HAVE_FUNC(__builtin_clzll, (0ULL))
117 PA_HAVE_FUNC(__builtin_expect, (1,1))
119 dnl Functions for which we have replacements available in lib/
120 AC_CHECK_FUNCS([vsnprintf _vsnprintf])
121 AC_CHECK_FUNCS([snprintf _snprintf])
122 AC_CHECK_FUNCS([strlcpy])
124 dnl Check for functions that might not be declared in the headers for
125 dnl various idiotic reasons (mostly because of library authors
126 dnl abusing the meaning of __STRICT_ANSI__)
127 AC_CHECK_DECLS(strcasecmp)
128 AC_CHECK_DECLS(stricmp)
129 AC_CHECK_DECLS(strncasecmp)
130 AC_CHECK_DECLS(strnicmp)
131 AC_CHECK_DECLS(strsep)
132 AC_CHECK_DECLS(strlcpy)
133 AC_CHECK_DECLS(strnlen)
135 dnl Check for missing types
136 AC_TYPE_UINTPTR_T
139 dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
140 dnl support these, but don't define __GNUC__ as they don't support
141 dnl some other features of gcc.
143 PA_ADD_CFLAGS([-Werror=attributes])
144 PA_FUNC_ATTRIBUTE(noreturn)
145 PA_FUNC_ATTRIBUTE(returns_nonnull)
146 PA_FUNC_ATTRIBUTE(malloc)
147 PA_FUNC_ATTRIBUTE(alloc_size, (1))
148 PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
149 PA_FUNC_ATTRIBUTE(const)
150 PA_FUNC_ATTRIBUTE(pure)
151 PA_FUNC_ATTRIBUTE_ERROR
154 dnl support function sections
156 AC_ARG_ENABLE([sections],
157 [AC_HELP_STRING([--enable-sections], [compile with function/data section support])],
158 [PA_ADD_CFLAGS([-ffunction-sections]),
159 PA_ADD_CFLAGS([-fdata-sections])],
163 dnl support LTO
165 AC_ARG_ENABLE([lto],
166 [AC_HELP_STRING([--enable-lto], [compile with gcc link time optimization])],
167 [PA_ADD_CLDFLAGS([-flto])
168 dnl Note: we use _PROG rather than _TOOL since we are prepending the full
169 dnl CC name which ought to already contain the host triplet if needed
170 ccbase=`echo "$CC" | awk '{ print $1; }'`
171 AC_CHECK_PROG(CC_AR, [${ccbase}-ar], [${ccbase}-ar], [$ac_cv_prog_AR])
172 AR="$CC_AR"
173 AC_CHECK_PROG(CC_RANLIB, [${ccbase}-ranlib], [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
174 RANLIB="$CC_RANLIB"
175 ], [])
177 dnl If we have gcc, add appropriate code cleanliness options
178 PA_ADD_CFLAGS([-W])
179 PA_ADD_CFLAGS([-Wall])
180 PA_ADD_CFLAGS([-pedantic])
181 dnl LLVM doesn't error out on invalid -W options unless this option is
182 dnl specified first.  Enable this so this script can actually discover
183 dnl which -W options are possible for this compiler.
184 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
185 dnl Suppress format warning on Windows targets due to their <inttypes.h>
186 PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
187 PA_ADD_CFLAGS([-Wc90-c99-compat])
188 PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
189 dnl PA_ADD_CFLAGS([-Wwrite-strings])
190 AC_ARG_ENABLE([werror],
191 [AC_HELP_STRING([--enable-werror],
192 [compile with -Werror to error out on any warning])],
193 [], [enable_werror=no])
194 AS_IF([test x"$enable_werror" != xno],
195 [PA_ADD_CFLAGS([-Werror])],
196 [PA_ADD_CFLAGS([-Werror=implicit])
197 PA_ADD_CFLAGS([-Werror=missing-braces])
198 PA_ADD_CFLAGS([-Werror=return-type])
199 PA_ADD_CFLAGS([-Werror=trigraphs])
200 PA_ADD_CFLAGS([-Werror=pointer-arith])
201 PA_ADD_CFLAGS([-Werror=strict-prototypes])
202 PA_ADD_CFLAGS([-Werror=missing-prototypes])
203 PA_ADD_CFLAGS([-Werror=missing-declarations])
204 PA_ADD_CFLAGS([-Werror=comment])
205 PA_ADD_CFLAGS([-Werror=vla])])
208 dnl support ccache
210 AC_ARG_ENABLE([ccache],
211 [AC_HELP_STRING([--enable-ccache], [compile with ccache])],
212 [CC="ccache $CC"],
215 AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm])
216 AC_OUTPUT(Makefile rdoff/Makefile doc/Makefile)