home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-2.LHA / CLISP960530-ki.lha / ffcall / autoconf / aclocal.m4 < prev    next >
Encoding:
M4 Source File  |  1996-04-19  |  30.8 KB  |  1,113 lines

  1. dnl local autoconf macros
  2. dnl Bruno Haible 17.6.1995
  3. dnl Marcus Daniels 31.10.1994
  4. dnl
  5. dnl without AC_MSG_...:   with AC_MSG_... and caching:
  6. dnl   AC_TRY_CPP          CL_CPP_CHECK
  7. dnl   AC_TRY_COMPILE      CL_COMPILE_CHECK
  8. dnl   AC_TRY_LINK         CL_LINK_CHECK
  9. dnl   AC_TRY_RUN          CL_RUN_CHECK - would require cross-compiling support
  10. dnl Usage:
  11. dnl AC_TRY_CPP(INCLUDES,
  12. dnl            ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
  13. dnl CL_CPP_CHECK(ECHO-TEXT, CACHE-ID,
  14. dnl              INCLUDES,
  15. dnl              ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
  16. dnl AC_TRY_xxx(INCLUDES, FUNCTION-BODY,
  17. dnl            ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
  18. dnl CL_xxx_CHECK(ECHO-TEXT, CACHE-ID,
  19. dnl              INCLUDES, FUNCTION-BODY,
  20. dnl              ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
  21. dnl
  22. define(CL_CPP_CHECK,
  23. [AC_CACHE_CHECK([for $1],$2,
  24. [AC_TRY_CPP([$3], $2=yes, $2=no)
  25. ])
  26. if test [$]$2 = yes; then
  27.   ifelse([$4], , :, [$4])
  28. ifelse([$5], , , [else
  29.   $5
  30. ])dnl
  31. fi
  32. ])dnl
  33. dnl
  34. define(CL_COMPILE_CHECK,
  35. [AC_CACHE_CHECK([for $1],$2,
  36. [AC_TRY_COMPILE([$3],[$4], $2=yes, $2=no)
  37. ])
  38. if test [$]$2 = yes; then
  39.   ifelse([$5], , :, [$5])
  40. ifelse([$6], , , [else
  41.   $6
  42. ])dnl
  43. fi
  44. ])dnl
  45. dnl
  46. define(CL_LINK_CHECK,
  47. [AC_CACHE_CHECK([for $1],$2,
  48. [AC_TRY_LINK([$3],[$4], $2=yes, $2=no)
  49. ])
  50. if test [$]$2 = yes; then
  51.   ifelse([$5], , :, [$5])
  52. ifelse([$6], , , [else
  53.   $6
  54. ])dnl
  55. fi
  56. ])dnl
  57. dnl
  58. dnl Expands to the "extern ..." prefix used for system declarations.
  59. dnl CL_LANG_EXTERN()
  60. define(CL_LANG_EXTERN,
  61. [extern[]dnl
  62. ifelse(AC_LANG, CPLUSPLUS, [
  63. #ifdef __cplusplus
  64. "C"
  65. #endif
  66. ], [ ])dnl
  67. ])
  68. dnl
  69. dnl CL_MSG_RESULTPROTO(RESULT-PROTOTYPE-DESCRIPTION)
  70. define(CL_MSG_RESULTPROTO,
  71. [AC_MSG_RESULT(${ac_t}[$1])
  72. ])dnl
  73. dnl
  74. dnl CL_PROTO(IDENTIFIER, ACTION-IF-NOT-FOUND, FINAL-PROTOTYPE)
  75. define(CL_PROTO,
  76. [AC_MSG_CHECKING([for $1 declaration])
  77. AC_CACHE_VAL(cl_cv_proto_[$1], $2[
  78. cl_cv_proto_$1="$3"])
  79. cl_cv_proto_$1=`echo "[$]cl_cv_proto_$1" | tr -s ' ' | sed -e 's/( /(/'`
  80. CL_MSG_RESULTPROTO([$]cl_cv_proto_$1)
  81. ])dnl
  82. dnl
  83. dnl CL_PROTO_RET(INCLUDES, DECL, CACHE-ID, TYPE-IF-OK, TYPE-IF-FAILS)
  84. define(CL_PROTO_RET,
  85. [AC_TRY_COMPILE([$1]
  86. CL_LANG_EXTERN[$2
  87. ], [], $3="$4", $3="$5")
  88. ])dnl
  89. dnl
  90. dnl CL_PROTO_TRY(INCLUDES, ANSI-DECL, TRAD-DECL, ACTION-IF-OK, ACTION-IF-FAILS)
  91. define(CL_PROTO_TRY,
  92. [AC_TRY_COMPILE([$1]
  93. CL_LANG_EXTERN
  94. [#ifdef __STDC__
  95. $2
  96. #else
  97. $3
  98. #endif
  99. ], [], $4, $5)
  100. ])dnl
  101. dnl
  102. dnl CL_PROTO_CONST(INCLUDES, ANSI-DECL, TRAD-DECL, CACHE-ID)
  103. define(CL_PROTO_CONST,
  104. [CL_PROTO_TRY([$1], [$2], [$3], $4="", $4="const")]
  105. )dnl
  106. dnl
  107. dnl CL_SILENT(ACTION)
  108. dnl performs ACTION, with AC_MSG_CHECKING and AC_MSG_RESULT being defined away.
  109. define(CL_SILENT,
  110. [pushdef([AC_MSG_CHECKING],[:])dnl
  111. pushdef([AC_CHECKING],[:])dnl
  112. pushdef([AC_MSG_RESULT],[:])dnl
  113. pushdef([CL_MSG_RESULTPROTO],[:])dnl
  114. $1[]dnl
  115. popdef([CL_MSG_RESULTPROTO])dnl
  116. popdef([AC_MSG_RESULT])dnl
  117. popdef([AC_CHECKING])dnl
  118. popdef([AC_MSG_CHECKING])dnl
  119. ])dnl
  120. dnl
  121. AC_DEFUN(CL_AS_UNDERSCORE,
  122. [AC_CACHE_CHECK([for underscore in external names],cl_cv_prog_as_underscore,
  123. [cat > conftest.c <<EOF
  124. int foo() { return 0; }
  125. EOF
  126. ${CC-cc} -c conftest.c >/dev/null 2>&1
  127. # check whether nm exists
  128. if (nm conftest.o) >/dev/null 2>&1 ; then
  129.   # use nm to see the assembly language name
  130.   if nm conftest.o | grep _foo >/dev/null 2>&1 ; then
  131.     cl_cv_prog_as_underscore=yes
  132.   else
  133.     cl_cv_prog_as_underscore=no
  134.   fi
  135. else
  136.   # look for the assembly language name in the .s file
  137.   ${CC-cc} -S conftest.c >/dev/null 2>&1
  138.   if grep _foo conftest.s >/dev/null ; then
  139.     cl_cv_prog_as_underscore=yes
  140.   else
  141.     cl_cv_prog_as_underscore=no
  142.   fi
  143. fi
  144. rm -f conftest*
  145. ])
  146. if test $cl_cv_prog_as_underscore = yes; then
  147.   AS_UNDERSCORE=true
  148. else
  149.   AS_UNDERSCORE=false
  150. fi
  151. AC_SUBST(AS_UNDERSCORE)dnl
  152. ])dnl
  153. dnl
  154. AC_DEFUN(CL_PROG_RANLIB, [AC_CHECK_PROG(RANLIB, ranlib, ranlib, true)])dnl
  155. dnl
  156. AC_DEFUN(CL_PROG_INSTALL,
  157. [dnl This is mostly copied from AC_PROG_INSTALL.
  158. # Find a good install program.  We prefer a C program (faster),
  159. # so one script is as good as another.  But avoid the broken or
  160. # incompatible versions:
  161. # SysV /etc/install, /usr/sbin/install
  162. # SunOS /usr/etc/install
  163. # IRIX /sbin/install
  164. # AIX /bin/install
  165. # AFS /usr/afsws/bin/install, which mishandles nonexistent args
  166. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
  167. # ./install, which can be erroneously created by make from ./install.sh.
  168. AC_MSG_CHECKING(for a BSD compatible install)
  169. if test -z "$INSTALL"; then
  170. AC_CACHE_VAL(cl_cv_path_install,
  171. [  IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  172.   for ac_dir in $PATH; do
  173.     case "$ac_dir" in
  174.     ''|.|/etc|/usr/sbin|/usr/etc|/sbin|/usr/afsws/bin|/usr/ucb) ;;
  175.     *)
  176.       # OSF1 and SCO ODT 3.0 have their own names for install.
  177.       for ac_prog in ginstall installbsd scoinst install; do
  178.         if test -f $ac_dir/$ac_prog; then
  179.       if test $ac_prog = install &&
  180.             grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
  181.         # AIX install.  It has an incompatible calling convention.
  182.         # OSF/1 installbsd also uses dspmsg, but is usable.
  183.         :
  184.       else
  185.         cl_cv_path_install="$ac_dir/$ac_prog -c"
  186.         break 2
  187.       fi
  188.     fi
  189.       done
  190.       ;;
  191.     esac
  192.   done
  193.   IFS="$ac_save_ifs"
  194.   # As a last resort, use cp.
  195.   test -z "$cl_cv_path_install" && cl_cv_path_install="cp"
  196. ])dnl
  197.   INSTALL="$cl_cv_path_install"
  198. fi
  199. dnl We do special magic for INSTALL instead of AC_SUBST, to get
  200. dnl relative paths right. 
  201. AC_MSG_RESULT($INSTALL)
  202. AC_SUBST(INSTALL)dnl
  203. # Use test -z because SunOS4 sh mishandles braces in ${var-val}.
  204. # It thinks the first close brace ends the variable substitution.
  205. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='$(INSTALL)'
  206. AC_SUBST(INSTALL_PROGRAM)dnl
  207. if test -z "$INSTALL_DATA"; then
  208.   case "$INSTALL" in
  209.     cp | */cp ) INSTALL_DATA='$(INSTALL)' ;;
  210.     * )         INSTALL_DATA='$(INSTALL) -m 644' ;;
  211.   esac
  212. fi
  213. AC_SUBST(INSTALL_DATA)dnl
  214. ])dnl
  215. dnl
  216. AC_DEFUN(CL_CANONICAL_HOST,
  217. [AC_REQUIRE([AC_PROG_CC]) dnl Actually: AC_REQUIRE([CL_CC_WORKS])
  218. dnl A substitute for AC_CONFIG_AUX_DIR_DEFAULT, so we don't need install.sh.
  219. AC_CACHE_CHECK([host system type],cl_cv_host,
  220. [ac_aux_dir=${srcdir}/$1
  221. ac_config_guess=$ac_aux_dir/config.guess
  222. ac_config_sub=$ac_aux_dir/config.sub
  223. dnl Mostly copied from AC_CANONICAL_HOST.
  224. # Make sure we can run config.sub.
  225. if $ac_config_sub sun4 >/dev/null 2>&1; then :
  226. else AC_MSG_ERROR(can not run $ac_config_sub)
  227. fi
  228. host_alias=$host
  229. case "$host_alias" in
  230. NONE)
  231.   case $nonopt in
  232.   NONE) dnl config.guess needs to compile things
  233.         host_alias=`export CC; $ac_config_guess` ;;
  234.   *)    host_alias=$nonopt ;;
  235.   esac ;;
  236. esac
  237. # Don't fail just because the system is not listed in GNU's database.
  238. if test -n "$host_alias"; then
  239.   host=`$ac_config_sub $host_alias`
  240. else
  241.   host=unknown-unknown-unknown
  242. fi
  243. if test -z "$host" ; then
  244.   host="$host_alias"
  245. fi
  246. cl_cv_host="$host"
  247. ])
  248. host="$cl_cv_host"
  249. host_cpu=`echo $host | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\1/'`
  250. host_vendor=`echo $host | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\2/'`
  251. host_os=`echo $host | sed 's/^\(.*\)-\(.*\)-\(.*\)$/\3/'`
  252. AC_SUBST(host)dnl
  253. AC_SUBST(host_cpu)dnl
  254. AC_SUBST(host_vendor)dnl
  255. AC_SUBST(host_os)dnl
  256. ])dnl
  257. dnl
  258. AC_DEFUN(CL_CANONICAL_HOST_CPU,
  259. [AC_REQUIRE([CL_CANONICAL_HOST])
  260. if test "$host_cpu" = i486 -o "$host_cpu" = i586; then
  261.   host_cpu=i386
  262. fi
  263. if test "$host_cpu" = hppa1.0 -o "$host_cpu" = hppa1.1; then
  264.   host_cpu=hppa
  265. fi
  266. if test "$host_cpu" = c1 -o "$host_cpu" = c2 -o "$host_cpu" = c32 -o "$host_cpu" = c34 -o "$host_cpu" = c38 -o "$host_cpu" = c4; then
  267.   host_cpu=convex
  268. fi
  269. ])dnl
  270. dnl
  271. AC_DEFUN(CL_VOID,
  272. [CL_COMPILE_CHECK([working void], cl_cv_c_void, ,
  273. [void f();
  274. typedef void x; x g();
  275. typedef void* y; y a;
  276. ], have_void=1, AC_DEFINE(void,char))dnl
  277. if test -n "$have_void"; then
  278. CL_COMPILE_CHECK([working \"return void\"], cl_cv_c_return_void,
  279. [void f() {} typedef void x; x g() { return f(); }], [],
  280. AC_DEFINE(return_void,[return]))dnl
  281. fi
  282. ])dnl
  283. dnl
  284. AC_DEFUN(CL_PCC_STRUCT_RETURN,
  285. [AC_CACHE_CHECK([for pcc non-reentrant struct return convention],cl_cv_c_struct_return_static,
  286. [AC_TRY_RUN([typedef struct { int a; int b; int c; int d; int e; } foo;
  287. foo foofun () { static foo foopi = {3141,5926,5358,9793,2385}; return foopi; }
  288. foo* (*fun) () = (foo* (*) ()) foofun;
  289. main()
  290. { foo foo1;
  291.   foo* fooptr1;
  292.   foo foo2;
  293.   foo* fooptr2;
  294.   foo1 = foofun(); fooptr1 = (*fun)(&foo1);
  295.   foo2 = foofun(); fooptr2 = (*fun)(&foo2);
  296.   exit(!(fooptr1 == fooptr2 && fooptr1->c == 5358));
  297. }], cl_cv_c_struct_return_static=yes, rm -f core
  298. cl_cv_c_struct_return_static=no,
  299. dnl When cross-compiling, don't assume anything.
  300. dnl There are even weirder return value passing conventions than pcc.
  301. cl_cv_c_struct_return_static="guessing no")
  302. ])
  303. case "$cl_cv_c_struct_return_static" in
  304.   *yes) AC_DEFINE(__PCC_STRUCT_RETURN__) ;;
  305.   *no) ;;
  306. esac
  307. ])dnl
  308. dnl
  309. AC_DEFUN(CL_SMALL_STRUCT_RETURN,
  310. [AC_CACHE_CHECK([whether small structs are returned in registers],cl_cv_c_struct_return_small,
  311. [AC_TRY_RUN([typedef struct { int x; } foo; int y;
  312. foo foofun () { foo f; f.x = y; return f; }
  313. int (*fun) () = (int (*) ()) foofun;
  314. main()
  315. { y = 37; if ((*fun)() != 37) exit(1);
  316.   y = 55; if ((*fun)() != 55) exit(1);
  317.   exit(0);
  318. }], cl_cv_c_struct_return_small=yes, rm -f core
  319. cl_cv_c_struct_return_small=no,
  320. dnl When cross-compiling, don't assume anything.
  321. dnl There are even weirder return value passing conventions than pcc.
  322. cl_cv_c_struct_return_small="guessing no")
  323. ])
  324. case "$cl_cv_c_struct_return_small" in
  325.   *yes) AC_DEFINE(__SMALL_STRUCT_RETURN__) ;;
  326.   *no) ;;
  327. esac
  328. ])dnl
  329. dnl
  330. AC_DEFUN(CL_STDC_HEADERS,
  331. dnl This is AC_STDC_HEADERS from Autoconf 1.2. The AC_STDC_HEADERS from
  332. dnl Autoconf 1.3 fails on 386BSD because it checks for correct ANSI ctype
  333. dnl macros and 386BSD (as well as SGI's /bin/cc from Irix-4.0.5) doesn't
  334. dnl have them. But we don't need them!
  335. dnl The same holds for the mem* functions in <string.h> and SunOS.
  336. [CL_CPP_CHECK([ANSI C header files], cl_cv_header_stdc,
  337. [#include <stdlib.h>
  338. #include <stdarg.h>
  339. #include <string.h>
  340. #include <float.h>
  341. #include <limits.h>], AC_DEFINE(STDC_HEADERS))
  342. ])dnl
  343. dnl
  344. AC_DEFUN(CL_STDLIB_H,
  345. [AC_BEFORE([$0], [CL_ABORT])
  346. AC_CHECK_HEADERS(stdlib.h)]
  347. )dnl
  348. dnl
  349. AC_DEFUN(CL_UNISTD_H,
  350. [AC_CHECK_HEADERS(unistd.h)]
  351. )dnl
  352. dnl
  353. AC_DEFUN(CL_OPENFLAGS,
  354. dnl BSD systems require #include <sys/file.h> for O_RDWR etc. being defined.
  355. [AC_BEFORE([$0], [CL_MMAP])
  356. AC_CHECK_HEADERS(sys/file.h)
  357. if test $ac_cv_header_sys_file_h = yes; then
  358. openflags_decl='#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  359. #include <stdlib.h>
  360. #endif
  361. #ifdef HAVE_UNISTD_H
  362. #include <sys/types.h>
  363. #include <unistd.h>
  364. #endif
  365. #include <fcntl.h>
  366. '
  367. openflags_prog='int x = O_RDWR | O_RDONLY | O_WRONLY | O_CREAT | O_TRUNC;'
  368. CL_COMPILE_CHECK([O_RDWR in fcntl.h], cl_cv_decl_O_RDWR_fcntl_h,
  369. $openflags_decl, $openflags_prog, openflags_ok=1)dnl
  370. if test -z "$openflags_ok"; then
  371. dnl CL_COMPILE_CHECK([O_RDWR in sys/file.h], cl_cv_decl_O_RDWR_sys_file_h,
  372. dnl $openflags_decl[#include <sys/file.h>], $openflags_prog,
  373. AC_DEFINE(NEED_SYS_FILE_H)
  374. dnl openflags_ok=1)dnl
  375. fi
  376. fi
  377. ])dnl
  378. dnl
  379. AC_DEFUN(CL_SHM_H,
  380. [AC_BEFORE([$0], [CL_SHMGET])dnl
  381. AC_BEFORE([$0], [CL_SHMAT])dnl
  382. AC_BEFORE([$0], [CL_SHMCTL])dnl
  383. AC_BEFORE([$0], [CL_SHM_RMID])dnl
  384. AC_CHECK_HEADERS(sys/shm.h)
  385. if test $ac_cv_header_sys_shm_h = yes; then
  386. AC_CHECK_HEADERS(sys/ipc.h)
  387. fi
  388. ])dnl
  389. dnl
  390. AC_DEFUN(CL_MALLOC,
  391. [CL_PROTO([malloc], [
  392. AC_EGREP_HEADER([void.*\*.*malloc], stdlib.h, malloc_void=1)dnl
  393. if test -z "$malloc_void"; then
  394. AC_TRY_COMPILE([
  395. #ifdef HAVE_STDLIB_H
  396. #include <stdlib.h>
  397. #endif
  398. #ifdef HAVE_UNISTD_H
  399. #include <unistd.h>
  400. #endif
  401. ]CL_LANG_EXTERN[void* malloc();], [],
  402. malloc_void=1)
  403. fi
  404. if test -n "$malloc_void"; then
  405. cl_cv_proto_malloc_ret="void*"
  406. else
  407. cl_cv_proto_malloc_ret="char*"
  408. fi
  409. CL_PROTO_TRY([
  410. #ifdef HAVE_STDLIB_H
  411. #include <stdlib.h>
  412. #endif
  413. #ifdef HAVE_UNISTD_H
  414. #include <unistd.h>
  415. #endif
  416. ], [$cl_cv_proto_malloc_ret malloc (unsigned int size);],
  417. [$cl_cv_proto_malloc_ret malloc();],
  418. cl_cv_proto_malloc_arg1="unsigned int", cl_cv_proto_malloc_arg1="size_t")
  419. ], [extern $cl_cv_proto_malloc_ret malloc ($cl_cv_proto_malloc_arg1);])
  420. AC_DEFINE_UNQUOTED(RETMALLOCTYPE,$cl_cv_proto_malloc_ret)
  421. AC_DEFINE_UNQUOTED(MALLOC_SIZE_T,$cl_cv_proto_malloc_arg1)
  422. ])dnl
  423. dnl
  424. AC_DEFUN(CL_FREE,
  425. [CL_PROTO([free], [
  426. CL_PROTO_RET([
  427. #ifdef HAVE_STDLIB_H
  428. #include <stdlib.h>
  429. #endif
  430. #ifdef HAVE_UNISTD_H
  431. #include <unistd.h>
  432. #endif
  433. ], [int free();], cl_cv_proto_free_ret, int, void)],
  434. [extern $cl_cv_proto_free_ret free ($cl_cv_proto_malloc_ret);])
  435. AC_DEFINE_UNQUOTED(RETFREETYPE,$cl_cv_proto_free_ret)
  436. ])dnl
  437. dnl
  438. AC_DEFUN(CL_ABORT,
  439. [AC_REQUIRE([CL_STDLIB_H])dnl
  440. CL_PROTO([abort], [
  441. CL_PROTO_RET([
  442. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  443. #include <stdlib.h>
  444. #endif
  445. #ifdef HAVE_UNISTD_H
  446. #include <unistd.h>
  447. #endif
  448. ], [int abort();], cl_cv_proto_abort_ret, int, void)
  449. CL_PROTO_RET([
  450. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  451. #include <stdlib.h>
  452. #endif
  453. #ifdef HAVE_UNISTD_H
  454. #include <unistd.h>
  455. #endif
  456. ], [$cl_cv_proto_abort_ret abort();], cl_cv_proto_abort_vol, [], [__volatile__])
  457. ], [extern $cl_cv_proto_abort_vol $cl_cv_proto_abort_ret abort (void);])
  458. AC_DEFINE_UNQUOTED(RETABORTTYPE,$cl_cv_proto_abort_ret)
  459. AC_DEFINE_UNQUOTED(ABORT_VOLATILE,$cl_cv_proto_abort_vol)
  460. ])dnl
  461. dnl
  462. AC_DEFUN(CL_MKDIR,
  463. [AC_BEFORE([$0], [CL_OPEN])
  464. CL_PROTO([mkdir], [
  465. AC_EGREP_HEADER(mode_t, sys/types.h,
  466. dnl mode_t defined. check if it is really used by mkdir() :
  467. CL_PROTO_TRY([
  468. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  469. #include <stdlib.h>
  470. #endif
  471. #ifdef HAVE_UNISTD_H
  472. #include <unistd.h>
  473. #endif
  474. #include <sys/types.h>
  475. #include <sys/stat.h>
  476. ], [int mkdir (char* path, mode_t mode);], [int mkdir();], mode_t_unneeded=1, )
  477. if test -z "$mode_t_unneeded"; then
  478. CL_PROTO_TRY([
  479. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  480. #include <stdlib.h>
  481. #endif
  482. #ifdef HAVE_UNISTD_H
  483. #include <unistd.h>
  484. #endif
  485. #include <sys/types.h>
  486. #include <sys/stat.h>
  487. ], [int mkdir (const char* path, mode_t mode);], [int mkdir();], mode_t_unneeded=1, )
  488. fi)dnl
  489. if test -n "$mode_t_unneeded"; then
  490. cl_cv_type_mode_t="mode_t"
  491. else
  492. cl_cv_type_mode_t="int"
  493. fi
  494. dnl Now MODE_T should be correct, check for const:
  495. CL_PROTO_CONST([
  496. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  497. #include <stdlib.h>
  498. #endif
  499. #ifdef HAVE_UNISTD_H
  500. #include <unistd.h>
  501. #endif
  502. #include <sys/types.h>
  503. #include <sys/stat.h>
  504. ], [int mkdir (char* path, $cl_cv_type_mode_t mode);], [int mkdir();], cl_cv_proto_mkdir_arg1)
  505. ], [extern int mkdir ($cl_cv_proto_mkdir_arg1 char*, $cl_cv_type_mode_t);])
  506. AC_DEFINE_UNQUOTED(MODE_T,$cl_cv_type_mode_t)
  507. AC_DEFINE_UNQUOTED(MKDIR_CONST,$cl_cv_proto_mkdir_arg1)
  508. ])dnl
  509. dnl
  510. AC_DEFUN(CL_OPEN,
  511. [AC_REQUIRE([CL_MKDIR])dnl defines MODE_T
  512. AC_BEFORE([$0], [CL_FILECHARSET])dnl
  513. CL_PROTO([open], [
  514. for y in 'MODE_T mode' '...'; do
  515. for x in '' 'const'; do
  516. if test -z "$have_open"; then
  517. CL_PROTO_TRY([
  518. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  519. #include <stdlib.h>
  520. #endif
  521. #ifdef HAVE_UNISTD_H
  522. #include <unistd.h>
  523. #endif
  524. #include <fcntl.h>
  525. ], [int open ($x char* path, int flags, $y);], [int open();], [
  526. cl_cv_proto_open_arg1="$x"
  527. if test "$y" = "..."; then
  528. cl_cv_proto_open_dots=yes
  529. else
  530. cl_cv_proto_open_dots=no
  531. fi
  532. have_open=1])
  533. fi
  534. done
  535. done
  536. if test -z "$cl_cv_proto_open_dots"; then
  537. dnl This actually happens with AIX 3.2.5 cc: cc understands prototypes but
  538. dnl does not define __STDC__. The include files contain a declaration
  539. dnl "int open (const char*, int, ...);" which gives an error against
  540. dnl "int open ();". The right solution would be a macro CL_C_PROTOTYPES.
  541.   cl_cv_proto_open_arg1="const"
  542.   cl_cv_proto_open_dots=yes
  543. fi
  544. [ dnl Mysteriously, we need to quote this once more because of the commas.
  545. if test $cl_cv_proto_open_dots = yes; then
  546. cl_cv_proto_open_args="$cl_cv_proto_open_arg1 char*, int, ..."
  547. else
  548. cl_cv_proto_open_args="$cl_cv_proto_open_arg1 char*, int, $cl_cv_type_mode_t"
  549. fi
  550. ]], [extern int open ($cl_cv_proto_open_args);])
  551. AC_DEFINE_UNQUOTED(OPEN_CONST,$cl_cv_proto_open_arg1)
  552. if test $cl_cv_proto_open_dots = yes; then
  553. AC_DEFINE(OPEN_DOTS)
  554. fi
  555. ])dnl
  556. dnl
  557. AC_DEFUN(CL_GETPAGESIZE,
  558. [AC_BEFORE([$0], [CL_MPROTECT])
  559. CL_LINK_CHECK([getpagesize], cl_cv_func_getpagesize, , [getpagesize();],
  560. AC_DEFINE(HAVE_GETPAGESIZE)
  561. have_getpagesize=1)dnl
  562. if test -n "$have_getpagesize"; then
  563. CL_PROTO([getpagesize], [
  564. CL_PROTO_RET([
  565. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  566. #include <stdlib.h>
  567. #endif
  568. #ifdef HAVE_UNISTD_H
  569. #include <unistd.h>
  570. #endif
  571. ], [int getpagesize();], cl_cv_proto_getpagesize_ret, int, size_t)
  572. ], [extern $cl_cv_proto_getpagesize_ret getpagesize (void);])
  573. AC_DEFINE_UNQUOTED(RETGETPAGESIZETYPE,$cl_cv_proto_getpagesize_ret)
  574. fi
  575. ])dnl
  576. dnl
  577. AC_DEFUN(CL_MACH_VM,
  578. [CL_LINK_CHECK([vm_allocate], cl_cv_func_vm,
  579.  , [vm_allocate(); task_self();],
  580. AC_DEFINE(HAVE_MACH_VM)dnl
  581. )])dnl
  582. dnl
  583. AC_DEFUN(CL_MMAP,
  584. [AC_REQUIRE([CL_OPENFLAGS])dnl
  585. AC_REQUIRE([AC_TYPE_SIZE_T])dnl On AIX, the mmap() prototype references size_t which is undefined.
  586. AC_REQUIRE([AC_TYPE_OFF_T])dnl We use off_t below.
  587. AC_BEFORE([$0], [CL_MUNMAP])AC_BEFORE([$0], [CL_MPROTECT])
  588. AC_CHECK_HEADER(sys/mman.h, , no_mmap=1)dnl
  589. if test -z "$no_mmap"; then
  590. AC_CHECK_FUNC(mmap, , no_mmap=1)dnl
  591. if test -z "$no_mmap"; then
  592. AC_DEFINE(HAVE_MMAP)
  593. CL_PROTO([mmap], [
  594. # Note: gcc2 does not consider
  595. #   void* mmap (void*, size_t, int, int, int, off_t);
  596. #   char* mmap();
  597. # to be an error, if the first declaration comes from a system include file.
  598. CL_PROTO_RET([
  599. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  600. #include <stdlib.h>
  601. #endif
  602. #ifdef HAVE_UNISTD_H
  603. #include <unistd.h>
  604. #endif
  605. #include <sys/types.h>
  606. #include <sys/mman.h>
  607. ], [void* mmap();], cl_cv_proto_mmap_ret, [void*], [caddr_t])
  608. for y in 'int' 'size_t'; do
  609. for x in 'void*' 'caddr_t'; do
  610. if test -z "$have_mmap_decl"; then
  611. CL_PROTO_TRY([
  612. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  613. #include <stdlib.h>
  614. #endif
  615. #ifdef HAVE_UNISTD_H
  616. #include <unistd.h>
  617. #endif
  618. #include <sys/types.h>
  619. #include <sys/mman.h>
  620. ], [$cl_cv_proto_mmap_ret mmap ($x addr, $y length, int prot, int flags, int fd, off_t off);],
  621. [$cl_cv_proto_mmap_ret mmap();], [
  622. cl_cv_proto_mmap_arg1="$x"
  623. cl_cv_proto_mmap_arg2="$y"
  624. have_mmap_decl=1])
  625. fi
  626. done
  627. done
  628. ], [extern $cl_cv_proto_mmap_ret mmap ($cl_cv_proto_mmap_arg1, $cl_cv_proto_mmap_arg2, int, int, int, off_t);])
  629. AC_DEFINE_UNQUOTED(RETMMAPTYPE,$cl_cv_proto_mmap_ret)
  630. AC_DEFINE_UNQUOTED(MMAP_ADDR_T,$cl_cv_proto_mmap_arg1)
  631. AC_DEFINE_UNQUOTED(MMAP_SIZE_T,$cl_cv_proto_mmap_arg2)
  632. AC_CACHE_CHECK([for working mmap],cl_cv_func_mmap_works, 
  633. [case "$host" in
  634.   i[34]86-*-sysv4*)
  635.     # UNIX_SYSV_UHC_1
  636.     avoid=0x08000000 ;;
  637.   mips-sgi-irix* | mips-dec-ultrix*)
  638.     # UNIX_IRIX, UNIX_DEC_ULTRIX
  639.     avoid=0x10000000 ;;
  640.   rs6000-ibm-aix*)
  641.     # UNIX_AIX
  642.     avoid=0x20000000 ;;
  643.   *)
  644.     avoid=0 ;;
  645. esac
  646. mmap_prog_1='
  647. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  648. #include <stdlib.h>
  649. #endif
  650. #ifdef HAVE_UNISTD_H
  651. #include <unistd.h>
  652. #endif
  653. #include <fcntl.h>
  654. #ifdef NEED_SYS_FILE_H
  655. #include <sys/file.h>
  656. #endif
  657. #include <sys/types.h>
  658. #include <sys/mman.h>
  659. ]CL_LANG_EXTERN[
  660. #ifdef __STDC__
  661. RETMMAPTYPE mmap (MMAP_ADDR_T addr, MMAP_SIZE_T length, int prot, int flags, int fd, off_t off);
  662. #else
  663. RETMMAPTYPE mmap();
  664. #endif
  665. main () {
  666. '
  667. mmap_prog_2="#define bits_to_avoid $avoid"'
  668. #define my_shift 24
  669. #define my_low   1
  670. #ifdef FOR_SUN4_29
  671. #define my_high  31
  672. #define my_size  32768 /* hope that 32768 is a multiple of the page size */
  673. /* i*32 KB for i=1..31 gives a total of 15.5 MB, which is close to what we need */
  674. #else
  675. #define my_high  64
  676. #define my_size  8192 /* hope that 8192 is a multiple of the page size */
  677. /* i*8 KB for i=1..64 gives a total of 16.25 MB, which is close to what we need */
  678. #endif
  679.  {long i;
  680. #define i_ok(i)  ((i) & (bits_to_avoid >> my_shift) == 0)
  681.   for (i=my_low; i<=my_high; i++)
  682.     if (i_ok(i))
  683.       { caddr_t addr = (caddr_t)(i << my_shift);
  684. /* Check for 8 MB, not 16 MB. This is more likely to work on Solaris 2. */
  685. #if bits_to_avoid
  686.         long size = i*my_size;
  687. #else
  688.         long size = ((i+1)/2)*my_size;
  689. #endif
  690.         if (mmap(addr,size,PROT_READ|PROT_WRITE,flags|MAP_FIXED,fd,0) == (RETMMAPTYPE)-1) exit(1);
  691.     }
  692. #define x(i)  *(unsigned char *) ((i<<my_shift) + (i*i))
  693. #define y(i)  (unsigned char)((3*i-4)*(7*i+3))
  694.   for (i=my_low; i<=my_high; i++) if (i_ok(i)) { x(i) = y(i); }
  695.   for (i=my_high; i>=my_low; i--) if (i_ok(i)) { if (x(i) != y(i)) exit(1); }
  696.   exit(0);
  697. }}
  698. '
  699. AC_TRY_RUN([$mmap_prog_1
  700.   int flags = MAP_ANON | MAP_PRIVATE;
  701.   int fd = -1;
  702. $mmap_prog_2
  703. ], have_mmap_anon=1
  704. cl_cv_func_mmap_anon=yes, rm -f core,
  705. : # When cross-compiling, don't assume anything.
  706. )
  707. AC_TRY_RUN([$mmap_prog_1
  708.   int flags = MAP_ANONYMOUS | MAP_PRIVATE;
  709.   int fd = -1;
  710. $mmap_prog_2
  711. ], have_mmap_anon=1
  712. cl_cv_func_mmap_anonymous=yes, rm -f core,
  713. : # When cross-compiling, don't assume anything.
  714. )
  715. AC_TRY_RUN([$mmap_prog_1
  716. #ifndef MAP_FILE
  717. #define MAP_FILE 0
  718. #endif
  719.   int flags = MAP_FILE | MAP_PRIVATE;
  720.   int fd = open("/dev/zero",O_RDONLY,0666);
  721.   if (fd<0) exit(1);
  722. $mmap_prog_2
  723. ], have_mmap_devzero=1
  724. cl_cv_func_mmap_devzero=yes, rm -f core
  725. retry_mmap=1,
  726. : # When cross-compiling, don't assume anything.
  727. )
  728. if test -n "$retry_mmap"; then
  729. AC_TRY_RUN([#define FOR_SUN4_29
  730. $mmap_prog_1
  731. #ifndef MAP_FILE
  732. #define MAP_FILE 0
  733. #endif
  734.   int flags = MAP_FILE | MAP_PRIVATE;
  735.   int fd = open("/dev/zero",O_RDONLY,0666);
  736.   if (fd<0) exit(1);
  737. $mmap_prog_2
  738. ], have_mmap_devzero=1
  739. cl_cv_func_mmap_devzero_sun4_29=yes, rm -f core,
  740. : # When cross-compiling, don't assume anything.
  741. )
  742. fi
  743. if test -n "$have_mmap_anon" -o -n "$have_mmap_devzero"; then
  744. cl_cv_func_mmap_works=yes
  745. else
  746. cl_cv_func_mmap_works=no
  747. fi
  748. ])
  749. if test "$cl_cv_func_mmap_anon" = yes; then
  750. AC_DEFINE(HAVE_MMAP_ANON)
  751. fi
  752. if test "$cl_cv_func_mmap_anonymous" = yes; then
  753. AC_DEFINE(HAVE_MMAP_ANONYMOUS)
  754. fi
  755. if test "$cl_cv_func_mmap_devzero" = yes; then
  756. AC_DEFINE(HAVE_MMAP_DEVZERO)
  757. fi
  758. if test "$cl_cv_func_mmap_devzero_sun4_29" = yes; then
  759. AC_DEFINE(HAVE_MMAP_DEVZERO_SUN4_29)
  760. fi
  761. fi
  762. fi
  763. ])dnl
  764. dnl
  765. AC_DEFUN(CL_MPROTECT,
  766. [AC_REQUIRE([CL_GETPAGESIZE])dnl
  767. AC_REQUIRE([CL_MMAP])dnl
  768. AC_CHECK_FUNCS(mprotect)dnl
  769. if test $ac_cv_func_mprotect = yes; then
  770. CL_PROTO([mprotect], [
  771. CL_PROTO_CONST([
  772. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  773. #include <stdlib.h>
  774. #endif
  775. #ifdef HAVE_UNISTD_H
  776. #include <unistd.h>
  777. #endif
  778. #include <sys/types.h>
  779. #include <sys/mman.h>
  780. ], [int mprotect (MMAP_ADDR_T addr, MMAP_SIZE_T len, int prot);],
  781. [int mprotect();], cl_cv_proto_mprotect_arg1)
  782. ], [extern int mprotect ($cl_cv_proto_mprotect_arg1 $cl_cv_proto_mmap_arg1, $cl_cv_proto_mmap_arg2, int);])
  783. AC_DEFINE_UNQUOTED(MPROTECT_CONST,$cl_cv_proto_mprotect_arg1)
  784. AC_CACHE_CHECK([for working mprotect],cl_cv_func_mprotect_works, 
  785. [mprotect_prog='
  786. #include <sys/types.h>
  787. /* declare malloc() */
  788. #ifdef HAVE_STDLIB_H
  789. #include <stdlib.h>
  790. #endif
  791. #ifdef HAVE_UNISTD_H
  792. #include <unistd.h>
  793. #endif
  794. #ifndef malloc
  795. ]CL_LANG_EXTERN[
  796. #ifdef __STDC__
  797. RETMALLOCTYPE malloc (MALLOC_SIZE_T size);
  798. #else
  799. RETMALLOCTYPE malloc();
  800. #endif
  801. #endif
  802. /* declare getpagesize() and mprotect() */
  803. #include <sys/mman.h>
  804. #ifndef HAVE_GETPAGESIZE
  805. #include <sys/param.h>
  806. #define getpagesize() PAGESIZE
  807. #else
  808. ]CL_LANG_EXTERN[
  809. #ifdef __STDC__
  810. RETGETPAGESIZETYPE getpagesize (void);
  811. #else
  812. RETGETPAGESIZETYPE getpagesize();
  813. #endif
  814. #endif
  815. ]CL_LANG_EXTERN[
  816. #ifdef __STDC__
  817. int mprotect (MPROTECT_CONST MMAP_ADDR_T addr, MMAP_SIZE_T len, int prot);
  818. #else
  819. int mprotect();
  820. #endif
  821. char foo;
  822. main () {
  823.   unsigned long pagesize = getpagesize();
  824. #define page_align(address)  (char*)((unsigned long)(address) & -pagesize)
  825. '
  826. AC_TRY_RUN([$mprotect_prog
  827.   if ((pagesize-1) & pagesize) exit(1);
  828.   exit(0); }], , no_mprotect=1,
  829. # When cross-compiling, don't assume anything.
  830. no_mprotect=1)
  831. mprotect_prog="$mprotect_prog"'
  832.   char* area = malloc(6*pagesize);
  833.   char* fault_address = area + pagesize*7/2;
  834. '
  835. if test -z "$no_mprotect"; then
  836. AC_TRY_RUN([$mprotect_prog
  837.   if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
  838.   foo = *fault_address; /* this should cause a core dump */
  839.   exit(0); }],
  840.   no_mprotect=1, rm -f core,
  841. : # When cross-compiling, don't assume anything.
  842. )
  843. fi
  844. if test -z "$no_mprotect"; then
  845. AC_TRY_RUN([$mprotect_prog
  846.   if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
  847.   *fault_address = 'z'; /* this should cause a core dump */
  848.   exit(0); }],
  849.   no_mprotect=1, rm -f core,
  850. : # When cross-compiling, don't assume anything.
  851. )
  852. fi
  853. if test -z "$no_mprotect"; then
  854. AC_TRY_RUN([$mprotect_prog
  855.   if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(0);
  856.   *fault_address = 'z'; /* this should cause a core dump */
  857.   exit(0); }],
  858.   no_mprotect=1, rm -f core,
  859. : # When cross-compiling, don't assume anything.
  860. )
  861. fi
  862. if test -z "$no_mprotect"; then
  863. AC_TRY_RUN([$mprotect_prog
  864.   if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(1);
  865.   if (mprotect(page_align(fault_address),pagesize,PROT_READ|PROT_WRITE) < 0) exit(1);
  866.   *fault_address = 'z'; /* this should not cause a core dump */
  867.   exit(0); }], , no_mprotect=1
  868. rm -f core,
  869. : # When cross-compiling, don't assume anything.
  870. )
  871. fi
  872. if test -z "$no_mprotect"; then
  873.   cl_cv_func_mprotect_works=yes
  874. else
  875.   cl_cv_func_mprotect_works=no
  876. fi
  877. ])
  878. if test $cl_cv_func_mprotect_works = yes; then
  879.   AC_DEFINE(HAVE_WORKING_MPROTECT)
  880. fi
  881. fi
  882. ])dnl
  883. dnl
  884. AC_DEFUN(CL_CODEEXEC,
  885. [AC_CACHE_CHECK([whether code in malloc'ed memory is executable],cl_cv_codeexec, 
  886. [dnl The test below does not work on host=hppa*-hp-hpux* because on this system
  887. dnl function pointers are actually pointers into(!) a two-pointer struct.
  888. dnl The test below does not work on host=rs6000-*-* because on this system
  889. dnl function pointers are actually pointers to a three-pointer struct.
  890. case "$host_os" in
  891.   hpux*) cl_cv_codeexec="guessing yes" ;;
  892.   *)
  893. case "$host_cpu" in
  894.   # On host=rs6000-*-aix3.2.5 malloc'ed memory is indeed not executable.
  895.   rs6000) cl_cv_codeexec="guessing no" ;;
  896.   *)
  897. AC_TRY_RUN([
  898. #include <sys/types.h>
  899. /* declare malloc() */
  900. #ifdef HAVE_STDLIB_H
  901. #include <stdlib.h>
  902. #endif
  903. #ifdef HAVE_UNISTD_H
  904. #include <unistd.h>
  905. #endif
  906. #ifndef malloc
  907. ]CL_LANG_EXTERN[
  908. #ifdef __STDC__
  909. RETMALLOCTYPE malloc (MALLOC_SIZE_T size);
  910. #else
  911. RETMALLOCTYPE malloc();
  912. #endif
  913. #endif
  914. int fun () { return 31415926; }
  915. main ()
  916. { long size = (char*)&main - (char*)&fun;
  917.   char* funcopy = malloc(size);
  918.   int i;
  919.   for (i = 0; i < size; i++) { funcopy[i] = ((char*)&fun)[i]; }
  920.   exit(!((*(int(*)())funcopy)() == 31415926));
  921. }], cl_cv_codeexec=yes, rm -f core
  922. cl_cv_codeexec=no, cl_cv_codeexec="guessing yes")
  923.   ;;
  924. esac
  925.   ;;
  926. esac
  927. ])
  928. case "$cl_cv_codeexec" in
  929.   *yes) AC_DEFINE(CODE_EXECUTABLE) ;;
  930.   *no)  ;;
  931. esac
  932. ])dnl
  933. dnl
  934. AC_DEFUN(CL_SHMGET,
  935. [AC_REQUIRE([CL_SHM_H])dnl
  936. AC_BEFORE([$0], [CL_SHM])dnl
  937. if test "$ac_cv_header_sys_shm_h" = yes -a "$ac_cv_header_sys_ipc_h" = yes; then
  938. CL_PROTO([shmget], [
  939. CL_PROTO_TRY([
  940. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  941. #include <stdlib.h>
  942. #endif
  943. #ifdef HAVE_UNISTD_H
  944. #include <unistd.h>
  945. #endif
  946. #include <sys/types.h>
  947. #include <sys/ipc.h>
  948. #include <sys/shm.h>
  949. ], [int shmget (key_t key, int size, int shmflg);], [int shmget();],
  950. cl_cv_proto_shmget_arg2="int", cl_cv_proto_shmget_arg2="size_t")
  951. ], [extern int shmget (key_t, $cl_cv_proto_shmget_arg2, int);])
  952. AC_DEFINE_UNQUOTED(SHMGET_SIZE_T,$cl_cv_proto_shmget_arg2)
  953. fi
  954. ])dnl
  955. dnl
  956. AC_DEFUN(CL_SHMAT,
  957. [AC_REQUIRE([CL_SHM_H])dnl
  958. AC_BEFORE([$0], [CL_SHM])dnl
  959. if test "$ac_cv_header_sys_shm_h" = yes -a "$ac_cv_header_sys_ipc_h" = yes; then
  960. CL_PROTO([shmat], [
  961. CL_PROTO_RET([
  962. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  963. #include <stdlib.h>
  964. #endif
  965. #ifdef HAVE_UNISTD_H
  966. #include <unistd.h>
  967. #endif
  968. #include <sys/types.h>
  969. #include <sys/ipc.h>
  970. #include <sys/shm.h>
  971. ], [void* shmat();],
  972. cl_cv_proto_shmat_ret, [void*], [char*])
  973. CL_PROTO_CONST([
  974. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  975. #include <stdlib.h>
  976. #endif
  977. #ifdef HAVE_UNISTD_H
  978. #include <unistd.h>
  979. #endif
  980. #include <sys/types.h>
  981. #include <sys/ipc.h>
  982. #include <sys/shm.h>
  983. ], [$cl_cv_proto_shmat_ret shmat (int shmid, $cl_cv_proto_shmat_ret shmaddr, int shmflg);],
  984. [$cl_cv_proto_shmat_ret shmat();], cl_cv_proto_shmat_arg2)
  985. ], [extern $cl_cv_proto_shmat_ret shmat (int, $cl_cv_proto_shmat_arg2 $cl_cv_proto_shmat_ret, int);])
  986. AC_DEFINE_UNQUOTED(RETSHMATTYPE,$cl_cv_proto_shmat_ret)
  987. AC_DEFINE_UNQUOTED(SHMAT_CONST,$cl_cv_proto_shmat_arg2)
  988. fi
  989. ])dnl
  990. dnl
  991. AC_DEFUN(CL_SHMCTL,
  992. [AC_REQUIRE([CL_SHM_H])dnl
  993. AC_BEFORE([$0], [CL_SHM])dnl
  994. if test "$ac_cv_header_sys_shm_h" = yes -a "$ac_cv_header_sys_ipc_h" = yes; then
  995. CL_PROTO([shmctl], [
  996. CL_PROTO_TRY([
  997. #if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  998. #include <stdlib.h>
  999. #endif
  1000. #ifdef HAVE_UNISTD_H
  1001. #include <unistd.h>
  1002. #endif
  1003. #include <sys/types.h>
  1004. #include <sys/ipc.h>
  1005. #include <sys/shm.h>
  1006. ], [int shmctl (int shmid, int cmd, struct shmid_ds * buf);], [int shmctl();],
  1007. [[[ dnl Mysteriously, we need to quote this three times because of the commas.
  1008. cl_cv_proto_shmctl_dots=no
  1009. cl_cv_proto_shmctl_args="int, int, struct shmid_ds *"]]],
  1010. [[[ dnl Mysteriously, we need to quote this three times because of the commas.
  1011. cl_cv_proto_shmctl_dots=yes
  1012. cl_cv_proto_shmctl_args="int, int, ..."]]])
  1013. ], [extern int shmctl ($cl_cv_proto_shmctl_args);])
  1014. if test $cl_cv_proto_shmctl_dots = yes; then
  1015.   AC_DEFINE(SHMCTL_DOTS)
  1016. fi
  1017. fi
  1018. ])dnl
  1019. dnl
  1020. AC_DEFUN(CL_SHM,
  1021. [AC_REQUIRE([CL_SHMGET])dnl
  1022. AC_REQUIRE([CL_SHMAT])dnl
  1023. AC_REQUIRE([CL_SHMCTL])dnl
  1024. AC_BEFORE([$0], [CL_SHM_RMID])dnl
  1025. if test "$ac_cv_header_sys_shm_h" = yes -a "$ac_cv_header_sys_ipc_h" = yes; then
  1026. # This test is from Marcus Daniels
  1027. AC_CACHE_CHECK([for working shared memory],cl_cv_sys_shm_works,
  1028. [AC_TRY_RUN([#include <sys/types.h>
  1029. #include <sys/ipc.h>
  1030. #include <sys/shm.h>
  1031. ]CL_LANG_EXTERN[
  1032. #ifdef __STDC__
  1033. int shmget (key_t key, $cl_cv_proto_shmget_arg2 size, int shmflg);
  1034. #else
  1035. int shmget();
  1036. #endif
  1037. ]CL_LANG_EXTERN[
  1038. #ifdef __STDC__
  1039. $cl_cv_proto_shmat_ret shmat (int shmid, $cl_cv_proto_shmat_arg2 $cl_cv_proto_shmat_ret shmaddr, int shmflg);
  1040. #else
  1041. $cl_cv_proto_shmat_ret shmat();
  1042. #endif
  1043. ]CL_LANG_EXTERN[
  1044. #ifdef __STDC__
  1045. int shmdt ($cl_cv_proto_shmat_arg2 $cl_cv_proto_shmat_ret shmaddr);
  1046. #else
  1047. int shmdt();
  1048. #endif
  1049. ]CL_LANG_EXTERN[
  1050. #ifdef __STDC__
  1051. int shmctl ($cl_cv_proto_shmctl_args);
  1052. #else
  1053. int shmctl();
  1054. #endif
  1055. /* try attaching a single segment to multiple addresses */
  1056. #define segsize 0x10000
  1057. #define attaches 128
  1058. #define base_addr 0x01000000
  1059. main ()
  1060. { int shmid, i; char* addr; char* result;
  1061.   if ((shmid = shmget(IPC_PRIVATE,segsize,0400)) < 0) exit(1);
  1062.   for (i=0, addr = (char*)0x01000000; i<attaches; i++, addr += segsize)
  1063.     { if ((result = shmat(shmid,addr,SHM_RDONLY)) == (char*)(-1)) break; }
  1064.   for (i=0, addr = (char*)0x01000000; i<attaches; i++, addr += segsize)
  1065.     shmdt(addr);
  1066.   shmctl(shmid,IPC_RMID,0);
  1067.   exit(result == (char*)(-1));
  1068. }], cl_cv_sys_shm_works=yes, cl_cv_sys_shm_works=no,
  1069. dnl When cross-compiling, don't assume anything.
  1070. cl_cv_sys_shm_works="guessing no")
  1071. ])
  1072. fi
  1073. case "$cl_cv_sys_shm_works" in
  1074.   *yes) have_shm=1
  1075.         AC_DEFINE(HAVE_SHM)
  1076.         AC_CHECK_HEADERS(sys/sysmacros.h)
  1077.         ;;
  1078.   *) ;;
  1079. esac
  1080. ])dnl
  1081. dnl
  1082. AC_DEFUN(CL_CHAR_UNSIGNED,
  1083. [dnl This is mostly copied from AC_C_CHAR_UNSIGNED.
  1084. AC_CACHE_CHECK([whether characters are unsigned],ac_cv_c_char_unsigned,
  1085. [if test $ac_cv_prog_gcc = yes; then
  1086.   # GCC predefines this symbol on systems where it applies.
  1087. AC_EGREP_CPP(yes,
  1088. [#ifdef __CHAR_UNSIGNED__
  1089.   yes
  1090. #endif
  1091. ], ac_cv_c_char_unsigned=yes, ac_cv_c_char_unsigned=no)
  1092. else
  1093. AC_TRY_RUN(
  1094. [/* volatile prevents gcc2 from optimizing the test away on sparcs.  */
  1095. #if !defined(__STDC__) || __STDC__ != 1
  1096. #define volatile
  1097. #endif
  1098. main() {
  1099.   volatile char c = 255; exit(c < 0);
  1100. }], ac_cv_c_char_unsigned=yes, ac_cv_c_char_unsigned=no,
  1101. ac_cv_c_char_unsigned="guessing no")
  1102. fi])
  1103. dnl
  1104. if test $ac_cv_prog_gcc = no; then
  1105.   # GCC defines __CHAR_UNSIGNED__ by itself, no need to fix up.
  1106.   case "$ac_cv_c_char_unsigned" in
  1107.     *yes) AC_DEFINE(__CHAR_UNSIGNED__) ;;
  1108.     *no) ;;
  1109.   esac
  1110. fi
  1111. ])dnl
  1112. dnl
  1113.