aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: 8c96e876992804e2cc470470565b9de4fbedf540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
dnl Process this file with autoconf 2.69 or later to produce
dnl a configure script.
AC_PREREQ([2.69])

AC_CONFIG_MACRO_DIR(autoconf)
AC_CONFIG_MACRO_DIRS(autoconf)

AC_INIT(abc80.c)
AC_CONFIG_HEADERS(config/config.h)

AC_CONFIG_AUX_DIR(autoconf/helpers)

dnl If we have wine installed, don't run it when checking for cross-compile
WINELOADER=/dev/null
export WINELOADER

AC_PREFIX_PROGRAM(abc80)

dnl What to build
TARGETS='abc80$(X)'
AC_SUBST(TARGETS)

dnl Get canonical target ("host") name
AC_CANONICAL_HOST

dnl Checks for programs.
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_TYPE_SIZE_T

dnl Checks for standard header files.
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(stdnoreturn.h)
AC_CHECK_HEADERS(stdatomic.h)

dnl Force gcc and gcc-compatible compilers treat signed integers
dnl as 2's complement
PA_ADD_CFLAGS([-fwrapv])

dnl Some environments abuse __STRICT_ANSI__ to disable some
dnl function declarations
PA_ADD_CPPFLAGS([-U__STRICT_ANSI__])

dnl Add -O3 unless disabled; seems to help this program quite a bit
PA_ARG_DISABLED([O3], [don't compile with -O3 optimization],
 [], [PA_ADD_CFLAGS(-O3)])

dnl Can we be selective about libraries?
PA_ADD_LDFLAGS([-Wl,--as-needed])

dnl Don't put things in common if we can avoid it.  We don't want to
dnl assume all compilers support common, and this will help find those
dnl problems.  This also works around an OSX linker problem.
PA_ADD_CFLAGS([-fno-common])

dnl See if we can find sdl-config
AC_CHECK_TOOL([SDL_CONFIG], [sdl-config], [false])
AS_IF(["$SDL_CONFIG" --cflags >/dev/null 2>&1],
      [CPPFLAGS="$CPPFLAGS `"$SDL_CONFIG" --cflags`"
       LIBS="$LIBS `"$SDL_CONFIG" --libs`"],
      [AC_MSG_WARN([sdl-config not found or not functional, this is probably bad news])])

dnl Hack: on windows, build as a console app but create abc80win.exe
pa_libs_win="`echo "$LIBS" | sed -e 's/-mwindows//'`"
AS_IF([test x"$LIBS" != x"$pa_libs_win"],
      [LIBS="$pa_libs_win"
       TARGETS="$TARGETS abc80win\$(X)"
      ])

dnl SDL headers
AC_CHECK_HEADERS(SDL.h)
AC_CHECK_HEADERS(png.h)

dnl Compiler intrinsics
PA_ADD_HEADERS(intrin.h)
PA_ADD_HEADERS(x86intrin.h)
PA_HAVE_FUNC(__builtin_expect, (1,1))
PA_HAVE_FUNC(__builtin_constant_p, (0))
PA_HAVE_FUNC(__rdtsc, ())
PA_HAVE_FUNC(__umulh, (1ULL, 1ULL))
PA_HAVE_FUNC(__emulu, (1U, 1U))
PA_HAVE_FUNC(_addcarry_u64, (1, 1ULL, 1ULL, NULL))

dnl System headers
PA_ADD_HEADERS(windows.h)

AC_CHECK_HEADERS(dirent.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/stat.h)
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(paths.h)
AC_CHECK_HEADERS(termios.h)

AC_CHECK_HEADERS(io.h)
AC_CHECK_HEADERS(direct.h)
AC_CHECK_HEADERS(synchapi.h)
AC_CHECK_HEADERS(mmsystem.h)
AC_CHECK_HEADERS(timeapi.h)

dnl Useful functions which we may lack
AC_CHECK_FUNCS([mempcpy])
AC_CHECK_FUNCS([asprintf])

dnl 128-bit integers?
AC_CHECK_TYPES([uint128_t])
AC_CHECK_TYPES([__uint128_t])
AC_CHECK_TYPES([__uint128])
AC_CHECK_TYPES([unsigned __int128])

dnl Windows stat functions are a bit different, sigh...
AC_CHECK_TYPES([struct _stat64])
AC_CHECK_TYPES([struct stat])
AC_CHECK_FUNCS([stat _stat64])
AC_CHECK_FUNCS([fstat _fstat64])

dnl Newer versions of POSIX have this
AC_CHECK_TYPES(mode_t)

dnl Windows directory handling
AC_CHECK_FUNCS(_mkdir)
AC_CHECK_FUNCS([_findfirst _findfirst64])

dnl Temporary file functions
AC_CHECK_FUNCS([mkstemp tempnam])

dnl Windows file attributes
AC_CHECK_FUNCS([_setmode])

dnl How to set file size
AC_CHECK_FUNCS([ftruncate _chsize_s _chsize])

dnl Memory mapping
PA_ADD_HEADERS(sys/mman.h)
AC_CHECK_FUNCS([sysconf])
AC_CHECK_FUNCS([getpagesize])
AC_CHECK_FUNCS([mmap])
AC_CHECK_FUNCS([msync])

dnl Timekeeping...
AC_CHECK_FUNCS(clock_gettime)
AC_CHECK_FUNCS(clock_nanosleep)
AC_CHECK_FUNCS(nanosleep)
AC_CHECK_FUNCS(gettimeofday)

dnl Console handling
AC_CHECK_FUNCS(setsid)
PA_HAVE_FUNC(AllocConsole, ())
AC_FUNC_FORK

dnl Checks for library functions.
AC_SEARCH_LIBS([deflate], [z])
AC_SEARCH_LIBS([png_write_png], [png])
AC_SEARCH_LIBS([clock_gettime], [rt])
AC_SEARCH_LIBS([timeBeginPeriod], [winmm])

dnl
dnl Some rather useful gcc extensions...
dnl
PA_HAVE_FUNC(__builtin_constant_p, (0))
PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))

