Get glibc version with a distro-agnostic check.
[sxemacs] / m4 / sxe-libc.m4
1 dnl sxe-libc.m4 -- libc stuff
2 dnl
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
4 dnl
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 dnl
7 dnl Redistribution and use in source and binary forms, with or without
8 dnl modification, are permitted provided that the following conditions
9 dnl are met:
10 dnl
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl    notice, this list of conditions and the following disclaimer.
13 dnl
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.
17 dnl
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.
21 dnl
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.
33 dnl
34 dnl This file is part of SXEmacs.
35
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.
39
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 ******* ======= ******** &&&&&&&&
45 #endif
46 ]])], [have_glibc=yes], [have_glibc=no])
47         AC_MSG_RESULT($have_glibc)
48
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
56                         /* WTF?! */
57                         #ifndef _ALL_SOURCE
58                         # define _ALL_SOURCE    1
59                         #endif
60                         ])
61                 AH_VERBATIM([_POSIX_PTHREAD_SEMANTICS], [dnl
62                         /* WTF?! */
63                         #ifndef _POSIX_PTHREAD_SEMANTICS
64                         # define _POSIX_PTHREAD_SEMANTICS       1
65                         #endif
66                         ])
67                 AH_VERBATIM([_TANDEM_SOURCE], [dnl
68                         /* WTF?! */
69                         #ifndef _TANDEM_SOURCE
70                         # define _TANDEM_SOURCE 1
71                         #endif
72                         ])
73         fi
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])
78         fi
79
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
83         case "$opsys" in
84         sol2)
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!])
99                 fi
100                 ;;
101
102         linux)
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!])
107                 ;;
108
109         freebsd4*)
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)
114                 ;;
115         esac
116 ])dnl SXE_CHECK_LIBC
117
118
119
120 AC_DEFUN([SXE_CHECK_LIBC_VERSION], [dnl
121         libc_version=""
122         AC_MSG_CHECKING(for standard C library version information)
123
124         if test "$have_glibc" = "yes"; then
125                 AC_RUN_IFELSE([AC_LANG_SOURCE([[
126 #include <stdio.h>
127 #include <gnu/libc-version.h>
128 int main(void) { puts (gnu_get_libc_version()); return 0; }]])], [dnl
129 libc_version=`./conftest`], [libc_version=""],
130          [AC_MSG_WARN([Cross-compiling? Good luck. Let us know how it goes.])]
131                 if test -f /etc/os-release; then
132                         source /etc/os-release
133                         libc_version="GNU libc $libc_version (${PRETTY_NAME})"
134                 else
135                         libc_version="GNU libc $libc_version (Unknown OS)"
136                 fi
137         fi
138
139         dnl Amazingly some people don't run Linux, or so I'm told. --SY
140         if test -z "$libc_version"; then
141                 case "$ac_cv_build" in
142                 *-*-aix*)
143                         libc_version="bos.rte.libc `lslpp -Lqc bos.rte.libc | cut -f3 -d:`"
144                         ;;
145
146                 *-*-solaris*)
147                         libc=`pkginfo -l SUNWcsl | grep VERSION: | awk '{print $2}'`
148                         libc_version="SUNWcsl $libc"
149                         ;;
150
151                 mips-sgi-irix*)
152                         libc_version="IRIX libc `uname -sRm`"
153                         ;;
154
155                 alpha*-dec-osf*)
156                         dnl Another ugly case
157                         (cd /usr/.smdb.;
158                                 libc_version=` grep -h libc.so *.inv | awk '$9 == "f" {print $12}' | tr '\n' ','`
159                         )
160                         ;;
161
162                 *-apple-darwin*)
163                         dnl MacOS guys, does this work?
164                         libc_version="`$LDD /usr/lib/libc.dylib | head -n1 | sed -e 's/.*current version[ ]*\([0-9.]*\).*$/\1/'`"
165                         ;;
166
167                 *)
168                         libc_version=""
169                         ;;
170                 esac
171         fi
172
173         AC_MSG_RESULT($libc_version)
174
175         dnl Awww, shucks.
176         if test -z "libc_version"; then
177                 libc_version="detection failed (please report this)"
178         fi
179 ])dnl SXE_CHECK_LIBC_VERSION
180
181 AC_DEFUN([SXE_CHECK_BASIC_HEADERS], [dnl
182         AC_HEADER_DIRENT
183         AC_HEADER_STAT
184         AC_HEADER_SYS_WAIT
185         AC_HEADER_MAJOR
186         ## check for stdbool, but turn off warnings before
187         SXE_DUMP_LIBS
188         SXE_LANG_WERROR([off])
189         AC_HEADER_STDBOOL
190         SXE_RESTORE_LIBS
191
192         SXE_CHECK_HEADERS([stddef.h stdlib.h string.h wchar.h])
193         SXE_CHECK_HEADERS([fcntl.h float.h inttypes.h limits.h locale.h mach/mach.h malloc.h memory.h unistd.h ulimit.h])
194         SXE_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/param.h sys/pstat.h sys/resource.h sys/vlimit.h])
195         SXE_CHECK_HEADERS([a.out.h elf.h])
196         SXE_CHECK_HEADERS([ctype.h errno.h])
197         SXE_CHECK_HEADERS([getopt.h])
198
199         ## just to be ubersure
200         unset ac_cv_header_stdbool_h
201         SXE_CHECK_HEADERS([stdbool.h])
202 ])dnl SXE_CHECK_BASIC_HEADERS
203
204
205 AC_DEFUN([SXE_CHECK_BASIC_TYPES], [dnl
206         pushdef([INC_STDBOOL_H], [
207 #if defined HAVE_STDBOOL_H
208 # include <stdbool.h>
209 #endif
210                 ])
211
212         ## checks for typedefs
213         AC_TYPE_INT16_T
214         AC_TYPE_INT32_T
215         AC_TYPE_INT64_T
216         AC_TYPE_INT8_T
217         AC_TYPE_MODE_T
218         AC_TYPE_OFF_T
219         AC_TYPE_PID_T
220         AC_TYPE_INTPTR_T
221         ## next one is obsolete, it is safe to assume that RETSIGTYPE
222         ## is always `void' these days
223         dnl AC_TYPE_SIGNAL
224         AC_TYPE_SIZE_T
225         AC_TYPE_SSIZE_T
226         AC_TYPE_UID_T
227         AC_TYPE_UINT16_T
228         AC_TYPE_UINT32_T
229         AC_TYPE_UINT64_T
230         AC_TYPE_UINT8_T
231         AC_TYPE_UINTMAX_T
232         AC_TYPE_UINTPTR_T
233         AC_CHECK_TYPES([wchar_t])
234         AC_CHECK_TYPE([bool], [], [], INC_STDBOOL_H)
235         AC_CHECK_TYPES([long long int])
236         AC_CHECK_TYPES([longopts])
237
238         dnl We immediately jump off the cliff when using a cross compiler
239         dnl Why?
240         AC_CHECK_SIZEOF([char], [0])
241         AC_CHECK_SIZEOF([short], [0])
242         AC_CHECK_SIZEOF([int], [0])
243         AC_CHECK_SIZEOF([long], [0])
244         AC_CHECK_SIZEOF([long long int], [0])
245         AC_CHECK_SIZEOF([wchar_t], [0])
246         AC_CHECK_SIZEOF([void *], [0])
247         AC_CHECK_SIZEOF([float], [0])
248         AC_CHECK_SIZEOF([double], [0])
249         AC_CHECK_SIZEOF([long double], [0])
250         AC_CHECK_SIZEOF([size_t], [0])
251         AC_CHECK_SIZEOF([char *], [0])
252         AC_CHECK_SIZEOF([bool], [0], INC_STDBOOL_H)
253
254         ## we used to do:
255         ## if test "$ac_cv_sizeof_short" = 0; then
256         ##      echo ""
257         ##      echo "*** PANIC *** Configure tests are not working - compiler is broken."
258         ##      echo "*** PANIC *** Please examine config.log for compilation errors."
259         ##      exit 1
260         ## fi
261
262         ## treat RETSIGTYPE specially since we've kicked the detection
263         ## routine for it
264         AC_DEFINE([RETSIGTYPE], [void], [Return type of signal handler funs])
265
266         popdef([INC_STDBOOL_H])
267 ])dnl SXE_CHECK_BASIC_TYPES
268
269
270 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUN], [dnl
271         ## arg #1 is the fun
272         pushdef([FUN], [$1])
273         pushdef([INC_CTYPE_H], [
274 #ifdef HAVE_CTYPE_H
275 # include <ctype.h>
276 #endif
277                 ])
278
279         ## naive check
280         AC_CHECK_FUNC(FUN)
281         AC_CHECK_DECL(FUN)
282
283         ## now as they are usually in ctype.h, check there
284         if test "$ac_cv_func_[]FUN[]" != "yes"; then
285                 unset ac_cv_func_[]FUN[]
286                 AC_CHECK_FUNCS(FUN, [], [], INC_CTYPE_H)
287         else
288                 ## just to define them symbols
289                 AC_CHECK_FUNCS(FUN)
290         fi
291         if test "$ac_cv_have_decl_[]FUN[]" != "yes"; then
292                 unset ac_cv_have_decl_[]FUN[]
293                 AC_CHECK_DECLS(FUN, [], [], INC_CTYPE_H)
294         else
295                 ## just to define them symbols
296                 AC_CHECK_DECLS(FUN)
297         fi
298
299         popdef([FUN])
300         popdef([INC_CTYPE_H])
301 ])dnl _SXE_CHECK_CTYPE_H_FUN
302
303 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUNS], [dnl
304         ## arg #1 are the funs, space separated
305         m4_foreach([_FUN], [$1], [_SXE_CHECK_CTYPE_H_FUN(_FUN)])
306 ])dnl _SXE_CHECK_CTYPE_H_FUNS
307
308 AC_DEFUN([SXE_CHECK_BASIC_FUNS], [dnl
309         ## turn off that Werror thing
310         SXE_LANG_WERROR([push+off])
311
312         AC_CHECK_FUNCS([strdup strcat strncat strcmp strncmp strcpy strncpy])
313         AC_CHECK_DECLS([strdup, strcat, strncat, strcmp, strncmp, strcpy, strncpy])
314         AC_CHECK_FUNCS([strlen stpcpy stpncpy])
315         AC_CHECK_DECLS([strlen, stpcpy, stpncpy])
316         AC_CHECK_FUNCS([malloc realloc calloc free])
317         AC_CHECK_DECLS([malloc, realloc, calloc, free])
318         AC_CHECK_FUNCS([getopt getopt_long])
319         AC_CHECK_DECLS([getopt, getopt_long])
320
321         _SXE_CHECK_CTYPE_H_FUNS([isalnum, isalpha, isascii, isdigit])
322         _SXE_CHECK_CTYPE_H_FUNS([isblank, isspace, ispunct, isgraph])
323         _SXE_CHECK_CTYPE_H_FUNS([islower, isupper, isxdigit])
324         _SXE_CHECK_CTYPE_H_FUNS([iscntrl, isprint])
325 ])dnl SXE_CHECK_BASIC_FUNS
326
327
328 AC_DEFUN([SXE_CHECK_SIGNALS], [dnl
329         SXE_CHECK_HEADERS([string.h])
330         AC_CHECK_FUNCS([strsignal])
331         AC_CHECK_DECLS([sys_siglist], [], [], [
332 #include <signal.h>
333 /* NetBSD declares sys_siglist in unistd.h.  */
334 #if HAVE_UNISTD_H
335 # include <unistd.h>
336 #endif
337                 ])
338         AC_CHECK_DECLS([sys_siglist])
339 ])dnl SXE_CHECK_SIGNALS
340
341 AC_DEFUN([SXE_CHECK_INTPTR_T], [dnl
342         SXE_CHECK_HEADERS([inttypes.h])
343         AC_CHECK_TYPE([intptr_t], [], [], [
344 #if defined HAVE_SYS_TYPES_H
345 #  include <sys/types.h>
346 #endif
347                 ])
348         if test "$ac_cv_type_intptr_t" = "yes"; then
349                 AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1], [Description here!])
350         fi
351
352         dnl if test "$ac_cv_header_inttypes_h" != "yes"; then
353         dnl     AC_MSG_CHECKING([for intptr_t in sys/types.h])
354         dnl     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
355         dnl #include <sys/types.h>
356         dnl ]], [[
357         dnl intptr_t x;
358         dnl ]])], [dnl
359         dnl             AC_MSG_RESULT(yes)
360         dnl             AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1],
361         dnl                     [Description here!])
362         dnl             ], [dnl
363         dnl             AC_MSG_RESULT(no)])
364         dnl fi
365 ])dnl SXE_CHECK_INTPTR_T
366
367 dnl sxe-libc.m4 ends here