aczsh.m4 19.1 KB
Newer Older
Tanaka Akira's avatar
Tanaka Akira committed
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
dnl
dnl  Autconf tests for zsh.
dnl
dnl  Copyright (c) 1995-1997 Richard Coleman
dnl  All rights reserved.
dnl
dnl  Permission is hereby granted, without written agreement and without
dnl  license or royalty fees, to use, copy, modify, and distribute this
dnl  software and to distribute modified versions of this software for any
dnl  purpose, provided that the above copyright notice and the following
dnl  two paragraphs appear in all copies of this software.
dnl
dnl  In no event shall Richard Coleman or the Zsh Development Group be liable
dnl  to any party for direct, indirect, special, incidental, or consequential
dnl  damages arising out of the use of this software and its documentation,
dnl  even if Richard Coleman and the Zsh Development Group have been advised of
dnl  the possibility of such damage.
dnl
dnl  Richard Coleman and the Zsh Development Group specifically disclaim any
dnl  warranties, including, but not limited to, the implied warranties of
dnl  merchantability and fitness for a particular purpose.  The software
dnl  provided hereunder is on an "as is" basis, and Richard Coleman and the
dnl  Zsh Development Group have no obligation to provide maintenance,
dnl  support, updates, enhancements, or modifications.
dnl