dnl
dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
dnl support these, but don't define __GNUC__ as they don't support
dnl some other features of gcc.
dnl
PA_ADD_CFLAGS([-Werror=attributes])
PA_FUNC_ATTRIBUTE(noreturn)
PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null)
PA_FUNC_ATTRIBUTE(malloc)
PA_FUNC_ATTRIBUTE(alloc_size,[1])
PA_FUNC_ATTRIBUTE(alloc_size,[1,2])
PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null)
PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1])
PA_FUNC_ATTRIBUTE(const)
PA_FUNC_ATTRIBUTE(pure)
PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
PA_FUNC_ATTRIBUTE(unused)
PA_FUNC_ATTRIBUTE_ERROR

dnl
dnl Support function sections (if available)
dnl Would be nice to know how to do this on other compilers...
dnl
PA_ARG_DISABLED([gc],
 [don't compile with dead code elimination],
 [],
 [PA_ADD_CFLAGS([-ffunction-sections])
  PA_ADD_CFLAGS([-fdata-sections])
  PA_ADD_CFLAGS([-Wl,--gc-sections])])

dnl
dnl support LTO
dnl
PA_ARG_ENABLED([lto],
 [compile with gcc-style link time optimization],
 [PA_ADD_CFLAGS([-flto])
  dnl Note: we use _PROG rather than _TOOL since we are prepending the full
  dnl CC name which ought to already contain the host triplet if needed
  ccbase=`echo "$CC" | awk '{ print $1; }'`
  AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
  AR="$CC_AR"
  AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
  RANLIB="$CC_RANLIB"], [])

dnl
dnl support sanitizers (if available)
dnl
PA_ARG_ENABLED([sanitizer],
 [compile with sanitizers enabled],
 [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
  PA_ADD_CFLAGS([-fsanitize=address])
  PA_ADD_CFLAGS([-fsanitize=undefined])])

dnl
dnl Don't make symbols visible, there is no point and it just
dnl makes the code slower.
dnl
PA_ADD_CFLAGS([-fvisibility=hidden])

dnl If we have gcc, add appropriate code cleanliness options
PA_ADD_CPPFLAGS([-W])
PA_ADD_CPPFLAGS([-Wall])
dnl LLVM doesn't error out on invalid -W options unless this option is
dnl specified first.  Enable this so this script can actually discover
dnl which -W options are possible for this compiler.
PA_ADD_CPPFLAGS([-Werror=unknown-warning-option])
dnl Suppress format warning on Windows targets due to their <inttypes.h>
PA_ADD_CPPFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
dnl This is needed because we intentionally expect strncpy() to fill
dnl in a zero-padded (not zero-terminated) buffer in several backends
PA_ADD_CPPFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
dnl PA_ADD_CPPFLAGS([-Wwrite-strings])

dnl Various warnings...
PA_ADD_CPPFLAGS([-Wimplicit])
PA_ADD_CPPFLAGS([-Wmissing-braces])
PA_ADD_CPPFLAGS([-Wreturn-type])
PA_ADD_CPPFLAGS([-Wtrigraphs])
PA_ADD_CPPFLAGS([-Wpointer-arith])
PA_ADD_CPPFLAGS([-Wstrict-prototypes])
PA_ADD_CPPFLAGS([-Wmissing-prototypes])
PA_ADD_CPPFLAGS([-Wmissing-declarations])
PA_ADD_CPPFLAGS([-Wcomment])
PA_ADD_CPPFLAGS([-Wvla])]
PA_ARG_ENABLED([werror],
 [compile with -Werror to error out on any warning],
 [PA_ADD_CPPFLAGS([-Werror])],
)

dnl Warnings that are probabilistic based on the compiler version, and
dnl only should be used specifically when looking for opportunities to
dnl address or optimize these cases.
PA_ARG_ENABLED([suggestions],
 [compile with compiler suggestion warnings enabled],
 [PA_ADD_CFLAGS([-Wsuggest-attribute=pure])
  PA_ADD_CFLAGS([-Wsuggest-attribute=const])
  PA_ADD_CFLAGS([-Wsuggest-attribute=noreturn])
  PA_ADD_CFLAGS([-Wsuggest-attribute=format])
  PA_ADD_CFLAGS([-Wsuggest-attribute=cold])
  PA_ADD_CFLAGS([-Wsuggest-attribute=malloc])])

dnl
dnl On some versions of gcc, -Werror=missing-prototypes causes problems
dnl with C99-style external inlines.  Test this *after* adding the -Werror
dnl options.
dnl
PA_CHECK_BAD_STDC_INLINE
PA_C_TYPEOF

dnl
dnl support ccache
dnl
PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT