ObjFW  Diff

Differences From Artifact [9214c38119]:

To Artifact [5a6b4fb150]:


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

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
-
+




















-
-
-




-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+
+

-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+

-
-
-
-
+
+
+
+

-
-
+
+
+

-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+
-
-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+







AC_INIT(ObjFW, 1.1-dev, js@nil.im)
AC_INIT(ObjFW, 1.1dev, js@nil.im)
AC_CONFIG_SRCDIR(src)
AC_CONFIG_AUX_DIR(build-aux)
AC_CONFIG_MACRO_DIR(build-aux/m4)

AC_DEFINE(OBJFW_VERSION_MAJOR, 1, [The major version of ObjFW])
AC_DEFINE(OBJFW_VERSION_MINOR, 1, [The minor version of ObjFW])
dnl This may only be set to 1.1 once 1.1 is released
AC_SUBST(BUNDLE_VERSION, 1.0.0)
AC_SUBST(BUNDLE_SHORT_VERSION, 1.0)

for i in configure.ac build-aux/m4/*; do
	AS_IF([test $i -nt configure], [
		AC_MSG_ERROR([$i is newer than configure! Run ./autogen.sh!])
	])
done

BUILDSYS_INIT

AC_CANONICAL_HOST

AC_ARG_WITH(ixemul,
	AS_HELP_STRING([--with-ixemul], [build with ixemul]))

dnl Used to disable checking for -pedantic on some platforms where it's broken
check_pedantic="yes"

case "$host" in
	arm-*-riscos*)
		AS_IF([test x"$OBJCFLAGS" = x""], [
arm-*-riscos*)
	AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2 -g"])
			OBJCFLAGS="-O2 -g"
		])
		flags="-mfloat-abi=softfp -mfpu=vfp -mlibscl"
		ASFLAGS="$ASFLAGS -mfloat-abi=softfp -mfpu=vfp"
		OBJCFLAGS="$OBJCFLAGS $flags"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
		LDFLAGS="$LDFLAGS $flags"
	flags="-mfloat-abi=softfp -mfpu=vfp -mlibscl"
	ASFLAGS="$ASFLAGS -mfloat-abi=softfp -mfpu=vfp"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	LDFLAGS="$LDFLAGS $flags"

		enable_shared="no"
		enable_threads="no"
		enable_sockets="no"
		enable_files="no"
		;;
	m68k-*-amigaos*)
		AS_IF([test x"$OBJCFLAGS" = x""], [
	enable_shared="no"
	enable_threads="no"
	enable_sockets="no"
	enable_files="no"
	;;
m68k-*-amigaos*)
	AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O0"])
			OBJCFLAGS="-O0"
		])
		OBJCFLAGS="$OBJCFLAGS -noixemul"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul"
		CPPFLAGS="$CPPFLAGS -D__NO_NET_API"
		LDFLAGS="$LDFLAGS -noixemul"
	OBJCFLAGS="$OBJCFLAGS -noixemul"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul"
	CPPFLAGS="$CPPFLAGS -D__NO_NET_API"
	LDFLAGS="$LDFLAGS -noixemul"
	LIBS="$LIBS -ldebug"

		enable_files="yes"	# Required for reading ENV:
		enable_shared="no"
		supports_amiga_lib="yes"
	enable_files="yes"	# Required for reading ENV:
	enable_shared="no"
	with_tls="no"
	supports_amiga_lib="yes"

		AS_IF([test x"$enable_amiga_lib" != x"no"], [
			AC_SUBST(OBJFWRT_AMIGA_LIB, objfwrt68k.library)
			AC_SUBST(SFDC_TARGET, m68k-amigaos)
	AS_IF([test x"$enable_amiga_lib" != x"no"], [
		AC_SUBST(OBJFWRT_AMIGA_LIB,
			['objfwrt${OBJFWRT_LIB_MAJOR}.library'])
			AC_SUBST(SFD_FILE, amigaos3.sfd)
			AC_SUBST(SFDC_INLINE_H, inline.h)
			dnl For 68000, GCC emits calls to helper functions that
			dnl do not work properly in a library.
			t="-mcpu=68020 -fbaserel -noixemul"
			AC_SUBST(AMIGA_LIB_CFLAGS, "$t -ffreestanding")
			AC_SUBST(AMIGA_LIB_LDFLAGS,
		dnl For 68000, GCC emits calls to helper functions that
		dnl do not work properly in a library.
		t="-mcpu=68020 -fbaserel -noixemul -ffreestanding"
		AC_SUBST(AMIGA_LIB_CFLAGS, $t)
		t="$t -resident -nostartfiles -nodefaultlibs -ldebug -lc"
		AC_SUBST(AMIGA_LIB_LDFLAGS, $t)
				"$t -resident -nostartfiles")
		])
	])

		AC_SUBST(LIBBASES_M, libbases.m)
		;;
	powerpc-*-amigaos*)
		CPPFLAGS="$CPPFLAGS -D__USE_INLINE__"
	AC_SUBST(LIBBASES_M, libbases.m)
	;;
powerpc-*-amigaos*)
	CPPFLAGS="$CPPFLAGS -D__USE_INLINE__"

		enable_files="yes"	# Required for reading ENV:
		enable_shared="no"
	enable_files="yes"	# Required for reading ENV:
	enable_shared="no"
	with_tls="no"

		AC_SUBST(LIBBASES_M, libbases.m)
		;;
	*-morphos*)
	AC_SUBST(LIBBASES_M, libbases.m)
	;;
*-morphos*)
		AS_IF([test x"$with_ixemul" != x"yes"], [
			AS_IF([test x"$OBJCFLAGS" = x""], [
	AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2 -g"])
				OBJCFLAGS="-O2 -g"
			])
			OBJCFLAGS="$OBJCFLAGS -noixemul"
			OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul"
			LDFLAGS="$LDFLAGS -noixemul"
			enable_files="yes"	# Required for reading ENV:
			supports_amiga_lib="yes"
	OBJCFLAGS="$OBJCFLAGS -noixemul"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul"
	LDFLAGS="$LDFLAGS -noixemul"
	LIBS="$LIBS -ldebug"

	enable_files="yes"	# Required for reading ENV:
	enable_shared="no"
	supports_amiga_lib="yes"
			check_pedantic="no"	# Breaks generated inlines

			AS_IF([test x"$enable_amiga_lib" != x"no"], [
				AC_SUBST(OBJFWRT_AMIGA_LIB, objfwrt.library)
				AC_SUBST(CVINCLUDE_INLINE_H, inline.h)
				t="-mresident32 -ffreestanding -noixemul"
				AC_SUBST(AMIGA_LIB_CFLAGS, $t)
				t="-mresident32 -nostartfiles -nodefaultlibs"
	AS_IF([test x"$enable_amiga_lib" != x"no"], [
		AC_SUBST(OBJFWRT_AMIGA_LIB,
			['objfwrt${OBJFW_LIB_MAJOR}ppc.library'])
		t="-mresident32 -ffreestanding -noixemul"
		AC_SUBST(AMIGA_LIB_CFLAGS, $t)
		t="-mresident32 -nostartfiles -nodefaultlibs -noixemul -ldebug"
				t="$t -noixemul -lc"
				AC_SUBST(AMIGA_LIB_LDFLAGS, $t)
			])
		AC_SUBST(AMIGA_LIB_LDFLAGS, "$t -lc")
	])

			AC_SUBST(LIBBASES_M, libbases.m)
	AC_SUBST(LIBBASES_M, libbases.m)
		])

		enable_shared="no"
		enable_threads="no"
		;;
	*-msdosdjgpp*)
		enable_shared="no"
		enable_threads="no"
		enable_sockets="no"
		;;
	*-*-mingw*)
		LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
		LIBS="$LIBS -lversion"
	;;
*-msdosdjgpp*)
	enable_shared="no"
	enable_threads="no"
	enable_sockets="no"
	;;
*-*-mingw*)
	LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
	LIBS="$LIBS -lversion"

		AC_SUBST(USE_SRCS_WINDOWS, '${SRCS_WINDOWS}')
		;;
	*-psp-*)
		AS_IF([test x"$DEVKITPSP" = x""], [
	AC_SUBST(USE_SRCS_WINDOWS, '${SRCS_WINDOWS}')
	;;
*-psp-*)
	AS_IF([test x"$DEVKITPSP" = x""], [
			AC_MSG_ERROR(
				[DEVKITPSP is not set! Please set DEVKITPSP.])
		])
		AC_MSG_ERROR([DEVKITPSP is not set! Please set DEVKITPSP.])
	])

		AS_IF([test x"$OBJCFLAGS" = x""], [
	AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2"])
			OBJCFLAGS="-O2"
		])
		OBJCFLAGS="$OBJCFLAGS -G0"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -G0"
		CPPFLAGS="$CPPFLAGS -I$DEVKITPSP/psp/sdk/include"
		LDFLAGS="$LDFLAGS -G0"
		LIBS="$LIBS -L$DEVKITPSP/psp/sdk/lib -lpspdebug -lpspdisplay"
		LIBS="$LIBS -lpspge -lpspctrl -lpspsdk -lc -lpspnet"
		LIBS="$LIBS -lpspnet_inet -lpspnet_apctl -lpspnet_resolver"
		LIBS="$LIBS -lpsputility -lpspuser -lpspkernel -lgcc -lpsplibc"
		enable_shared="no"
		enable_threads="no"	# TODO
		enable_sockets="no"	# TODO
		check_pedantic="no"
	OBJCFLAGS="$OBJCFLAGS -G0"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -G0"
	CPPFLAGS="$CPPFLAGS -I$DEVKITPSP/psp/sdk/include"
	LDFLAGS="$LDFLAGS -G0"
	LIBS="$LIBS -L$DEVKITPSP/psp/sdk/lib -lpspdebug -lpspdisplay"
	LIBS="$LIBS -lpspge -lpspctrl -lpspsdk -lc -lpspnet"
	LIBS="$LIBS -lpspnet_inet -lpspnet_apctl -lpspnet_resolver"
	LIBS="$LIBS -lpsputility -lpspuser -lpspkernel -lgcc -lpsplibc"
	enable_shared="no"
	enable_threads="no"	# TODO
	enable_sockets="no"	# TODO
	check_pedantic="no"

		AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
		;;
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
	;;
hppa*-*-hpux*)
	dnl Don't default to -g: It creates errors from the assembler and breaks
	dnl exceptions.
	AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2"])
	dnl HP-UX 11.11's inttypes.h defines UINTPTR_MAX etc. to nothing. GCC's
	dnl stdint.h defines those correctly, but if inttypes.h gets included
	dnl after something included stdint.h, it gets broken again. Therefore,
	dnl always include inttypes.h as the very first thing.
	dnl We need to put this into OBJCFLAGS and not CPPFLAGS as CPPFLAGS are
	dnl also used for .S files.
	OBJCFLAGS="$OBJCFLAGS -include inttypes.h"
	dnl We need -latomic for GCC's atomics to work.
	LIBS="$LIBS -latomic"
	;;
*-*-mint*)
	enable_shared="no"
	enable_threads="no"	# TODO
	with_tls="no"
	;;
esac

AS_IF([test x"$host_os" = x"msdosdjgpp" -a x"$build_os" = x"msdosdjgpp"], [
	dnl Hack to make configure find these on DOS.
	: ${AR:=ar.exe}
	: ${GREP:=grep.exe}
	: ${RANLIB:=ranlib.exe}
])

AC_LANG([Objective C])
case "$host_os" in
morphos*)
	dnl Don't use clang on MorphOS - it does not support baserel, which is
	dnl required for the .library.
	potential_compilers="gcc"
	;;
*)
AC_PROG_OBJC([clang egcc gcc])
AC_PROG_OBJCPP
AC_PROG_LN_S
AC_PROG_INSTALL
	potential_compilers="clang egcc gcc"
	;;
esac
AC_PROG_OBJC($potential_compilers)
AC_PROG_OBJCPP
AC_PROG_LN_S
AC_PROG_EGREP

BUILDSYS_CHECK_IOS

AC_ARG_WITH(wii,
	AS_HELP_STRING([--with-wii], [build for Wii]))
AS_IF([test x"$with_wii" = x"yes"], [
171
172
173
174
175
176
177

178
179
180
181
182
183
184
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198







+







	CPPFLAGS="$CPPFLAGS -DGEKKO -I$DEVKITPRO/libogc/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DGEKKO -I\$DEVKITPRO/libogc/include"
	LDFLAGS="$LDFLAGS -mrvl -mcpu=750 -meabi -mhard-float"
	LIBS="$LIBS -L$DEVKITPRO/libogc/lib/wii -lfat -logc"
	TESTS_LIBS="$TESTS_LIBS -lwiiuse -lbte"
	enable_shared="no"
	enable_threads="no"	# TODO
	with_tls="no"

	AC_DEFINE(OF_WII, 1, [Whether we are compiling for Wii])
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

AC_ARG_WITH(wii-u,
	AS_HELP_STRING([--with-wii-u], [build for Wii U]))
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
290
291
292
293


294
295
296
297
298
299
300






301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
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







290
291
292
293
294
295


296


297









298
299







300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318






319


320
321
322
323
324
325
326







+


















-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+













-
-
-
-
-
-
+
-
-







	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM11 -I\$DEVKITPRO/libctru/include"
	ASFLAGS="$ASFLAGS -march=armv6k"
	LDFLAGS="$LDFLAGS -specs=3dsx.specs -march=armv6k -mtune=mpcore"
	LDFLAGS="$LDFLAGS -mfloat-abi=hard -mtp=soft -mword-relocations"
	LIBS="$LIBS -L$DEVKITPRO/libctru/lib -lctru"
	enable_shared="no"
	enable_threads="no"	# TODO
	with_tls="no"
	check_pedantic="no"

	AC_DEFINE(OF_NINTENDO_3DS, 1,
		[Whether we are compiling for Nintendo 3DS])
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

CPP="$OBJCPP"
CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS -DOF_COMPILING_OBJFW"
flags="-fexceptions -fobjc-exceptions -funwind-tables"
flags="$flags -fconstant-string-class=OFConstantString"
OBJCFLAGS="$OBJCFLAGS -Wall $flags"
OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
dnl amiga-gcc requires -fexceptions in LDFLAGS in order to link in the glue code
dnl for registering the frames.
LDFLAGS="$LDFLAGS -fexceptions"

case "$OBJC" in
	*clang*)
		case "$host" in
			dnl Clang generates MIPS assembly not accepted by GNU
			dnl as, however, Clang's integrated assembler doesn't
			dnl accept everything used in ObjFW's assembly files.
			dnl Therefore, use the integrated assembler for ObjC
			dnl files, but not for assembly files.
*clang*)
	case "$host" in
	mips*-*-*)
		dnl Clang generates MIPS assembly not accepted by GNU as,
		dnl however, Clang's integrated assembler doesn't accept
		dnl everything used in ObjFW's assembly files. Therefore, use
		dnl the integrated assembler for ObjC files, but not for
		dnl assembly files.
			mips*-*-*)
				flag="-integrated-as"
				OBJCFLAGS="$OBJCFLAGS $flag"
				OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
				;;
			dnl Don't use -no-integrated-as on Darwin. It breaks
			dnl building for the iOS simulator.
		OBJCFLAGS="$OBJCFLAGS -integrated-as"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -integrated-as"
		;;
	i?86-*-darwin* | x86_64-*-darwin*)
		dnl Don't use -no-integrated-as on Darwin. It breaks building
		dnl for the iOS simulator.
			i?86-*-darwin* | x86_64-*-darwin*)
				;;
		;;
			dnl Many older Clang versions don't support jmp short.
			i?86-*-* | x86_64-*-*)
	sparc64-*-*openbsd*)
				ASFLAGS="$ASFLAGS -no-integrated-as"
				;;
			dnl Clang's assembler on Windows is not complete yet
			dnl and cannot compile all .S files.
			*-*-mingw*)
				ASFLAGS="$ASFLAGS -no-integrated-as"
				;;
			dnl Clang generates assembly output on SPARC64 that
			dnl OpenBSD's assembler does not accept.
		dnl Clang generates assembly output on SPARC64 that OpenBSD's
		dnl assembler does not accept.
			sparc64-*-*openbsd*)
				flag="-integrated-as"
				OBJCFLAGS="$OBJCFLAGS $flag"
				OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
				;;
		esac
		;;
		flag="-integrated-as"
		OBJCFLAGS="$OBJCFLAGS $flag"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
		;;
	esac
	;;
esac

AX_CHECK_COMPILER_FLAGS(-std=gnu11, [
	OBJCFLAGS="$OBJCFLAGS -std=gnu11"
], [
	AX_CHECK_COMPILER_FLAGS(-std=gnu1x, [
		OBJCFLAGS="$OBJCFLAGS -std=gnu1x"
	], [
		AX_CHECK_COMPILER_FLAGS(-std=gnu99,
			[OBJCFLAGS="$OBJCFLAGS -std=gnu99"])
	])
])

case "$build_os" in
	morphos*)
		# MorphOS 3.10 has a buggy ixemul that does not work with -pipe.
		;;
	*)
		AX_CHECK_COMPILER_FLAGS(-pipe, [OBJCFLAGS="$OBJCFLAGS -pipe"])
AX_CHECK_COMPILER_FLAGS(-pipe, [OBJCFLAGS="$OBJCFLAGS -pipe"])
		;;
esac
AX_CHECK_COMPILER_FLAGS(-fno-common, [OBJCFLAGS="$OBJCFLAGS -fno-common"])
AX_CHECK_COMPILER_FLAGS(-Xclang -fno-constant-cfstrings, [
	flag="-Xclang -fno-constant-cfstrings"
	OBJCFLAGS="$OBJCFLAGS $flag"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
])
AX_CHECK_COMPILER_FLAGS([-Wsign-compare -Werror],
339
340
341
342
343
344
345
346
347


348
349
350


351
352
353
354
355
356
357
358
359
360
361
362
363











364
365
366
367
368
369
370







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
337
338
339
340
341
342
343


344
345



346
347
348
349
350










351
352
353
354
355
356
357
358
359
360
361
362






363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385

386



387

388
389
390
391
392
393
394







-
-
+
+
-
-
-
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
















-

-
-
-

-







	[OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body"])
AX_CHECK_COMPILER_FLAGS([-Wobjc-missing-property-synthesis -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis"])
AX_CHECK_COMPILER_FLAGS([-Wmissing-method-return-type -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wmissing-method-return-type"])

case "$host" in
	m68k-*-amigaos*)
		dnl The inline headers generate code that triggers
m68k-*-amigaos*)
	dnl The inline headers generate code that triggers -Wpointer-sign.
		dnl -Wpointer-sign.
		OBJCFLAGS="$OBJCFLAGS -Wno-pointer-sign"
		;;
	OBJCFLAGS="$OBJCFLAGS -Wno-pointer-sign"
	;;
esac

AC_MSG_CHECKING(whether Objective C compiler supports properties)
AC_TRY_COMPILE([
	#ifdef __has_attribute
	# if __has_attribute(objc_root_class)
	__attribute__((__objc_root_class__))
	# endif
	#endif
	@interface Foo
	{
		id bar;
	}
AC_COMPILE_IFELSE([
	AC_LANG_PROGRAM([
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Foo
		{
			id bar;
		}

	@property (nonatomic, retain) id bar;
	@end
], [
	Foo *foo = (id)0;
	[foo setBar: (id)0];
	foo = [foo bar];
		@property (nonatomic, retain) id bar;
		@end
	], [[
		Foo *foo = (id)0;
		[foo setBar: (id)0];
		foo = [foo bar];
	]])
], [
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)
	AC_MSG_ERROR(Compiler does not support properties!)
])

AC_CHECK_TOOL(AR, ar)
AC_PROG_RANLIB

AC_ARG_ENABLE(shared,
	AS_HELP_STRING([--disable-shared], [do not build shared library]))
AS_IF([test x"$enable_shared" != x"no"], [
	BUILDSYS_SHARED_LIB
	AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}")
	AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a")
	AC_SUBST(EXCEPTIONS_EXCEPTIONS_LIB_A, "exceptions/exceptions.lib.a")
	AC_SUBST(FORWARDING_LIB_A, "forwarding.lib.a")
	AC_SUBST(FORWARDING_FORWARDING_LIB_A, "forwarding/forwarding.lib.a")
	AC_SUBST(INVOCATION_LIB_A, "invocation.lib.a")
	AC_SUBST(INVOCATION_INVOCATION_LIB_A, "invocation/invocation.lib.a")
	AC_SUBST(LOOKUP_ASM_LIB_A, "lookup-asm.lib.a")
	AC_SUBST(LOOKUP_ASM_LOOKUP_ASM_LIB_A, "lookup-asm/lookup-asm.lib.a")

	BUILDSYS_FRAMEWORK([
		AC_SUBST(OBJFW_FRAMEWORK, "ObjFW.framework")
		build_framework="yes"
	])
], [
	AC_DEFINE(OF_NO_SHARED, 1, [Whether no shared library was built])
410
411
412
413
414
415
416
417
418
419





420
421
422



423

424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
404
405
406
407
408
409
410



411
412
413
414
415
416
417
418
419
420
421

422
423
424

425



426

427
428
429
430
431
432
433







-
-
-
+
+
+
+
+



+
+
+
-
+


-

-
-
-

-







	TESTS_LIBS="-L../src/runtime -L../src/runtime/linklib $TESTS_LIBS"
	TESTS_LIBS="-L../src -lobjfw $TESTS_LIBS"
])

AC_ARG_ENABLE(amiga-lib,
	AS_HELP_STRING([--disable-amiga-lib], [do not build Amiga library]))
AS_IF([test x"$supports_amiga_lib" != x"yes"], [enable_amiga_lib="no"])

AS_IF([test x"$enable_shared" = x"no" -a x"$enable_amiga_lib" = x"no"], [
	enable_static="yes"
AS_IF([test x"$enable_amiga_lib" != x"no"], [
	AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a")
	AC_SUBST(EXCEPTIONS_A, "exceptions.a")
	AC_SUBST(FORWARDING_A, "forwarding.a")
	AC_SUBST(LOOKUP_ASM_AMIGALIB_A, "lookup-asm.amigalib.a")
])

AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library]))
AS_IF([test x"$enable_shared" = x"no" -a x"$enable_amiga_lib" = x"no"], [
	enable_static="yes"
])
AS_IF([test x"$enable_static" = x"yes" -o x"$enable_amiga_lib" != x"no"], [
AS_IF([test x"$enable_static" = x"yes"], [
	AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a")
	AC_SUBST(EXCEPTIONS_A, "exceptions.a")
	AC_SUBST(EXCEPTIONS_EXCEPTIONS_A, "exceptions/exceptions.a")
	AC_SUBST(FORWARDING_A, "forwarding.a")
	AC_SUBST(FORWARDING_FORWARDING_A, "forwarding/forwarding.a")
	AC_SUBST(INVOCATION_A, "invocation.a")
	AC_SUBST(INVOCATION_INVOCATION_A, "invocation/invocation.a")
	AC_SUBST(LOOKUP_ASM_A, "lookup-asm.a")
	AC_SUBST(LOOKUP_ASM_LOOKUP_ASM_A, "lookup-asm/lookup-asm.a")
])

AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins])
AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [
	AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}')
	AC_SUBST(TESTPLUGIN, "plugin")
	AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support])
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470
471
472



473
474
475
476
477
478
479
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459
460
461
462
463



464
465
466
467
468
469
470
471
472
473







-
+











-
-
-
+
+
+







])

AC_MSG_CHECKING(whether we need -D_GNU_SOURCE)
AC_EGREP_CPP(egrep_cpp_yes, [
	#include <stdlib.h>

	#if defined(__GLIBC__) || defined(__MINGW32__) || \
	    defined(__NEWLIB__) || defined(__MORPHOS__)
	    defined(__NEWLIB__) || defined(__MORPHOS__) || defined(__MINT__)
	egrep_cpp_yes
	#endif
], [
	AC_MSG_RESULT(yes)
	CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS"
	gnu_source="yes"
], [
	AC_MSG_RESULT(no)
])

case "$host_os" in
	solaris*)
		CPPFLAGS="-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS $CPPFLAGS"
		;;
solaris*)
	CPPFLAGS="-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS $CPPFLAGS"
	;;
esac

objc_runtime="ObjFW runtime"
AC_CHECK_HEADER(objc/objc.h)
AC_MSG_CHECKING(which Objective C runtime to use)
AC_ARG_ENABLE(runtime,
	AS_HELP_STRING([--enable-runtime], [use the included runtime]))
495
496
497
498
499
500
501
502
503


504
505
506

507
508
509
510




511
512
513
514
515
516
517
489
490
491
492
493
494
495


496
497

498

499
500



501
502
503
504
505
506
507
508
509
510
511







-
-
+
+
-

-
+

-
-
-
+
+
+
+







			:
		])
	])
])
AC_MSG_RESULT($objc_runtime)

case "$objc_runtime" in
	"ObjFW runtime")
		AC_DEFINE(OF_OBJFW_RUNTIME, 1,
"ObjFW runtime")
	AC_DEFINE(OF_OBJFW_RUNTIME, 1, [Whether we use the ObjFW runtime])
			[Whether we use the ObjFW runtime])

		AC_MSG_CHECKING([whether -fobjc-runtime=objfw is supported])
	AC_MSG_CHECKING([whether -fobjc-runtime=objfw is supported])

		old_OBJCFLAGS="$OBJCFLAGS"
		OBJCFLAGS="$OBJCFLAGS -Xclang -fobjc-runtime=objfw"
		AC_TRY_LINK([
	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -Xclang -fobjc-runtime=objfw"
	AC_LINK_IFELSE([
		AC_LANG_PROGRAM([
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Test
			+ (void)test;
529
530
531
532
533
534
535
536

537

538

539
540
541
542



543
544
545
546
547
548





549
550
551


552
553
554
555
556




557
558
559
560



561
562
563
564
565




566
567
568
569
570
571
572
573
574
575









576
577
578


579
580
581
582



583
584
585


586
587

588
589
590



591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610













611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632





















633
634
635
636
637
638





639
640
641
642



643
644
645
646
647



648
649
650
651
652




653
654
655
656
657
658
659
660






661



662
663
664
665
666
667
668









669
670








671



672
673
674
675
676
677
678





679
680
681


682
683
684
685
686
687
688
689
690
691
692
693











694
695
696


697
698
699
700
701
702





703
704
705
706
707
708
709
710
711
712
713
714
715
716
717











718
719
720


721
722
723
724
725
726
727
728
729
730










731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791
792
793
794
795
796
797
798
799
800
801
802

803


804
805
806
807
808
809
810
523
524
525
526
527
528
529

530
531
532

533




534
535
536






537
538
539
540
541
542


543
544
545




546
547
548
549
550



551
552
553
554




555
556
557
558
559









560
561
562
563
564
565
566
567
568
569


570
571




572
573
574
575


576
577


578
579


580
581
582
583
584
585
586
587
588
589
590













591
592
593
594
595
596
597
598
599
600
601
602
603
604





















605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626





627
628
629
630
631
632



633
634
635





636
637
638
639




640
641
642
643

644






645
646
647
648
649
650
651
652
653
654







655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678





679
680
681
682
683



684
685
686











687
688
689
690
691
692
693
694
695
696
697
698


699
700
701





702
703
704
705
706
707
708
709
710
711










712
713
714
715
716
717
718
719
720
721
722
723


724
725
726









727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752





























753
754
755
756
757
758
759
760
761
762
763
764


765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782
783
784
785
786
787
788







-
+

+
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+
-
-
-
-
+
+
+

-
-
+
+
-
-
+

-
-
+
+
+







+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+
-
-
-
-
-
+
+
+

-
-
-
-
+
+
+
+
-

-
-
-
-
-
-
+
+
+
+
+
+

+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
-
+
+
+


-
-
-
-
-
+
+
+
+
+
-
-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
-
+













+
-
+
+







				return (void *)0;
			}

			void
			__objc_exec_class(void *module)
			{
			}
		], [
		], [[
			[Test test];
		]])
		], [
	], [
			flag="-Xclang -fobjc-runtime=objfw"
			OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
			AC_MSG_RESULT(yes)
		], [
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fobjc-runtime=objfw"
		AC_MSG_RESULT(yes)
	], [
			flag="-fgnu-runtime"
			OBJCFLAGS="$old_OBJCFLAGS $flag"
			OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
			AC_MSG_RESULT(no)
			old_compiler="yes"
		])
		OBJCFLAGS="$old_OBJCFLAGS -fgnu-runtime"
		OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -fgnu-runtime"
		AC_MSG_RESULT(no)
		old_compiler="yes"
	])

		AC_SUBST(RUNTIME, "runtime")
		AC_CONFIG_FILES(src/runtime/Info.plist)
	AC_SUBST(RUNTIME, "runtime")
	AC_CONFIG_FILES(src/runtime/Info.plist)

		AS_IF([test x"$enable_shared" != x"no"], [
			AC_SUBST(OBJFWRT_SHARED_LIB,
				"${LIB_PREFIX}objfwrt${LIB_SUFFIX}")
		])
	AS_IF([test x"$enable_shared" != x"no"], [
		AC_SUBST(OBJFWRT_SHARED_LIB,
			"${LIB_PREFIX}objfwrt${LIB_SUFFIX}")
	])

		AS_IF([test x"$enable_static" = x"yes"], [
			AC_SUBST(OBJFWRT_STATIC_LIB, "libobjfwrt.a")
		])
	AS_IF([test x"$enable_static" = x"yes"], [
		AC_SUBST(OBJFWRT_STATIC_LIB, "libobjfwrt.a")
	])

		AS_IF([test x"$build_framework" = x"yes"], [
			AC_SUBST(OBJFWRT_FRAMEWORK, "ObjFWRT.framework")
			AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-framework ObjFWRT")
		])
	AS_IF([test x"$build_framework" = x"yes"], [
		AC_SUBST(OBJFWRT_FRAMEWORK, "ObjFWRT.framework")
		AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-framework ObjFWRT")
	])

		AS_IF([test x"$enable_amiga_lib" != x"no"], [
			AC_SUBST(RUNTIME_LIBS, "-lobjfwrt.library")
			AC_SUBST(LINKLIB, linklib)
			tmp="../src/runtime/linklib/libobjfwrt.library.a"
			AC_SUBST(LIBOBJFWRT_DEP, "$tmp")
			AC_SUBST(LIBOBJFWRT_DEP_LVL2, "../$tmp")
		], [
			AC_SUBST(RUNTIME_LIBS, "-lobjfwrt")
		])
	AS_IF([test x"$enable_amiga_lib" != x"no"], [
		AC_SUBST(RUNTIME_LIBS, "-lobjfwrt.library")
		AC_SUBST(LINKLIB, linklib)
		tmp="../src/runtime/linklib/libobjfwrt.library.a"
		AC_SUBST(LIBOBJFWRT_DEP, "$tmp")
		AC_SUBST(LIBOBJFWRT_DEP_LVL2, "../$tmp")
	], [
		AC_SUBST(RUNTIME_LIBS, "-lobjfwrt")
	])

		AS_IF([test x"$enable_shared" = x"no" \
				-a x"$enable_amiga_lib" = x"no"], [
	AS_IF([test x"$enable_shared" = x"no" \
	    -a x"$enable_amiga_lib" = x"no"], [
			tmp="../src/runtime/libobjfwrt.a"
			AC_SUBST(LIBOBJFWRT_DEP, "$tmp")
			AC_SUBST(LIBOBJFWRT_DEP_LVL2, "../$tmp")
		])
		AC_SUBST(LIBOBJFWRT_DEP, "../src/runtime/libobjfwrt.a")
		AC_SUBST(LIBOBJFWRT_DEP_LVL2, "../../src/runtime/libobjfwrt.a")
	])

		AS_IF([test x"$enable_seluid24" = x"yes"], [
			AC_DEFINE(OF_SELUID24, 1,
	AS_IF([test x"$enable_seluid24" = x"yes"], [
		AC_DEFINE(OF_SELUID24, 1, [Whether to use 24 bit selector UIDs])
				[Whether to use 24 bit selector UIDs])
		])
	])

		AC_MSG_CHECKING(for exception type)
		AC_TRY_COMPILE([
	AC_MSG_CHECKING(for exception type)
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
			extern void foo();
		], [
			@try {
				foo();
			} @finally {
				foo();
			}
		])
		], [
			AS_IF([$EGREP __gnu_objc_personality_v0 \
					conftest.$ac_objext >/dev/null], [
				exception_type="DWARF"
			])
			AS_IF([$EGREP __gnu_objc_personality_sj0 \
					conftest.$ac_objext >/dev/null], [
				exception_type="SjLj"
			])
			AS_IF([$EGREP __gnu_objc_personality_seh0 \
					conftest.$ac_objext >/dev/null], [
				exception_type="SEH"
			])
	], [
		AS_IF([$EGREP __gnu_objc_personality_v0 conftest.$ac_objext \
		    >/dev/null], [
			exception_type="DWARF"
		])
		AS_IF([$EGREP __gnu_objc_personality_sj0 conftest.$ac_objext \
		    >/dev/null], [
			exception_type="SjLj"
		])
		AS_IF([$EGREP __gnu_objc_personality_seh0 conftest.$ac_objext \
		    >/dev/null], [
			exception_type="SEH"
		])

			raise_exception="_Unwind_RaiseException"

			case "$exception_type" in
			DWARF)
				AC_DEFINE(HAVE_DWARF_EXCEPTIONS, 1,
					[Whether DWARF exceptions are used])
				;;
			SjLj)
				AC_DEFINE(HAVE_SJLJ_EXCEPTIONS, 1,
					[Whether SjLj exceptions are used])
				raise_exception="_Unwind_SjLj_RaiseException"
				;;
			SEH)
				AC_DEFINE(HAVE_SEH_EXCEPTIONS, 1,
					[Whether SEH exceptions are used])
				;;
			*)
				AC_MSG_RESULT(unknown)
				AC_MSG_ERROR([Exception type not detected!])
				;;
			esac
		case "$exception_type" in
		DWARF)
			AC_DEFINE(HAVE_DWARF_EXCEPTIONS, 1,
				[Whether DWARF exceptions are used])
			raise_exception="_Unwind_RaiseException"
			;;
		SjLj)
			AC_DEFINE(HAVE_SJLJ_EXCEPTIONS, 1,
				[Whether SjLj exceptions are used])
			raise_exception="_Unwind_SjLj_RaiseException"
			;;
		SEH)
			AC_DEFINE(HAVE_SEH_EXCEPTIONS, 1,
				[Whether SEH exceptions are used])
			raise_exception="_Unwind_RaiseException"
			;;
		*)
			AC_MSG_RESULT(unknown)
			AC_MSG_ERROR([Exception type not detected!])
			;;
		esac

			AC_MSG_RESULT($exception_type)
		], [
			AC_MSG_RESULT(exceptions unavailable!)
			AC_MSG_ERROR([Exceptions not accepted by compiler!])
		])
		AC_MSG_RESULT($exception_type)
	], [
		AC_MSG_RESULT(exceptions unavailable!)
		AC_MSG_ERROR([Exceptions not accepted by compiler!])
	])

		AC_SEARCH_LIBS($raise_exception, [c++abi gcc_s gcc], [
			dnl c++abi requires pthread on OpenBSD
			AS_IF([test x"$ac_lib" = x"c++abi"], [
	AC_SEARCH_LIBS($raise_exception, [c++abi gcc_s gcc unwind], [
		dnl c++abi requires pthread on OpenBSD
		AS_IF([test x"$ac_lib" = x"c++abi"], [LIBS="$LIBS -lpthread"])
				LIBS="$LIBS -lpthread"
			])
		], [
			AC_MSG_ERROR([$raise_exception missing!])
		], [-lpthread])
	], [
		AC_MSG_ERROR([$raise_exception missing!])
	], [-lpthread])

		AC_CHECK_FUNCS(_Unwind_GetDataRelBase _Unwind_GetTextRelBase)
		;;
	"Apple runtime")
		AC_DEFINE(OF_APPLE_RUNTIME, 1,
	AC_CHECK_FUNCS(_Unwind_GetDataRelBase _Unwind_GetTextRelBase)
	;;
"Apple runtime")
	AC_DEFINE(OF_APPLE_RUNTIME, 1, [Whether we use the Apple ObjC runtime])
			[Whether we use the Apple ObjC runtime])

		AC_CHECK_LIB(objc, objc_msgSend, [
			AC_SUBST(RUNTIME_LIBS, "-lobjc")
			AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-lobjc")
		], [
			AC_MSG_ERROR([libobjc not found!])
		])
	AC_CHECK_LIB(objc, objc_msgSend, [
		AC_SUBST(RUNTIME_LIBS, "-lobjc")
		AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-lobjc")
	], [
		AC_MSG_ERROR([libobjc not found!])
	])

	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -lobjc"

		AC_CHECK_FUNC(objc_autoreleasePoolPush, [], [
			AC_SUBST(RUNTIME_AUTORELEASE_M, "runtime/autorelease.m")
		])
		AC_CHECK_FUNC(objc_constructInstance, [], [
			AC_SUBST(RUNTIME_INSTANCE_M, "runtime/instance.m")
		])
		;;
	AC_CHECK_FUNC(objc_autoreleasePoolPush, [], [
		AC_SUBST(RUNTIME_AUTORELEASE_M, "runtime/autorelease.m")
	])
	AC_CHECK_FUNC(objc_constructInstance, [], [
		AC_SUBST(RUNTIME_INSTANCE_M, "runtime/instance.m")
	])

	OBJCFLAGS="$old_OBJCFLAGS"
	;;
esac

case "$host_os" in
mint*)
	dnl _Unwind_Backtrace crashes on MiNT
	;;
hpux*)
	dnl _Unwind_Backtrace() returns complete garbage on HP-UX.
	;;
*)
AC_CHECK_FUNCS(_Unwind_Backtrace)
	AC_CHECK_FUNCS(_Unwind_Backtrace)
	;;
esac

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
			AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjc"])
			AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK,
darwin*)
	AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
	AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
		AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjc"])
		AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK, ["-Wl,-reexport-lobjc"])
				["-Wl,-reexport-lobjc"])
			LDFLAGS="$LDFLAGS -Wl,-U,_NSFoundationVersionNumber"
		])
		LDFLAGS="$LDFLAGS -Wl,-U,_NSFoundationVersionNumber"
	])

		AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [
			AS_IF([test x"$exception_type" = x"DWARF"], [
				LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0"
			])
			AS_IF([test x"$exception_type" = x"SjLj"], [
				LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_sj0"
			])
			AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjfwrt"])
			AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK,
				["-Wl,-reexport_framework,ObjFWRT"])
		])
	AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [
		AS_IF([test x"$exception_type" = x"DWARF"], [
			LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0"
		])
		AS_IF([test x"$exception_type" = x"SjLj"], [
			LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_sj0"
		])
		AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjfwrt"])
		AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK,
			["-Wl,-reexport_framework,ObjFWRT"])
	])

		AC_CHECK_HEADERS(sysdir.h)
		AC_CHECK_FUNCS(sysdir_start_search_path_enumeration)
	AC_CHECK_HEADERS(sysdir.h)
	AC_CHECK_FUNCS(sysdir_start_search_path_enumeration)

		AS_IF([test x"$host_is_ios" = x"yes"], [
			AC_SUBST(TESTS_STATIC_LIB, tests.a)
			TESTS_LIBS="$TESTS_LIBS -framework CoreFoundation"
		])
		;;
	AS_IF([test x"$host_is_ios" = x"yes"], [
		AC_SUBST(TESTS_STATIC_LIB, tests.a)
		TESTS_LIBS="$TESTS_LIBS -framework CoreFoundation"
	])
	;;
esac

AC_MSG_CHECKING(whether Objective C compiler supports ARC)
old_OBJCFLAGS="$OBJCFLAGS"
OBJCFLAGS="$OBJCFLAGS -fobjc-arc -fobjc-arc-exceptions"
AC_TRY_COMPILE([
	#ifdef __has_attribute
	# if __has_attribute(objc_root_class)
	__attribute__((__objc_root_class__))
	# endif
	#endif
	@interface Foo
	{
		struct objc_class *_isa;
	}
AC_COMPILE_IFELSE([
	AC_LANG_PROGRAM([
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Foo
		{
			struct objc_class *_isa;
		}

	+ (id)alloc;
	@end
		+ (id)alloc;
		@end

	@implementation Foo
	+ (id)alloc
	{
		return (id)0;
	}
	@end
], [
	__weak id foo = [Foo alloc];
	(void)foo;
		@implementation Foo
		+ (id)alloc
		{
			return (id)0;
		}
		@end
	], [[
		__weak id foo = [Foo alloc];
		(void)foo;
	]])
], [
	AC_MSG_RESULT(yes)
	AC_DEFINE(COMPILER_SUPPORTS_ARC, 1, [Whether the compiler supports ARC])
	AC_SUBST(RUNTIME_ARC_TESTS_M, RuntimeARCTests.m)
], [
	AC_MSG_RESULT(no)
])
OBJCFLAGS="$old_OBJCFLAGS"

AC_C_BIGENDIAN([
	AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian])
])
AS_IF([test x"$ac_cv_c_bigendian" = x"universal"], [
	AC_DEFINE(OF_UNIVERSAL, 1, [Whether we are building a universal binary])
])

AC_MSG_CHECKING(for SIZE_MAX)
AC_EGREP_CPP(egrep_cpp_yes, [
	#include <stdint.h>
	#include <limits.h>

	#ifdef SIZE_MAX
	egrep_cpp_yes
	#endif
], [
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)
	AC_MSG_CHECKING(for SIZE_T_MAX)
	AC_EGREP_CPP(egrep_cpp_yes, [
		#include <stdint.h>
		#include <limits.h>

		#ifdef SIZE_T_MAX
		egrep_cpp_yes
		#endif
	], [
		AC_MSG_RESULT(yes)
		size_max="SIZE_T_MAX"
	], [
		AC_MSG_RESULT(no)
		size_max="(~(size_t)0)"
	])
	AC_DEFINE_UNQUOTED(SIZE_MAX, $size_max, [Maximum value for size_t])
])
AC_MSG_CHECKING(for SSIZE_MAX)
AC_EGREP_CPP(egrep_cpp_yes, [
	#include <stdint.h>
	#include <limits.h>

	#ifdef SSIZE_MAX
	egrep_cpp_yes
	#endif
], [
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)
	AC_DEFINE(SSIZE_MAX, [((ssize_t)(SIZE_MAX / 2))],
		[Maximum value for ssize_t])
	AC_DEFINE(SSIZE_MAX, [(SIZE_MAX / 2)], [Maximum value for ssize_t])
])
AC_MSG_CHECKING(for UINTPTR_MAX)
AC_EGREP_CPP(egrep_cpp_yes, [
	#include <stdint.h>
	#include <limits.h>

	#ifdef UINTPTR_MAX
	egrep_cpp_yes
	#endif
], [
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)
	AC_CHECK_SIZEOF(uintptr_t)
	AC_DEFINE(UINTPTR_MAX, [(~(uintptr_t)0)], [Maximum value for uintptr_t])
	AC_DEFINE(UINTPTR_MAX,
		[(SIZEOF_UINTPTR_T * CHAR_BIT)], [Maximum value for uintptr_t])
])

AC_CHECK_HEADER(inttypes.h,
	[AC_DEFINE(OF_HAVE_INTTYPES_H, 1, [Whether we have inttypes.h])])

AC_CHECK_HEADER(sys/types.h,
	[AC_DEFINE(OF_HAVE_SYS_TYPES_H, 1, [Whether we have sys/types.h])])
823
824
825
826
827
828
829
830
831
832




833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882




883
884
885
886
887
888

889
890
891
892
893
894
895







896
897
898
899
900


901
902




903
904


905
906
907
908
909
910
911
912
913
914









915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938


939
940
941
942
943
944
945
946
947
948





949
950
951


952
953
954
955




956
957
958


959
960
961
962



963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983










984
985
986
987
988
989
990
801
802
803
804
805
806
807



808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830



























831



832
833
834
835
836
837
838
839
840
841
842







843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862


863
864










865
866
867
868
869
870
871
872
873

874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893



894
895
896
897
898
899
900





901
902
903
904
905
906


907
908
909



910
911
912
913



914
915




916
917
918


919
920
921
922
923
924
925
926
927










928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944







-
-
-
+
+
+
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
+
+
+






+
-
-
-
-
-
-
-
+
+
+
+
+
+
+





+
+


+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-




















-
-
-
+
+





-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-









-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







AS_IF([test x"$ac_cv_sizeof_float" != x"4" -o x"$ac_cv_sizeof_double" != x"8"],
	[AC_MSG_ERROR(
		[Floating point implementation does not conform to IEEE 754!])])

AC_MSG_CHECKING(for floating point endianess)
fp_endianess="unknown"
AS_IF([test x"$ac_cv_c_bigendian" != x"universal"], [
	AC_TRY_COMPILE([
		double endianess = 2.993700760838795055656993580068609688772747263874402942272934826871811872228512759832626847251963763755836687759498519784550143745834860002945223766052808125982053455555265216112722718870586961456110693379343178124592311441022662940307099598578775368547768968914916965731708568179631324904813506101190853720749196062963892799499230635163056742330563321122389331703618066046034494287335316842529021563862331183541255013987734473643350285400060357711238514186776429325214739886098119655678483017894951556639821088508565036657794343031121375178126860889964700274558728491825977274341798997758923017217660272136611938897932105874133412726223468780517578125e-259;
	], [
	AC_COMPILE_IFELSE([
		AC_LANG_SOURCE([
			double endianess = 2.993700760838795055656993580068609688772747263874402942272934826871811872228512759832626847251963763755836687759498519784550143745834860002945223766052808125982053455555265216112722718870586961456110693379343178124592311441022662940307099598578775368547768968914916965731708568179631324904813506101190853720749196062963892799499230635163056742330563321122389331703618066046034494287335316842529021563862331183541255013987734473643350285400060357711238514186776429325214739886098119655678483017894951556639821088508565036657794343031121375178126860889964700274558728491825977274341798997758923017217660272136611938897932105874133412726223468780517578125e-259;
		])
	], [
		AS_IF([$EGREP BigEnd conftest.$ac_objext >/dev/null], [
			AC_DEFINE(OF_FLOAT_BIG_ENDIAN, 1,
				[Whether floats are big endian])
			fp_endianess="big endian"
		], [
			AS_IF([$EGREP dnEgiB conftest.$ac_objext >/dev/null], [
				fp_endianess="little endian"
			])
		])
	])
], [
	fp_endianess="universal"
])
AC_MSG_RESULT($fp_endianess)
AS_IF([test x"$fp_endianess" = x"unknown"], [
	AC_MSG_ERROR(
		[Floating point implementation does not conform to IEEE 754!])])

AC_MSG_CHECKING(for INFINITY)
AC_TRY_COMPILE([
	#include <stdio.h>
	#include <math.h>
], [
	printf("%f", INFINITY);
], [
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)

	AC_MSG_CHECKING(for __builtin_inf)
	AC_TRY_COMPILE([
		#include <stdio.h>
	], [
		printf("%f", __builtin_inf());
	], [
		AC_MSG_RESULT(yes)
		AC_DEFINE(INFINITY, [(__builtin_inf())],
			[Workaround for missing INFINITY])
	], [
		AC_MSG_RESULT(no)

		AC_MSG_ERROR([Neither INFINITY or __builtin_inf was found!])
	])
])

case "$host_cpu" in
	arm* | earm*)
		AC_MSG_CHECKING(for VFP2 or above)
		AC_TRY_COMPILE([], [
arm* | earm*)
	AC_MSG_CHECKING(for VFP2 or above)
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([], [
			#if !defined(__arm64__) && !defined(__aarch64__) && \
			    !defined(__ARM64_ARCH_8__)
			__asm__ __volatile__ (
			    "vstmdb	sp!, {d0-d7}"
			);
			#endif
		])
		], [
			AC_DEFINE(HAVE_VFP2, 1, [Whether we have VFP2 or above])
			AC_MSG_RESULT(yes)
		], [
			AC_MSG_RESULT(no)
		])
		;;
	], [
		AC_DEFINE(HAVE_VFP2, 1, [Whether we have VFP2 or above])
		AC_MSG_RESULT(yes)
	], [
		AC_MSG_RESULT(no)
	])
	;;
esac

AC_CHECK_LIB(m, fmod, LIBS="$LIBS -lm")
AC_CHECK_LIB(complex, creal, TESTS_LIBS="$TESTS_LIBS -lcomplex")

AC_CHECK_FUNCS(strtof truncf)

AC_CHECK_FUNC(asprintf, [
	case "$host" in
	*-*-mint*)
		dnl asprintf is not in headers
		have_asprintf="no"
		;;
		*-*-mingw*)
			dnl asprintf from MinGW is broken on older Windows
	*-*-mingw*)
		dnl asprintf from MinGW is broken on older Windows versions
			dnl versions
			have_asprintf="no"
			;;
		*-psp-*)
			dnl asprintf is broken on the PSP
			have_asprintf="no"
			;;
		*)
			have_asprintf="yes"
			AC_DEFINE(HAVE_ASPRINTF, 1,
		have_asprintf="no"
		;;
	*-psp-*)
		dnl asprintf is broken on the PSP
		have_asprintf="no"
		;;
	*)
		have_asprintf="yes"
		AC_DEFINE(HAVE_ASPRINTF, 1, [Whether we have asprintf()])
				[Whether we have asprintf()])
		;;
	esac
], [
	have_asprintf="no"
])

AC_ARG_ENABLE(unicode-tables,
	AS_HELP_STRING([--disable-unicode-tables], [Disable Unicode tables]))
AS_IF([test x"$enable_unicode_tables" != x"no"], [
	AC_DEFINE(OF_HAVE_UNICODE_TABLES, 1,
		[Whether to build with Unicode tables])
	AC_SUBST(UNICODE_M, "unicode.m")
])

ENCODINGS_SRCS=""
AC_DEFUN([ENCODING_FLAG], [
	AC_ARG_ENABLE($1,
		AS_HELP_STRING([--disable-$1],
			[Disables support for $3]))
	AS_IF([test x"$enable_$2" != x"no"], [
		AC_DEFINE($4, 1,
			[Whether we have support for $3])
		ENCODINGS_SRCS="$ENCODINGS_SRCS $2.m"
		AC_DEFINE($4, 1, [Whether we have support for $3])
		ENCODINGS_SRCS="$ENCODINGS_SRCS $1.m"
	])
])
ENCODING_FLAG(codepage-437, codepage_437, [Codepage 437], HAVE_CODEPAGE_437)
ENCODING_FLAG(codepage-850, codepage_850, [Codepage 850], HAVE_CODEPAGE_850)
ENCODING_FLAG(codepage-858, codepage_858, [Codepage 858], HAVE_CODEPAGE_858)
ENCODING_FLAG(iso-8859-2, iso_8859-2, [ISO 8859-2], HAVE_ISO_8859_2)
ENCODING_FLAG(iso-8859-3, iso_8859-3, [ISO 8859-3], HAVE_ISO_8859_3)
ENCODING_FLAG(iso-8859-15, iso_8859-15, [ISO 8859-15], HAVE_ISO_8859_15)
ENCODING_FLAG(koi8-r, koi8-r, [KOI8-R], HAVE_KOI8_R)
ENCODING_FLAG(koi8-u, koi8-u, [KOI8-U], HAVE_KOI8_U)
ENCODING_FLAG(iso-8859-2, iso_8859_2, [ISO 8859-2], HAVE_ISO_8859_2)
ENCODING_FLAG(iso-8859-3, iso_8859_3, [ISO 8859-3], HAVE_ISO_8859_3)
ENCODING_FLAG(iso-8859-15, iso_8859_15, [ISO 8859-15], HAVE_ISO_8859_15)
ENCODING_FLAG(koi8-r, koi8_r, [KOI8-R], HAVE_KOI8_R)
ENCODING_FLAG(koi8-u, koi8_u, [KOI8-U], HAVE_KOI8_U)
ENCODING_FLAG(mac-roman, mac_roman, [Mac Roman encoding], HAVE_MAC_ROMAN)
ENCODING_FLAG(windows-1251, windows-1251, [Windows-1251], HAVE_WINDOWS_1251)
ENCODING_FLAG(windows-1252, windows-1252, [Windows-1252], HAVE_WINDOWS_1252)
ENCODING_FLAG(windows-1251, windows_1251, [Windows-1251], HAVE_WINDOWS_1251)
ENCODING_FLAG(windows-1252, windows_1252, [Windows-1252], HAVE_WINDOWS_1252)

AC_SUBST(ENCODINGS_SRCS)
AS_IF([test x"$ENCODINGS_SRCS" != x""], [
	AC_SUBST(ENCODINGS, "encodings")
AS_IF([test x"$ENCODINGS_SRCS" = x""], [
	ENCODINGS_SRCS="dummy.m"
])
AC_SUBST(ENCODINGS_SRCS)

	AS_IF([test x"$enable_shared" != x"no"], [
		AC_SUBST(ENCODINGS_LIB_A, "encodings.lib.a")
AS_IF([test x"$enable_shared" != x"no"], [
	AC_SUBST(ENCODINGS_LIB_A, "encodings.lib.a")
		AC_SUBST(ENCODINGS_ENCODINGS_LIB_A, "encodings/encodings.lib.a")
	])
	AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [
		AC_SUBST(ENCODINGS_A, "encodings.a")
])
AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [
	AC_SUBST(ENCODINGS_A, "encodings.a")
		AC_SUBST(ENCODINGS_ENCODINGS_A, "encodings/encodings.a")
	])
])

AC_CHECK_FUNCS(arc4random arc4random_buf getrandom random, break)

AS_IF([test x"$host_os" != x"morphos"], [
	AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl")
])
AC_CHECK_HEADERS_ONCE(dlfcn.h)
case "$host_os" in
	netbsd*)
		dnl dladdr exists on NetBSD, but it is completely broken.
		dnl When using it with code that uses __thread, it freezes the
		dnl process so that it has to be killed using SIGKILL.
		dnl When disabling __thread, it doesn't freeze, but all symbols
		dnl are wrong.
		;;
	*)
		AC_CHECK_FUNCS(dladdr)
		;;
netbsd*)
	dnl dladdr exists on NetBSD, but it is completely broken.
	dnl When using it with code that uses __thread, it freezes the process
	dnl so that it has to be killed using SIGKILL.
	dnl When disabling __thread, it doesn't freeze, but all symbols are
	dnl wrong.
	;;
*)
	AC_CHECK_FUNCS(dladdr)
	;;
esac

AC_CHECK_HEADERS(sys/mman.h)
AC_CHECK_FUNCS(mmap mlock)

AC_ARG_ENABLE(threads,
	AS_HELP_STRING([--disable-threads], [disable thread support]))
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017






1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029








1030
1031
1032
1033
1034
1035
1036
959
960
961
962
963
964
965

966
967




968
969
970
971
972
973
974
975
976
977
978
979






980
981
982
983
984
985
986
987
988
989
990
991
992
993
994







-
+

-
-
-
-
+
+
+
+
+
+






-
-
-
-
-
-
+
+
+
+
+
+
+
+







		dnl Use -Wp, as we only use it for the preprocessor.
		AX_CHECK_COMPILER_FLAGS([-Wp,-pthread], [
			CPPFLAGS="$CPPFLAGS -Wp,-pthread"
		], [
			CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE"
		])

		AC_CHECK_LIB(pthread, pthread_create, LIBS="$LIBS -lpthread")
		AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")

		AC_TRY_LINK([
			#include <pthread.h>
		], [
			pthread_create(NULL, NULL, NULL, NULL);
		AC_LINK_IFELSE([
			AC_LANG_PROGRAM([
				#include <pthread.h>
			], [
				pthread_create(NULL, NULL, NULL, NULL);
			])
		], [], [
			AC_MSG_ERROR(No supported threads found!)
		])

		AC_DEFINE(OF_HAVE_PTHREADS, 1, [Whether we have pthreads])

		AC_TRY_COMPILE([
			#include <pthread.h>
		], [
			pthread_mutexattr_t attr;
			pthread_mutexattr_settype(&attr,
			    PTHREAD_MUTEX_RECURSIVE);
		AC_COMPILE_IFELSE([
			AC_LANG_PROGRAM([
				#include <pthread.h>
			], [
				pthread_mutexattr_t attr;
				pthread_mutexattr_settype(&attr,
				    PTHREAD_MUTEX_RECURSIVE);
			])
		], [
			AC_DEFINE(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES, 1,
				[If pthread mutexes can be recursive])
		])

		AC_CHECK_FUNC(pthread_spin_lock, [
			have_spinlocks="yes"
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069













1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082






1083
1084
1085
1086
1087
1088
1089
1090






1091
1092
1093
1094
1095
1096
1097
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020








1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042




1043
1044
1045
1046
1047
1048
1049
1050
1051
1052




1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065







+






-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
+
+
+
+
+
+




-
-
-
-
+
+
+
+
+
+







		AC_CHECK_HEADERS(pthread_np.h, [], [], [#include <pthread.h>])
		AC_CHECK_FUNCS(pthread_set_name_np pthread_setname_np, break)
		;;
	esac

	AC_DEFINE(OF_HAVE_THREADS, 1, [Whether we have threads])
	AC_SUBST(USE_SRCS_THREADS, '${SRCS_THREADS}')
	AC_SUBST(OBJC_SYNC, objc_sync)

	AC_ARG_ENABLE(compiler-tls,
		AS_HELP_STRING([--disable-compiler-tls],
			[disable compiler thread local storage]))

	case "$host" in
		aarch64*-*-android*)
			# Compiler TLS is broken on AArch64 Android with Clang
			enable_compiler_tls="no"
			;;
		m68k-*-amigaos | powerpc-*-amigaos)
			# Compiler TLS is broken on AmigaOS
			enable_compiler_tls="no"
			;;
	aarch64*-*-android*)
		dnl Compiler TLS is broken on AArch64 Android with Clang
		enable_compiler_tls="no"
		;;
	m68k-*-amigaos* | powerpc-*-amigaos*)
		dnl Compiler TLS is broken on AmigaOS
		enable_compiler_tls="no"
		;;
	*-*-morphos*)
		dnl Compiler TLS needs helpers that we don't want in the
		dnl .library
		enable_compiler_tls="no"
		;;
	esac

	AS_IF([test x"$enable_compiler_tls" != x"no"], [
		AC_CHECK_HEADER(threads.h, [
			AC_DEFINE(OF_HAVE_THREADS_H, 1,
				[Whether we have threads.h])
		])

		AC_MSG_CHECKING(whether _Thread_local works)
		AC_TRY_LINK([
			static _Thread_local int x = 0;
		], [
			x++;
		AC_LINK_IFELSE([
			AC_LANG_PROGRAM([
				static _Thread_local int x = 0;
			], [
				x++;
			])
		], [
			AS_IF([test x"$enable_shared" != x"no"], [
				old_OBJCFLAGS="$OBJCFLAGS"
				OBJCFLAGS="$OBJCFLAGS -fPIC"
				AC_TRY_COMPILE([
					static _Thread_local int x = 0;
				], [
					x++;
				AC_COMPILE_IFELSE([
					AC_LANG_PROGRAM([
						static _Thread_local int x = 0;
					], [
						x++;
					])
				], [
					AC_MSG_RESULT(yes)
					AC_DEFINE(OF_HAVE__THREAD_LOCAL, 1,
						[Whether _Thread_local works])
					have_thread_local="yes"
				], [
					AC_MSG_RESULT(no)
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116








1117
1118
1119
1120




1121
1122
1123
1124
1125
1126
1127
1128






1129
1130
1131
1132
1133
1134
1135
1073
1074
1075
1076
1077
1078
1079





1080
1081
1082
1083
1084
1085
1086
1087
1088



1089
1090
1091
1092
1093
1094
1095
1096




1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109







-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+




-
-
-
-
+
+
+
+
+
+







			])
		], [
			AC_MSG_RESULT(no)
		])

		AS_IF([test x"$have_thread_local" != x"yes"], [
			AC_MSG_CHECKING(whether __thread works)
			AC_TRY_LINK([
				/* It seems __thread is buggy with GCC 4.1 */
				#if __GNUC__ == 4 && __GNUC_MINOR__ < 2
				# error buggy
				#endif
			AC_LINK_IFELSE([
				AC_LANG_PROGRAM([
					/*
					 * It seems __thread is buggy with
					 * GCC 4.1 */
					#if __GNUC__ == 4 && __GNUC_MINOR__ < 2
					# error buggy
					#endif

				__thread int x = 0;
			], [
				x++;
					__thread int x = 0;
				], [
					x++;
				])
			], [
				AS_IF([test x"$enable_shared" != x"no"], [
					old_OBJCFLAGS="$OBJCFLAGS"
					OBJCFLAGS="$OBJCFLAGS -fPIC"
					AC_TRY_COMPILE([
						__thread int x = 0;
					], [
						x++;
					AC_COMPILE_IFELSE([
						AC_LANG_PROGRAM([
							__thread int x = 0;
						], [
							x++;
						])
					], [
						AC_MSG_RESULT(yes)
						AC_DEFINE(OF_HAVE___THREAD, 1,
							[Whether __thread works]
						)
					], [
						AC_MSG_RESULT(no)
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176












1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187


1188
1189
1190
1191
1192







1193
1194
1195
1196
1197
1198
1199
1134
1135
1136
1137
1138
1139
1140










1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165





1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+











+
+
-
-
-
-
-
+
+
+
+
+
+
+







		AC_MSG_RESULT(yes)
		atomic_ops="assembly implementation"
	], [
		AC_MSG_RESULT(no)
	])

	AC_MSG_CHECKING(whether __atomic_* works)
	AC_TRY_LINK([
		#include <stdbool.h>
		#include <stdint.h>
	], [
		int32_t i, j;
		if (__atomic_add_fetch(&i, 1, __ATOMIC_RELAXED))
			j = __atomic_sub_fetch(&i, 1, __ATOMIC_RELAXED);
		while (!__atomic_compare_exchange_n(&i, &j, 1, false,
		    __ATOMIC_RELAXED, __ATOMIC_RELAXED));
		__atomic_thread_fence(__ATOMIC_SEQ_CST);
	AC_LINK_IFELSE([
		AC_LANG_PROGRAM([
			#include <stdbool.h>
			#include <stdint.h>
		], [
			int32_t i, j;
			if (__atomic_add_fetch(&i, 1, __ATOMIC_RELAXED))
				j = __atomic_sub_fetch(&i, 1, __ATOMIC_RELAXED);
			while (!__atomic_compare_exchange_n(&i, &j, 1, false,
			    __ATOMIC_RELAXED, __ATOMIC_RELAXED));
			__atomic_thread_fence(__ATOMIC_SEQ_CST);
		])
	], [
		AC_MSG_RESULT(yes)
		test x"$atomic_ops" = x"none" && \
			atomic_ops="__atomic_* builtins"
		AC_DEFINE(OF_HAVE_ATOMIC_BUILTINS, 1,
			[Whether __atomic_* builtins are available])
	], [
		AC_MSG_RESULT(no)
	])

	AC_MSG_CHECKING(whether __sync_* works)
	AC_LINK_IFELSE([
		AC_LANG_PROGRAM([
	AC_TRY_LINK([#include <stdint.h>], [
		int32_t i, j;
		if (__sync_add_and_fetch(&i, 1))
			j = __sync_sub_and_fetch(&i, 1);
		while (!__sync_bool_compare_and_swap(&i, 0, 1));
			#include <stdint.h>
		], [
			int32_t i, j;
			if (__sync_add_and_fetch(&i, 1))
				j = __sync_sub_and_fetch(&i, 1);
			while (!__sync_bool_compare_and_swap(&i, 0, 1));
		])
	], [
		AC_MSG_RESULT(yes)
		test x"$atomic_ops" = x"none" && \
			atomic_ops="__sync_* builtins"
		AC_DEFINE(OF_HAVE_SYNC_BUILTINS, 1,
			[Whether __sync_* builtins are available])
	], [
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234






1235
1236
1237
1238



1239
1240
1241
1242
1243
1244
1245
1202
1203
1204
1205
1206
1207
1208






1209
1210
1211
1212
1213
1214




1215
1216
1217
1218
1219
1220
1221
1222
1223
1224







-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+







AS_IF([test x"$enable_files" != x"no"], [
	AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files])
	AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}')
	AC_SUBST(OFARC, "ofarc")
	AC_SUBST(OFHASH, "ofhash")

	case "$host_os" in
		msdosdjgpp*)
			dnl DJGPP has the type, but it's not really usable.
			;;
		*)
			AC_CHECK_TYPE(off64_t, [
				AC_DEFINE(OF_HAVE_OFF64_T, 1,
	msdosdjgpp*)
		dnl DJGPP has the type, but it's not really usable.
		;;
	*)
		AC_CHECK_TYPE(off64_t, [
			AC_DEFINE(OF_HAVE_OFF64_T, 1, [Whether we have off64_t])
					[Whether we have off64_t])
				AC_CHECK_FUNCS([lseek64 lstat64 open64 stat64])
			])
			;;
			AC_CHECK_FUNCS([lseek64 lstat64 open64 stat64])
		])
		;;
	esac

	AC_CHECK_HEADERS([pwd.h grp.h])
	AC_CHECK_FUNC(chmod, [
		AC_DEFINE(OF_HAVE_CHMOD, 1, [Whether we have chmod()])
	])
	AC_CHECK_FUNC(chown, [
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266






1267
1268


1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279















1280
1281
1282
1283
1284
1285
1286
1287
1288
1289




1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304















1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323









1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342



1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363











1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388



1389
1390
1391
1392
1393
1394
1395
1234
1235
1236
1237
1238
1239
1240





1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258


1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280



1281
1282
1283
1284
1285














1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312







1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333







1334
1335
1336


1337
1338
1339
1340
1341
1342
1343
1344











1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369






1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384







-
-
-
-
-
+
+
+
+
+
+

-
+
+









-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+












-
-
-
-
-
-
-
+
+
+
-
-








-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+














-
-
-
-
-
-





+
+
+







	AC_CHECK_MEMBERS([struct stat.st_birthtime], [], [], [
		#include <sys/stat.h>
	])

	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -Werror"
	AC_MSG_CHECKING(for readdir_r)
	AC_TRY_COMPILE([
		#include <dirent.h>
	], [
		DIR *dir = 0;
		struct dirent entry, *result;
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
			#include <dirent.h>
		], [
			DIR *dir = 0;
			struct dirent entry, *result;

		readdir_r(dir, &entry, &result);
			readdir_r(dir, &entry, &result);
		])
	], [
		AC_MSG_RESULT(yes)
		AC_DEFINE(HAVE_READDIR_R, 1, [Whether we have readdir_r()])
	], [
		AC_MSG_RESULT(no)
	])
	OBJCFLAGS="$old_OBJCFLAGS"
])

AC_CHECK_HEADERS(fcntl.h dirent.h)
AC_CHECK_FUNCS([sysconf gmtime_r localtime_r nanosleep fcntl])
AC_CHECK_HEADERS(dirent.h)
AC_CHECK_FUNCS([sysconf gmtime_r localtime_r])

case "$host_os" in
amigaos* | morphos*)
	dnl We don't want fcntl() or nanosleep() on AmigaOS / MorphOS, despite
	dnl a symbol existing. The reason is that we cannot use fcntl() for
	dnl sockets and that nanosleep() is yet another function that uses
	dnl errno, so would need to be passed from the linklib.
	;;
*)
	AC_CHECK_HEADERS(fcntl.h)
	AC_CHECK_FUNCS([fcntl nanosleep])
	;;
esac

AC_CHECK_HEADERS(xlocale.h)
AC_CHECK_FUNCS([strtod_l strtof_l asprintf_l])
AS_IF([test x"$gnu_source" != x"yes" -a \( \
    x"$ac_cv_func_strtod_l" = x"yes" -o x"$ac_cv_func_strtof_l" = x"yes" -o \
    x"$ac_cv_func_asprintf_l" = x"yes" \)], [
	AC_MSG_CHECKING(whether *_l functions need _GNU_SOURCE)
	AC_TRY_COMPILE([
		#include <stdlib.h>
		#include <stdio.h>
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
			#include <stdlib.h>
			#include <stdio.h>

		#include <locale.h>
		#ifdef HAVE_XLOCALE_H
		# include <xlocale.h>
		#endif
	], [
		#ifdef HAVE_STRTOD_L
		(void)strtod_l;
		#endif
		#ifdef HAVE_STRTOF_L
		(void)strtof_l;
		#endif
		#ifdef HAVE_ASPRINTF_L
		(void)asprintf_l;
		#endif
			#include <locale.h>
			#ifdef HAVE_XLOCALE_H
			# include <xlocale.h>
			#endif
		], [
			#ifdef HAVE_STRTOD_L
			(void)strtod_l;
			#endif
			#ifdef HAVE_STRTOF_L
			(void)strtof_l;
			#endif
			#ifdef HAVE_ASPRINTF_L
			(void)asprintf_l;
			#endif
		])
	], [
		AC_MSG_RESULT(no)
	], [
		AC_MSG_RESULT(yes)
		CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS"
	])
])

dnl This check needs to happen after the above, as _GNU_SOURCE can change the
dnl return type.
AC_CHECK_FUNCS(strerror_r, [
	AC_MSG_CHECKING(for return type of strerror_r)
	AC_TRY_COMPILE([
		#include <stdio.h>
		#include <string.h>
	], [
		switch (strerror_r(0, NULL, 0)) {
		case 0:;
		}
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
			#include <stdio.h>
			#include <string.h>
		], [
			switch (strerror_r(0, NULL, 0)) {
			case 0:;
			}
		])
	], [
		AC_MSG_RESULT(int)
	], [
		AC_MSG_RESULT(char *)
		AC_DEFINE(STRERROR_R_RETURNS_CHARP, 1,
			[Whether strerror_r returns char *])
	])
])

