Merge remote-tracking branch 'origin/master' into for-steve
[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                 AH_VERBATIM([_ALL_SOURCE], [dnl
55                         /* WTF?! */
56                         #ifndef _ALL_SOURCE
57                         # define _ALL_SOURCE    1
58                         #endif
59                         ])
60                 AH_VERBATIM([_POSIX_PTHREAD_SEMANTICS], [dnl
61                         /* WTF?! */
62                         #ifndef _POSIX_PTHREAD_SEMANTICS
63                         # define _POSIX_PTHREAD_SEMANTICS       1
64                         #endif
65                         ])
66                 AH_VERBATIM([_TANDEM_SOURCE], [dnl
67                         /* WTF?! */
68                         #ifndef _TANDEM_SOURCE
69                         # define _TANDEM_SOURCE 1
70                         #endif
71                         ])
72         fi
73         if test "0" = "1"; then
74                 AC_DEFINE([_ALL_SOURCE], [], [Description])
75                 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [], [Description])
76                 AC_DEFINE([_TANDEM_SOURCE], [], [Description])
77         fi
78
79         dnl We'd like to use vendor extensions, where available.
80         dnl We'd like to use functions from the latest Unix98 standards.
81         dnl See http://www.opengroup.org/onlinepubs/007908799/xsh/compilation.html
82         case "$opsys" in
83         sol2)
84                 AC_DEFINE([__EXTENSIONS__], [1], [Description here!])
85                 dnl Solaris 2 before 2.5 had some bugs with feature
86                 dnl test macro interaction.
87                 if test "$os_release" -ge 510; then
88                         AC_DEFINE([_POSIX_C_SOURCE], [200112L], [Description here!])
89                         dnl #### should this be 600?
90                         AC_DEFINE([_XOPEN_SOURCE], [600], [Description here!])
91                 elif test "$os_release" -ge 506; then
92                         AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
93                         dnl #### should this be 600?
94                         AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
95                 elif test "$os_release" -ge 505; then
96                         AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
97                         AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [Description here!])
98                 fi
99                 ;;
100
101         linux)
102                 AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
103                 dnl #### should this be 600?
104                 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
105                 AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [Description here!])
106                 ;;
107
108         freebsd4*)
109                 AC_DEFINE([_POSIX_C_SOURCE], [199506L], [Description here!])
110                 dnl #### Do we want these too?  Apparently yes for _XOPEN_SOURCE=500.
111                 AC_DEFINE([_XOPEN_SOURCE], [500], [Description here!])
112                 dnl AC_DEFINE(_XOPEN_SOURCE_EXTENDED)
113                 ;;
114         esac
115 ])dnl SXE_CHECK_LIBC
116
117
118
119 AC_DEFUN([SXE_CHECK_LIBC_VERSION], [dnl
120         libc_version=""
121         AC_MSG_CHECKING(for standard C library version information)
122
123         case "$ac_cv_build" in
124         *-*-linux*)
125                 dnl #### who would ever _not_ be running the distro's libc?
126                 dnl Whose silly question is this? -hroptatyr
127                 dnl Maybe it would be better to get/augment this info with ldd?
128                 if test -f /etc/redhat-release ; then
129                         libc_version=`rpm -q glibc`
130                 elif test -f /etc/debian_version ; then
131                         libc_version=`dpkg-query --showformat='${version}' --show libc6`
132                         libc_version="GNU libc $libc_version (Debian)"
133                 elif test -f /etc/slackware-version ; then
134                         slackver=`cat /etc/slackware-version`
135                         libc_version=`/lib/libc.so.6|head -1|cut -d ' ' -f7|tr -d ,`
136                         if test "x$libc_version" = "x"; then
137                                 libc_version=`/lib64/libc.so.6|head -1|cut -d ' ' -f7|tr -d ,`
138                         fi
139                         libc_version="GNU libc $libc_version ($slackver)"
140                 dnl need SuSE et al checks here...
141                 fi
142                 dnl #### Tested on Debian, does this actually work elsewhere?  ;-)
143                 dnl #### NO! -hroptatyr
144                 dnl if test -z "$libc_version"; then
145                 dnl   libc_version=`ls /lib/libc-*.so | sed -e 's,/lib/libc-\(.*\)\.so,\1,'`
146                 dnl fi
147
148                 if test -z "$libc_version"; then
149                 AC_RUN_IFELSE([AC_LANG_SOURCE([[
150 int main() { return 0; }]])], [dnl
151 libc_file_we_use=`$LDD ./conftest | grep libc | sed -e "s/.*=>\(.*\) .*$/\1/"`],
152                         [],[libc_file_we_use=])
153                 libc_version=`$libc_file_we_use 2>/dev/null | sed "/version/q" | tr -cd "0-9.()"`
154                 fi
155                 ;;
156
157         *-*-aix*)
158                 libc_version="bos.rte.libc `lslpp -Lqc bos.rte.libc | cut -f3 -d:`"
159                 ;;
160
161         *-*-solaris*)
162                 libc=`pkginfo -l SUNWcsl | grep VERSION: | awk '{print $2}'`
163                 libc_version="SUNWcsl $libc"
164                 ;;
165
166         mips-sgi-irix*)
167                 libc_version="IRIX libc `uname -sRm`"
168                 ;;
169
170         alpha*-dec-osf*)
171                 dnl Another ugly case
172                 (cd /usr/.smdb.;
173                         libc_version=` grep -h libc.so *.inv | awk '$9 == "f" {print $12}' | tr '\n' ','`
174                 )
175                 ;;
176
177         *-apple-darwin*)
178                 dnl MacOS guys, does this work?
179                 libc_version="`$LDD /usr/lib/libc.dylib | head -n1 | sed -e 's/.*current version[ ]*\([0-9.]*\).*$/\1/'`"
180                 ;;
181
182         *)
183                 libc_version=""
184                 ;;
185         esac
186
187         AC_MSG_RESULT($libc_version)
188
189         dnl Awww, shucks.
190         if test -z "libc_version"; then
191                 libc_version="detection failed (please report this)"
192         fi
193 ])dnl SXE_CHECK_LIBC_VERSION
194
195 AC_DEFUN([SXE_CHECK_BASIC_HEADERS], [dnl
196         AC_HEADER_DIRENT
197         AC_HEADER_STAT
198         AC_HEADER_SYS_WAIT
199         AC_HEADER_MAJOR
200         ## check for stdbool, but turn off warnings before
201         SXE_DUMP_LIBS
202         SXE_LANG_WERROR([off])
203         AC_HEADER_STDBOOL
204         SXE_RESTORE_LIBS
205
206         SXE_CHECK_HEADERS([stddef.h stdlib.h string.h wchar.h])
207         SXE_CHECK_HEADERS([fcntl.h float.h inttypes.h limits.h locale.h mach/mach.h malloc.h memory.h unistd.h ulimit.h])
208         SXE_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/param.h sys/pstat.h sys/resource.h sys/vlimit.h])
209         SXE_CHECK_HEADERS([a.out.h elf.h])
210         SXE_CHECK_HEADERS([ctype.h errno.h])
211         SXE_CHECK_HEADERS([getopt.h])
212
213         ## just to be ubersure
214         unset ac_cv_header_stdbool_h
215         SXE_CHECK_HEADERS([stdbool.h])
216 ])dnl SXE_CHECK_BASIC_HEADERS
217
218
219 AC_DEFUN([SXE_CHECK_BASIC_TYPES], [dnl
220         pushdef([INC_STDBOOL_H], [
221 #if defined HAVE_STDBOOL_H
222 # include <stdbool.h>
223 #endif
224                 ])
225
226         ## checks for typedefs
227         AC_TYPE_INT16_T
228         AC_TYPE_INT32_T
229         AC_TYPE_INT64_T
230         AC_TYPE_INT8_T
231         AC_TYPE_MODE_T
232         AC_TYPE_OFF_T
233         AC_TYPE_PID_T
234         AC_TYPE_INTPTR_T
235         ## next one is obsolete, it is safe to assume that RETSIGTYPE
236         ## is always `void' these days
237         dnl AC_TYPE_SIGNAL
238         AC_TYPE_SIZE_T
239         AC_TYPE_SSIZE_T
240         AC_TYPE_UID_T
241         AC_TYPE_UINT16_T
242         AC_TYPE_UINT32_T
243         AC_TYPE_UINT64_T
244         AC_TYPE_UINT8_T
245         AC_TYPE_UINTMAX_T
246         AC_TYPE_UINTPTR_T
247         AC_CHECK_TYPES([wchar_t])
248         AC_CHECK_TYPE([bool], [], [], INC_STDBOOL_H)
249         AC_CHECK_TYPES([long long int])
250         AC_CHECK_TYPES([longopts])
251
252         dnl We immediately jump off the cliff when using a cross compiler
253         dnl Why?
254         AC_CHECK_SIZEOF([char], [0])
255         AC_CHECK_SIZEOF([short], [0])
256         AC_CHECK_SIZEOF([int], [0])
257         AC_CHECK_SIZEOF([long], [0])
258         AC_CHECK_SIZEOF([long long int], [0])
259         AC_CHECK_SIZEOF([wchar_t], [0])
260         AC_CHECK_SIZEOF([void *], [0])
261         AC_CHECK_SIZEOF([float], [0])
262         AC_CHECK_SIZEOF([double], [0])
263         AC_CHECK_SIZEOF([long double], [0])
264         AC_CHECK_SIZEOF([size_t], [0])
265         AC_CHECK_SIZEOF([char *], [0])
266         AC_CHECK_SIZEOF([bool], [0], INC_STDBOOL_H)
267
268         ## we used to do:
269         ## if test "$ac_cv_sizeof_short" = 0; then
270         ##      echo ""
271         ##      echo "*** PANIC *** Configure tests are not working - compiler is broken."
272         ##      echo "*** PANIC *** Please examine config.log for compilation errors."
273         ##      exit 1
274         ## fi
275
276         ## treat RETSIGTYPE specially since we've kicked the detection
277         ## routine for it
278         AC_DEFINE([RETSIGTYPE], [void], [Return type of signal handler funs])
279
280         popdef([INC_STDBOOL_H])
281 ])dnl SXE_CHECK_BASIC_TYPES
282
283
284 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUN], [dnl
285         ## arg #1 is the fun
286         pushdef([FUN], [$1])
287         pushdef([INC_CTYPE_H], [
288 #ifdef HAVE_CTYPE_H
289 # include <ctype.h>
290 #endif
291                 ])
292
293         ## naive check
294         AC_CHECK_FUNC(FUN)
295         AC_CHECK_DECL(FUN)
296
297         ## now as they are usually in ctype.h, check there
298         if test "$ac_cv_func_[]FUN[]" != "yes"; then
299                 unset ac_cv_func_[]FUN[]
300                 AC_CHECK_FUNCS(FUN, [], [], INC_CTYPE_H)
301         else
302                 ## just to define them symbols
303                 AC_CHECK_FUNCS(FUN)
304         fi
305         if test "$ac_cv_have_decl_[]FUN[]" != "yes"; then
306                 unset ac_cv_have_decl_[]FUN[]
307                 AC_CHECK_DECLS(FUN, [], [], INC_CTYPE_H)
308         else
309                 ## just to define them symbols
310                 AC_CHECK_DECLS(FUN)
311         fi
312
313         popdef([FUN])
314         popdef([INC_CTYPE_H])
315 ])dnl _SXE_CHECK_CTYPE_H_FUN
316
317 AC_DEFUN([_SXE_CHECK_CTYPE_H_FUNS], [dnl
318         ## arg #1 are the funs, space separated
319         m4_foreach([_FUN], [$1], [_SXE_CHECK_CTYPE_H_FUN(_FUN)])
320 ])dnl _SXE_CHECK_CTYPE_H_FUNS
321
322 AC_DEFUN([SXE_CHECK_BASIC_FUNS], [dnl
323         ## turn off that Werror thing
324         SXE_LANG_WERROR([push+off])
325
326         AC_CHECK_FUNCS([strdup strcat strncat strcmp strncmp strcpy strncpy])
327         AC_CHECK_DECLS([strdup, strcat, strncat, strcmp, strncmp, strcpy, strncpy])
328         AC_CHECK_FUNCS([strlen stpcpy stpncpy])
329         AC_CHECK_DECLS([strlen, stpcpy, stpncpy])
330         AC_CHECK_FUNCS([malloc realloc calloc free])
331         AC_CHECK_DECLS([malloc, realloc, calloc, free])
332         AC_CHECK_FUNCS([getopt getopt_long])
333         AC_CHECK_DECLS([getopt, getopt_long])
334
335         _SXE_CHECK_CTYPE_H_FUNS([isalnum, isalpha, isascii, isdigit])
336         _SXE_CHECK_CTYPE_H_FUNS([isblank, isspace, ispunct, isgraph])
337         _SXE_CHECK_CTYPE_H_FUNS([islower, isupper, isxdigit])
338         _SXE_CHECK_CTYPE_H_FUNS([iscntrl, isprint])
339 ])dnl SXE_CHECK_BASIC_FUNS
340
341
342 AC_DEFUN([SXE_CHECK_SIGNALS], [dnl
343         SXE_CHECK_HEADERS([string.h])
344         AC_CHECK_FUNCS([strsignal])
345         AC_CHECK_DECLS([sys_siglist], [], [], [
346 #include <signal.h>
347 /* NetBSD declares sys_siglist in unistd.h.  */
348 #if HAVE_UNISTD_H
349 # include <unistd.h>
350 #endif
351                 ])
352         AC_CHECK_DECLS([sys_siglist])
353 ])dnl SXE_CHECK_SIGNALS
354
355 AC_DEFUN([SXE_CHECK_INTPTR_T], [dnl
356         SXE_CHECK_HEADERS([inttypes.h])
357         AC_CHECK_TYPE([intptr_t], [], [], [
358 #if defined HAVE_SYS_TYPES_H
359 #  include <sys/types.h>
360 #endif
361                 ])
362         if test "$ac_cv_type_intptr_t" = "yes"; then
363                 AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1], [Description here!])
364         fi
365
366         dnl if test "$ac_cv_header_inttypes_h" != "yes"; then
367         dnl     AC_MSG_CHECKING([for intptr_t in sys/types.h])
368         dnl     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
369         dnl #include <sys/types.h>
370         dnl ]], [[
371         dnl intptr_t x;
372         dnl ]])], [dnl
373         dnl             AC_MSG_RESULT(yes)
374         dnl             AC_DEFINE([HAVE_INTPTR_T_IN_SYS_TYPES_H], [1],
375         dnl                     [Description here!])
376         dnl             ], [dnl
377         dnl             AC_MSG_RESULT(no)])
378         dnl fi
379 ])dnl SXE_CHECK_INTPTR_T
380
381 dnl sxe-libc.m4 ends here