2 dnl Autconf tests for zsh.
4 dnl Copyright (c) 1995-1997 Richard Coleman
5 dnl All rights reserved.
7 dnl Permission is hereby granted, without written agreement and without
8 dnl license or royalty fees, to use, copy, modify, and distribute this
9 dnl software and to distribute modified versions of this software for any
10 dnl purpose, provided that the above copyright notice and the following
11 dnl two paragraphs appear in all copies of this software.
13 dnl In no event shall Richard Coleman or the Zsh Development Group be liable
14 dnl to any party for direct, indirect, special, incidental, or consequential
15 dnl damages arising out of the use of this software and its documentation,
16 dnl even if Richard Coleman and the Zsh Development Group have been advised of
17 dnl the possibility of such damage.
19 dnl Richard Coleman and the Zsh Development Group specifically disclaim any
20 dnl warranties, including, but not limited to, the implied warranties of
21 dnl merchantability and fitness for a particular purpose. The software
22 dnl provided hereunder is on an "as is" basis, and Richard Coleman and the
23 dnl Zsh Development Group have no obligation to provide maintenance,
24 dnl support, updates, enhancements, or modifications.
29 dnl Check whether the first argument works as a 64-bit type.
30 dnl If there is a non-zero third argument, we just assume it works
31 dnl when we're cross compiling. This is to allow a type to be
32 dnl specified directly as --enable-lfs="long long".
33 dnl Sets the variable given in the second argument to the first argument
34 dnl if the test worked, `no' otherwise. Be careful testing this, as it
35 dnl may produce two words `long long' on an unquoted substitution.
36 dnl Also check that the compiler does not mind it being cast to int.
37 dnl This macro does not produce messages as it may be run several times
38 dnl before finding the right type.
41 AC_DEFUN(zsh_64_BIT_TYPE,
43 #ifdef HAVE_SYS_TYPES_H
44 #include <sys/types.h>
51 return sizeof($1) != 8;
54 [if test x$3 != x ; then
63 dnl zsh_SHARED_FUNCTION
65 dnl This is just a frontend to zsh_SHARED_SYMBOL
67 dnl Usage: zsh_SHARED_FUNCTION(name[,rettype[,paramtype]])
70 AC_DEFUN(zsh_SHARED_FUNCTION,
71 [zsh_SHARED_SYMBOL($1, ifelse([$2], ,[int ],[$2]) $1 [(]ifelse([$3], ,[ ],[$3])[)], $1)])
74 dnl zsh_SHARED_VARIABLE
76 dnl This is just a frontend to zsh_SHARED_SYMBOL
78 dnl Usage: zsh_SHARED_VARIABLE(name[,type])
81 AC_DEFUN(zsh_SHARED_VARIABLE,
82 [zsh_SHARED_SYMBOL($1, ifelse([$2], ,[int ],[$2]) $1, [&$1])])
86 dnl Check whether symbol is available in static or shared library
88 dnl On some systems, static modifiable library symbols (such as environ)
89 dnl may appear only in statically linked libraries. If this is the case,
90 dnl then two shared libraries that reference the same symbol, each linked
91 dnl with the static library, could be given distinct copies of the symbol.
93 dnl Usage: zsh_SHARED_SYMBOL(name,declaration,address)
94 dnl Sets zsh_cv_shared_$1 cache variable to yes/no
97 AC_DEFUN(zsh_SHARED_SYMBOL,
98 [AC_CACHE_CHECK([if $1 is available in shared libraries],
100 [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
109 __attribute__((__dllimport__))
115 sed 's/zsh_getaddr1/zsh_getaddr2/' < conftest1.c > conftest2.c
116 if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
117 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
118 AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
119 AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
123 #define RTLD_LAZY BIND_DEFERRED
124 #define RTLD_GLOBAL DYNAMIC_PATH
126 char *zsh_gl_sym_addr ;
128 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
129 #define dlclose(handle) shl_unload((shl_t)(handle))
130 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
136 #include <sys/types.h>
145 #define RTLD_GLOBAL 0
150 void *handle1, *handle2;
151 void *(*zsh_getaddr1)(), *(*zsh_getaddr2)();
153 handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
154 if(!handle1) exit(1);
155 handle2 = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
156 if(!handle2) exit(1);
157 zsh_getaddr1 = (void *(*)()) dlsym(handle1, "${us}zsh_getaddr1");
158 zsh_getaddr2 = (void *(*)()) dlsym(handle2, "${us}zsh_getaddr2");
159 sym1 = zsh_getaddr1();
160 sym2 = zsh_getaddr2();
161 if(!sym1 || !sym2) exit(1);
162 if(sym1 != sym2) exit(1);
164 handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
165 if(!handle1) exit(1);
166 zsh_getaddr1 = (void *(*)()) dlsym(handle1, "${us}zsh_getaddr1");
167 sym1 = zsh_getaddr1();
169 if(sym1 != sym2) exit(1);
172 ], [zsh_cv_shared_$1=yes],
173 [zsh_cv_shared_$1=no],
174 [zsh_cv_shared_$1=no]
183 dnl zsh_SYS_DYNAMIC_CLASH
184 dnl Check whether symbol name clashes in shared libraries are acceptable.
187 AC_DEFUN(zsh_SYS_DYNAMIC_CLASH,
188 [AC_CACHE_CHECK([if name clashes in shared objects are OK],
189 zsh_cv_sys_dynamic_clash_ok,
190 [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
195 echo 'int fred () { return 42; }' > conftest1.c
196 echo 'int fred () { return 69; }' > conftest2.c
197 if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
198 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
199 AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
200 AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
204 #define RTLD_LAZY BIND_DEFERRED
205 #define RTLD_GLOBAL DYNAMIC_PATH
207 char *zsh_gl_sym_addr ;
209 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
210 #define dlclose(handle) shl_unload((shl_t)(handle))
211 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
217 #include <sys/types.h>
226 #define RTLD_GLOBAL 0
232 void *handle1, *handle2;
233 int (*fred1)(), (*fred2)();
234 handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
235 if(!handle1) exit(1);
236 handle2 = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
237 if(!handle2) exit(1);
238 fred1 = (int (*)()) dlsym(handle1, "${us}fred");
239 fred2 = (int (*)()) dlsym(handle2, "${us}fred");
240 if(!fred1 || !fred2) exit(1);
241 exit((*fred1)() != 42 || (*fred2)() != 69);
243 ], [zsh_cv_sys_dynamic_clash_ok=yes],
244 [zsh_cv_sys_dynamic_clash_ok=no],
245 [zsh_cv_sys_dynamic_clash_ok=no]
248 zsh_cv_sys_dynamic_clash_ok=no
251 if test "$zsh_cv_sys_dynamic_clash_ok" = yes; then
252 AC_DEFINE(DYNAMIC_NAME_CLASH_OK)
257 dnl zsh_SYS_DYNAMIC_GLOBAL
258 dnl Check whether symbols in one dynamically loaded library are
259 dnl available to another dynamically loaded library.
262 AC_DEFUN(zsh_SYS_DYNAMIC_GLOBAL,
263 [AC_CACHE_CHECK([for working RTLD_GLOBAL],
264 zsh_cv_sys_dynamic_rtld_global,
265 [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
270 echo 'int fred () { return 42; }' > conftest1.c
271 echo 'extern int fred(); int barney () { return fred() + 27; }' > conftest2.c
272 if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
273 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
274 AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
275 AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
279 #define RTLD_LAZY BIND_DEFERRED
280 #define RTLD_GLOBAL DYNAMIC_PATH
282 char *zsh_gl_sym_addr ;
284 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
285 #define dlclose(handle) shl_unload((shl_t)(handle))
286 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
292 #include <sys/types.h>
301 #define RTLD_GLOBAL 0
308 handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
310 handle = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
312 barneysym = (int (*)()) dlsym(handle, "${us}barney");
313 if(!barneysym) exit(1);
314 exit((*barneysym)() != 69);
316 ], [zsh_cv_sys_dynamic_rtld_global=yes],
317 [zsh_cv_sys_dynamic_rtld_global=no],
318 [zsh_cv_sys_dynamic_rtld_global=no]
321 zsh_cv_sys_dynamic_rtld_global=no
327 dnl zsh_SYS_DYNAMIC_EXECSYMS
328 dnl Check whether symbols in the executable are available to dynamically
329 dnl loaded libraries.
332 AC_DEFUN(zsh_SYS_DYNAMIC_EXECSYMS,
333 [AC_CACHE_CHECK([whether symbols in the executable are available],
334 zsh_cv_sys_dynamic_execsyms,
335 [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
340 echo 'extern int fred(); int barney () { return fred() + 27; }' > conftest1.c
341 if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
342 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC); then
343 save_ldflags=$LDFLAGS
344 LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS"
348 #define RTLD_LAZY BIND_DEFERRED
349 #define RTLD_GLOBAL DYNAMIC_PATH
351 char *zsh_gl_sym_addr ;
353 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
354 #define dlclose(handle) shl_unload((shl_t)(handle))
355 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
361 #include <sys/types.h>
370 #define RTLD_GLOBAL 0
377 handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
379 barneysym = (int (*)()) dlsym(handle, "${us}barney");
380 if(!barneysym) exit(1);
381 exit((*barneysym)() != 69);
384 int fred () { return 42; }
385 ], [zsh_cv_sys_dynamic_execsyms=yes],
386 [zsh_cv_sys_dynamic_execsyms=no],
387 [zsh_cv_sys_dynamic_execsyms=no]
389 LDFLAGS=$save_ldflags
391 zsh_cv_sys_dynamic_execsyms=no
397 dnl zsh_SYS_DYNAMIC_STRIP_EXE
398 dnl Check whether it is safe to strip executables.
401 AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_EXE,
402 [AC_REQUIRE([zsh_SYS_DYNAMIC_EXECSYMS])
403 AC_CACHE_CHECK([whether executables can be stripped],
404 zsh_cv_sys_dynamic_strip_exe,
405 [if test "$zsh_cv_sys_dynamic_execsyms" != yes; then
406 zsh_cv_sys_dynamic_strip_exe=yes
408 if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
413 echo 'extern int fred(); int barney() { return fred() + 27; }' > conftest1.c
414 AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
415 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC); then
416 save_ldflags=$LDFLAGS
417 LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS -s"
421 #define RTLD_LAZY BIND_DEFERRED
422 #define RTLD_GLOBAL DYNAMIC_PATH
424 char *zsh_gl_sym_addr ;
426 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
427 #define dlclose(handle) shl_unload((shl_t)(handle))
428 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
434 #include <sys/types.h>
443 #define RTLD_GLOBAL 0
450 handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
452 barneysym = (int (*)()) dlsym(handle, "${us}barney");
453 if(!barneysym) exit(1);
454 exit((*barneysym)() != 69);
457 int fred () { return 42; }
458 ], [zsh_cv_sys_dynamic_strip_exe=yes],
459 [zsh_cv_sys_dynamic_strip_exe=no],
460 [zsh_cv_sys_dynamic_strip_exe=no]
462 LDFLAGS=$save_ldflags
464 zsh_cv_sys_dynamic_strip_exe=no
470 dnl zsh_SYS_DYNAMIC_STRIP_EXE
471 dnl Check whether it is safe to strip dynamically loaded libraries.
474 AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_LIB,
475 [AC_CACHE_CHECK([whether libraries can be stripped],
476 zsh_cv_sys_dynamic_strip_lib,
477 [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
482 echo 'int fred () { return 42; }' > conftest1.c
483 if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
484 AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS -s conftest1.o $LIBS 1>&AC_FD_CC); then
488 #define RTLD_LAZY BIND_DEFERRED
489 #define RTLD_GLOBAL DYNAMIC_PATH
491 char *zsh_gl_sym_addr ;
493 #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
494 #define dlclose(handle) shl_unload((shl_t)(handle))
495 #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
501 #include <sys/types.h>
510 #define RTLD_GLOBAL 0
517 handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
519 fredsym = (int (*)()) dlsym(handle, "${us}fred");
520 if(!fredsym) exit(1);
521 exit((*fredsym)() != 42);
523 ], [zsh_cv_sys_dynamic_strip_lib=yes],
524 [zsh_cv_sys_dynamic_strip_lib=no],
525 [zsh_cv_sys_dynamic_strip_lib=no]
528 zsh_cv_sys_dynamic_strip_lib=no
534 dnl zsh_PATH_UTMP(filename)
535 dnl Search for a specified utmp-type file.
538 AC_DEFUN(zsh_PATH_UTMP,
539 [AC_CACHE_CHECK([for $1 file], [zsh_cv_path_$1],
540 [for dir in /etc /usr/etc /var/adm /usr/adm /var/run /var/log ./conftest; do
541 zsh_cv_path_$1=${dir}/$1
542 test -f $zsh_cv_path_$1 && break
546 AH_TEMPLATE([PATH_]translit($1, [a-z], [A-Z])[_FILE],
547 [Define to be location of ]$1[ file.])
548 if test $zsh_cv_path_$1 != no; then
549 AC_DEFINE_UNQUOTED([PATH_]translit($1, [a-z], [A-Z])[_FILE],
555 dnl zsh_TYPE_EXISTS(#includes, type name)
556 dnl Check whether a specified type exists.
559 AC_DEFUN(zsh_TYPE_EXISTS,
560 [AC_CACHE_CHECK([for $2], [zsh_cv_type_exists_[]translit($2, [ ], [_])],
561 [AC_TRY_COMPILE([$1], [$2 testvar;],
562 [zsh_cv_type_exists_[]translit($2, [ ], [_])=yes],
563 [zsh_cv_type_exists_[]translit($2, [ ], [_])=no])
565 AH_TEMPLATE([HAVE_]translit($2, [ a-z], [_A-Z]),
566 [Define to 1 if ]$2[ is defined by a system header])
567 if test $zsh_cv_type_exists_[]translit($2, [ ], [_]) = yes; then
568 AC_DEFINE([HAVE_]translit($2, [ a-z], [_A-Z]))
573 dnl zsh_STRUCT_MEMBER(#includes, type name, member name)
574 dnl Check whether a specified aggregate type exists and contains
575 dnl a specified member.
578 AC_DEFUN(zsh_STRUCT_MEMBER,
579 [AC_CACHE_CHECK([for $3 in $2], [zsh_cv_struct_member_[]translit($2, [ ], [_])_$3],
580 [AC_TRY_COMPILE([$1], [$2 testvar; testvar.$3;],
581 [zsh_cv_struct_member_[]translit($2, [ ], [_])_$3=yes],
582 [zsh_cv_struct_member_[]translit($2, [ ], [_])_$3=no])
584 AH_TEMPLATE([HAVE_]translit($2_$3, [ a-z], [_A-Z]),
585 [Define if your system's ]$2[ has a member named ]$3[.])
586 if test $zsh_cv_struct_member_[]translit($2, [ ], [_])_$3 = yes; then
587 AC_DEFINE([HAVE_]translit($2_$3, [ a-z], [_A-Z]))
593 dnl Handle AC_ARG_PROGRAM substitutions into other zsh configure macros.
594 dnl After processing this macro, the configure script may refer to
595 dnl and $tzsh_name, and @tzsh@ is defined for make substitutions.
598 AC_DEFUN(zsh_ARG_PROGRAM,
600 # Un-double any \ or $ (doubled by AC_ARG_PROGRAM).
601 cat <<\EOF_SED > conftestsed
602 s,\\\\,\\,g; s,\$\$,$,g
604 zsh_transform_name=`echo "${program_transform_name}" | sed -f conftestsed`
606 tzsh_name=`echo zsh | sed -e "${zsh_transform_name}"`
607 # Double any \ or $ in the transformed name that results.
608 cat <<\EOF_SED >> conftestsed
609 s,\\,\\\\,g; s,\$,$$,g
611 tzsh=`echo ${tzsh_name} | sed -f conftestsed`
616 AC_DEFUN(zsh_COMPILE_FLAGS,
617 [AC_ARG_ENABLE(cppflags,
618 AC_HELP_STRING([--enable-cppflags=...], [specify C preprocessor flags]),
619 if test "$enableval" = "yes"
621 else CPPFLAGS="$enable_cppflags"
623 AC_ARG_ENABLE(cflags,
624 AC_HELP_STRING([--enable-cflags=...], [specify C compiler flags]),
625 if test "$enableval" = "yes"
627 else CFLAGS="$enable_cflags"
629 AC_ARG_ENABLE(ldflags,
630 AC_HELP_STRING([--enable-ldflags=...], [specify linker flags]),
631 if test "$enableval" = "yes"
633 else LDFLAGS="$enable_ldflags"
636 AC_HELP_STRING([--enable-libs=...], [specify link libraries]),
637 if test "$enableval" = "yes"
639 else LIBS="$enable_libs"
643 dnl zsh_CHECK_SOCKLEN_T
645 dnl check type of third argument of some network functions; currently
646 dnl tested are size_t *, unsigned long *, int *.
647 dnl call the result ZSOCKLEN_T since some systems have SOCKLEN_T already
649 AC_DEFUN([zsh_CHECK_SOCKLEN_T],[
651 [base type of the third argument to accept],
652 [zsh_cv_type_socklen_t],
653 [zsh_cv_type_socklen_t=
654 for zsh_type in socklen_t int "unsigned long" size_t ; do
656 [#include <sys/types.h>
657 #include <sys/socket.h>],
658 [extern int accept (int, struct sockaddr *, $zsh_type *);],
659 [zsh_cv_type_socklen_t="$zsh_type"; break],
663 if test -z "$zsh_cv_type_socklen_t"; then
664 zsh_cv_type_socklen_t=int
667 AC_DEFINE_UNQUOTED([ZSOCKLEN_T], [$zsh_cv_type_socklen_t],
668 [Define to the base type of the third argument of accept])]
671 dnl Check for limit $1 e.g. RLIMIT_RSS.
672 AC_DEFUN(zsh_LIMIT_PRESENT,
673 [AH_TEMPLATE([HAVE_]$1,
674 [Define to 1 if ]$1[ is present (whether or not as a macro).])
675 AC_CACHE_CHECK([for limit $1],
678 #include <sys/types.h>
679 #ifdef HAVE_SYS_TIME_H
680 #include <sys/time.h>
682 #include <sys/resource.h>],
687 if test $zsh_cv_have_$1 = yes; then