27 28 29 30 31 32 33 34 35
dnl
dnl zsh_64_BIT_TYPE
dnl   Check whether the first argument works as a 64-bit type.
dnl   If there is a non-zero third argument, we just assume it works
dnl   when we're cross compiling.  This is to allow a type to be
dnl   specified directly as --enable-lfs="long long".
dnl   Sets the variable given in the second argument to the first argument
dnl   if the test worked, `no' otherwise.  Be careful testing this, as it
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 38 39 40 41 42 43 44 45 46 47 48 49
dnl   This macro does not produce messages as it may be run several times
dnl   before finding the right type.
dnl

AC_DEFUN(zsh_64_BIT_TYPE,
[AC_TRY_RUN([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

main()
{
  $1 foo = 0; 
50
  int bar = (int) foo;
51 52 53 54 55 56 57 58 59 60 61
  return sizeof($1) != 8;
}
], $2="$1", $2=no,
  [if test x$3 != x ; then
    $2="$1"
  else
    $2=no
  fi])
])


Tanaka Akira's avatar
Tanaka Akira committed
62
dnl
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
dnl zsh_SHARED_FUNCTION
dnl
dnl This is just a frontend to zsh_SHARED_SYMBOL
dnl
dnl Usage: zsh_SHARED_FUNCTION(name[,rettype[,paramtype]])
dnl

AC_DEFUN(zsh_SHARED_FUNCTION,
[zsh_SHARED_SYMBOL($1, ifelse([$2], ,[int ],[$2]) $1 [(]ifelse([$3], ,[ ],[$3])[)], $1)])

dnl
dnl zsh_SHARED_VARIABLE
dnl
dnl This is just a frontend to zsh_SHARED_SYMBOL
dnl
dnl Usage: zsh_SHARED_VARIABLE(name[,type])
dnl

AC_DEFUN(zsh_SHARED_VARIABLE,
[zsh_SHARED_SYMBOL($1, ifelse([$2], ,[int ],[$2]) $1, [&$1])])

dnl
dnl zsh_SHARED_SYMBOL
dnl   Check whether symbol is available in static or shared library
Tanaka Akira's avatar
Tanaka Akira committed
87 88 89 90 91
dnl
dnl   On some systems, static modifiable library symbols (such as environ)
dnl   may appear only in statically linked libraries.  If this is the case,
dnl   then two shared libraries that reference the same symbol, each linked
dnl   with the static library, could be given distinct copies of the symbol.
92 93 94
dnl
dnl Usage: zsh_SHARED_SYMBOL(name,declaration,address)
dnl Sets zsh_cv_shared_$1 cache variable to yes/no
Tanaka Akira's avatar
Tanaka Akira committed
95 96
dnl

97 98 99
AC_DEFUN(zsh_SHARED_SYMBOL,
[AC_CACHE_CHECK([if $1 is available in shared libraries],
zsh_cv_shared_$1,
Tanaka Akira's avatar
Tanaka Akira committed
100 101 102 103 104 105
[if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
    us=_
else
    us=
fi
echo '
106 107 108 109 110 111 112 113
void *zsh_getaddr1()
{
#ifdef __CYGWIN__
	__attribute__((__dllimport__))	
#endif
	extern $2;
	return $3;
};
Tanaka Akira's avatar
Tanaka Akira committed
114
' > conftest1.c
115
sed 's/zsh_getaddr1/zsh_getaddr2/' < conftest1.c > conftest2.c
116 117 118 119
if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
120
    AC_TRY_RUN([
121
#ifdef HPUX10DYNAMIC
122 123 124 125 126 127 128 129 130 131 132
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
133 134 135 136 137 138 139
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
140
#endif
Tanaka Akira's avatar
Tanaka Akira committed
141 142 143 144 145 146 147 148 149 150
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

main()
{
    void *handle1, *handle2;
151 152
    void *(*zsh_getaddr1)(), *(*zsh_getaddr2)();
    void *sym1, *sym2;
Tanaka Akira's avatar
Tanaka Akira committed
153 154 155 156
    handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle1) exit(1);
    handle2 = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle2) exit(1);
157 158 159 160 161 162 163 164 165 166 167 168 169
    zsh_getaddr1 = (void *(*)()) dlsym(handle1, "${us}zsh_getaddr1");
    zsh_getaddr2 = (void *(*)()) dlsym(handle2, "${us}zsh_getaddr2");
    sym1 = zsh_getaddr1();
    sym2 = zsh_getaddr2();
    if(!sym1 || !sym2) exit(1);
    if(sym1 != sym2) exit(1);
    dlclose(handle1);
    handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle1) exit(1);
    zsh_getaddr1 = (void *(*)()) dlsym(handle1, "${us}zsh_getaddr1");
    sym1 = zsh_getaddr1();
    if(!sym1) exit(1);
    if(sym1 != sym2) exit(1);
Tanaka Akira's avatar
Tanaka Akira committed
170 171
    exit(0);
}
172 173 174
], [zsh_cv_shared_$1=yes],
[zsh_cv_shared_$1=no],
[zsh_cv_shared_$1=no]
Tanaka Akira's avatar
Tanaka Akira committed
175 176
)
else
177
    zsh_cv_shared_$1=no
Tanaka Akira's avatar
Tanaka Akira committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
fi
])
])

dnl
dnl zsh_SYS_DYNAMIC_CLASH
dnl   Check whether symbol name clashes in shared libraries are acceptable.
dnl

AC_DEFUN(zsh_SYS_DYNAMIC_CLASH,
[AC_CACHE_CHECK([if name clashes in shared objects are OK],
zsh_cv_sys_dynamic_clash_ok,
[if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
    us=_
else
    us=
fi
echo 'int fred () { return 42; }' > conftest1.c
echo 'int fred () { return 69; }' > conftest2.c
197 198 199 200
if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
201
    AC_TRY_RUN([
202
#ifdef HPUX10DYNAMIC
203 204 205 206 207 208 209 210 211 212 213
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
214 215 216 217 218 219 220
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
221
#endif
Tanaka Akira's avatar
Tanaka Akira committed
222 223 224 225 226 227 228
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

229

Tanaka Akira's avatar
Tanaka Akira committed
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
main()
{
    void *handle1, *handle2;
    int (*fred1)(), (*fred2)();
    handle1 = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle1) exit(1);
    handle2 = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle2) exit(1);
    fred1 = (int (*)()) dlsym(handle1, "${us}fred");
    fred2 = (int (*)()) dlsym(handle2, "${us}fred");
    if(!fred1 || !fred2) exit(1);
    exit((*fred1)() != 42 || (*fred2)() != 69);
}
], [zsh_cv_sys_dynamic_clash_ok=yes],
[zsh_cv_sys_dynamic_clash_ok=no],
[zsh_cv_sys_dynamic_clash_ok=no]
)
else
    zsh_cv_sys_dynamic_clash_ok=no
fi
])
if test "$zsh_cv_sys_dynamic_clash_ok" = yes; then
    AC_DEFINE(DYNAMIC_NAME_CLASH_OK)
fi
])

dnl
dnl zsh_SYS_DYNAMIC_GLOBAL
dnl   Check whether symbols in one dynamically loaded library are
dnl   available to another dynamically loaded library.
dnl

AC_DEFUN(zsh_SYS_DYNAMIC_GLOBAL,
[AC_CACHE_CHECK([for working RTLD_GLOBAL],
zsh_cv_sys_dynamic_rtld_global,
[if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
    us=_
else
    us=
fi
echo 'int fred () { return 42; }' > conftest1.c
echo 'extern int fred(); int barney () { return fred() + 27; }' > conftest2.c
272 273 274 275
if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC) &&
AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
276
    AC_TRY_RUN([
277
#ifdef HPUX10DYNAMIC
278 279 280 281 282 283 284 285 286 287 288
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
289 290 291 292 293 294 295
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
296
#endif
Tanaka Akira's avatar
Tanaka Akira committed
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
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

main()
{
    void *handle;
    int (*barneysym)();
    handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle) exit(1);
    handle = dlopen("./conftest2.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle) exit(1);
    barneysym = (int (*)()) dlsym(handle, "${us}barney");
    if(!barneysym) exit(1);
    exit((*barneysym)() != 69);
}
], [zsh_cv_sys_dynamic_rtld_global=yes],
[zsh_cv_sys_dynamic_rtld_global=no],
[zsh_cv_sys_dynamic_rtld_global=no]
)
else
    zsh_cv_sys_dynamic_rtld_global=no
fi
])
])

dnl
dnl zsh_SYS_DYNAMIC_EXECSYMS
dnl   Check whether symbols in the executable are available to dynamically
dnl   loaded libraries.
dnl

AC_DEFUN(zsh_SYS_DYNAMIC_EXECSYMS,
[AC_CACHE_CHECK([whether symbols in the executable are available],
zsh_cv_sys_dynamic_execsyms,
[if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
    us=_
else
    us=
fi
echo 'extern int fred(); int barney () { return fred() + 27; }' > conftest1.c
341 342
if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
343 344 345
    save_ldflags=$LDFLAGS
    LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS"
    AC_TRY_RUN([
346
#ifdef HPUX10DYNAMIC
347 348 349 350 351 352 353 354 355 356 357
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
358 359 360 361 362 363 364
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
365
#endif
Tanaka Akira's avatar
Tanaka Akira committed
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
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

main()
{
    void *handle;
    int (*barneysym)();
    handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle) exit(1);
    barneysym = (int (*)()) dlsym(handle, "${us}barney");
    if(!barneysym) exit(1);
    exit((*barneysym)() != 69);
}

int fred () { return 42; }
], [zsh_cv_sys_dynamic_execsyms=yes],
[zsh_cv_sys_dynamic_execsyms=no],
[zsh_cv_sys_dynamic_execsyms=no]
)
    LDFLAGS=$save_ldflags
else
    zsh_cv_sys_dynamic_execsyms=no
fi
])
])

dnl
dnl zsh_SYS_DYNAMIC_STRIP_EXE
dnl   Check whether it is safe to strip executables.
dnl

AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_EXE,
[AC_REQUIRE([zsh_SYS_DYNAMIC_EXECSYMS])
AC_CACHE_CHECK([whether executables can be stripped],
zsh_cv_sys_dynamic_strip_exe,
[if test "$zsh_cv_sys_dynamic_execsyms" != yes; then
    zsh_cv_sys_dynamic_strip_exe=yes
elif
    if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
	us=_
    else
	us=
    fi
    echo 'extern int fred(); int barney() { return fred() + 27; }' > conftest1.c
414 415
    AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
    AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
416 417 418
    save_ldflags=$LDFLAGS
    LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS -s"
    AC_TRY_RUN([
419
#ifdef HPUX10DYNAMIC
420 421 422 423 424 425 426 427 428 429 430
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
431 432 433 434 435 436 437
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
438
#endif
Tanaka Akira's avatar
Tanaka Akira committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

main()
{
    void *handle;
    int (*barneysym)();
    handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle) exit(1);
    barneysym = (int (*)()) dlsym(handle, "${us}barney");
    if(!barneysym) exit(1);
    exit((*barneysym)() != 69);
}

int fred () { return 42; }
], [zsh_cv_sys_dynamic_strip_exe=yes],
[zsh_cv_sys_dynamic_strip_exe=no],
[zsh_cv_sys_dynamic_strip_exe=no]
)
    LDFLAGS=$save_ldflags
else
    zsh_cv_sys_dynamic_strip_exe=no
fi
])
])

dnl
dnl zsh_SYS_DYNAMIC_STRIP_EXE
dnl   Check whether it is safe to strip dynamically loaded libraries.
dnl

AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_LIB,
[AC_CACHE_CHECK([whether libraries can be stripped],
zsh_cv_sys_dynamic_strip_lib,
[if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
    us=_
else
    us=
fi
echo 'int fred () { return 42; }' > conftest1.c
483 484
if AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&AC_FD_CC) &&
AC_TRY_COMMAND($DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS -s conftest1.o $LIBS 1>&AC_FD_CC); then
Tanaka Akira's avatar
Tanaka Akira committed
485
    AC_TRY_RUN([
486
#ifdef HPUX10DYNAMIC
487 488 489 490 491 492 493 494 495 496 497
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#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)
#define dlerror() 0
#else
Tanaka Akira's avatar
Tanaka Akira committed
498 499 500 501 502 503 504
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
505
#endif
Tanaka Akira's avatar
Tanaka Akira committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

main()
{
    void *handle;
    int (*fredsym)();
    handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
    if(!handle) exit(1);
    fredsym = (int (*)()) dlsym(handle, "${us}fred");
    if(!fredsym) exit(1);
    exit((*fredsym)() != 42);
}
], [zsh_cv_sys_dynamic_strip_lib=yes],
[zsh_cv_sys_dynamic_strip_lib=no],
[zsh_cv_sys_dynamic_strip_lib=no]
)
else
    zsh_cv_sys_dynamic_strip_lib=no
fi
])
])

dnl
dnl zsh_PATH_UTMP(filename)
dnl   Search for a specified utmp-type file.
dnl

AC_DEFUN(zsh_PATH_UTMP,
[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
Tanaka Akira's avatar
Tanaka Akira committed
541 542 543 544 545
  zsh_cv_path_$1=${dir}/$1
  test -f $zsh_cv_path_$1 && break
  zsh_cv_path_$1=no
done
])
546 547
AH_TEMPLATE([PATH_]translit($1, [a-z], [A-Z])[_FILE],
[Define to be location of ]$1[ file.])
Tanaka Akira's avatar
Tanaka Akira committed
548
if test $zsh_cv_path_$1 != no; then
549 550
  AC_DEFINE_UNQUOTED([PATH_]translit($1, [a-z], [A-Z])[_FILE],
  "$zsh_cv_path_$1")
Tanaka Akira's avatar
Tanaka Akira committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564
fi
])

dnl
dnl zsh_TYPE_EXISTS(#includes, type name)
dnl   Check whether a specified type exists.
dnl

AC_DEFUN(zsh_TYPE_EXISTS,
[AC_CACHE_CHECK([for $2], [zsh_cv_type_exists_[]translit($2, [ ], [_])],
[AC_TRY_COMPILE([$1], [$2 testvar;],
[zsh_cv_type_exists_[]translit($2, [ ], [_])=yes],
[zsh_cv_type_exists_[]translit($2, [ ], [_])=no])
])
565 566
AH_TEMPLATE([HAVE_]translit($2, [ a-z], [_A-Z]),
[Define to 1 if ]$2[ is defined by a system header])
Tanaka Akira's avatar
Tanaka Akira committed
567
if test $zsh_cv_type_exists_[]translit($2, [ ], [_]) = yes; then
568
  AC_DEFINE([HAVE_]translit($2, [ a-z], [_A-Z]))
Tanaka Akira's avatar
Tanaka Akira committed
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
fi
])

dnl
dnl zsh_STRUCT_MEMBER(#includes, type name, member name)
dnl   Check whether a specified aggregate type exists and contains
dnl   a specified member.
dnl

AC_DEFUN(zsh_STRUCT_MEMBER,
[AC_CACHE_CHECK([for $3 in $2], [zsh_cv_struct_member_[]translit($2, [ ], [_])_$3],
[AC_TRY_COMPILE([$1], [$2 testvar; testvar.$3;],
[zsh_cv_struct_member_[]translit($2, [ ], [_])_$3=yes],
[zsh_cv_struct_member_[]translit($2, [ ], [_])_$3=no])
])
584 585
AH_TEMPLATE([HAVE_]translit($2_$3, [ a-z], [_A-Z]),
[Define if your system's ]$2[ has a member named ]$3[.])
Tanaka Akira's avatar
Tanaka Akira committed
586
if test $zsh_cv_struct_member_[]translit($2, [ ], [_])_$3 = yes; then
587
  AC_DEFINE([HAVE_]translit($2_$3, [ a-z], [_A-Z]))
Tanaka Akira's avatar
Tanaka Akira committed
588 589
fi
])
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617

dnl
dnl zsh_ARG_PROGRAM
dnl   Handle AC_ARG_PROGRAM substitutions into other zsh configure macros.
dnl   After processing this macro, the configure script may refer to
dnl   and $tzsh_name, and @tzsh@ is defined for make substitutions.
dnl

AC_DEFUN(zsh_ARG_PROGRAM,
[AC_ARG_PROGRAM
# Un-double any \ or $ (doubled by AC_ARG_PROGRAM).
cat <<\EOF_SED > conftestsed
s,\\\\,\\,g; s,\$\$,$,g
EOF_SED
zsh_transform_name=`echo "${program_transform_name}" | sed -f conftestsed`
rm -f conftestsed
tzsh_name=`echo zsh | sed -e "${zsh_transform_name}"`
# Double any \ or $ in the transformed name that results.
cat <<\EOF_SED >> conftestsed
s,\\,\\\\,g; s,\$,$$,g
EOF_SED
tzsh=`echo ${tzsh_name} | sed -f conftestsed`
rm -f conftestsed
AC_SUBST(tzsh)dnl
])

AC_DEFUN(zsh_COMPILE_FLAGS,
    [AC_ARG_ENABLE(cppflags,
618
	AC_HELP_STRING([--enable-cppflags=...], [specify C preprocessor flags]),
619 620 621 622 623
	if test "$enableval" = "yes"
	then CPPFLAGS="$1"
	else CPPFLAGS="$enable_cppflags"
	fi)
    AC_ARG_ENABLE(cflags,
624
	AC_HELP_STRING([--enable-cflags=...], [specify C compiler flags]),
625
	if test "$enableval" = "yes"
626
	then CFLAGS="$2"
627 628 629
	else CFLAGS="$enable_cflags"
	fi)
    AC_ARG_ENABLE(ldflags,
630
	AC_HELP_STRING([--enable-ldflags=...], [specify linker flags]),
631
	if test "$enableval" = "yes"
632
	then LDFLAGS="$3"
633 634 635
	else LDFLAGS="$enable_ldflags"
	fi)
    AC_ARG_ENABLE(libs,
636
	AC_HELP_STRING([--enable-libs=...], [specify link libraries]),
637
	if test "$enableval" = "yes"
638
	then LIBS="$4"
639 640
	else LIBS="$enable_libs"
	fi)])
641 642 643 644 645 646

dnl 
dnl zsh_CHECK_SOCKLEN_T
dnl
dnl	check type of third argument of some network functions; currently
dnl	tested are size_t *, unsigned long *, int *.
647
dnl     call the result ZSOCKLEN_T since some systems have SOCKLEN_T already
648 649 650 651 652 653
dnl
AC_DEFUN([zsh_CHECK_SOCKLEN_T],[
  AC_CACHE_CHECK(
    [base type of the third argument to accept],
    [zsh_cv_type_socklen_t],
    [zsh_cv_type_socklen_t=
654
    for zsh_type in socklen_t int "unsigned long" size_t ; do
655 656 657 658 659 660 661 662 663 664 665 666
      AC_TRY_COMPILE(
        [#include <sys/types.h>
         #include <sys/socket.h>],
        [extern int accept (int, struct sockaddr *, $zsh_type *);],
        [zsh_cv_type_socklen_t="$zsh_type"; break],
        []
      )
    done
    if test -z "$zsh_cv_type_socklen_t"; then
      zsh_cv_type_socklen_t=int
    fi]
  )
667
  AC_DEFINE_UNQUOTED([ZSOCKLEN_T], [$zsh_cv_type_socklen_t],
668
  [Define to the base type of the third argument of accept])]
669 670
)

671 672
dnl Check for limit $1 e.g. RLIMIT_RSS.
AC_DEFUN(zsh_LIMIT_PRESENT,
673 674 675
[AH_TEMPLATE([HAVE_]$1,
[Define to 1 if ]$1[ is present (whether or not as a macro).])
AC_CACHE_CHECK([for limit $1],
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
zsh_cv_have_$1,
[AC_TRY_COMPILE([
#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>],
[$1],
  zsh_cv_have_$1=yes,
  zsh_cv_have_$1=no)])

if test $zsh_cv_have_$1 = yes; then
  AC_DEFINE(HAVE_$1)
fi])