aboutsummaryrefslogtreecommitdiff
path: root/m4/nx-macros.m4
blob: 6e58b7f0239236d2140971378c7b88d0c5b6431f (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
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
329
330
331
332
333
334
335
336
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
395
396
397
398
399
400
401
402
403
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
dnl nx-macros.m4.  Generated from xorg-macros.m4.in xorgversion.m4 by configure.
dnl
dnl Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
dnl Copyright (c) 2017, Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
dnl
dnl Permission is hereby granted, free of charge, to any person obtaining a
dnl copy of this software and associated documentation files (the "Software"),
dnl to deal in the Software without restriction, including without limitation
dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
dnl and/or sell copies of the Software, and to permit persons to whom the
dnl Software is furnished to do so, subject to the following conditions:
dnl
dnl The above copyright notice and this permission notice (including the next
dnl paragraph) shall be included in all copies or substantial portions of the
dnl Software.
dnl
dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
dnl DEALINGS IN THE SOFTWARE.

# NX_COMPILER_BRAND
# -------------------
# Checks for various brands of compilers and sets flags as appropriate:
#   GNU gcc - relies on AC_PROG_CC (via AC_PROG_CC_C99) to set GCC to "yes"
#   GNU g++ - relies on AC_PROG_CXX to set GXX to "yes"
#   clang compiler - sets CLANGCC to "yes"
#   Intel compiler - sets INTELCC to "yes"
#   Sun/Oracle Solaris Studio cc - sets SUNCC to "yes"
#
# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to
# nxcomp{,shad}.

AC_DEFUN([NX_COMPILER_BRAND], [
AC_LANG_CASE(
	[C], [
		AC_REQUIRE([AC_PROG_CC_C99])
	],
	[C++], [
		AC_REQUIRE([AC_PROG_CXX])
	]
)
AC_CHECK_DECL([__clang__], [CLANGCC="yes"], [CLANGCC="no"])
AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"])
AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
]) # NX_COMPILER_BRAND

# NX_TESTSET_CFLAG(<variable>, <flag>, [<alternative flag>, ...])
# ---------------
# Test if the compiler works when passed the given flag as a command line argument.
# If it succeeds, the flag is appended to the given variable.  If not, it tries the
# next flag in the list until there are no more options.
#
# Note that this does not guarantee that the compiler supports the flag as some
# compilers will simply ignore arguments that they do not understand, but we do
# attempt to weed out false positives by using -Werror=unknown-warning-option and
# -Werror=unused-command-line-argument
#
# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to
# nxcomp{,shad}.

AC_DEFUN([NX_TESTSET_CFLAG], [
m4_if([$#], 0, [m4_fatal([NX_TESTSET_CFLAG was given with an unsupported number of arguments])])
m4_if([$#], 1, [m4_fatal([NX_TESTSET_CFLAG was given with an unsupported number of arguments])])

AC_LANG_COMPILER_REQUIRE

AC_LANG_CASE(
	[C], [
		AC_REQUIRE([AC_PROG_CC_C99])
		define([PREFIX], [C])
		define([CACHE_PREFIX], [cc])
		define([COMPILER], [$CC])
	],
	[C++], [
		define([PREFIX], [CXX])
		define([CACHE_PREFIX], [cxx])
		define([COMPILER], [$CXX])
	]
)

[nx_testset_save_]PREFIX[FLAGS]="$PREFIX[FLAGS]"

if test "x$[nx_testset_]CACHE_PREFIX[_unknown_warning_option]" = "x" ; then
	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unknown-warning-option],
			[nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option],
			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
					  [nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option=yes],
					  [nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option=no]))
	[nx_testset_]CACHE_PREFIX[_unknown_warning_option]=$[nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option]
	PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]"
fi

if test "x$[nx_testset_]CACHE_PREFIX[_unused_command_line_argument]" = "x" ; then
	if test "x$[nx_testset_]CACHE_PREFIX[_unknown_warning_option]" = "xyes" ; then
		PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
	fi
	PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
	AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unused-command-line-argument],
			[nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument],
			AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
					  [nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=yes],
					  [nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=no]))
	[nx_testset_]CACHE_PREFIX[_unused_command_line_argument]=$[nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument]
	PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]"
