1 dnl sxe-libc.m4 -- libc stuff
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 dnl Redistribution and use in source and binary forms, with or without
8 dnl modification, are permitted provided that the following conditions
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl notice, this list of conditions and the following disclaimer.
14 dnl 2. Redistributions in binary form must reproduce the above copyright
15 dnl notice, this list of conditions and the following disclaimer in the
16 dnl documentation and/or other materials provided with the distribution.
18 dnl 3. Neither the name of the author nor the names of any contributors
19 dnl may be used to endorse or promote products derived from this
20 dnl software without specific prior written permission.
22 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
23 dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 dnl DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 dnl This file is part of SXEmacs.
36 AC_DEFUN([SXE_CHECK_LIBC], [dnl
37 dnl We want feature macros defined here *and* in config.h.in, so that
38 dnl the compilation environment at configure time and compile time agree.
40 AC_MSG_CHECKING([for GNU libc])
41 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <features.h>]],[[
42 #if ! (defined __GLIBC__ || defined __GNU_LIBRARY__)
43 #error Not a GNU libc system :-(
44 ******* ======= ******** &&&&&&&&
46 ]])], [have_glibc=yes], [have_glibc=no])
47 AC_MSG_RESULT($have_glibc)
49 dnl I'm tired of pop being broken with GLIBC -slb
50 dnl Well. then why not fix fucking pop?
51 if test "$have_glibc" = "yes"; then
52 AC_DEFINE([_GNU_SOURCE], [1],
53 [Enable GNU extensions on systems that have them.])
54 AC_DEFINE([HAVE_GLIBC], [1], [Define if libc is glibc])
55 AH_VERBATIM([_ALL_SOURCE], [dnl
58 # define _ALL_SOURCE 1
61 AH_VERBATIM([_POSIX_PTHREAD_SEMANTICS], [dnl
63 #ifndef _POSIX_PTHREAD_SEMANTICS
64 # define _POSIX_PTHREAD_SEMANTICS 1
67 AH_VERBATIM([_TANDEM_SOURCE], [dnl
69 #ifndef _TANDEM_SOURCE
70 # define _TANDEM_SOURCE 1
74 if test "0" = "1"; then
75 AC_DEFINE([_ALL_SOURCE], [], [Description])
76 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [], [Description])
77 AC_DEFINE([_TANDEM_SOURCE], [], [Description])
80 dnl We'd like to use vendor extensions, where available.
81 dnl We'd like to use functions from the latest Unix98 standards.
82 dnl See http://www.opengroup.org/onlinepubs/007908799/xsh/compilation.html
85 AC_DEFINE([__EXTENSIONS__], [1], [Description here!])
86 dnl Solaris 2 before 2.5 had some bugs with feature
87 dnl test macro interaction.
88 if test "$os_release" -ge 510; then
89 AC_DEFINE([_POSIX_C_SOURCE], [200112L], [Description here!])
90 dnl #### should this be 600?
91 AC_DEFINE([_XOPEN_SOURCE], [600], [Description here!])
92 elif test "$os_release" -ge 506; then
93 AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
94 dnl #### should this be 600?
95 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
96 elif test "$os_release" -ge 505; then
97 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
98 AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [Description here!])
103 AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
104 dnl #### should this be 600?
105 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
106 AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [Description here!])
110 AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
111 dnl #### Do we want these too? Apparently yes for _XOPEN_SOURCE=500.
112 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
113 dnl AC_DEFINE(_XOPEN_SOURCE_EXTENDED)
120 AC_DEFUN([SXE_CHECK_LIBC_VERSION], [dnl
122 AC_MSG_CHECKING(for standard C library version information)
124 case "$ac_cv_build" in
126 dnl #### who would ever _not_ be running the distro's libc?
127 dnl Whose silly question is this? -hroptatyr
128 dnl Maybe it would be better to get/augment this info with ldd?
129 if test -f /etc/redhat-release ; then
130 libc_version=`rpm -q glibc`
131 elif test -f /etc/debian_version ; then
132 libc_version=`dpkg-query --showformat='${version}' --show libc6`
133 libc_version="GNU libc $libc_version (Debian)"
134 elif test -f /etc/slackware-version ; then
135 slackver=`cat /etc/slackware-version`
136 libc_version=`/lib/libc.so.6|head -1|cut -d ' ' -f7|tr -d ,`
137 if test "x$libc_version" = "x"; then
138 libc_version=`/lib64/libc.so.6|head -1|cut -d ' ' -f7|tr -d ,`
140 libc_version="GNU libc $libc_version ($slackver)"
141 dnl need SuSE et al checks here...
143 dnl #### Tested on Debian, does this actually work elsewhere? ;-)
144 dnl #### NO! -hroptatyr
145 dnl if test -z "$libc_version"; then
146 dnl libc_version=`ls /lib/libc-*.so | sed -e 's,/lib/libc-\(.*\)\.so,\1,'`
149 if test -z "$libc_version"; then
150 AC_RUN_IFELSE([AC_LANG_SOURCE([[
151 int main() { return 0; }]])], [dnl
152 libc_file_we_use=`$LDD ./conftest | grep libc | sed -e "s/.*=>\(.*\) .*$/\1/"`],
153 [],[libc_file_we_use=])
154 libc_version=`$libc_file_we_use 2>/dev/null | sed "/version/q" | tr -cd "0-9.()"`
159 libc_version="bos.rte.libc `lslpp -Lqc bos.rte.libc | cut -f3 -d:`"
163 libc=`pkginfo -l SUNWcsl | grep VERSION: | awk '{print $2}'`
164 libc_version="SUNWcsl $libc"
168 libc_version="IRIX libc `uname -sRm`"
172 dnl Another ugly case
174 libc_version=` grep -h libc.so *.inv | awk '$9 == "f" {print $12}' | tr '\n' ','`
179 dnl MacOS guys, does this work?
180 libc_version="`$LDD /usr/lib/libc.dylib | head -n1 | sed -e 's/.*current version[ ]*\([0-9.]*\).*$/\1/'`"
188 AC_MSG_RESULT($libc_version)
191 if test -z "libc_version"; then
192 libc_version="detection failed (please report this)"
194 ])dnl SXE_CHECK_LIBC_VERSION
196 AC_DEFUN([SXE_CHECK_BASIC_HEADERS], [dnl
201 ## check for stdbool, but turn off warnings before
203 SXE_LANG_WERROR([off])
207 SXE_CHECK_HEADERS([stddef.h stdlib.h string.h wchar.h])
208 SXE_CHECK_HEADERS([fcntl.h float.h inttypes.h limits.h locale.h mach/mach.h malloc.h memory.h unistd.h ulimit.h])
209 SXE_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/param.h sys/pstat.h sys/resource.h sys/vlimit.h])
210 SXE_CHECK_HEADERS([a.out.h elf.h])
211 SXE_CHECK_HEADERS([ctype.h errno.h])
212 SXE_CHECK_HEADERS([getopt.h])
214 ## just to be ubersure
215 unset ac_cv_header_stdbool_h
216 SXE_CHECK_HEADERS([stdbool.h])
217 ])dnl SXE_CHECK_BASIC_HEADERS
220 AC_DEFUN([SXE_CHECK_BASIC_TYPES], [dnl
221 pushdef([INC_STDBOOL_H], [
222 #if defined HAVE_STDBOOL_H
223 # include <stdbool.h>
227 ## checks for typedefs
236 ## next one is obsolete, it is safe to assume that RETSIGTYPE
237 ## is always `void' these days
248 AC_CHECK_TYPES([wchar_t])
249 AC_CHECK_TYPE([bool], [], [], INC_STDBOOL_H)
250 AC_CHECK_TYPES([long long int])
251 AC_CHECK_TYPES([longopts])
253 dnl We immediately jump off the cliff when using a cross compiler
255 AC_CHECK_SIZEOF([char], [0])
256 AC_CHECK_SIZEOF([short], [0])
257 AC_CHECK_SIZEOF([int], [0])
258 AC_CHECK_SIZEOF([long], [0])
259 AC_CHECK_SIZEOF([long long int], [0])
260 AC_CHECK_SIZEOF([wchar_t], [0])
261 AC_CHECK_SIZEOF([void *], [0])
262 AC_CHECK_SIZEOF([float], [0])
263 AC_CHECK_SIZEOF([double], [0])
264 AC_CHECK_SIZEOF([long double], [0])
265 AC_CHECK_SIZEOF([size_t], [0])
266 AC_CHECK_SIZEOF([char *], [0])
267 AC_CHECK_SIZEOF([bool], [0], INC_STDBOOL_H)
270 ## if test "$ac_cv_sizeof_short" = 0; then
272 ## echo "*** PANIC *** Configure tests are not working - compiler is broken."
273 ## echo "*** PANIC *** Please examine config.log for compilation errors."
277 ## treat RETSIGTYPE specially since we've kicked the detection
279 AC_DEFINE([RETSIGTYPE], [void], [Return type of signal handler funs])
281 popdef([INC_STDBOOL_H])
282 ])dnl SXE_CHECK_BASIC_TYPES
285 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUN], [dnl
288 pushdef([INC_CTYPE_H], [
298 ## now as they are usually in ctype.h, check there
299 if test "$ac_cv_func_[]FUN[]" != "yes"; then
300 unset ac_cv_func_[]FUN[]
301 AC_CHECK_FUNCS(FUN, [], [], INC_CTYPE_H)
303 ## just to define them symbols
306 if test "$ac_cv_have_decl_[]FUN[]" != "yes"; then
307 unset ac_cv_have_decl_[]FUN[]
308 AC_CHECK_DECLS(FUN, [], [], INC_CTYPE_H)
310 ## just to define them symbols
315 popdef([INC_CTYPE_H])
316 ])dnl _SXE_CHECK_CTYPE_H_FUN
318 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUNS], [dnl
319 ## arg #1 are the funs, space separated
320 m4_foreach([_FUN], [$1], [_SXE_CHECK_CTYPE_H_FUN(_FUN)])
321 ])dnl _SXE_CHECK_CTYPE_H_FUNS
323 AC_DEFUN([SXE_CHECK_BASIC_FUNS], [dnl
324 ## turn off that Werror thing
325 SXE_LANG_WERROR([push+off])
327 AC_CHECK_FUNCS([strdup strcat strncat strcmp strncmp strcpy strncpy])
328 AC_CHECK_DECLS([strdup, strcat, strncat, strcmp, strncmp, strcpy, strncpy])
329 AC_CHECK_FUNCS([strlen stpcpy stpncpy])
330 AC_CHECK_DECLS([strlen, stpcpy, stpncpy])
331 AC_CHECK_FUNCS([malloc realloc calloc free])
332 AC_CHECK_DECLS([malloc, realloc, calloc, free])
333 AC_CHECK_FUNCS([getopt getopt_long])
334 AC_CHECK_DECLS([getopt, getopt_long])
336 _SXE_CHECK_CTYPE_H_FUNS([isalnum, isalpha, isascii, isdigit])
337 _SXE_CHECK_CTYPE_H_FUNS([isblank, isspace, ispunct, isgraph])
338 _SXE_CHECK_CTYPE_H_FUNS([islower, isupper, isxdigit])
339 _SXE_CHECK_CTYPE_H_FUNS([iscntrl, isprint])
340 ])dnl SXE_CHECK_BASIC_FUNS
343 AC_DEFUN([SXE_CHECK_SIGNALS], [dnl
344 SXE_CHECK_HEADERS([string.h])
345 AC_CHECK_FUNCS([strsignal])
346 AC_CHECK_DECLS([sys_siglist], [], [], [
348 /* NetBSD declares sys_siglist in unistd.h. */
353 AC_CHECK_DECLS([sys_siglist])
354 ])dnl SXE_CHECK_SIGNALS
356 AC_DEFUN([SXE_CHECK_INTPTR_T], [dnl
357 SXE_CHECK_HEADERS([inttypes.h])
358 AC_CHECK_TYPE([intptr_t], [], [], [
359 #if defined HAVE_SYS_TYPES_H
360 # include <sys/types.h>
363 if test "$ac_cv_type_intptr_t" = "yes"; then
364 AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1], [Description here!])
367 dnl if test "$ac_cv_header_inttypes_h" != "yes"; then
368 dnl AC_MSG_CHECKING([for intptr_t in sys/types.h])
369 dnl AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
370 dnl #include <sys/types.h>
374 dnl AC_MSG_RESULT(yes)
375 dnl AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1],
376 dnl [Description here!])
378 dnl AC_MSG_RESULT(no)])
380 ])dnl SXE_CHECK_INTPTR_T
382 dnl sxe-libc.m4 ends here