home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / rcs567s.zip / rcs / src / conf.sh.orig < prev    next >
Text File  |  1994-04-14  |  50KB  |  2,134 lines

  1. #!/bin/sh
  2. # Output RCS compile-time configuration.
  3. Id='$Id: conf.sh,v 5.22 1994/04/14 06:55:24 eggert Exp $'
  4. #    Copyright 1990, 1991, 1992, 1993, 1994 Paul Eggert
  5. #    Distributed under license by the Free Software Foundation, Inc.
  6.  
  7. # This file is part of RCS.
  8. #
  9. # RCS is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # RCS is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with RCS; see the file COPYING.  If not, write to
  21. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #
  23. # Report problems and direct all questions to:
  24. #
  25. #    rcs-bugs@cs.purdue.edu
  26.  
  27.  
  28. # Standard output should already be directed to "a.h";
  29. # later parts of this procedure need it.
  30. # Standard error can be ignored if a.h is OK,
  31. # and can be inspected for clues otherwise.
  32.  
  33. # The Makefile overrides the following defaults.
  34. : ${RCSPREFIX=/usr/local/bin/}
  35. : ${CC=cc}
  36. : ${CFLAGS=-O}
  37. : ${COMPAT2=0}
  38. : ${DIFF3=${RCSPREFIX}diff3}
  39. : ${DIFF3_A=0}
  40. : ${DIFF3_BIN=1}
  41. : ${DIFF=${RCSPREFIX}diff}
  42. : ${DIFF_FLAGS=-an}
  43. : ${DIFF_L=1}
  44. : ${DIFF_SUCCESS=0} ${DIFF_FAILURE=1} ${DIFF_TROUBLE=2}
  45. : ${ED=/bin/ed}
  46. : ${SENDMAIL='"/usr/lib/sendmail"'}
  47. # : ${LDFLAGS=} ${LDLIBS=} tickles old shell bug
  48.  
  49. C="$CC $CFLAGS"
  50. CL="$CC $CFLAGS $LDFLAGS -o a.out"
  51. L=$LDLIBS
  52.  
  53. cat <<EOF
  54. /* RCS compile-time configuration */
  55.  
  56.     /* $Id */
  57.  
  58. /*
  59.  * This file is generated automatically.
  60.  * If you edit it by hand your changes may be lost.
  61.  * Instead, please try to fix conf.sh,
  62.  * and send your fixes to rcs-bugs@cs.purdue.edu.
  63.  */
  64.  
  65. EOF
  66.  
  67. n='
  68. '
  69. case `echo -n` in
  70. -n)
  71.     ech='echo' dots='... \c';;
  72. *)
  73.     ech='echo -n' dots='... '
  74. esac
  75.  
  76. $ech >&3 "$0: testing compiler for plausibility $dots"
  77. echo 'this is not a C source file' >a.c
  78. rm -f a.exe a.out || exit
  79. $CL a.c $L >&2 && {
  80.     echo >&3 "$n$0: The command '$CL a.c $L' succeeds when it should fail."
  81.     exit 1
  82. }
  83. echo >&3 OK
  84.  
  85. $ech >&3 "$0: configuring exitmain $dots"
  86. cat >a.c <<EOF
  87. #include "a.h"
  88. int main(argc,argv) int argc; char **argv; { return argc-1; }
  89. EOF
  90. rm -f a.exe a.out || exit
  91. if $CL a.c $L >&2
  92. then A_H=a.h
  93. else
  94.     echo >&3 failed
  95.     $ech >&3 "$0: attempting to work around Domain/OS brain damage $dots"
  96.     cat >a.c <<EOF
  97. #include "a.hap"
  98. int main(argc,argv) int argc; char **argv; { return argc-1; }
  99. EOF
  100.     cat <a.h >a.hap &&
  101.     $CL a.c $L >&2 || exit 1
  102.     # The Domain/OS C compiler refuses to read a.h because the file
  103.     # is currently open for writing.  Work around this brain damage by
  104.     # copying it to a.hap before each compilation; include a.hap instead.
  105.     A_H=a.hap
  106. fi
  107. if test -f a.out
  108. then aout=./a.out
  109. elif test -f a.exe
  110. then aout=./a.exe
  111. else
  112.     echo >&3 "$n$0: C compiler creates neither a.out nor a.exe."
  113.     exit 1
  114. fi
  115. e='exit(n), 3 /* lint fodder */'
  116. if $aout -
  117. then :
  118. elif $aout
  119. then e=n
  120. fi
  121. case $e in
  122. n) echo >&3 OK;;
  123. *) echo >&3 "return does not work; using exit instead"
  124. esac
  125. echo "#define exitmain(n) return $e /* how to exit from main() */"
  126.  
  127. : PREPARE_CC
  128. case $A_H in
  129. a.h)
  130.     PREPARE_CC="rm -f $aout";;
  131. *)
  132.     echo "rm -f $aout \$1 && cat <a.h >$A_H" >a.pre
  133.     PREPARE_CC="sh a.pre"
  134. esac
  135.  
  136. $ech >&3 "$0: configuring _POSIX_SOURCE $dots"
  137. cat >a.c <<EOF
  138. #include "$A_H"
  139. #include <stdio.h>
  140. int
  141. main() {
  142. #    ifdef fileno
  143. #        define f(x) fileno(x)
  144. #    else
  145.         /* Force a compile-time error if fileno isn't declared.  */
  146.         int (*p)() = fileno;
  147. #        define f(x) (*p)(x)
  148. #    endif
  149.     /* Some buggy linkers seem to need the getchar.  */
  150.     exitmain(getchar() != '#' || fileno(stdout) != 1);
  151. }
  152. #if syntax_error
  153. syntax error
  154. #endif
  155. EOF
  156. a='/* ' z='*/ '
  157. $PREPARE_CC || exit
  158. if ($CL a.c $L && $aout <a.c) >&2
  159. then :
  160. elif $PREPARE_CC || exit; ($CL -D_POSIX_SOURCE a.c $L && $aout <a.c) >&2
  161. then a= z=
  162. fi
  163. case $a in
  164. ?*) echo >&3 OK;;
  165. '') echo >&3 "must define it, unfortunately"
  166. esac
  167. cat <<EOF
  168. $a#define _POSIX_SOURCE $z/* Define this if Posix + strict Standard C.  */
  169.  
  170. #include <errno.h>
  171. #include <stdio.h>
  172. #include <time.h>
  173. EOF
  174.  
  175. cat <<'EOF'
  176.  
  177. /* Comment out #include lines below that do not work.  */
  178. EOF
  179.  
  180. $ech >&3 "$0: configuring how to check for syntax errors $dots"
  181. # Run `$CS a.c $LS' instead of `$CL a.c $L' for compile-time checking only.
  182. # This speeds up the configuration process.
  183. if
  184.     rm -f a.s && $C -S a.c >&2 && test -s a.s && rm -f a.s &&
  185.     if $C -S -Dsyntax_error=1 a.c >&2 && test -s a.s
  186.     then false
  187.     else :
  188.     fi
  189. then
  190.     # Generate assembly language output.
  191.     CS="$C -S" LS= o=a.s PREPARE_CC="$PREPARE_CC $o"
  192. elif
  193.     rm -f a.o a.obj && $C -c a.c >&2 &&
  194.     if test -s a.o
  195.     then o=a.o
  196.     elif test -s a.obj
  197.     then o=a.obj
  198.     else false
  199.     fi &&
  200.     if $C -c -Dsyntax_error=1 a.c >&2 && test -s $o
  201.     then false
  202.     else :
  203.     fi
  204. then
  205.     # Generate object code.
  206.     CS="$C -c" LS= PREPARE_CC="$PREPARE_CC $o"
  207. else
  208.     # Generate an executable.
  209.     CS=$CL LS=$L o=$aout
  210. fi
  211. CS_OK="test -s $o"
  212. echo >&3 $CS
  213.  
  214. # standard include files
  215. # sys/types.h and sys/stat.h must come first because others depend on them.
  216. has_signal=1
  217. for h in \
  218.     sys/types sys/stat \
  219.     dirent fcntl limits pwd siginfo signal stdlib string \
  220.     sys/mman sys/wait ucontext unistd utime vfork
  221. do
  222.     i="#include <$h.h>"
  223.     $ech >&3 "$0: configuring $i $dots"
  224.     cat >a.c <<EOF
  225. #include "$A_H"
  226. $i
  227. int main(){ exitmain(0); }
  228. EOF
  229.     $PREPARE_CC || exit
  230.     ok=OK
  231.     $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK || {
  232.         case $h in
  233.         string)
  234.             i='#include <strings.h>'
  235.             ok="$i instead";;
  236.         *)
  237.             i="/* $i */"
  238.             ok="commenting it out"
  239.         esac
  240.         case $h in
  241.         signal) has_signal=0
  242.         esac
  243.     }
  244.     echo >&3 "$ok"
  245.     echo "$i"
  246. done
  247.  
  248. cat <<'EOF'
  249.  
  250. /* Define the following symbols to be 1 or 0.  */
  251. EOF
  252.  
  253. # has_sys_*_h
  254. for H in dir param
  255. do
  256.     $ech >&3 "$0: configuring has_sys_${H}_h $dots"
  257.     cat >a.c <<EOF
  258. #include "$A_H"
  259. #include <sys/$H.h>
  260. int main() { exitmain(0); }
  261. EOF
  262.     $PREPARE_CC || exit
  263.     if $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  264.     then h=1 ok=OK
  265.     else h=0 ok=absent
  266.     fi
  267.     echo >&3 $ok
  268.     echo "#define has_sys_${H}_h $h /* Does #include <sys/$H.h> work?  */"
  269. done
  270.  
  271. # We must do errno next, because has_readlink needs it.
  272. /* <errno.h> */
  273. $ech >&3 "$0: configuring errno $dots"
  274. cat >a.c <<EOF
  275. #include "$A_H"
  276. int main() { exitmain(errno != errno); }
  277. EOF
  278. $PREPARE_CC || exit
  279. if $CS a.c $LS >&2
  280. then a='/* ' z=' */' ok=OK
  281. else a= z= ok='declaration missing'
  282. fi
  283. echo >&3 $ok
  284. echo "${a}extern int errno;$z /* Uncomment if <errno.h> doesn't declare errno.  */"
  285. rm -f a.c || exit
  286.  
  287. # We must do has_readlink next, because it might generate
  288. # #include directives that affect later definitions.
  289.  
  290. $ech >&3 "$0: configuring has_readlink, readlink_isreg_errno $dots"
  291. cat >a.c <<EOF
  292. #include "$A_H"
  293. static char b[7];
  294. int
  295. main() {
  296.     if (readlink("a.sym2",b,7) == 6  &&  strcmp(b,"a.sym1") == 0  &&
  297.         readlink("a.c",b,7) == -1  &&  errno != ENOENT
  298.     ) {
  299.         if (errno == EINVAL)
  300.             printf("EINVAL\n");
  301.         else
  302.             printf("%d\n", errno);
  303.         exitmain(ferror(stdout) || fclose(stdout)!=0);
  304.     }
  305.     exitmain(1);
  306. }
  307. EOF
  308. $PREPARE_CC a.sym* || exit
  309. readlink_isreg_errno='?'
  310. if (ln -s a.sym1 a.sym2 && $CL a.c $L) >&2 && readlink_isreg_errno=`$aout`
  311. then h=1
  312. else h=0
  313. fi
  314. echo >&3 $h, $readlink_isreg_errno
  315. cat <<EOF
  316. #define has_readlink $h /* Does readlink() work?  */
  317. #define readlink_isreg_errno $readlink_isreg_errno /* errno after readlink on regular file */
  318.  
  319. #if !defined(PATH_MAX) && !defined(_POSIX_PATH_MAX)
  320. #    if has_sys_param_h
  321. #        include <sys/param.h>
  322. #        define included_sys_param_h 1
  323. #    endif
  324. #    ifndef PATH_MAX
  325. #        ifndef MAXPATHLEN
  326. #            define MAXPATHLEN 1024
  327. #        endif
  328. #        define PATH_MAX (MAXPATHLEN-1)
  329. #    endif
  330. #endif
  331. #if has_readlink && !defined(MAXSYMLINKS)
  332. #    if has_sys_param_h && !included_sys_param_h
  333. #        include <sys/param.h>
  334. #    endif
  335. #    ifndef MAXSYMLINKS
  336. #        define MAXSYMLINKS 20 /* BSD; not standard yet */
  337. #    endif
  338. #endif
  339. EOF
  340.  
  341. # *_t
  342. cat <<'EOF'
  343.  
  344. /* Comment out the typedefs below if the types are already declared.  */
  345. /* Fix any uncommented typedefs that are wrong.  */
  346. EOF
  347. cat >a.c <<EOF
  348. #include "$A_H"
  349. t x;
  350. int main() { exitmain(0); }
  351. EOF
  352. for t in mode_t off_t pid_t sig_atomic_t size_t ssize_t time_t uid_t
  353. do
  354.     $ech >&3 "$0: configuring $t $dots"
  355.     case $t in
  356.     size_t) i=unsigned;;
  357.     off_t|time_t) i=long;;
  358.     *) i=int;;
  359.     esac
  360.     if $PREPARE_CC && $CS -Dt=$t a.c $LS >&2 && $CS_OK
  361.     then ok=OK a='/* ' z=' */'
  362.     else ok=$i a= z=
  363.     fi
  364.     echo >&3 $ok
  365.     echo "${a}typedef $i $t;$z"
  366. done
  367.  
  368. cat <<'EOF'
  369.  
  370. /* Comment out the keyword definitions below if the keywords work.  */
  371. EOF
  372.  
  373. for i in const volatile
  374. do
  375.     $ech >&3 "$0: configuring $i $dots"
  376.     cat >a.c <<EOF
  377. #    include "$A_H"
  378.     int main();
  379.     enum Boolean { false, true };
  380.     int id();
  381.     static enum Boolean $i zero;
  382.     int id(x) int x; { return x; }  /* HP-UX 8.05 barfs on this.  */
  383.     static enum Boolean $i * $i azero = &zero;
  384.     static enum Boolean $i * $i * $i aazero = &azero;
  385.     static enum Boolean * $i arzero[1];
  386.     static sig_atomic_t $i sigzero;
  387.     int sco32v4barf() {
  388.         /* SCO 3.2v4 native compiler barfs on this.  */
  389.         char *t;
  390.         char $i *s = 0 ? (char *)0 : (char $i *)0;
  391.         *t++ = '\0';
  392.     }
  393.     int main() {
  394.         enum Boolean *p = arzero[sigzero];
  395.         switch (zero) {
  396.             case false: exitmain(!p || **aazero);
  397.             default: exitmain(id(1));
  398.         }
  399.     }
  400. EOF
  401.     a= z= ok='broken'
  402.     if $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  403.     then
  404.         cat >a.c <<EOF
  405.             char $i *p;
  406.             char *q;
  407.             typedef unsigned char $i *Iptr_type;
  408.             struct { Iptr_type lim; } s, *f = &s;
  409.             int main() {
  410.                 Iptr_type lim;
  411.                 lim = f->lim;
  412.                 p = p == q ? p : "";
  413.                 p = p == "" ? p : q;
  414.                 return !!lim;
  415.             }
  416. EOF
  417.         if $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  418.         then
  419.             case $i in
  420.             const)
  421.                 # Check for common execv misdeclaration.
  422.                 cat >a.c <<EOF
  423. #                    include "$A_H"
  424.                     static char * const *p;
  425.                     int main() { return execv("/bin/sh", p); }
  426. EOF
  427.                 $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  428.             esac && a='/* ' z=' */' ok=OK
  429.         fi
  430.     fi
  431.     echo >&3 $ok
  432.     echo "$a#define $i$z"
  433. done
  434.  
  435. echo >&3 "$0: configuring has_prototypes, has_stdarg, has_varargs, va_start_args $dots"
  436. cat >a.ha <<'EOF'
  437. #if has_prototypes
  438. #    define P(params) params
  439. #else
  440. #    define P(params) ()
  441. #endif
  442. #if has_stdarg
  443. #    include <stdarg.h>
  444. #else
  445. #    if has_varargs
  446. #        include <varargs.h>
  447. #    else
  448.         typedef char *va_list;
  449. #        define va_dcl int va_alist;
  450. #        define va_start(ap) ((ap) = (va_list)&va_alist)
  451. #        define va_arg(ap,t) (((t*) ((ap)+=sizeof(t)))  [-1])
  452. #        define va_end(ap)
  453. #    endif
  454. #endif
  455. #if va_start_args == 2
  456. #    define vararg_start va_start
  457. #else
  458. #    define vararg_start(ap,p) va_start(ap)
  459. #endif
  460. EOF
  461. cat >a.c <<EOF
  462. #include "$A_H"
  463. #include "a.ha"
  464.  
  465. struct buf { int x; };
  466. int pairnames P((int,char**,FILE*(*)P((struct buf*,struct stat*,int)),int,int)); /* a la rcsbase.h */
  467. FILE *(*rcsopen)P((struct buf*,struct stat*,int));  /* a la rcsfnms.c */
  468.  
  469. static char *e(p,i) char **p; int i; { return p[i]; }
  470. #if has_prototypes
  471. static char *f(char *(*g)(char**,int), char **p, ...)
  472. #else
  473. static char *f(g, p, va_alist) char *(*g)(); char **p; va_dcl
  474. #endif
  475. {
  476.     char *s;
  477.     va_list v;
  478.     vararg_start(v,p);
  479.     s = g(p, va_arg(v,int));
  480.     va_end(v);
  481.     return s;
  482. }
  483. int main P((int, char**));
  484. int
  485. main(argc, argv) int argc; char **argv; {
  486.     exitmain(f(e,argv,0) != argv[0]  ||  f(e,argv,1) != argv[1]);
  487. }
  488. EOF
  489. for has_prototypes in 1 0
  490. do
  491.     for has_stdarg in 1 v 0
  492.     do
  493.         case $has_stdarg in
  494.         v) has_varargs=1 has_stdarg=0;;
  495.         *) has_varargs=0
  496.         esac
  497.         case $has_stdarg in
  498.         0) as='1 2';;
  499.         1) as='2 1'
  500.         esac
  501.         for va_start_args in $as
  502.         do
  503.             $PREPARE_CC || exit
  504.             $CL \
  505.                 -Dhas_prototypes=$has_prototypes \
  506.                 -Dhas_stdarg=$has_stdarg \
  507.                 -Dhas_varargs=$has_varargs \
  508.                 -Dva_start_args=$va_start_args \
  509.                 a.c $L >&2 && $aout && break
  510.         done && break
  511.     done && break
  512. done || {
  513.     echo >&3 $0: cannot deduce has_prototypes, has_stdarg, va_start_args
  514.     exit 1
  515. }
  516. echo >&3 $has_prototypes, $has_stdarg, $has_varargs, $va_start_args
  517. cat - a.ha <<EOF
  518.  
  519. /* Define the following symbols to be 1 or 0.  */
  520. #define has_prototypes $has_prototypes /* Do function prototypes work?  */
  521. #define has_stdarg $has_stdarg /* Does <stdarg.h> work?  */
  522. #define has_varargs $has_varargs /* Does <varargs.h> work?  */
  523. #define va_start_args $va_start_args /* How many args does va_start() take?  */
  524. EOF
  525.  
  526. $ech >&3 "$0: configuring text_equals_binary_stdio $dots"
  527. cat >a.c <<EOF
  528. #include "$A_H"
  529.     static int
  530. copy(from, to, mode) char const *from, *to, *mode; {
  531.     int c;
  532.     FILE *f, *g;
  533.     if (!(f = fopen(from, "rb")) || !(g = fopen(to, mode)))
  534.         return 1;
  535.     while (c=getc(f), !feof(f))
  536.         if (ferror(f))
  537.             return 1;
  538.         else
  539.             putc(c,g);
  540.     return fclose(f)!=0 || ferror(g) || fclose(g)!=0;
  541. }
  542.     int
  543. main(argc, argv) int argc; char **argv; {
  544.     exitmain(copy(argv[1], "a.d", "w+b") || copy(argv[1], "a.e", "w+"));
  545. }
  546. EOF
  547. e=1 ok=OK
  548. $PREPARE_CC && $CL a.c $L >&2 || exit
  549. for i in a.c $aout
  550. do
  551.     rm -f a.d a.e || exit
  552.     $aout $i  &&  cmp $i a.d >&2  &&  {
  553.         cmp $i a.e >&2 || { e=0; ok=no; break; }
  554.     }
  555. done
  556. echo >&3 $ok
  557. cat <<EOF
  558.  
  559. #define text_equals_binary_stdio $e /* Does stdio treat text like binary?  */
  560. #define text_work_stdio 0 /* Text i/o for working file, binary for RCS file?  */
  561. #if text_equals_binary_stdio
  562.     /* Text and binary i/o behave the same, or binary i/o does not work.  */
  563. #    define FOPEN_R "r"
  564. #    define FOPEN_W "w"
  565. #    define FOPEN_WPLUS "w+"
  566. #    define OPEN_O_BINARY 0
  567. #else
  568.     /* Text and binary i/o behave differently.  */
  569.     /* This is incompatible with Posix and Unix.  */
  570. #    define FOPEN_R "rb"
  571. #    define FOPEN_W "wb"
  572. #    define FOPEN_WPLUS "w+b"
  573. #    define OPEN_O_BINARY O_BINARY
  574. #    ifndef O_BINARY
  575. #    define O_BINARY 0
  576. #    endif
  577. #endif
  578. #if text_work_stdio
  579. #    define FOPEN_R_WORK "r"
  580. #    define FOPEN_W_WORK "w"
  581. #    define FOPEN_WPLUS_WORK "w+"
  582. #    define OPEN_O_WORK 0
  583. #else
  584. #    define FOPEN_R_WORK FOPEN_R
  585. #    define FOPEN_W_WORK FOPEN_W
  586. #    define FOPEN_WPLUS_WORK FOPEN_WPLUS
  587. #    define OPEN_O_WORK OPEN_O_BINARY
  588. #endif
  589.  
  590. /* This may need changing on non-Unix systems (notably DOS).  */
  591. #define OPEN_CREAT_READONLY (S_IRUSR|S_IRGRP|S_IROTH) /* lock file mode */
  592. #define OPEN_O_LOCK 0 /* extra open flags for creating lock file */
  593.  
  594. /* Define or comment out the following symbols as needed.  */
  595. EOF
  596.  
  597. $ech >&3 "$0: configuring bad_chmod_close $dots"
  598. cat >a.c <<EOF
  599. #include "$A_H"
  600. #ifndef O_RDONLY
  601. #    define O_RDONLY 0
  602. #endif
  603. int
  604. main() {
  605.     int f;
  606.     exitmain(
  607.         (f = open("a.c", O_RDONLY)) < 0 ||
  608.         chmod("a.c", 0) != 0 ||
  609.         close(f) != 0
  610.     );
  611. }
  612. EOF
  613. $PREPARE_CC || exit
  614. if $CL a.c $L >&2 && $aout
  615. then b=0 ok=OK
  616. else b=1 ok='will work around bug'
  617. fi
  618. echo >&3 $ok
  619. echo "#define bad_chmod_close $b /* Can chmod() close file descriptors?  */"
  620. rm -f a.c || exit
  621.  
  622. $ech >&3 "$0: configuring bad_creat0 $dots"
  623. cat >a.c <<EOF
  624. #include "$A_H"
  625. #if defined(O_CREAT) && defined(O_WRONLY)
  626. #    define creat0(f) open(f, O_CREAT|O_WRONLY, 0)
  627. #else
  628. #    define creat0(f) creat(f, 0)
  629. #endif
  630. char buf[17000];
  631. int
  632. main() {
  633.     int f;
  634.     exitmain(
  635.         (f = creat0("a.d")) < 0  ||
  636.         write(f, buf, sizeof(buf)) != sizeof(buf) ||
  637.         close(f) != 0
  638.     );
  639. }
  640. EOF
  641. $PREPARE_CC a.d || exit
  642. if $CL a.c $L >&2 && $aout && test -f a.d && test ! -w a.d
  643. then b=0 ok=OK
  644. else b=1 ok='will work around bug'
  645. fi
  646. echo >&3 $ok
  647. echo "#define bad_creat0 $b /* Do writes fail after creat(f,0)?  */"
  648. rm -f a.d || exit
  649.  
  650. $ech >&3 "$0: configuring bad_fopen_wplus $dots"
  651. cat >a.c <<EOF
  652. #include "$A_H"
  653. int main() { exitmain(!fopen("a.d",FOPEN_WPLUS)); }
  654. EOF
  655. $PREPARE_CC || exit
  656. if echo nonempty >a.d && $CL a.c $L >&2 && $aout && test ! -s a.d
  657. then b=0 ok=OK
  658. else b=1 ok='will work around bug'
  659. fi
  660. echo >&3 $ok
  661. echo "#define bad_fopen_wplus $b /* Does fopen(f,FOPEN_WPLUS) fail to truncate f?  */"
  662.  
  663. echo "#define getlogin_is_secure 0 /* Is getlogin() secure?  Usually it's not.  */"
  664.  
  665. $ech >&3 "$0: configuring has_attribute_noreturn $dots"
  666. cat >a.c <<EOF
  667. #include "$A_H"
  668. static void e P((int)) __attribute__((noreturn));
  669. static void e(i) int i; { exit(i); }
  670. int main() { e(0); }
  671. EOF
  672. $PREPARE_CC || exit
  673. h=0 ok='does not work'
  674. if out=`$CS a.c $LS 2>&1`
  675. then
  676.     case $out in
  677.     *noreturn*) ;;
  678.     *) h=1 ok=OK
  679.     esac
  680. fi
  681. echo >&2 "$out"
  682. echo >&3 $ok
  683. cat <<EOF
  684. #define has_attribute_noreturn $h /* Does __attribute__((noreturn)) work?  */
  685. #if has_attribute_noreturn
  686. #    define exiting __attribute__((noreturn))
  687. #else
  688. #    define exiting
  689. #endif
  690. EOF
  691. rm -f a.c || exit
  692.  
  693. $ech >&3 "$0: configuring has_dirent, void_closedir $dots"
  694. cat >a.c <<EOF
  695. #include "$A_H"
  696. #if void_closedir
  697. #    define close_directory(d) (closedir(d), 0)
  698. #else
  699. #    define close_directory(d) closedir(d)
  700. #endif
  701. int
  702. main() {
  703.     DIR *d = opendir(".");
  704.     struct dirent *e;
  705.     while ((e = readdir(d)))
  706.         if (strcmp(e->d_name, "a.c") == 0  &&  close_directory(d) == 0)
  707.             exitmain(0);
  708.     exitmain(1);
  709. }
  710. EOF
  711. $PREPARE_CC || exit
  712. has_dirent=0 ok='does not work'
  713. void_closedir=? a='/* ' z='*/ '
  714. for v in 0 1
  715. do
  716.     if $CL -Dvoid_closedir=$v a.c $L >&2 && $aout
  717.     then
  718.         has_dirent=1 ok=OK
  719.         void_closedir=$v a= z=
  720.         case $v in
  721.         1) ok='OK, but closedir yields void'
  722.         esac
  723.         break
  724.     fi
  725. done
  726. echo >&3 $ok
  727. echo "#define has_dirent $has_dirent /* Do opendir(), readdir(), closedir() work?  */"
  728. echo "$a#define void_closedir $void_closedir $z/* Does closedir() yield void?  */"
  729.  
  730. $ech >&3 "$0: configuring has_fchmod $dots"
  731. cat >a.c <<EOF
  732. #include "$A_H"
  733. int main() { exitmain(fchmod(fileno(stdin),0) != 0); }
  734. EOF
  735. $PREPARE_CC || exit
  736. if $CL a.c $L >&2 && $aout <a.c && test ! -r a.c
  737. then h=1 ok=OK
  738. else h=0 ok='does not work'
  739. fi
  740. echo >&3 $ok
  741. echo "#define has_fchmod $h /* Does fchmod() work?  */"
  742. rm -f a.c || exit
  743.  
  744. $ech >&3 "$0: configuring has_fflush_input $dots"
  745. cat >a.c <<EOF
  746. #include "$A_H"
  747. int main() { exitmain(fflush(stdin) != 0); }
  748. EOF
  749. $PREPARE_CC || exit
  750. if $CL a.c $L >&2 && $aout <a.c
  751. then h=1 ok=OK
  752. else h=0 ok='does not work'
  753. fi
  754. echo >&3 $ok
  755. echo "#define has_fflush_input $h /* Does fflush() work on input files?  */"
  756. rm -f a.c || exit
  757.  
  758. $ech >&3 "$0: configuring has_fputs $dots"
  759. cat >a.c <<EOF
  760. #include "$A_H"
  761. int main() { exitmain(fputs("Hello\"\nworld", stdout) < 0); }
  762. EOF
  763. Hello='Hello"
  764. world'
  765. $PREPARE_CC a.a || exit
  766. if $CL a.c $L >&2 && $aout >a.a && x=`$aout` && test " $x" = " $Hello"
  767. then h=1 ok=OK
  768. else h=0 ok='does not work'
  769. fi
  770. echo >&3 $ok
  771. echo "#define has_fputs $h /* Does fputs() work?  */"
  772.  
  773. $ech >&3 "$0: configuring has_ftruncate $dots"
  774. cat >a.c <<EOF
  775. #include "$A_H"
  776. /*
  777.  * We'd like to test ftruncate(creat(f,0), 0),
  778.  * since that's the way RCS uses it,
  779.  * but a common bug causes it to fail over NFS.
  780.  * Since we must defend against this bug at run time anyway,
  781.  * we don't bother to check for it at compile time.
  782.  * So we test ftruncate(creat(f,0200), 0) instead.
  783.  */
  784. #if defined(O_CREAT) && defined(O_WRONLY) && defined(S_IWUSR)
  785. #    define creat0200(f) open(f, O_CREAT|O_WRONLY, S_IWUSR)
  786. #else
  787. #    define creat0200(f) creat(f, 0200)
  788. #endif
  789. int
  790. main(argc, argv) int argc; char **argv; {
  791.     int f = creat0200(argv[1]);
  792.     if (f<0 || write(f,"abc",3)!=3 || ftruncate(f,(off_t)0)!=0 || close(f)!=0)
  793.         exitmain(1);
  794.     exitmain(0);
  795. }
  796. EOF
  797. $PREPARE_CC a.a || exit
  798. if ($CL a.c $L && $aout a.a && test -w a.a && test ! -s a.a) >&2
  799. then h=1 ok=OK
  800. else h=0 ok='does not work'
  801. fi
  802. echo >&3 $ok
  803. echo "#define has_ftruncate $h /* Does ftruncate() work?  */"
  804.  
  805. $ech >&3 "$0: configuring has_getuid $dots"
  806. cat >a.c <<EOF
  807. #include "$A_H"
  808. int main() { exitmain(getuid()!=getuid()); }
  809. EOF
  810. $PREPARE_CC || exit
  811. if ($CL a.c $L && $aout) >&2
  812. then has_getuid=1 ok=OK
  813. else has_getuid=0 ok='does not work'
  814. fi
  815. echo >&3 $ok
  816. echo "#define has_getuid $has_getuid /* Does getuid() work?  */"
  817.  
  818. case $has_getuid in
  819. 0)
  820.     a='/* ' z='*/ ' h=?;;
  821. *)
  822.     $ech >&3 "$0: configuring has_getpwuid $dots"
  823.     a= z=
  824.     cat >a.c <<EOF
  825. #include "$A_H"
  826. int main() { exitmain(!getpwuid(0)); }
  827. EOF
  828.     $PREPARE_CC || exit
  829.     if ($CL a.c $L && $aout) >&2
  830.     then h=1 ok=OK
  831.     else h=0 ok='does not work'
  832.     fi
  833.     echo >&3 $ok
  834. esac
  835. echo "$a#define has_getpwuid $h $z/* Does getpwuid() work?  */"
  836.  
  837. $ech >&3 "$0: configuring has_kill $dots"
  838. cat >a.c <<EOF
  839. #include "$A_H"
  840. int main() { exitmain(kill(getpid(), 0) != 0); }
  841. EOF
  842. $PREPARE_CC || exit
  843. if ($CL a.c $L && $aout) >&2
  844. then has_kill=1 ok=OK
  845. else has_kill=0 ok='does not work'
  846. fi
  847. echo >&3 $ok
  848. # Used only by this script, not by RCS, so we don't output it to stdout.
  849.  
  850. $ech >&3 "$0: configuring has_memcmp $dots"
  851. cat >a.c <<EOF
  852. #include "$A_H"
  853. int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); }
  854. EOF
  855. $PREPARE_CC || exit
  856. if ($CL a.c $L && $aout) >&2
  857. then h=1 ok=OK
  858. else h=0 ok='does not work'
  859. fi
  860. echo >&3 $ok
  861. echo "#define has_memcmp $h /* Does memcmp() work?  */"
  862.  
  863. $ech >&3 "$0: configuring has_memcpy $dots"
  864. cat >a.c <<EOF
  865. #include "$A_H"
  866. char a[3];
  867. int
  868. main() {
  869.     memcpy(a,"xy",3);
  870.     exitmain(strcmp(a,"xy")!=0);
  871. }
  872. EOF
  873. $PREPARE_CC || exit
  874. if ($CL a.c $L && $aout) >&2
  875. then h=1 ok=OK
  876. else h=0 ok='does not work'
  877. fi
  878. echo >&3 $ok
  879. echo "#define has_memcpy $h /* Does memcpy() work?  */"
  880.  
  881. $ech >&3 "$0: configuring has_memmove $dots"
  882. cat >a.c <<EOF
  883. #include "$A_H"
  884. static char a[4];
  885. int
  886. main() {
  887.     strcpy(a, "xy");
  888.     memmove(a+1, a, 3);
  889.     exitmain(strcmp(a,"xxy")!=0);
  890. }
  891. EOF
  892. $PREPARE_CC || exit
  893. if ($CL a.c $L && $aout) >&2
  894. then h=1 ok=OK
  895. else h=0 ok='does not work'
  896. fi
  897. echo >&3 $ok
  898. echo "#define has_memmove $h /* Does memmove() work?  */"
  899.  
  900. $ech >&3 "$0: configuring has_mmap, has_madvise, caddr_t, mmap_signal $dots"
  901. rm -f a.c a.d a.e || exit
  902. cat >a.c <<EOF
  903. #define CHAR1 '#' /* the first character in this file */
  904. #include "$A_H"
  905. #if !has_caddr_t
  906.     typedef char *caddr_t;
  907. #endif
  908. static caddr_t a;
  909. static struct stat b;
  910. #ifndef MADVISE_OK
  911. #define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0)
  912. #endif
  913. #ifndef WTERMSIG
  914. #define WTERMSIG(s) ((s)&0177)
  915. #undef WIFSIGNALED /* Avoid 4.3BSD incompatibility with Posix.  */
  916. #endif
  917. #ifndef WIFSIGNALED
  918. #define WIFSIGNALED(s) (((s)&0377) != 0177  &&  WTERMSIG(s) != 0)
  919. #endif
  920. int
  921. main(argc, argv) int argc; char **argv; {
  922.     int s = 0;
  923.     if (fstat(fileno(stdin), &b) != 0) {
  924.         perror("fstat");
  925.         exitmain(1);
  926.     }
  927.     a = mmap(
  928.         (caddr_t)0, b.st_size, PROT_READ, MAP_SHARED,
  929.         fileno(stdin), (off_t)0
  930.     );
  931.     if (a == (caddr_t)-1) {
  932.         perror("mmap");
  933.         exitmain(1);
  934.     }
  935.     if (!MADVISE_OK) {
  936.         perror("madvise");
  937.         exitmain(1);
  938.     }
  939.     if (*a != CHAR1)
  940.         exitmain(1);
  941.     if (1 < argc) {
  942.         pid_t p, w;
  943.         int f = creat(argv[1], 0);
  944.         if (f < 0 || close(f) != 0) {
  945.             perror(argv[1]);
  946.             exitmain(1);
  947.         }
  948.         if ((p = fork()) < 0) {
  949.             perror("fork");
  950.             exitmain(1);
  951.         }
  952.         if (!p)
  953.             /* Refer to nonexistent storage, causing a signal in the child.  */
  954.             _exit(a[b.st_size - 1] == 0);
  955.         while ((w = wait(&s)) != p)
  956.             if (w < 0) {
  957.                 perror("wait");
  958.                 exitmain(1);
  959.             }
  960.         s = WIFSIGNALED(s) ? WTERMSIG(s) : 0;
  961.     }
  962.     if (munmap(a, b.st_size)  !=  0) {
  963.         perror("munmap");
  964.         exitmain(1);
  965.     }
  966.     if (1 < argc) {
  967. #        ifdef SIGBUS
  968.             if (s == SIGBUS) { printf("SIGBUS\n"); s = 0; }
  969. #        endif
  970. #        ifdef SIGSEGV
  971.             if (s == SIGSEGV) { printf("SIGSEGV\n"); s = 0; }
  972. #        endif
  973.         if (s) printf("%d\n", s);
  974.     }
  975.     exitmain(ferror(stdout) || fclose(stdout)!=0);
  976. }
  977. EOF
  978. # AIX 3.2.0 read-only mmap updates last-modified time of file!  Check for this.
  979. sleep 2
  980. cp a.c a.d || exit
  981. sleep 2
  982. a=0 has_mmap=0 mmap_signal=
  983. case `(uname -s -r) 2>/dev/null` in
  984. 'HP-UX '[A-Z].08.07*)
  985.     # mmap can crash the OS under HP-UX 8.07, so don't even test for it.
  986.     ;;
  987. *)
  988.     for has_caddr_t in 1 0
  989.     do
  990.         $PREPARE_CC || exit
  991.         if (
  992.             $CL -Dhas_caddr_t=$has_caddr_t -DMADVISE_OK=1 a.c $L && $aout <a.c
  993.         ) >&2
  994.         then
  995.             case `ls -t a.c a.d` in
  996.             a.d*)
  997.                 has_mmap=1
  998.                 # Find out what signal is sent to RCS
  999.                 # when someone unexpectedly truncates a file
  1000.                 # while RCS has it mmapped.
  1001.                 rm -f a.e && cp a.c a.e &&
  1002.                 mmap_signal=`$aout a.e <a.e` || exit
  1003.                 $PREPARE_CC || exit
  1004.                 ($CL -Dhas_caddr_t=$has_caddr_t a.c $L && $aout <a.c) >&2 && a=1
  1005.                 break
  1006.             esac
  1007.         fi
  1008.     done
  1009. esac
  1010. echo >&3 $has_mmap, $a, $has_caddr_t, $mmap_signal
  1011. echo "#define has_madvise $a /* Does madvise() work?  */"
  1012. echo "#define has_mmap $has_mmap /* Does mmap() work on regular files?  */"
  1013. case $has_caddr_t,$has_mmap in
  1014. 0,1) a= z=;;
  1015. *) a='/* ' z='*/ '
  1016. esac
  1017. echo "${a}typedef char *caddr_t; $z/* mmap argument type */"
  1018. case $mmap_signal in
  1019. ?*) a= z=;;
  1020. '') a='/* ' z='*/ ' mmap_signal='?'
  1021. esac
  1022. echo "$a#define mmap_signal $mmap_signal $z/* signal received if you reference nonexistent part of mmapped file */"
  1023.  
  1024. $ech >&3 "$0: configuring has_rename, bad_a_rename, bad_b_rename $dots"
  1025. cat >a.c <<EOF
  1026. #include "$A_H"
  1027. int main() { exitmain(rename("a.a","a.b") != 0); }
  1028. EOF
  1029. echo a >a.a && $PREPARE_CC a.b || exit
  1030. if ($CL a.c $L && $aout && test -f a.b) >&2
  1031. then
  1032.     h=1
  1033.     rm -f a.a a.b &&
  1034.     echo a >a.a && chmod -w a.a || exit
  1035.     if $aout && test ! -f a.a && test -f a.b
  1036.     then a=0
  1037.     else a=1
  1038.     fi
  1039.     rm -f a.a a.b &&
  1040.     echo a >a.a && echo b >a.b && chmod -w a.b || exit
  1041.     if $aout && test ! -f a.a && test -f a.b
  1042.     then b=0
  1043.     else b=1
  1044.     fi
  1045.     rm -f a.a a.b || exit
  1046. else h=0 a=0 b=0
  1047. fi
  1048. echo >&3 $h, $a, $b
  1049. echo "#define has_rename $h /* Does rename() work?  */"
  1050. echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable?  */"
  1051. echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable?  */"
  1052.  
  1053. $ech >&3 "$0: configuring void, VOID $dots"
  1054. cat >a.c <<EOF
  1055. #include "$A_H"
  1056. void f() {}
  1057. int main() {f(); exitmain(0);}
  1058. EOF
  1059. if $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  1060. then
  1061.     v='(void) '
  1062.     echo '/* typedef int void; */ /* Some ancient compilers need this.  */'
  1063.     ok=OK
  1064. else
  1065.     v=
  1066.     echo 'typedef int void;'
  1067.     ok='your compiler is a museum piece'
  1068. fi
  1069. echo >&3 $ok
  1070. echo "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'.  */"
  1071.  
  1072. case $has_getuid in
  1073. 0)
  1074.     a='/* ' z='*/ ' has_seteuid=?;;
  1075. *)
  1076.     $ech >&3 "$0: configuring has_seteuid $dots"
  1077.     a= z=
  1078.     cat >a.c <<EOF
  1079. #include "$A_H"
  1080. int
  1081. main() {
  1082. /* Guess, don't test.  Ugh.  Testing would require running conf.sh setuid.  */
  1083. /* If the guess is wrong, a setuid RCS will detect the problem at runtime.  */
  1084. #if !_POSIX_VERSION
  1085.     exitmain(1);
  1086. #else
  1087.     exitmain(seteuid(geteuid()) != 0);
  1088. #endif
  1089. }
  1090. EOF
  1091.     $PREPARE_CC || exit
  1092.     if ($CL a.c $L && $aout) >&2
  1093.     then has_seteuid=1 ok='OK, I guess'
  1094.     else has_seteuid=0 ok='does not work'
  1095.     fi
  1096.     echo >&3 $ok
  1097. esac
  1098. echo "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work?  See INSTALL.  */"
  1099.  
  1100. echo "#define has_setreuid 0 /* Does setreuid() work?  See INSTALL.  */"
  1101.  
  1102. $ech >&3 "$0: configuring has_setuid $dots"
  1103. h=$has_seteuid
  1104. case $h in
  1105. 0)
  1106.     cat >a.c <<EOF
  1107. #include "$A_H"
  1108. int main() { exitmain(setuid(getuid()) != 0); }
  1109. EOF
  1110.     $PREPARE_CC || exit
  1111.     ($CL a.c $L && $aout) >&2 && h=1 ok='OK, I guess'
  1112. esac
  1113. echo >&3 $ok
  1114. echo "$a#define has_setuid $h $z/* Does setuid() exist?  */"
  1115.  
  1116. $ech >&3 "$0: configuring has_sigaction $dots"
  1117. cat >a.c <<EOF
  1118. #include "$A_H"
  1119. static sig_atomic_t volatile gotsig;
  1120. static void catchsig(i) int i; { gotsig = 1; }
  1121. int
  1122. main(argc, argv) int argc; char **argv; {
  1123.     struct sigaction s;
  1124.     if (sigaction(SIGINT, (struct sigaction*)0, &s) != 0)
  1125.         exitmain(1);
  1126.     s.sa_handler = catchsig;
  1127.     if (sigaddset(&s.sa_mask, SIGINT) != 0)
  1128.         exitmain(1);
  1129.     if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0)
  1130.         exitmain(1);
  1131. #    if has_kill
  1132.         kill(getpid(), SIGINT);
  1133. #    else
  1134.         raise(SIGINT);
  1135. #    endif
  1136.     exitmain(gotsig != 1);
  1137. }
  1138. EOF
  1139. $PREPARE_CC || exit
  1140. if ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2
  1141. then has_sigaction=1 ok=OK
  1142. else has_sigaction=0 ok='does not work'
  1143. fi
  1144. echo >&3 $ok
  1145. echo "#define has_sigaction $has_sigaction /* Does struct sigaction work?  */"
  1146.  
  1147. $ech >&3 "$0: configuring has_signal, signal_type, sig_zaps_handler $dots"
  1148. case $has_signal,$has_sigaction in
  1149. 1,0)
  1150.     cat >a.c <<EOF
  1151. #include "$A_H"
  1152. #if !defined(signal) && declare_signal
  1153.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  1154. #endif
  1155. static signal_type nothing(i) int i; {}
  1156. int
  1157. main(argc, argv) int argc; char **argv; {
  1158.     signal(SIGINT, nothing);
  1159. #    if has_kill
  1160.         while (--argc)
  1161.             kill(getpid(), SIGINT);
  1162.         exitmain(0);
  1163. #    else
  1164.         /* Pretend that sig_zaps_handler; better safe than sorry.  */
  1165.         exitmain(2 < argc);
  1166. #    endif
  1167. }
  1168. EOF
  1169.     for declare_signal in 1 0
  1170.     do
  1171.         for signal_type in void int
  1172.         do
  1173.             for signal_args in 'P((int))' '()'
  1174.             do
  1175.                 $PREPARE_CC || exit
  1176.                 ($CL \
  1177.                     -Ddeclare_signal=$declare_signal \
  1178.                     -Dhas_kill=$has_kill \
  1179.                     -Dsignal_args="$signal_args" \
  1180.                     -Dsignal_type=$signal_type \
  1181.                         a.c $L && $aout 1) >&2 && break
  1182.             done && break
  1183.         done && break
  1184.     done || {
  1185.         echo >&3 $0: cannot deduce signal_type
  1186.         exit 1
  1187.     }
  1188.     if $aout 1 2 >&2
  1189.     then sig_zaps_handler=0
  1190.     else sig_zaps_handler=1
  1191.     fi;;
  1192. *)
  1193.     signal_type=void
  1194.     sig_zaps_handler=0
  1195. esac
  1196. echo >&3 $has_signal, $signal_type, $sig_zaps_handler
  1197. cat <<EOF
  1198. #define has_signal $has_signal /* Does signal() work?  */
  1199. #define signal_type $signal_type /* type returned by signal handlers */
  1200. #define sig_zaps_handler $sig_zaps_handler /* Must a signal handler reinvoke signal()?  */
  1201. EOF
  1202.  
  1203. a='/* ' z='*/ '
  1204. b='/* ' y='*/ '
  1205. case $has_sigaction in
  1206. 1)
  1207.     h=?;;
  1208. *)
  1209.     $ech >&3 "$0: configuring has_sigblock, sigmask $dots"
  1210.     ok=OK
  1211.     a= z=
  1212.     cat >a.c <<EOF
  1213. #include "$A_H"
  1214. #include <signal.h>
  1215. #if define_sigmask
  1216. #    define sigmask(s) (1 << ((s)-1))
  1217. #endif
  1218. int
  1219. main() {
  1220.     sigblock(sigmask(SIGHUP));
  1221. #    if has_kill
  1222.         exitmain(kill(getpid(), SIGHUP) != 0);
  1223. #    else
  1224.         exitmain(raise(SIGHUP) != 0);
  1225. #    endif
  1226. }
  1227. EOF
  1228.     if
  1229.         $PREPARE_CC || exit
  1230.         ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2
  1231.     then h=1
  1232.     elif
  1233.         $PREPARE_CC || exit
  1234.         ($CL -Dhas_kill=$has_kill -Ddefine_sigmask=1 a.c $L && $aout) >&2
  1235.     then h=1 b= y= ok='definition needed'
  1236.     else h=0
  1237.     fi
  1238.     echo >&3 "$h, $ok"
  1239. esac
  1240. echo "$a#define has_sigblock $h $z/* Does sigblock() work?  */"
  1241. echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number.  */"
  1242.  
  1243. $ech >&3 "$0: configuring fread_type, freadarg_type $dots"
  1244. cat >a.c <<EOF
  1245. #define CHAR1 '#' /* the first character in this file */
  1246. #include "$A_H"
  1247. #if !defined(fread) && declare_fread
  1248.     fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  1249. #endif
  1250. int
  1251. main() {
  1252.     char b;
  1253.     exitmain(!(
  1254.         fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1  &&
  1255.         b==CHAR1
  1256.     ));
  1257. }
  1258. EOF
  1259. for declare_fread in 1 0
  1260. do
  1261.     for fread_type in ssize_t size_t int unsigned
  1262.     do
  1263.         for freadarg_type in size_t ssize_t unsigned int
  1264.         do
  1265.             $PREPARE_CC || exit
  1266.             (
  1267.                 $CL \
  1268.                     -Ddeclare_fread=$declare_fread \
  1269.                     -Dfreadarg_type=$freadarg_type \
  1270.                     -Dfread_type=$fread_type \
  1271.                     a.c $L &&
  1272.                 $aout <a.c
  1273.             ) >&2 && break
  1274.         done && break
  1275.     done && break
  1276. done || {
  1277.     echo >&3 $0: cannot deduce fread types
  1278.     exit 1
  1279. }
  1280. echo >&3 $fread_type, $freadarg_type
  1281. cat <<EOF
  1282. typedef $fread_type fread_type; /* type returned by fread() and fwrite() */
  1283. typedef $freadarg_type freadarg_type; /* type of their size arguments */
  1284. EOF
  1285.  
  1286. $ech >&3 "$0: configuring malloc_type $dots"
  1287. cat >a.c <<EOF
  1288. #include "$A_H"
  1289. typedef void *malloc_type;
  1290. #ifndef malloc
  1291.     malloc_type malloc();
  1292. #endif
  1293. static malloc_type identity P((malloc_type));
  1294. static malloc_type identity(x) malloc_type x; { return x; }
  1295. int main() { exitmain(!identity(malloc(1))); }
  1296. EOF
  1297. if $PREPARE_CC && $CS a.c $LS >&2 && $CS_OK
  1298. then t=void
  1299. else t=char
  1300. fi
  1301. echo >&3 $t
  1302. echo "typedef $t *malloc_type; /* type returned by malloc() */"
  1303.  
  1304. $ech >&3 "$0: configuring has_getcwd $dots"
  1305. cat >a.c <<EOF
  1306. #include "$A_H"
  1307. #ifndef getcwd
  1308.     char *getcwd();
  1309. #endif
  1310. static char buf[10000];
  1311. int main() { exitmain(!getcwd(buf,10000)); }
  1312. EOF
  1313. $PREPARE_CC || exit
  1314. if ($CL a.c $L && $aout) >&2
  1315. then has_getcwd=1 ok=OK
  1316. else has_getcwd=0 ok='does not work'
  1317. fi
  1318. echo >&3 $ok
  1319. echo "#define has_getcwd $has_getcwd /* Does getcwd() work?  */"
  1320.  
  1321. case $has_getcwd in
  1322. 1)
  1323.     a='/* ' z='*/ ' h=?;;
  1324. *)
  1325.     a= z=
  1326.     $ech >&3 "$0: configuring has_getwd $dots"
  1327.     cat >a.c <<EOF
  1328. #include "$A_H"
  1329. #include <sys/param.h>
  1330. #ifndef getwd
  1331.     char *getwd();
  1332. #endif
  1333. static char buf[MAXPATHLEN];
  1334. int main() { exitmain(!getwd(buf)); }
  1335. EOF
  1336.     $PREPARE_CC || exit
  1337.     if ($CL a.c $L && $aout) >&2
  1338.     then h=1 ok=OK
  1339.     else h=0 ok='does not work'
  1340.     fi
  1341.     echo >&3 $ok
  1342. esac
  1343. echo "$a#define has_getwd $h $z/* Does getwd() work?  */"
  1344. echo "#define needs_getabsname 0 /* Must we define getabsname?  */"
  1345.  
  1346. $ech >&3 "$0: configuring has_mktemp $dots"
  1347. cat >a.c <<EOF
  1348. #include "$A_H"
  1349. #ifndef mktemp
  1350.     char *mktemp();
  1351. #endif
  1352. int
  1353. main() {
  1354.     char b[9];
  1355.     strcpy(b, "a.XXXXXX");
  1356.     exitmain(!mktemp(b));
  1357. }
  1358. EOF
  1359. $PREPARE_CC || exit
  1360. if ($CL a.c $L && $aout) >&2
  1361. then h=1 ok=OK
  1362. else h=0 ok=absent
  1363. fi
  1364. echo >&3 $ok
  1365. echo "#define has_mktemp $h /* Does mktemp() work?  */"
  1366.  
  1367. : configuring has_NFS
  1368. echo "#define has_NFS 1 /* Might NFS be used?  */"
  1369.  
  1370. case $has_signal,$has_sigaction in
  1371. 1,0)
  1372.     h=0;;
  1373. *)
  1374.     $ech >&3 "$0: configuring has_psiginfo $dots"
  1375.     cat >a.c <<EOF
  1376. #include "$A_H"
  1377. static signal_type
  1378. catchsig(s, i, c) int s; siginfo_t *i; ucontext_t *c; {
  1379.     if (i)
  1380.         psiginfo(i, "test");
  1381.     exit(0);
  1382. }
  1383. int
  1384. main() {
  1385.     struct sigaction s;
  1386.     if (sigaction(SIGINT, (struct sigaction*)0, &s) != 0)
  1387.         exitmain(1);
  1388.     s.sa_handler = catchsig;
  1389.     if (sigaddset(&s.sa_mask, SIGINT) != 0)
  1390.         exitmain(1);
  1391.     s.sa_flags |= SA_SIGINFO;
  1392.     if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0)
  1393.         exitmain(1);
  1394. #    if has_kill
  1395.         kill(getpid(), SIGINT);
  1396. #    else
  1397.         raise(SIGINT);
  1398. #    endif
  1399.     exitmain(1);
  1400. }
  1401. EOF
  1402.     $PREPARE_CC || exit
  1403.     if ($CL a.c $L && $aout) >&2
  1404.     then h=1 ok=OK
  1405.     else h=0 ok=absent
  1406.     fi
  1407.     echo >&3 $ok
  1408. esac
  1409. echo "#define has_psiginfo $h /* Does psiginfo() work?  */"
  1410.  
  1411. case $has_signal in
  1412. 1)
  1413.     $ech >&3 "$0: configuring has_psignal $dots"
  1414.     cat >a.c <<EOF
  1415. #include "$A_H"
  1416. int main() { psignal(SIGINT, ""); exitmain(0); }
  1417. EOF
  1418.     $PREPARE_CC || exit
  1419.     if ($CL a.c $L && $aout) >&2
  1420.     then has_psignal=1 ok=OK
  1421.     else has_psignal=0 ok=absent
  1422.     fi
  1423.     echo >&3 $ok;;
  1424. *)    has_psignal=0
  1425. esac
  1426. echo "#define has_psignal $has_psignal /* Does psignal() work?  */"
  1427.  
  1428. case $has_signal,$has_psignal in
  1429. 1,0)
  1430.     $ech >&3 "$0: configuring has_sys_siglist $dots"
  1431.     cat >a.c <<EOF
  1432. #include "$A_H"
  1433. #if !defined(sys_siglist) && declare_sys_siglist
  1434.     extern char const * const sys_siglist[];
  1435. #endif
  1436. int main() { exitmain(!sys_siglist[1][0]); }
  1437. EOF
  1438.     $PREPARE_CC || exit
  1439.     h=0 ok=absent
  1440.     for d in 1 0
  1441.     do ($CL -Ddeclare_sys_siglist=$d a.c $L && $aout) >&2 &&
  1442.         h=1 && ok=OK && break
  1443.     done
  1444.     echo >&3 $ok
  1445.     a= z=;;
  1446. *)    h=? a='/* ' z='*/ '
  1447. esac
  1448. echo "$a#define has_sys_siglist $h $z/* Does sys_siglist[] work?  */"
  1449.  
  1450. $ech >&3 "$0: configuring strchr $dots"
  1451. cat >a.c <<EOF
  1452. #include "$A_H"
  1453. #ifndef strchr
  1454.     char *strchr();
  1455. #endif
  1456. int main() {exitmain(!strchr("abc", 'c'));}
  1457. EOF
  1458. $PREPARE_CC || exit
  1459. if ($CL a.c $L && $aout) >&2
  1460. then a='/* ' z='*/ ' ok=OK
  1461. else a= z= ok='does not work'
  1462. fi
  1463. echo >&3 $ok
  1464. echo "$a#define strchr index $z/* Use old-fashioned name for strchr()?  */"
  1465.  
  1466. $ech >&3 "$0: configuring strrchr $dots"
  1467. cat >a.c <<EOF
  1468. #include "$A_H"
  1469. #ifndef strrchr
  1470.     char *strrchr();
  1471. #endif
  1472. int main() {exitmain(!strrchr("abc", 'c'));}
  1473. EOF
  1474. $PREPARE_CC || exit
  1475. if ($CL a.c $L && $aout) >&2
  1476. then a='/* ' z='*/ ' ok=OK
  1477. else a= z= ok='does not work'
  1478. fi
  1479. echo >&3 $ok
  1480. echo "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()?  */"
  1481.  
  1482. $ech >&3 "$0: configuring bad_unlink $dots"
  1483. cat >a.c <<EOF
  1484. #include "$A_H"
  1485. int main() { exitmain(unlink("a.c") != 0); }
  1486. EOF
  1487. $PREPARE_CC && chmod -w a.c || exit
  1488. if ($CL a.c $L && $aout) >&2 && test ! -f a.c
  1489. then b=0 ok=OK
  1490. else b=1 ok='will work around bug'
  1491. fi
  1492. rm -f a.c || exit
  1493. echo >&3 $ok
  1494. echo "#define bad_unlink $b /* Does unlink() fail on unwritable files?  */"
  1495.  
  1496. $ech >&3 "$0: configuring has_vfork $dots"
  1497. cat >a.c <<EOF
  1498. #include "$A_H"
  1499. #if !TRY_VFORK
  1500. #    undef vfork
  1501. #    define vfork fork
  1502. #endif
  1503. #if !TRY_WAITPID
  1504. #    undef waitpid
  1505. #    define waitpid(p,s,o) wait(s)
  1506. #endif
  1507.  
  1508. int
  1509. main() {
  1510.     pid_t parent = getpid();
  1511.     pid_t child = vfork();
  1512.  
  1513.     if (child == 0) {
  1514.         /*
  1515.          * On sparc systems, changes by the child to local and incoming
  1516.          * argument registers are propagated back to the parent.
  1517.          * The compiler is told about this with #include <vfork.h>,
  1518.          * but some compilers (e.g. gcc -O) don't grok <vfork.h>.
  1519.          * Test for this by using lots of local variables, at least
  1520.          * as many local variables as 'main' has allocated so far
  1521.          * including compiler temporaries.  4 locals are enough for
  1522.          * gcc 1.40.3 on a sparc, but we use 8 to be safe.
  1523.          * A buggy compiler should reuse the register of 'parent'
  1524.          * for one of the local variables, since it will think that
  1525.          * 'parent' can't possibly be used any more in this routine.
  1526.          * Assigning to the local variable will thus munge 'parent'
  1527.          * in the parent process.
  1528.          */
  1529.         pid_t
  1530.             p = getpid(),
  1531.             p1 = getpid(), p2 = getpid(),
  1532.             p3 = getpid(), p4 = getpid(),
  1533.             p5 = getpid(), p6 = getpid(),
  1534.             p7 = getpid();
  1535.         /*
  1536.          * Convince the compiler that p..p7 are live; otherwise, it might
  1537.          * use the same hardware register for all 8 local variables.
  1538.          */
  1539.         if (p!=p1 || p!=p2 || p!=p3 || p!=p4 || p!=p5 || p!=p6 || p!=p7)
  1540.             _exit(1);
  1541.  
  1542.         /*
  1543.          * On some systems (e.g. IRIX 3.3),
  1544.          * vfork doesn't separate parent from child file descriptors.
  1545.          * If the child closes a descriptor before it execs or exits,
  1546.          * this munges the parent's descriptor as well.
  1547.          * Test for this by closing stdout in the child.
  1548.          */
  1549.         _exit(close(fileno(stdout)) != 0);
  1550.  
  1551.     } else {
  1552.         int status;
  1553.         struct stat st;
  1554.         exit(
  1555.             /* Was there some problem with vforking?  */
  1556.             child < 0
  1557.  
  1558.             /* Was there some problem in waiting for the child?  */
  1559.             || waitpid(child, &status, 0) != child
  1560.  
  1561.             /* Did the child fail?  (This shouldn't happen.)  */
  1562.             || status
  1563.  
  1564.             /* Did the vfork/compiler bug occur?  */
  1565.             || parent != getpid()
  1566.  
  1567.             /* Did the file descriptor bug occur?  */
  1568.             || fstat(fileno(stdout), &st) != 0
  1569.         );
  1570.     }
  1571. }
  1572. EOF
  1573. $PREPARE_CC || exit
  1574. if ($CL -DTRY_VFORK=1 a.c $L && $aout) >&2
  1575. then has_vfork=1 ok=OK
  1576. else has_vfork=0 ok='absent or broken'
  1577. fi
  1578. echo >&3 $ok
  1579. echo "#define has_vfork $has_vfork /* Does vfork() work?  */"
  1580. h=$has_vfork
  1581. case $h in
  1582. 0)
  1583.     $ech >&3 "$0: configuring has_fork $dots"
  1584.     $PREPARE_CC || exit
  1585.     ok='does not work'
  1586.     ($CL a.c $L && $aout) >&2 && h=1 ok=OK
  1587.     echo >&3 $ok
  1588. esac
  1589. echo "#define has_fork $h /* Does fork() work?  */"
  1590. $PREPARE_CC || exit
  1591. $ech >&3 "$0: configuring has_waitpid $dots"
  1592. if ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && $aout) >&2
  1593. then h=1 ok=OK
  1594. else h=0 ok='does not work'
  1595. fi
  1596. echo >&3 $ok
  1597. echo "#define has_spawn 0 /* Does spawn*() work?  */"
  1598. echo "#define has_waitpid $h /* Does waitpid() work?  */"
  1599. echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */'
  1600.  
  1601. $ech >&3 "$0: configuring has_printf_dot $dots"
  1602. cat >a.c <<EOF
  1603. #include "$A_H"
  1604. int main() { printf("%.2d", 1); exitmain(ferror(stdout) || fclose(stdout)!=0); }
  1605. EOF
  1606. $PREPARE_CC && $CL a.c $L >&2 && r=`$aout` || exit
  1607. case $r in
  1608. 01)    h=1 ok=OK;;
  1609. *)    h=0 ok='does not work'
  1610. esac
  1611. echo >&3 $ok
  1612. echo "#define has_printf_dot $h /* Does \"%.2d\" print leading 0?  */"
  1613.  
  1614. $ech >&3 "$0: configuring has_vfprintf, has_attribute_format_printf $dots"
  1615. cat >a.c <<EOF
  1616. #include "$A_H"
  1617. #if has_attribute_format_printf
  1618. #    define printf_string(m, n) __attribute__((format(printf, m, n)))
  1619. #else
  1620. #    define printf_string(m, n)
  1621. #endif
  1622. int p P((char const*,...)) printf_string(1, 2);
  1623. #if has_prototypes
  1624. int p(char const*format,...)
  1625. #else
  1626. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1627. #endif
  1628. {
  1629.     int r;
  1630.     va_list args;
  1631.     vararg_start(args, format);
  1632.     r = vfprintf(stderr, format, args);
  1633.     va_end(args);
  1634.     return r;
  1635. }
  1636. int main() { exitmain(p("hello") != 5); }
  1637. EOF
  1638. $PREPARE_CC || exit
  1639. h=0 p=0
  1640. if ($CL a.c $L && sh -c 'pid=$$; (sleep 3; kill $pid)& exec '$aout) >&2
  1641. then
  1642.     h=1
  1643.     $PREPARE_CC && $CS -Dhas_attribute_format_printf=1 a.c >&2 &&
  1644.     $CS_OK && p=1
  1645. else
  1646.     status=$?
  1647.     sh -c 'pid=$$; (sleep 3; kill $pid)& exec sleep 6' >&2
  1648.     if test $? = $status
  1649.     then
  1650.         echo >&3 "$0: stdio library loops forever.  Giving up.
  1651. $0: (Perhaps you are using Solaris 2.x /usr/ucb/cc?)
  1652. $0: Please use a working stdio library instead."
  1653.         exit 1
  1654.     fi
  1655. fi
  1656. echo >&3 $h, $p
  1657. cat <<EOF
  1658. #define has_vfprintf $h /* Does vfprintf() work?  */
  1659. #define has_attribute_format_printf $p /* Does __attribute__((format(printf,N,N+1))) work?  */
  1660. #if has_attribute_format_printf
  1661. #    define printf_string(m, n) __attribute__((format(printf, m, n)))
  1662. #else
  1663. #    define printf_string(m, n)
  1664. #endif
  1665. #if has_attribute_format_printf && has_attribute_noreturn
  1666.     /* Work around a bug in GCC 2.5.x.  */
  1667. #    define printf_string_exiting(m, n) __attribute__((format(printf, m, n), noreturn))
  1668. #else
  1669. #    define printf_string_exiting(m, n) printf_string(m, n) exiting
  1670. #endif
  1671. EOF
  1672.  
  1673. case $h in
  1674. 1)
  1675.     h=? a='/* ' z='*/ ';;
  1676. *)
  1677.     $ech >&3 "$0: configuring has__doprintf $dots"
  1678.     a= z=
  1679.     cat >a.c <<EOF
  1680. #include "$A_H"
  1681. #if has_prototypes
  1682. static int
  1683. p(char const*format,...)
  1684. #else
  1685. /*VARARGS1*/ static int p(format, va_alist) char *format; va_dcl
  1686. #endif
  1687. {
  1688.     va_list args;
  1689.     vararg_start(args, format);
  1690. #    if TRY__DOPRINTF
  1691.         _doprintf(stderr, format, args);
  1692. #    else
  1693.         _doprnt(format, args, stderr);
  1694. #    endif
  1695.     va_end(args);
  1696. }
  1697. int main() { p(""); exitmain(0); }
  1698. EOF
  1699.     $PREPARE_CC || exit
  1700.     if ($CL -DTRY__DOPRINTF=1 a.c $L && $aout) >&2
  1701.     then h=1 ok=OK
  1702.     else h=0 ok='does not work'
  1703.     fi
  1704.     echo >&3 $ok
  1705. esac
  1706. echo "$a#define has__doprintf $h $z/* Does _doprintf() work?  */"
  1707. case $h in
  1708. 0)
  1709.     $ech >&3 "$0: configuring has__doprnt $dots"
  1710.     $PREPARE_CC || exit
  1711.     if ($CL a.c $L && $aout) >&2
  1712.     then h=1 ok=OK
  1713.     else h=0 ok='does not work'
  1714.     fi
  1715.     echo >&3 $ok
  1716.     a= z=;;
  1717. *)
  1718.     h=? a='/* ' z='*/ '
  1719. esac
  1720. echo "$a#define has__doprnt $h $z/* Does _doprnt() work?  */"
  1721.  
  1722. $ech >&3 "$0: configuring EXIT_FAILURE $dots"
  1723. cat >a.c <<EOF
  1724. #include "$A_H"
  1725. int main() { exitmain(EXIT_FAILURE); }
  1726. EOF
  1727. $PREPARE_CC || exit
  1728. if $CL a.c $L >&2 && $aout
  1729. then a= z= ok='will work around bug'
  1730. else a='/* ' z='*/ ' ok=OK
  1731. fi
  1732. echo >&3 $ok
  1733. echo "$a#undef EXIT_FAILURE $z/* Uncomment this if EXIT_FAILURE is broken.  */"
  1734.  
  1735. : configuring large_memory
  1736. echo "#define large_memory $has_mmap /* Can main memory hold entire RCS files?  */"
  1737.  
  1738. $ech >&3 "$0: configuring LONG_MAX $dots"
  1739. cat >a.c <<EOF
  1740. #include "$A_H"
  1741. static unsigned long ulong_max;
  1742. static long long_max;
  1743. int
  1744. main() {
  1745.     ulong_max--;
  1746.     long_max = ulong_max >> 1;
  1747.     printf("#ifndef LONG_MAX\n");
  1748.     printf("#define LONG_MAX %ldL /* long maximum */\n", long_max);
  1749.     printf("#endif\n");
  1750.     exitmain(ferror(stdout) || fclose(stdout)!=0);
  1751. }
  1752. EOF
  1753. $PREPARE_CC && $CL a.c $L >&2 && $aout || exit
  1754. echo >&3 OK
  1755.  
  1756. : configuring same_file
  1757. echo "/* Do struct stat s and t describe the same file?  Answer d if unknown.  */"
  1758. echo "#define same_file(s,t,d) ((s).st_ino==(t).st_ino && (s).st_dev==(t).st_dev)"
  1759.  
  1760. $ech >&3 "$0: configuring struct utimbuf $dots"
  1761. cat >a.c <<EOF
  1762. #include "$A_H"
  1763. static struct utimbuf s;
  1764. int main() { s.actime = s.modtime = 1; exitmain(utime("a.c", &s) != 0); }
  1765. EOF
  1766. $PREPARE_CC || exit
  1767. if ($CL a.c $L && $aout) >&2
  1768. then h=1 ok=OK
  1769. else h=0 ok='does not work'
  1770. fi
  1771. echo >&3 $ok
  1772. echo "#define has_utimbuf $h /* Does struct utimbuf work?  */"
  1773.  
  1774. : configuring CO
  1775. echo "#define CO \"${RCSPREFIX}co\" /* name of 'co' program */"
  1776.  
  1777. : configuring COMPAT2
  1778. echo "#define COMPAT2 $COMPAT2 /* Are version 2 files supported?  */"
  1779.  
  1780. : configuring DIFF
  1781. echo "#define DIFF \"${DIFF}\" /* name of 'diff' program */"
  1782.  
  1783. : configuring DIFF3
  1784. echo "#define DIFF3 \"${DIFF3}\" /* name of 'diff3' program */"
  1785.  
  1786. : configuring DIFF3_A
  1787. echo "#define DIFF3_A $DIFF3_A /* Does diff3 -A work?  */"
  1788.  
  1789. : configuring DIFF3_BIN
  1790. echo "#define DIFF3_BIN $DIFF3_BIN /* Is diff3 user-visible (not the /usr/lib auxiliary)?  */"
  1791.  
  1792. : configuring DIFF_FLAGS
  1793. dfs=
  1794. for df in $DIFF_FLAGS
  1795. do dfs="$dfs, \"${df}\""
  1796. done
  1797. echo "#define DIFF_FLAGS $dfs /* Make diff output suitable for RCS.  */"
  1798.  
  1799. : configuring DIFF_L
  1800. echo "#define DIFF_L $DIFF_L /* Does diff -L work? */"
  1801.  
  1802. : configuring DIFF_SUCCESS, DIFF_FAILURE, DIFF_TROUBLE
  1803. cat <<EOF
  1804. #define DIFF_SUCCESS $DIFF_SUCCESS /* DIFF status if no differences are found */
  1805. #define DIFF_FAILURE $DIFF_FAILURE /* DIFF status if differences are found */
  1806. #define DIFF_TROUBLE $DIFF_TROUBLE /* DIFF status if trouble */
  1807. EOF
  1808.  
  1809. : configuring ED
  1810. echo "#define ED \"${ED}\" /* name of 'ed' program (used only if !DIFF3_BIN) */"
  1811.  
  1812. : configuring MERGE
  1813. echo "#define MERGE \"${RCSPREFIX}merge\" /* name of 'merge' program */"
  1814.  
  1815. : configuring '*SLASH*', ROOTPATH, TMPDIR, X_DEFAULT
  1816. case ${PWD-`pwd`} in
  1817. /*) # Posix
  1818.     SLASH=/
  1819.     qSLASH="'/'"
  1820.     SLASHes=$qSLASH
  1821.     isSLASH='#define isSLASH(c) ((c) == SLASH)'
  1822.     ROOTPATH='isSLASH((p)[0])'
  1823.     X_DEFAULT=",v$SLASH";;
  1824. ?:[/\\\\]*) # MS-DOS # \\\\ instead of \\ doesn't hurt, and avoids common bugs
  1825.     SLASH='\'
  1826.     qSLASH="'\\\\'"
  1827.     SLASHes="$qSLASH: case '/': case ':'"
  1828.     isSLASH='int isSLASH P((int));'
  1829.     ROOTPATH="(isSLASH((p)[0]) || (p)[0] && (p)[1]==':')"
  1830.     X_DEFAULT="$SLASH,v";;
  1831. *)
  1832.     echo >&3 $0: cannot deduce SLASH
  1833.     exit 1
  1834. esac
  1835. cat <<EOF
  1836. #define TMPDIR "${SLASH}tmp" /* default directory for temporary files */
  1837. #define SLASH $qSLASH /* principal filename separator */
  1838. #define SLASHes $SLASHes /* \`case SLASHes:' labels all filename separators */
  1839. $isSLASH /* Is arg a filename separator?  */
  1840. #define ROOTPATH(p) $ROOTPATH /* Is p an absolute pathname?  */
  1841. #define X_DEFAULT "$X_DEFAULT" /* default value for -x option */
  1842. EOF
  1843.  
  1844. $ech >&3 "$0: configuring SLASHSLASH_is_SLASH $dots"
  1845. cat >a.c <<EOF
  1846. #include "$A_H"
  1847. static struct stat s, ss;
  1848. static char f[3];
  1849. int
  1850. main() {
  1851.     f[0] = SLASH; if (stat(f, &s ) != 0) exitmain(1);
  1852.     f[1] = SLASH; if (stat(f, &ss) != 0) exitmain(1);
  1853.     exitmain(!same_file(s, ss, 0));
  1854. }
  1855. EOF
  1856. $PREPARE_CC || exit
  1857. if ($CL a.c $L && $aout) >&2
  1858. then eq=1 ok=OK
  1859. else eq=0 ok=no
  1860. fi
  1861. echo >&3 $ok
  1862. echo "#define SLASHSLASH_is_SLASH $eq /* Are // and / the same directory?  */"
  1863.  
  1864. $ech >&3 "$0: configuring ALL_ABSOLUTE, DIFF_ABSOLUTE $dots"
  1865. cat >a.c <<EOF
  1866. #include "$A_H"
  1867. #ifndef isSLASH
  1868. static int
  1869. isSLASH(c) int c; {
  1870.     switch (c) { case SLASHes: return 1; } return 0;
  1871. }
  1872. #endif
  1873. int
  1874. main(argc, argv) int argc; char **argv; {
  1875.     exitmain(1<argc && !ROOTPATH(argv[1]));
  1876. }
  1877. EOF
  1878. $PREPARE_CC && ($CL a.c $L && $aout) >&2 || exit
  1879. a=1
  1880. for i in "$DIFF" "$DIFF3" "$ED" "$RCSPREFIX" "$SENDMAIL"
  1881. do
  1882.     case $i in
  1883.     \"*\") i=`expr "$i" : '"\(.*\)"'`
  1884.     esac
  1885.     case $i in
  1886.     ?*) $aout "$i" || { a=0; break; }
  1887.     esac
  1888. done
  1889. echo "#define ALL_ABSOLUTE $a /* Do all subprograms satisfy ROOTPATH?  */"
  1890. if $aout "$DIFF"
  1891. then a=1
  1892. else a=0
  1893. fi
  1894. echo "#define DIFF_ABSOLUTE $a /* Is ROOTPATH(DIFF) true?  */"
  1895. echo >&3 OK
  1896.  
  1897. : configuring SENDMAIL
  1898. case $SENDMAIL in
  1899. '') a='/* ' z='*/ ';;
  1900. *) a= z=
  1901. esac
  1902. echo "$a#define SENDMAIL $SENDMAIL $z/* how to send mail */"
  1903.  
  1904. : configuring TZ_must_be_set
  1905. echo "#define TZ_must_be_set 0 /* Must TZ be set for gmtime() to work?  */"
  1906.  
  1907.  
  1908. $ech >&3 "$0: configuring standard library declarations $dots"
  1909.  
  1910. cat <<'EOF'
  1911.  
  1912.  
  1913.  
  1914. /* Adjust the following declarations as needed.  */
  1915. EOF
  1916.  
  1917. cat >a.ha <<EOF
  1918.  
  1919.  
  1920. /* The rest is for the benefit of non-standard, traditional hosts.  */
  1921. /* Don't bother to declare functions that in traditional hosts do not appear, */
  1922. /* or are declared in .h files, or return int or void.  */
  1923.  
  1924.  
  1925. /* traditional BSD */
  1926.  
  1927. #if has_sys_siglist && !defined(sys_siglist)
  1928.     extern char const * const sys_siglist[];
  1929. #endif
  1930.  
  1931.  
  1932. /* Posix (ISO/IEC 9945-1: 1990 / IEEE Std 1003.1-1990) */
  1933.  
  1934. /* <fcntl.h> */
  1935. #ifdef O_CREAT
  1936. #    define open_can_creat 1
  1937. #else
  1938. #    define open_can_creat 0
  1939. #    define O_RDONLY 0
  1940. #    define O_WRONLY 1
  1941. #    define O_RDWR 2
  1942. #    define O_CREAT 01000
  1943. #    define O_TRUNC 02000
  1944. #endif
  1945. #ifndef O_EXCL
  1946. #define O_EXCL 0
  1947. #endif
  1948.  
  1949. /* <sys/stat.h> */
  1950. #ifndef S_IRUSR
  1951. #    ifdef S_IREAD
  1952. #        define S_IRUSR S_IREAD
  1953. #    else
  1954. #        define S_IRUSR 0400
  1955. #    endif
  1956. #    ifdef S_IWRITE
  1957. #        define S_IWUSR S_IWRITE
  1958. #    else
  1959. #        define S_IWUSR (S_IRUSR/2)
  1960. #    endif
  1961. #endif
  1962. #ifndef S_IRGRP
  1963. #    if has_getuid
  1964. #        define S_IRGRP (S_IRUSR / 0010)
  1965. #        define S_IWGRP (S_IWUSR / 0010)
  1966. #        define S_IROTH (S_IRUSR / 0100)
  1967. #        define S_IWOTH (S_IWUSR / 0100)
  1968. #    else
  1969.         /* single user OS -- not Posix or Unix */
  1970. #        define S_IRGRP 0
  1971. #        define S_IWGRP 0
  1972. #        define S_IROTH 0
  1973. #        define S_IWOTH 0
  1974. #    endif
  1975. #endif
  1976. #ifndef S_ISREG
  1977. #define S_ISREG(n) (((n) & S_IFMT) == S_IFREG)
  1978. #endif
  1979.  
  1980. /* <sys/wait.h> */
  1981. #ifndef WEXITSTATUS
  1982. #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  1983. #undef WIFEXITED /* Avoid 4.3BSD incompatibility with Posix.  */
  1984. #endif
  1985. #ifndef WIFEXITED
  1986. #define WIFEXITED(stat_val) (((stat_val)  &  0377) == 0)
  1987. #endif
  1988. #ifndef WTERMSIG
  1989. #define WTERMSIG(stat_val) ((stat_val) & 0177)
  1990. #undef WIFSIGNALED /* Avoid 4.3BSD incompatibility with Posix.  */
  1991. #endif
  1992. #ifndef WIFSIGNALED
  1993. #define WIFSIGNALED(stat_val) ((unsigned)(stat_val) - 1  <  0377)
  1994. #endif
  1995.  
  1996. /* <unistd.h> */
  1997. char *getlogin P((void));
  1998. #ifndef STDIN_FILENO
  1999. #    define STDIN_FILENO 0
  2000. #    define STDOUT_FILENO 1
  2001. #    define STDERR_FILENO 2
  2002. #endif
  2003. #if has_fork && !has_vfork
  2004. #    undef vfork
  2005. #    define vfork fork
  2006. #endif
  2007. #if has_getcwd || !has_getwd
  2008.     char *getcwd P((char*,size_t));
  2009. #else
  2010.     char *getwd P((char*));
  2011. #endif
  2012. #if has_setuid && !has_seteuid
  2013. #    undef seteuid
  2014. #    define seteuid setuid
  2015. #endif
  2016. #if has_spawn
  2017. #    if ALL_ABSOLUTE
  2018. #        define spawn_RCS spawnv
  2019. #    else
  2020. #        define spawn_RCS spawnvp
  2021. #    endif
  2022. #else
  2023. #    if ALL_ABSOLUTE
  2024. #        define exec_RCS execv
  2025. #    else
  2026. #        define exec_RCS execvp
  2027. #    endif
  2028. #endif
  2029.  
  2030. /* utime.h */
  2031. #if !has_utimbuf
  2032.     struct utimbuf { time_t actime, modtime; };
  2033. #endif
  2034.  
  2035.  
  2036. /* Standard C library */
  2037.  
  2038. /* <stdio.h> */
  2039. #ifndef L_tmpnam
  2040. #define L_tmpnam 32 /* power of 2 > sizeof("/usr/tmp/xxxxxxxxxxxxxxx") */
  2041. #endif
  2042. #ifndef SEEK_SET
  2043. #define SEEK_SET 0
  2044. #endif
  2045. #ifndef SEEK_CUR
  2046. #define SEEK_CUR 1
  2047. #endif
  2048. #if has_mktemp
  2049.     char *mktemp P((char*)); /* traditional */
  2050. #else
  2051.     char *tmpnam P((char*));
  2052. #endif
  2053.  
  2054. /* <stdlib.h> */
  2055. char *getenv P((char const*));
  2056. void _exit P((int)) exiting;
  2057. void exit P((int)) exiting;
  2058. malloc_type malloc P((size_t));
  2059. malloc_type realloc P((malloc_type,size_t));
  2060. #ifndef EXIT_FAILURE
  2061. #define EXIT_FAILURE 1
  2062. #endif
  2063. #ifndef EXIT_SUCCESS
  2064. #define EXIT_SUCCESS 0
  2065. #endif
  2066.  
  2067. /* <string.h> */
  2068. char *strcpy P((char*,char const*));
  2069. char *strchr P((char const*,int));
  2070. char *strrchr P((char const*,int));
  2071. void *memcpy P((void*,void const*,size_t));
  2072. #if has_memmove
  2073.     void *memmove P((void*,void const*,size_t));
  2074. #endif
  2075.  
  2076. /* <time.h> */
  2077. time_t time P((time_t*));
  2078. EOF
  2079.  
  2080. cat >a.c <<EOF
  2081. #include "$A_H"
  2082. #define a 0
  2083. #define b 1
  2084. #if H==a
  2085. #    include "a.ha"
  2086. #else
  2087. #    include "a.hb"
  2088. #endif
  2089. int main() { exitmain(0); }
  2090. EOF
  2091.  
  2092. # Comment out lines in a.ha that the compiler rejects.
  2093. # a.ha may not contain comments that cross line boundaries.
  2094. # Leave the result in a.h$H.
  2095. H=a L=1
  2096. U=`wc -l <a.ha | sed 's| ||g'`
  2097. commentOut='s|^[^#/][^/]*|/* & */|'
  2098.  
  2099. until
  2100.     test $U -lt $L  ||
  2101.     { $PREPARE_CC && $CS -DH=$H a.c $LS >&2 && $CS_OK; }
  2102. do
  2103.     case $H in
  2104.     a) I=b;;
  2105.     *) I=a
  2106.     esac
  2107.  
  2108.     # The compiler rejects some line in L..U.
  2109.     # Use binary search to set L to be the index of the first bad line in L..U.
  2110.     u=$U
  2111.     while test $L -lt $u
  2112.     do
  2113.         M=`expr '(' $L + $u ')' / 2`
  2114.         M1=`expr $M + 1`
  2115.         sed "$M1,\$$commentOut" a.h$H >a.h$I || exit
  2116.         if $PREPARE_CC && $CS -DH=$I a.c $LS >&2 && $CS_OK
  2117.         then L=$M1
  2118.         else u=$M
  2119.         fi
  2120.     done
  2121.  
  2122.     # Comment out the bad line.
  2123.     badline=`sed -n "$L{p;q;}" a.h$H`
  2124.     echo >&3 "$n$0: commenting out \`$badline' $dots"
  2125.     sed "$L$commentOut" a.h$H >a.h$I || exit
  2126.  
  2127.     H=$I
  2128.     L=`expr $L + 1`
  2129. done
  2130.  
  2131. cat a.h$H
  2132.  
  2133. echo >&3 OK
  2134.