fi

found="no"
m4_foreach([flag], m4_cdr($@), [
	if test $found = "no" ; then
		if test "x$nx_testset_]CACHE_PREFIX[_unknown_warning_option" = "xyes" ; then
			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
		fi

		if test "x$nx_testset_]CACHE_PREFIX[_unused_command_line_argument" = "xyes" ; then
			PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
		fi

		PREFIX[FLAGS]="$PREFIX[FLAGS] ]flag["

dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname
		AC_MSG_CHECKING([if ]COMPILER[ supports ]flag[])
		cacheid=AS_TR_SH([nx_cv_]CACHE_PREFIX[_flag_]flag[])
		AC_CACHE_VAL($cacheid,
			     [AC_LINK_IFELSE([AC_LANG_PROGRAM([int i;])],
					     [eval $cacheid=yes],
					     [eval $cacheid=no])])

		PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]"

		eval supported=\$$cacheid
		AC_MSG_RESULT([$supported])
		if test "$supported" = "yes" ; then
			$1="$$1 ]flag["
			found="yes"
		fi
	fi
])
]) # NX_TESTSET_CFLAG

# NX_COMPILER_FLAGS
# ---------------
# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line
# arguments supported by the selected compiler which do NOT alter the generated
# code.  These arguments will cause the compiler to print various warnings
# during compilation AND turn a conservative set of warnings into errors.
#
# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in
# future versions of util-macros as options are added to new compilers.
#
# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to
# nxcomp{,shad}.

AC_DEFUN([NX_COMPILER_FLAGS], [
AC_REQUIRE([NX_COMPILER_BRAND])

AC_ARG_ENABLE(selective-werror,
              AS_HELP_STRING([--disable-selective-werror],
                             [Turn off selective compiler errors. (default: enabled)]),
              [SELECTIVE_WERROR=$enableval],
              [SELECTIVE_WERROR=yes])

AC_LANG_CASE(
        [C], [
                define([PREFIX], [C])
        ],
        [C++], [
                define([PREFIX], [CXX])
        ]
)
# -v is too short to test reliably with NX_TESTSET_CFLAG
if test "x$SUNCC" = "xyes"; then
    [BASE_]PREFIX[FLAGS]="-v"
else
    [BASE_]PREFIX[FLAGS]=""
fi

# This chunk of warnings were those that existed in the legacy CWARNFLAGS
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat])

AC_LANG_CASE(
	[C], [
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes])
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes])
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs])
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast])
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition], [-fd])
		NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement])
	]
)

# This chunk adds additional warnings that could catch undesired effects.
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])

# These are currently disabled because they are noisy.  They will be enabled
# in the future once the codebase is sufficiently modernized to silence
# them.  For now, I don't want them to drown out the other warnings.
# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual])

# Turn some warnings into errors, so we don't accidentally get successful builds
# when there are problems that should be fixed.

if test "x$SELECTIVE_WERROR" = "xyes" ; then
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
else
AC_MSG_WARN([You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast])
NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast])
fi

AC_SUBST([BASE_]PREFIX[FLAGS])
]) # NX_COMPILER_FLAGS

# NX_STRICT_OPTION
# -----------------------
#
# Add configure option to enable strict compilation flags, such as treating
# warnings as fatal errors.
# If --enable-strict-compilation is passed to configure, adds strict flags to
# $BASE_CFLAGS or $BASE_CXXFLAGS.
#
# Also exports $STRICT_CFLAGS for use in other tests or when strict compilation
# is unconditionally desired.
AC_DEFUN([NX_STRICT_OPTION], [
AC_REQUIRE([NX_COMPILER_FLAGS])

AC_ARG_ENABLE(strict-compilation,
                          AS_HELP_STRING([--enable-strict-compilation],
                          [Enable all warnings from compiler and make them errors (default: disabled)]),
                          [STRICT_COMPILE=$enableval], [STRICT_COMPILE=no])

AC_LANG_CASE(
        [C], [
                define([PREFIX], [C])
        ],
        [C++], [
                define([PREFIX], [CXX])
        ]
)

[STRICT_]PREFIX[FLAGS]=""
NX_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-pedantic])
NX_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror], [-errwarn])

# Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
# activate it with -Werror, so we add it here explicitly.
NX_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror=attributes])

if test "x$STRICT_COMPILE" = "xyes"; then
    [BASE_]PREFIX[FLAGS]="$[BASE_]PREFIX[FLAGS] $[STRICT_]PREFIX[FLAGS]"
fi
AC_SUBST([STRICT_]PREFIX[FLAGS])
AC_SUBST([BASE_]PREFIX[FLAGS])
]) # NX_STRICT_OPTION

# NX_DEFAULT_OPTIONS
# --------------------
#
# Defines default options for X.Org-like modules.
#
AC_DEFUN([NX_DEFAULT_OPTIONS], [
AC_REQUIRE([AC_PROG_INSTALL])
NX_COMPILER_FLAGS
NX_STRICT_OPTION
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
    [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
]) # NX_DEFAULT_OPTIONS

# NX_CHECK_MALLOC_ZERO
# ----------------------
# Minimum version: 1.0.0
#
# Defines {MALLOC,XMALLOC,XTMALLOC}_ZERO_CFLAGS appropriately if
# malloc(0) returns NULL.  Packages should add one of these cflags to
# their AM_CFLAGS (or other appropriate *_CFLAGS) to use them.
AC_DEFUN([NX_CHECK_MALLOC_ZERO],[
AC_ARG_ENABLE(malloc0returnsnull,
        AS_HELP_STRING([--enable-malloc0returnsnull],
                       [malloc(0) returns NULL (default: auto)]),
        [MALLOC_ZERO_RETURNS_NULL=$enableval],
        [MALLOC_ZERO_RETURNS_NULL=auto])

AC_MSG_CHECKING([whether malloc(0) returns NULL])
if test "x$MALLOC_ZERO_RETURNS_NULL" = xauto; then
        AC_RUN_IFELSE([AC_LANG_PROGRAM([
#include <stdlib.h>
],[
    char *m0, *r0, *c0, *p;
    m0 = malloc(0);
    p = malloc(10);
    r0 = realloc(p,0);
    c0 = calloc(0,10);
    exit((m0 == 0 || r0 == 0 || c0 == 0) ? 0 : 1);
])],
                [MALLOC_ZERO_RETURNS_NULL=yes],
                [MALLOC_ZERO_RETURNS_NULL=no],
                [MALLOC_ZERO_RETURNS_NULL=yes])
fi
AC_MSG_RESULT([$MALLOC_ZERO_RETURNS_NULL])

if test "x$MALLOC_ZERO_RETURNS_NULL" = xyes; then
        MALLOC_ZERO_CFLAGS="-DMALLOC_0_RETURNS_NULL"
        XMALLOC_ZERO_CFLAGS=$MALLOC_ZERO_CFLAGS
        XTMALLOC_ZERO_CFLAGS="$MALLOC_ZERO_CFLAGS -DXTMALLOC_BC"
else
        MALLOC_ZERO_CFLAGS=""
        XMALLOC_ZERO_CFLAGS=""
        XTMALLOC_ZERO_CFLAGS=""
fi

AC_SUBST([MALLOC_ZERO_CFLAGS])
AC_SUBST([XMALLOC_ZERO_CFLAGS])
AC_SUBST([XTMALLOC_ZERO_CFLAGS])
]) # NX_CHECK_MALLOC_ZERO


dnl Check to see if we're running under Cygwin32.

AC_DEFUN([NX_BUILD_ON_CYGWIN32],
[AC_CACHE_CHECK([for Cygwin32 environment], nxconf_cv_cygwin32,
[AC_TRY_COMPILE(,[return __CYGWIN32__;],
nxconf_cv_cygwin32=yes, nxconf_cv_cygwin32=no)
rm -f conftest*])
CYGWIN32=
test "$nxconf_cv_cygwin32" = yes && CYGWIN32=yes
]) # NX_BUILD_ON_CYGWIN32

dnl Check whether we're building on a AMD64.

AC_DEFUN([NX_BUILD_ON_AMD64],
[AC_CACHE_CHECK([for Amd64 environment], nxconf_cv_amd64,
[AC_TRY_COMPILE(,[return (__amd64__ || __x86_64__);],
nxconf_cv_amd64=yes, nxconf_cv_amd64=no)
rm -f conftest*])
AMD64=
test "$nxconf_cv_amd64" = yes && AMD64=yes
]) # NX_BUILD_ON_AMD64

dnl Check for Darwin environment.

AC_DEFUN([NX_BUILD_ON_DARWIN],
[AC_CACHE_CHECK([for Darwin environment], nxconf_cv_darwin,
[AC_TRY_COMPILE(,[return __APPLE__;],
nxconf_cv_darwin=yes, nxconf_cv_darwin=no)
rm -f conftest*])
DARWIN=
test "$nxconf_cv_darwin" = yes && DARWIN=yes
]) # NX_BUILD_ON_DARWIN

# Check to see if we're running under Solaris.

AC_DEFUN([NX_BUILD_ON_SUN],
[AC_CACHE_CHECK([for Solaris environment], nxconf_cv_sun,
[AC_TRY_COMPILE(,[return __sun;],
nxconf_cv_sun=yes, nxconf_cv_sun=no)
rm -f conftest*])
SUN=
test "$nxconf_cv_sun" = yes && SUN=yes
]) # NX_BUILD_ON_SUN

# Check to see if we're running under FreeBSD.

AC_DEFUN([NX_BUILD_ON_FreeBSD],
[AC_CACHE_CHECK([for FreeBSD environment], nxconf_cv_freebsd,
[AC_TRY_COMPILE(,[return __FreeBSD__;],
nxconf_cv_freebsd=yes, nxconf_cv_freebsd=no)
rm -f conftest*])
FreeBSD=
test "$nxconf_cv_freebsd" = yes && FreeBSD=yes
]) # NX_BUILD_ON_FreeBSD

# Check to see if we're generating binaries in ELF format.

AC_DEFUN([NX_TARGET_USE_ELF],
[AC_CACHE_CHECK([if target system is ELF-based], [nxconf_cv_targetelf],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
#ifndef __ELF__
#error not an ELF-based system
error!
#endif
]],
[[
]])],
[nxconf_cv_targetelf=yes], [nxconf_cv_targetelf=no])])
AM_CONDITIONAL([TARGET_ELF], [test x"$nxconf_cv_targetelf" = "xyes"])
]) # NX_TARGET_USE_ELF