AC_CHECK_HEADERS(sys/utsname.h)
AC_CHECK_FUNCS(uname)

case "$host_os" in
	amigaos*)
		;;
	*)
		AC_CHECK_FUNC(pipe, [
			AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()])
		])
AC_CHECK_FUNC(pipe, [
	AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()])
])
		;;
esac

AC_ARG_ENABLE(sockets,
	AS_HELP_STRING([--disable-sockets], [disable socket support]))
AS_IF([test x"$enable_sockets" != x"no"], [
	AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets])
	AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}')

	case "$host_os" in
		amigaos*)
			;;
		haiku*)
			LIBS="$LIBS -lnetwork"
			;;
		mingw*)
			LIBS="$LIBS -lws2_32 -liphlpapi"
			;;
		*)
			AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
			;;
	amigaos* | morphos*)
		;;
	haiku*)
		LIBS="$LIBS -lnetwork"
		;;
	mingw*)
		LIBS="$LIBS -lws2_32 -liphlpapi"
		;;
	*)
		AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
		;;
	esac

	AC_CHECK_HEADER(sys/socket.h, [
		AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1,
			[Whether we have sys/socket.h])
	])
	AC_CHECK_HEADER(netinet/in.h, [
		AC_DEFINE(OF_HAVE_NETINET_IN_H, 1,
			[Whether we have netinet/in.h])
	])
	AC_CHECK_HEADER(netinet/tcp.h, [
		AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1,
			[Whether we have netinet/tcp.h])
	])
	AC_CHECK_HEADER(netinet/sctp.h, [
		AC_DEFINE(OF_HAVE_SCTP, 1, [Whether we have SCTP])
		AC_DEFINE(OF_HAVE_NETINET_SCTP_H, 1,
			[Whether we have netinet/sctp.h])
		AC_SUBST(USE_SRCS_SCTP, '${SRCS_SCTP}')
	])
	AC_CHECK_HEADERS([arpa/inet.h netdb.h])
	AC_CHECK_HEADER(netipx/ipx.h, [
		AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1,
			[Whether we have netipx/ipx.h])
	])
	AC_CHECK_HEADER(sys/un.h, [
		AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h])
	])

	AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [
		AC_EGREP_CPP(egrep_cpp_yes, [
			#ifdef _WIN32
			typedef int BOOL;
			#endif

1411
1412
1413
1414
1415
1416
1417



1418
1419
1420
1421
1422
1423
1424
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416







+
+
+







			#ifdef AF_INET6
			egrep_cpp_yes
			#endif
		], [
			AC_DEFINE(OF_HAVE_IPV6, 1, [Whether we have IPv6])
		])
	], [
		dnl Work around a bug in autoconf 2.61 that creates a broken
		dnl configure if this branch is empty.
		:
	], [
		#ifdef _WIN32
		typedef int BOOL;
		#endif

		#ifdef OF_HAVE_NETINET_IN_H
		# include <netinet/in.h>
1503
1504
1505
1506
1507
1508
1509


































1510
1511
1512
1513
1514
1515
1516
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			egrep_cpp_yes
			#endif
		], [
			AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX])
			AC_SUBST(USE_SRCS_IPX, '${SRCS_IPX}')
		])
	])

	AC_CHECK_HEADERS(afunix.h, [
		AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h])
	], [], [
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
	])
	AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [
		AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1,
			[Whether we have UNIX sockets])
		AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}')
	], [], [
		#ifdef OF_HAVE_SYS_TYPES_H
		# include <sys/types.h>
		#endif
		#ifdef OF_HAVE_SYS_UN_H
		# include <sys/un.h>
		#endif
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
		#ifdef HAVE_AFUNIX_H
		# include <afunix.h>
		#endif

		#ifdef __morphos__
		# error MorphOS has the struct but does not support it
		#endif

		#ifdef __MINT__
		# error Gives invalid argument at runtime
		#endif
	])

	AC_CHECK_FUNCS(paccept accept4, break)

	AC_CHECK_FUNCS(kqueue1 kqueue, [
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])
		AC_SUBST(OF_KQUEUE_KERNEL_EVENT_OBSERVER_M,
			"OFKqueueKernelEventObserver.m")
1533
1534
1535
1536
1537
1538
1539
1540
1541


1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553























































1554
1555

1556





























































1557
1558
1559
1560
1561
1562
1563

1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576









1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601






























1602
1603
1604
1605



1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623

















1624
1625
1626
1627



1628
1629
1630
1631
1632
1633
1634
1559
1560
1561
1562
1563
1564
1565


1566
1567












1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623

1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695

1696
1697
1698
1699







1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720













1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751



1752
1753
1754
1755

















1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773



1774
1775
1776
1777
1778
1779
1780
1781
1782
1783







-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+

-




-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+







			AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()])
			AC_SUBST(OF_POLL_KERNEL_EVENT_OBSERVER_M,
				"OFPollKernelEventObserver.m")
		])
	])

	case "$host_os" in
		amigaos* | mingw* | morphos*)
			AC_DEFINE(HAVE_SELECT, 1,
	amigaos* | mingw* | morphos*)
		AC_DEFINE(HAVE_SELECT, 1, [Whether we have select() or similar])
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
			;;
		*)
			AC_CHECK_HEADERS(sys/select.h)
			AC_CHECK_FUNC(select, [
				AC_DEFINE(HAVE_SELECT, 1,
					[Whether we have select() or similar])
				AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
					"OFSelectKernelEventObserver.m")
			])
		AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
			"OFSelectKernelEventObserver.m")
		;;
	*)
		AC_CHECK_HEADERS(sys/select.h)
		AC_CHECK_FUNC(select, [
			AC_DEFINE(HAVE_SELECT, 1,
				[Whether we have select() or similar])
			AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M,
				"OFSelectKernelEventObserver.m")
		])
		;;
	esac

	AC_ARG_WITH(tls,
		AS_HELP_STRING([--with-tls], [
			enable TLS support using the specified library
			(yes, openssl, gnutls, securetransport or no)]))
	AS_IF([test x"$with_tls" = x""], [with_tls="yes"])
	tls_support="no"

	AS_IF([test x"$with_tls" = x"securetransport" \
		-o x"$with_tls" = x"yes"], [
		AC_CHECK_HEADERS(Security/SecureTransport.h, [
			old_LIBS="$LIBS"
			LIBS="-framework Security -framework Foundation $LIBS"

			AC_CHECK_FUNC(SSLHandshake, [
				AC_DEFINE(HAVE_SECURE_TRANSPORT, 1,
					[Whether we have Secure Transport])

				tls_support="Secure Transport"
				TLS_LIBS="-framework Foundation $TLS_LIBS"
				TLS_LIBS="-framework Security $TLS_LIBS"

				AC_SUBST(OF_SECURE_TRANSPORT_TLS_STREAM_M,
					"OFSecureTransportTLSStream.m")

				AC_CHECK_FUNCS(SSLCreateContext)
			], [])

			LIBS="$old_LIBS"
		])
	])

	AS_IF([test x"$with_tls" = x"openssl" \
		-o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [
		case "$host_os" in
		morphos*)
			ssl="ssl_shared"
			crypto="crypto_shared"
			;;
		*)
			ssl="ssl"
			crypto="crypto"
			;;
	esac
		esac

		AC_CHECK_LIB($ssl, SSL_set1_host, [
			AC_CHECK_HEADER(openssl/ssl.h, [
				AC_DEFINE(HAVE_OPENSSL, 1,
					[Whether we have OpenSSL])

				tls_support="OpenSSL"
				TLS_LIBS="-l$ssl -l$crypto $TLS_LIBS"

				AC_SUBST(OF_OPENSSL_TLS_STREAM_M,
					"OFOpenSSLTLSStream.m")
			])
		], [], [-l$crypto])
	])

	AS_IF([test x"$with_tls" = x"gnutls" \
		-o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [
		PKG_CHECK_MODULES(gnutls, [gnutls >= 3.5.0], [
			AC_DEFINE(HAVE_GNUTLS, 1, [Whether we have GnuTLS])

			tls_support="GnuTLS"
			TLS_CPPFLAGS="$gnutls_CFLAGS $TLS_CPPFLAGS"
			TLS_LIBS="$gnutls_LIBS $TLS_LIBS"

			AC_SUBST(OF_GNUTLS_TLS_STREAM_M, "OFGnuTLSTLSStream.m")
		], [
			dnl Disable default action-if-not-found, which exits
			dnl configure with an error.
			:
		])
	])

	AS_IF([test x"$tls_support" != x"no"], [
		AC_SUBST(TLS, "tls")
		AC_SUBST(TLS_CPPFLAGS)
		AC_SUBST(TLS_LIBS)
		AC_DEFINE(HAVE_TLS_SUPPORT, 1,
			[Whether we have an implementation for TLS])
		AC_CONFIG_FILES(src/tls/Info.plist)

		OFHTTP_LIBS="-lobjfwtls $TLS_LIBS $OFHTTP_LIBS"

		AS_IF([test x"$enable_shared" != x"no"], [
			AC_SUBST(OBJFWTLS_SHARED_LIB,
				"${LIB_PREFIX}objfwtls${LIB_SUFFIX}")
		])
		AS_IF([test x"$enable_static" = x"yes" \
		    -o x"$enable_shared" = x"no"], [
			AC_SUBST(OBJFWTLS_STATIC_LIB, "libobjfwtls.a")
		])
		AS_IF([test x"$build_framework" = x"yes"], [
			AC_SUBST(OBJFWTLS_FRAMEWORK, "ObjFWTLS.framework")
		])
	])

	AS_IF([test x"$with_tls" != x"no" -a x"$tls_support" = x"no"], [
		AC_MSG_ERROR(m4_normalize([
			No TLS implementation was found. Please install OpenSSL,
			GnuTLS or use --without-tls.
		]))
	])

	AS_IF([test x"$enable_threads" != x"no"], [
		AC_SUBST(OF_HTTP_CLIENT_TESTS_M, "OFHTTPClientTests.m")
	])

	AC_SUBST(OFDNS, "ofdns")
	AS_IF([test x"$enable_files" != x"no"], [
		AC_SUBST(OFHTTP, "ofhttp")
		AC_SUBST(OFHTTP_LIBS)
	])
	AC_SUBST(OFSOCK, "ofsock")
])