AC_DEFUN([LIBJPEG_FALLBACK_CHECK],[
AC_MSG_CHECKING([for libjpeg shared library file and headers])
AC_CHECK_LIB([jpeg], [jpeg_destroy_compress],
    [have_jpeg_lib=yes], [have_jpeg_lib=no])
AC_CHECK_HEADERS([jpeglib.h],
    [have_jpeg_headers=yes], [have_jpeg_headers=no])

if test x"$have_jpeg_lib" = "xyes" && test x"$have_jpeg_headers" = "xyes"; then
    AC_MSG_RESULT([yes])
    JPEG_CFLAGS=""
    JPEG_LIBS="-ljpeg"
else
    AC_MSG_RESULT([no])
    AC_MSG_FAILURE([Could not find libjpeg on your system, make sure
the JPEG shared library and header files are installed.])
fi
]) # LIBJPEG_FALLBACK_CHECK

AC_DEFUN([ZLIB_FALLBACK_CHECK],[
AC_MSG_CHECKING([for zlib shared library file and headers])
AC_CHECK_LIB([z], [inflateEnd],
    [have_zlib_lib=yes], [have_zlib_lib=no])
AC_CHECK_HEADERS([zlib.h],
    [have_zlib_headers=yes], [have_zlib_headers=no])

if test x"$have_zlib_lib" = "xyes" && test x"$have_zlib_headers" = "xyes"; then
    AC_MSG_RESULT([yes])
    Z_CFLAGS=""
    Z_LIBS="-lz"
else
    AC_MSG_RESULT([no])
    AC_MSG_FAILURE([Could not find zlib on your system, make sure
the zlib shared library and header files are installed.])
fi
]) # ZLIB_FALLBACK_CHECK