AC_DEFUN([CHECK_BUILTIN_BSWAP], [
	AC_MSG_CHECKING(for __builtin_bswap$1)
	AC_TRY_LINK([
		#include <stdint.h>
		#include <stdio.h>
		#include <errno.h>
	], [
		uint$1_t i = errno;
		printf("%d", (int)__builtin_bswap$1(i));
	AC_LINK_IFELSE([
		AC_LANG_PROGRAM([
			#include <stdint.h>
			#include <stdio.h>
			#include <errno.h>
		], [
			uint$1_t i = errno;
			printf("%d", (int)__builtin_bswap$1(i));
		])
	], [
		AC_MSG_RESULT(yes)
		AC_DEFINE(OF_HAVE_BUILTIN_BSWAP$1, 1,
			[Whether we have __builtin_bswap$1])
	], [
		AC_MSG_RESULT(no)
	])
])
CHECK_BUILTIN_BSWAP(16)
CHECK_BUILTIN_BSWAP(32)
CHECK_BUILTIN_BSWAP(64)

case "$host" in
	arm*-apple-darwin*)
		have_processes="no"
		;;
	*-*-mingw*)
		have_processes="yes"
		;;
	*-*-msdosdjgpp*)
		have_processes="no"
		;;
	*)
		AC_HEADER_SYS_WAIT
		AC_CHECK_FUNCS(kill)
case "$host_os" in
darwin*)
	AC_MSG_CHECKING(whether we are compiling for macOS)
	AC_EGREP_CPP(egrep_cpp_yes, [
		#include <TargetConditionals.h>

		#if (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \
		    (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR)
		egrep_cpp_yes
		#endif
	], [
		AC_MSG_RESULT(yes)
		have_subprocesses="yes"

		AC_CHECK_FUNCS(posix_spawnp)
		AC_CHECK_HEADERS(spawn.h)
	], [
		AC_MSG_RESULT(no)
		have_subprocesses="no"
	])
	;;
mingw*)
	have_subprocesses="yes"
	;;
msdosdjgpp*)
	have_subprocesses="no"
	;;
*)
	AC_HEADER_SYS_WAIT
	AC_CHECK_FUNCS(kill)

		AC_CHECK_FUNCS(posix_spawnp, [
			AS_IF([test x"$ac_cv_func_kill" = x"yes"], [
				have_processes="yes"
	AC_CHECK_FUNCS(posix_spawnp, [
		AS_IF([test x"$ac_cv_func_kill" = x"yes"], [
			have_subprocesses="yes"

				AC_CHECK_HEADERS(spawn.h)
			])
		], [
			AC_CHECK_FUNCS([vfork dup2 execvp _exit], [
				AS_IF([test x"$ac_cv_func_vfork" = x"yes" \
				    -a x"$ac_cv_func_pipe" = x"yes" \
				    -a x"$ac_cv_func_dup2" = x"yes" \
				    -a x"$ac_cv_func_execvp" = x"yes" \
				    -a x"$ac_cv_func_kill" = x"yes" \
				    -a x"$ac_cv_func__exit" = x"yes"], [
					have_processes="yes"
				])
			], [
				break
			])
		])
		;;
			AC_CHECK_HEADERS(spawn.h)
		])
	], [
		AC_CHECK_FUNCS([vfork dup2 execvp _exit], [
			AS_IF([test x"$ac_cv_func_vfork" = x"yes" \
			    -a x"$ac_cv_func_pipe" = x"yes" \
			    -a x"$ac_cv_func_dup2" = x"yes" \
			    -a x"$ac_cv_func_execvp" = x"yes" \
			    -a x"$ac_cv_func_kill" = x"yes" \
			    -a x"$ac_cv_func__exit" = x"yes"], [
				have_subprocesses="yes"
			])
		], [
			break
		])
	])
	;;
esac
AS_IF([test x"$have_processes" = x"yes"], [
	AC_SUBST(OF_PROCESS_M, "OFProcess.m")
	AC_DEFINE(OF_HAVE_PROCESSES, 1, [Whether we have processes])
AS_IF([test x"$have_subprocesses" = x"yes"], [
	AC_SUBST(OF_SUBPROCESS_M, "OFSubprocess.m")
	AC_DEFINE(OF_HAVE_SUBPROCESSES, 1, [Whether we have subprocesses])
])

AC_CHECK_HEADERS_ONCE([complex.h sys/ioctl.h sys/ttycom.h])
AC_CHECK_FUNCS(isatty)

AC_CHECK_FUNC(pledge, [
	AC_DEFINE(OF_HAVE_PLEDGE, 1, [Whether we have pledge()])
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665





1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689












1690
1691
1692
1693
1694
1695
1696







1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716












1717
1718

1719
1720
1721


1722
1723
1724


1725
1726
1727
1728
1729
1730
1731






1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752












1753
1754
1755
1756
1757
1758
1759
1760
1761








1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773



1774

1775

1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789













1790
1791
1792


1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803










1804
1805
1806
1807
1808
1809
1810
1811







1812
1813

1814
1815
1816
1817
1818
1819
1820







1821
1822

1823
1824
1825


1826
1827
1828
1829
1830
1831
1832
1833








1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854


















1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867



1868
1869

1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880










1881
1882
1883
1884



1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896












1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910







1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929






1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953




1954
1955
1956
1957
1958
1959
1960
1805
1806
1807
1808
1809
1810
1811



1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829











1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842






1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858











1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871

1872
1873


1874
1875
1876


1877
1878
1879






1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895











1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908








1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926


1927
1928
1929
1930
1931

1932
1933













1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947


1948
1949
1950










1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961







1962
1963
1964
1965
1966
1967
1968
1969

1970
1971






1972
1973
1974
1975
1976
1977
1978
1979

1980
1981


1982
1983
1984







1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001












2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030


2031
2032
2033
2034

2035
2036










2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047



2048
2049
2050
2051











2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072





2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092






2093
2094
2095
2096
2097
2098
2099
2100
2101

2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114


2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130







-
-
-
+
+
+
+
+













-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+










-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+










-
-
+
+
+

+
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+
+

-
+

-
-
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
-
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
+
+
+
+
+
+
+













-
-
-
-
-
-
+
+
+
+
+
+



-













-
-





+
+
+
+








dnl This needs to be after all other header checks, as they include unistd.h,
dnl which in old glibc versions uses __block. This is worked around in the code
dnl by providing a wrapper for unistd.h which takes care of this.
AC_MSG_CHECKING(whether Objective C compiler supports blocks)
old_OBJCFLAGS="$OBJCFLAGS"
OBJCFLAGS="$OBJCFLAGS -Xclang -fblocks"
AC_TRY_COMPILE([], [
	int (^foo)(int bar);
	foo = ^ (int bar) { return 0; }
AC_COMPILE_IFELSE([
	AC_LANG_PROGRAM([], [
		int (^foo)(int bar);
		foo = ^ (int bar) { return 0; }
	])
], [
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fblocks"
	AC_SUBST(OF_BLOCK_TESTS_M, "OFBlockTests.m")
	AC_MSG_RESULT(yes)
], [
	AC_MSG_RESULT(no)
	OBJCFLAGS="$old_OBJCFLAGS"
])

AS_IF([test x"$GOBJC" = x"yes"], [
	OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wpointer-arith -Werror"

	AC_MSG_CHECKING(whether we need -Wno-strict-aliasing due to GCC bugs)
	AC_TRY_COMPILE([
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Foo
		{
			struct objc_class *_isa;
		}
		@end
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Foo
			{
				struct objc_class *_isa;
			}
			@end

		static struct {
			struct objc_class *_isa;
		} object;
	], [
		Foo *test = (Foo *)&object;
		(void)test; /* Get rid of unused variable warning */
			static struct {
				struct objc_class *_isa;
			} object;
		], [
			Foo *test = (Foo *)&object;
			(void)test; /* Get rid of unused variable warning */
		])
	], [
		AC_MSG_RESULT(no)
	], [
		AC_MSG_RESULT(yes)
		OBJCFLAGS="$OBJCFLAGS -Wno-strict-aliasing"
	])

	AC_MSG_CHECKING(
	    whether we need -Wno-unused-property-ivar due to Clang bugs)
	AC_TRY_COMPILE([
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Foo
		{
			struct objc_class *_isa;
			Foo *_foo;
		}
	AC_COMPILE_IFELSE([
		AC_LANG_SOURCE([
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Foo
			{
				struct objc_class *_isa;
				Foo *_foo;
			}

		@property (readonly, nonatomic) Foo *foo;
			@property (readonly, nonatomic) Foo *foo;

		+ (Foo *)foo;
		@end
			+ (Foo *)foo;
			@end

		@implementation Foo
		@synthesize foo = _foo;
			@implementation Foo
			@synthesize foo = _foo;

		+ (Foo *)foo
		{
			return (Foo *)0;
		}
		@end
	], [
			+ (Foo *)foo
			{
				return (Foo *)0;
			}
			@end
		])
	], [
		AC_MSG_RESULT(no)
	], [
		AC_MSG_RESULT(yes)
		OBJCFLAGS="$OBJCFLAGS -Wno-unused-property-ivar"
	])

	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -Wcast-align"
	AC_MSG_CHECKING(whether -Wcast-align is buggy)
	AC_TRY_COMPILE([
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Foo
		{
			struct objc_class *_isa;
		}
		@end
	AC_COMPILE_IFELSE([
		AC_LANG_SOURCE([
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Foo
			{
				struct objc_class *_isa;
			}
			@end

		@implementation Foo
		- (void)foo
		{
			struct objc_class *c = _isa;
			(void)c;
		}
		@end
	], [
			@implementation Foo
			- (void)foo
			{
				struct objc_class *c = _isa;
				(void)c;
			}
			@end
		])
	], [
		AC_MSG_RESULT(no)
	], [
		AC_MSG_RESULT(yes)
		OBJCFLAGS="$old_OBJCFLAGS"
	])

	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -Wunreachable-code"
	AC_MSG_CHECKING(whether -Wunreachable-code can be used)
	AC_TRY_COMPILE([
		#include <stdlib.h>
	AC_COMPILE_IFELSE([
		AC_LANG_SOURCE([[
			#include <stdlib.h>

			struct objc_selector;
		typedef void *SEL;
			typedef const struct objc_selector *SEL;

		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Object
		- (void)doesNotRecognizeSelector: (SEL)selector
		#ifdef __clang__
		    __attribute__((__noreturn__))
		#endif
		    ;
		- (void)dealloc;
		@end
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Object
			- (void)doesNotRecognizeSelector: (SEL)selector
			#ifdef __clang__
			    __attribute__((__noreturn__))
			#endif
			    ;
			- (void)dealloc;
			@end

		@interface Foo: Object
		@end
			@interface Foo: Object
			@end

		void
		test(void)
		{
			if (sizeof(int) == 4)
				__asm__ ("");
			else if (sizeof(int) == 8)
				__asm__ ("");
			else
				abort();
		}
			void
			test(void)
			{
				if (sizeof(int) == 4)
					__asm__ ("");
				else if (sizeof(int) == 8)
					__asm__ ("");
				else
					abort();
			}

		/*
		 * Unfortunately, this cannot be shorter, as it only works when
		 * it is used inside a macro.
		 */
		#ifdef __clang__
		# define OF_DEALLOC_UNSUPPORTED				\
			[self doesNotRecognizeSelector: _cmd];		\
			/*
			 * Unfortunately, this cannot be shorter, as it only
			 * works when it is used inside a macro.
			 */
			#ifdef __clang__
			# define OF_DEALLOC_UNSUPPORTED			\
				[self doesNotRecognizeSelector: _cmd];	\
									\
			abort();					\
				abort();				\
									\
			_Pragma("clang diagnostic push ignore \"-Wunreachable-code\"");	\
			[super dealloc];				\
			_Pragma("clang diagnostic pop");
		#else
		# define OF_DEALLOC_UNSUPPORTED				\
			[self doesNotRecognizeSelector: _cmd];		\
				_Pragma("clang diagnostic push ignore	\
				    \"-Wunreachable-code\"");		\
				[super dealloc];			\
				_Pragma("clang diagnostic pop");
			#else
			# define OF_DEALLOC_UNSUPPORTED			\
				[self doesNotRecognizeSelector: _cmd];	\
									\
			abort();					\
				abort();				\
									\
			[super dealloc];
		#endif
				[super dealloc];
			#endif

		@implementation Foo
		- (void)dealloc
		{
			OF_DEALLOC_UNSUPPORTED
		}
		@end
	], [], [
			@implementation Foo
			- (void)dealloc
			{
				OF_DEALLOC_UNSUPPORTED
			}
			@end
		]])
	], [
		AC_MSG_RESULT(yes)
	], [
		AC_MSG_RESULT(no)
		OBJCFLAGS="$old_OBJCFLAGS"
	])

	old_OBJCFLAGS="$OBJCFLAGS"
	OBJCFLAGS="$OBJCFLAGS -Wdocumentation"
	AC_MSG_CHECKING(whether -Wdocumentation works correctly)
	AC_TRY_COMPILE([
		/**
		 * @class Test conftest.m conftest.m
		 */
		#ifdef __has_attribute
		# if __has_attribute(objc_root_class)
		__attribute__((__objc_root_class__))
		# endif
		#endif
		@interface Test
		@end
	], [
	AC_COMPILE_IFELSE([
		AC_LANG_SOURCE([
			/**
			 * @class Test conftest.m conftest.m
			 */
			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Test
			@end

			/**
			 * @struct Foo conftest.m conftest.m
			 */
			typedef struct {} Foo;
		])
	], [
		AC_MSG_RESULT(yes)
	], [
		AC_MSG_RESULT(no)
		OBJCFLAGS="$old_OBJCFLAGS"
	])

	AS_IF([test x"$check_pedantic" = x"yes"], [
		old_OBJCFLAGS="$OBJCFLAGS"
		OBJCFLAGS="$OBJCFLAGS -pedantic"
		AC_MSG_CHECKING(whether -pedantic is buggy)
		AC_TRY_COMPILE([
			#include <stdlib.h>
		AC_COMPILE_IFELSE([
			AC_LANG_SOURCE([
				#include <stdlib.h>

			#include <assert.h>
				#include <assert.h>

			#ifdef __has_attribute
			# if __has_attribute(objc_root_class)
			__attribute__((__objc_root_class__))
			# endif
			#endif
			@interface Foo
			{
				void *foo;
			}
			@end
				#ifdef __has_attribute
				# if __has_attribute(objc_root_class)
				__attribute__((__objc_root_class__))
				# endif
				#endif
				@interface Foo
				{
					void *foo;
				}
				@end

			@interface Bar: Foo
			- (void)assert;
			@end
				@interface Bar: Foo
				- (void)assert;
				@end

			@implementation Bar
			- (void)assert
			{
				/*
				 * Some versions of glibc break with -pedantic
				 * when using assert.
				 */
				assert(1);
			}
			@end
		], [], [
				@implementation Bar
				- (void)assert
				{
					/*
					 * Some versions of glibc break with
					 * -pedantic when using assert.
					 */
					assert(1);
				}
				@end
			])
		], [
			AC_MSG_RESULT(no)
		], [
			AC_MSG_RESULT(yes)
			OBJCFLAGS="$old_OBJCFLAGS"
		])
	])

	AS_IF([test x"$ac_cv_header_complex_h" = x"yes"], [
		AC_MSG_CHECKING(whether we need -Wno-gnu-imaginary-constant)
		AC_TRY_COMPILE([
			#include <complex.h>
		], [
			complex float f = 0.5 + 0.5 * I;
			(void)f;
		AC_COMPILE_IFELSE([
			AC_LANG_PROGRAM([
				#include <complex.h>
			], [
				complex float f = 0.5 + 0.5 * I;
				(void)f;
			])
		], [
			AC_MSG_RESULT(no)
		], [
			AC_MSG_RESULT(yes)
			OBJCFLAGS="$OBJCFLAGS -Wno-gnu-imaginary-constant"
		])
	])
])

AS_IF([test x"$cross_compiling" = x"yes"], [
	AC_SUBST(BIN_PREFIX, "${host_alias}-")

	case "$host" in
		i?86-*-mingw*)
			AC_CHECK_PROG(WINE, wine, wine)
			;;
		x86_64-*-mingw*)
			AC_CHECK_PROG(WINE, wine64, wine64)
			;;
	i?86-*-mingw*)
		AC_CHECK_PROG(WINE, wine, wine)
		;;
	x86_64-*-mingw*)
		AC_CHECK_PROG(WINE, wine64, wine64)
		;;
	esac

	AS_IF([test x"$WINE" != x""], [
		AC_SUBST(RUN_TESTS, "run")
		AC_SUBST(WRAPPER, "$WINE")
	])

	AS_IF([test x"$with_wii" = x"yes"], [
		dnl Keep this lowercase, as WIILOAD is a variable used by
		dnl wiiload and thus likely already set by the user to something
		dnl that is not the path of the wiiload binary.
		AC_CHECK_PROG(wiiload, wiiload, wiiload)

		AS_IF([test x"$wiiload" != x""], [
			AC_SUBST(WRAPPER, "$wiiload")
		])
	])
], [
	AC_SUBST(RUN_TESTS, "run")
])

AC_ARG_WITH(fish_completions,
	AS_HELP_STRING([--with-fish-completions],
		[install completions for the fish shell]))
AS_IF([test x"$with_fish_completions" = x""], [
	AC_CHECK_PROG(FISH, fish, fish)
	AS_IF([test x"$FISH" != x""], [with_fish_completions="yes"])
])
AS_IF([test x"$with_fish_completions" = x"yes"], [
	AC_SUBST(FISH_COMPLETIONS, fish)
])

dnl We don't call AC_PROG_CPP, but only AC_PROG_OBJCPP and set CPP to OBJCPP
dnl and add OBJCPPFLAGS to CPPFLAGS, thus we need to AC_SUBST these ourself.
AC_SUBST(CPP)