home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / rcs-5.6.0.1.tar.gz / rcs-5.6.0.1.tar / rcs5.6.0.1 / src / conf.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1993-03-24  |  36KB  |  1,675 lines

  1. #!/bin/sh
  2. # Output RCS compile-time configuration.
  3. Id='$Id: conf.sh,v 5.14.0.1 1993/03/25 04:24:49 eggert Exp $'
  4. #    Copyright 1990, 1991 by 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. : ${CC=cc}
  35. : ${CFLAGS=-O}
  36. : ${COMPAT2=0}
  37. : ${DIFF3=${RCSPREFIX}diff3}
  38. : ${DIFF3_A=1}
  39. : ${DIFF3_BIN=1}
  40. : ${DIFF=${RCSPREFIX}diff}
  41. : ${DIFF_FLAGS=-an}
  42. : ${DIFF_L=1}
  43. : ${DIFF_SUCCESS=0} ${DIFF_FAILURE=1} ${DIFF_TROUBLE=2}
  44. : ${ED=/bin/ed}
  45. : ${RCSPREFIX=/usr/local/bin/}
  46. : ${SENDMAIL='"/usr/lib/sendmail"'}
  47. # : ${LDFLAGS=} ${LDLIBS=} tickles old shell bug
  48.  
  49. C="$CC $CFLAGS"
  50. CL="$CC $CFLAGS $LDFLAGS"
  51. L=$LDLIBS
  52. RM='rm -f a.out'
  53.  
  54. cat <<EOF
  55. /* RCS compile-time configuration */
  56.  
  57.     /* $Id */
  58.  
  59. /*
  60.  * This file is generated automatically.
  61.  * If you edit it by hand your changes may be lost.
  62.  * Instead, please try to fix conf.sh,
  63.  * and send your fixes to rcs-bugs@cs.purdue.edu.
  64.  */
  65.  
  66. EOF
  67.  
  68. : exitmain
  69. cat >a.c <<EOF
  70. #include "a.h"
  71. int main(argc,argv) int argc; char **argv; { return argc-1; }
  72. EOF
  73. $RM && $CL a.c $L >&2 || exit
  74. e='exit(n), 3 /* lint fodder */'
  75. if ./a.out -
  76. then :
  77. elif ./a.out
  78. then e=n
  79. fi
  80. echo "#define exitmain(n) return $e /* how to exit from main() */"
  81.  
  82. : _POSIX_SOURCE
  83. cat >a.c <<'EOF'
  84. #include "a.h"
  85. #include <stdio.h>
  86. int main() { exitmain(fileno(stdout) < 0); }
  87. EOF
  88. a='/* ' z='*/ '
  89. $RM || exit
  90. if ($CL a.c $L && ./a.out) >&2
  91. then :
  92. elif $RM || exit; ($CL -D_POSIX_SOURCE a.c $L && ./a.out) >&2
  93. then a= z=
  94. fi
  95. cat <<EOF
  96. $a#define _POSIX_SOURCE $z/* Define this if Posix + strict Standard C.  */
  97.  
  98. #include <errno.h>
  99. #include <stdio.h>
  100. #include <time.h>
  101. EOF
  102.  
  103. cat <<'EOF'
  104.  
  105. /* Comment out #include lines below that do not work.  */
  106. EOF
  107.  
  108. # Run `$CS a.c $LS' instead of `$CL a.c $L' for compile-time checking only.
  109. # This speeds up the configuration process.
  110. if $C -S a.c >&2
  111. then CS="$C -S" LS=    # Generate assembly language output.
  112. elif $C -c a.c >&2
  113. then CS="$C -c" LS=    # Generate object code.
  114. else CS=$CL LS=$L    # Generate an executable.
  115. fi
  116.  
  117. # standard include files
  118. # sys/types.h and sys/stat.h must come first because others depend on them.
  119. has_signal=1
  120. for h in \
  121.     sys/types sys/stat \
  122.     dirent fcntl limits pwd signal stdlib string sys/mman sys/wait unistd utime vfork
  123. do
  124.     i="#include <$h.h>"
  125.     : $i
  126.     cat >a.c <<EOF
  127. #include "a.h"
  128. $i
  129. int main(){ exitmain(0); }
  130. EOF
  131.     $RM || exit
  132.     ($CL a.c $L && ./a.out) >&2 || {
  133.         case $h in
  134.         string)
  135.             i='#include <strings.h>';;
  136.         *)
  137.             i="/* $i */"
  138.         esac
  139.         case $h in
  140.         signal) has_signal=0
  141.         esac
  142.     }
  143.     echo "$i"
  144. done
  145.  
  146. cat <<'EOF'
  147.  
  148. /* Define the following symbols to be 1 or 0.  */
  149. EOF
  150.  
  151. # has_sys_*_h
  152. for H in dir param
  153. do
  154.     : has_sys_${H}_h
  155.     cat >a.c <<EOF
  156. #include "a.h"
  157. #include <sys/$H.h>
  158. int main() { exitmain(0); }
  159. EOF
  160.     $RM || exit
  161.     if ($CL a.c $L && ./a.out) >&2
  162.     then h=1
  163.     else h=0
  164.     fi
  165.     echo "#define has_sys_${H}_h $h /* Does #include <sys/$H.h> work?  */"
  166. done
  167.  
  168.  
  169. # We must do NAME_MAX and has_readlink next, because they might generate
  170. # #include directives that affect later definitions.
  171.  
  172. : NAME_MAX
  173. cat >a.c <<'EOF'
  174. #include "a.h"
  175. char b[NAME_MAX + 2];
  176. main()
  177. {
  178. #if !defined(NAME_MAX)
  179.     exitmain(1);
  180. #else
  181.     int i;
  182.     b[0] = 'a'; b[1] = '.';
  183.     for (i = 2;  i < NAME_MAX;  i++)
  184.         b[i] = 'a';
  185.     b[i] = 'b';
  186.     exitmain(creat(b, 0) < 0);
  187. #endif
  188. }
  189. EOF
  190. $RM a.*ab || exit
  191. if $CL a.c $L >&2 && ./a.out && test -f a.*ab
  192. then a= z=
  193. else a='/* ' z='*/ '
  194. fi
  195. rm -f a.*ab || exit
  196.  
  197. : has_readlink
  198. cat >a.c <<'EOF'
  199. #include "a.h"
  200. char b[7];
  201. int main()
  202. {
  203.     exitmain(readlink("a.sym2",b,7) != 6  ||  strcmp(b, "a.sym1") != 0);
  204. }
  205. EOF
  206. $RM a.sym* || exit
  207. if (ln -s a.sym1 a.sym2 && $CL a.c $L && ./a.out) >&2
  208. then h=1
  209. else h=0
  210. fi
  211. cat <<EOF
  212. #define has_readlink $h /* Does readlink() work?  */
  213.  
  214. $a#undef NAME_MAX $z/* Uncomment this if NAME_MAX is broken.  */
  215.  
  216. #if !defined(NAME_MAX) && !defined(_POSIX_NAME_MAX)
  217. #    if has_sys_dir_h
  218. #        include <sys/dir.h>
  219. #    endif
  220. #    ifndef NAME_MAX
  221. #        ifndef MAXNAMLEN
  222. #            define MAXNAMLEN 14
  223. #        endif
  224. #        define NAME_MAX MAXNAMLEN
  225. #    endif
  226. #endif
  227. #if !defined(PATH_MAX) && !defined(_POSIX_PATH_MAX)
  228. #    if has_sys_param_h
  229. #        include <sys/param.h>
  230. #        define included_sys_param_h 1
  231. #    endif
  232. #    ifndef PATH_MAX
  233. #        ifndef MAXPATHLEN
  234. #            define MAXPATHLEN 1024
  235. #        endif
  236. #        define PATH_MAX (MAXPATHLEN-1)
  237. #    endif
  238. #endif
  239. #if has_readlink && !defined(MAXSYMLINKS)
  240. #    if has_sys_param_h && !included_sys_param_h
  241. #        include <sys/param.h>
  242. #    endif
  243. #    ifndef MAXSYMLINKS
  244. #        define MAXSYMLINKS 20 /* BSD; not standard yet */
  245. #    endif
  246. #endif
  247. EOF
  248.  
  249. cat <<'EOF'
  250.  
  251. /* Comment out the keyword definitions below if the keywords work.  */
  252. EOF
  253.  
  254. : const, volatile
  255. for i in const volatile
  256. do
  257.     cat >a.c <<EOF
  258. #    include "a.h"
  259.     enum Boolean { false, true };
  260.     static enum Boolean $i zero;
  261.     static enum Boolean $i * $i azero = &zero;
  262.     static enum Boolean $i * $i * $i aazero = &azero;
  263.     int main() { exitmain(!!**aazero); }
  264. EOF
  265.     a= z=
  266.     if $CS a.c $LS >&2
  267.     then
  268.         cat >a.c <<EOF
  269.             typedef unsigned char $i *Iptr_type;
  270.             struct { Iptr_type lim; } s, *f = &s;
  271.             int main() {
  272.                 Iptr_type lim;
  273.                 lim = f->lim;
  274.                 return !!lim;
  275.             }
  276. EOF
  277.         if $CS a.c $LS >&2
  278.         then a='/* ' z=' */'
  279.         fi
  280.     fi
  281.     echo "$a#define $i$z"
  282. done
  283.  
  284. # *_t
  285. cat <<'EOF'
  286.  
  287. /* Comment out the typedefs below if the types are already declared.  */
  288. /* Fix any uncommented typedefs that are wrong.  */
  289. EOF
  290. cat >a.c <<'EOF'
  291. #include "a.h"
  292. t x;
  293. int main() { exitmain(0); }
  294. EOF
  295. for t in mode_t pid_t sig_atomic_t size_t ssize_t time_t uid_t
  296. do
  297.     : $t
  298.     case $t in
  299.     size_t) i=unsigned;;
  300.     time_t) i=long;;
  301.     *) i=int;;
  302.     esac
  303.     if $CS -Dt=$t a.c $LS >&2
  304.     then a='/* ' z=' */'
  305.     else a= z=
  306.     fi
  307.     echo "${a}typedef $i $t;$z"
  308. done
  309.  
  310. : has_prototypes, has_stdarg, has_varargs, va_start_args
  311. cat >a.ha <<'EOF'
  312. #if has_prototypes
  313. #    define P(params) params
  314. #else
  315. #    define P(params) ()
  316. #endif
  317. #if has_stdarg
  318. #    include <stdarg.h>
  319. #else
  320. #    if has_varargs
  321. #        include <varargs.h>
  322. #    else
  323.         typedef char *va_list;
  324. #        define va_dcl int va_alist;
  325. #        define va_start(ap) ((ap) = (va_list)&va_alist)
  326. #        define va_arg(ap,t) (((t*) ((ap)+=sizeof(t)))  [-1])
  327. #        define va_end(ap)
  328. #    endif
  329. #endif
  330. #if va_start_args == 2
  331. #    define vararg_start va_start
  332. #else
  333. #    define vararg_start(ap,p) va_start(ap)
  334. #endif
  335. EOF
  336. cat >a.c <<'EOF'
  337. #include "a.h"
  338. #include "a.ha"
  339. #if has_prototypes
  340. char *f(char **p, ...)
  341. #else
  342. char *f(p, va_alist) char **p; va_dcl
  343. #endif
  344. {
  345.     char *s;
  346.     va_list v;
  347.     vararg_start(v,p);
  348.     s = p[va_arg(v,int)];
  349.     va_end(v);
  350.     return s;
  351. }
  352. int main P((int, char**));
  353. int main(argc, argv) int argc; char **argv; {
  354.     exitmain(f(argv,0) != argv[0]  ||  f(argv,1) != argv[1]);
  355. }
  356. EOF
  357. for has_prototypes in 1 0
  358. do
  359.     for has_stdarg in 1 v 0
  360.     do
  361.         case $has_stdarg in
  362.         v) has_varargs=1 has_stdarg=0;;
  363.         *) has_varargs=0
  364.         esac
  365.         case $has_stdarg in
  366.         0) as='1 2';;
  367.         1) as='2 1'
  368.         esac
  369.         for va_start_args in $as
  370.         do
  371.             $RM || exit
  372.             $CL \
  373.                 -Dhas_prototypes=$has_prototypes \
  374.                 -Dhas_stdarg=$has_stdarg \
  375.                 -Dhas_varargs=$has_varargs \
  376.                 -Dva_start_args=$va_start_args \
  377.                 a.c $L >&2 && ./a.out && break
  378.         done && break
  379.     done && break
  380. done || {
  381.     echo >&2 "cannot deduce has_prototypes, has_stdarg, va_start_args"
  382.     exit 1
  383. }
  384. cat - a.ha <<EOF
  385.  
  386. /* Define the following symbols to be 1 or 0.  */
  387. #define has_prototypes $has_prototypes /* Do function prototypes work?  */
  388. #define has_stdarg $has_stdarg /* Does <stdarg.h> work?  */
  389. #define has_varargs $has_varargs /* Does <varargs.h> work?  */
  390. #define va_start_args $va_start_args /* How many args does va_start() take?  */
  391. EOF
  392.  
  393. : text_equals_binary_stdio, FOPEN_...
  394. cat >a.c <<'EOF'
  395. #include "a.h"
  396.     int
  397. copyto(filename, mode)
  398.     char const *filename, *mode;
  399. {
  400.     int c;
  401.     FILE *f, *g;
  402.     if (!(f = fopen("a.out", "rb")) || !(g = fopen(filename, mode)))
  403.         return 1;
  404.     while (c=getc(f), !feof(f))
  405.         if (ferror(f)  ||  putc(c,g)<0 && ferror(g))
  406.             return 1;
  407.     return fclose(f)!=0 || fclose(g)!=0;
  408. }
  409. int main() { exitmain(copyto("a.d", "w+b") || copyto("a.e", "w+")); }
  410. EOF
  411. e=1
  412. $RM a.d a.e || exit
  413. $CL a.c $L >&2 && ./a.out && cmp a.out a.d && {
  414.     cmp a.out a.e || e=0
  415. }
  416. cat <<EOF
  417.  
  418. #define text_equals_binary_stdio $e /* Does stdio treat text like binary?  */
  419. #define text_work_stdio 0 /* Text i/o for working file, binary for RCS file?  */
  420. #if text_equals_binary_stdio
  421.     /* Text and binary i/o behave the same, or binary i/o does not work.  */
  422. #    define FOPEN_R "r"
  423. #    define FOPEN_W "w"
  424. #    define FOPEN_WPLUS "w+"
  425. #else
  426.     /* Text and binary i/o behave differently.  */
  427.     /* This is incompatible with Posix and Unix.  */
  428. #    define FOPEN_R "rb"
  429. #    define FOPEN_W "wb"
  430. #    define FOPEN_WPLUS "w+b"
  431. #endif
  432. #if text_work_stdio
  433. #    define FOPEN_R_WORK "r"
  434. #    define FOPEN_W_WORK "w"
  435. #    define FOPEN_WPLUS_WORK "w+"
  436. #else
  437. #    define FOPEN_R_WORK FOPEN_R
  438. #    define FOPEN_W_WORK FOPEN_W
  439. #    define FOPEN_WPLUS_WORK FOPEN_WPLUS
  440. #endif
  441.  
  442. /* Define or comment out the following symbols as needed.  */
  443. EOF
  444.  
  445. : bad_fopen_wplus
  446. cat >a.c <<'EOF'
  447. #include "a.h"
  448. int main() { exitmain(!fopen("a.d",FOPEN_WPLUS)); }
  449. EOF
  450. $RM || exit
  451. if echo nonempty >a.d && $CL a.c $L >&2 && ./a.out && test ! -s a.d
  452. then b=0
  453. else b=1
  454. fi
  455. echo "#define bad_fopen_wplus $b /* Does fopen(f,FOPEN_WPLUS) fail to truncate f?  */"
  456.  
  457. : getlogin_is_secure
  458. echo "#define getlogin_is_secure 0 /* Is getlogin() secure?  Usually it's not.  */"
  459.  
  460. : has_dirent
  461. cat >a.c <<'EOF'
  462. #include "a.h"
  463. int main() {
  464.     DIR *d = opendir(".");
  465.     struct dirent *e;
  466.     while ((e = readdir(d)))
  467.         if (strcmp(e->d_name, "a.c") == 0  &&  closedir(d) == 0)
  468.             exitmain(0);
  469.     exitmain(1);
  470. }
  471. EOF
  472. $RM || exit
  473. if $CL a.c $L >&2 && ./a.out
  474. then h=1
  475. else h=0
  476. fi
  477. echo "#define has_dirent $h /* Do opendir(), readdir(), closedir() work?  */"
  478.  
  479. : has_fchmod
  480. cat >a.c <<'EOF'
  481. #include "a.h"
  482. int main() { exitmain(fchmod(fileno(stdin),0) != 0); }
  483. EOF
  484. $RM || exit
  485. if $CL a.c $L >&2 && ./a.out <a.c && test ! -r a.c
  486. then h=1
  487. else h=0
  488. fi
  489. echo "#define has_fchmod $h /* Does fchmod() work?  */"
  490. rm -f a.c || exit
  491.  
  492. : has_fputs
  493. cat >a.c <<'EOF'
  494. #include "a.h"
  495. int main() { exitmain(fputs("Hello\"\nworld", stdout) != 12); }
  496. EOF
  497. Hello='Hello"
  498. world'
  499. $RM || exit
  500. if $CL a.c $L >&2 && ./a.out >/dev/null && x=`./a.out` && test " $x" = " $Hello"
  501. then h=1
  502. else h=0
  503. fi
  504. echo "#define has_fputs $h /* Does fputs() work?  */"
  505.  
  506. : has_ftruncate
  507. cat >a.c <<'EOF'
  508. #include "a.h"
  509. int main(argc, argv) int argc; char **argv; {
  510.     int f = creat(argv[1], 0);
  511.     if (f<0 || write(f,"abc",3)!=3 || ftruncate(f,(off_t)0)!=0 || close(f)!=0)
  512.             exitmain(1);
  513.     exitmain(0);
  514. }
  515. EOF
  516. $RM || exit
  517. if $CL a.c $L >&2
  518. then
  519.     h=1
  520.     # Check out /tmp too; it's buggy on some hosts.
  521.     for d in . /tmp
  522.     do
  523.         if test -d $d
  524.         then
  525.             f=$d/a.d
  526.             rm -f $f || exit
  527.             ./a.out $f && test ! -s $f && test -f $f  ||  h=0
  528.             rm -f $f || exit
  529.         fi
  530.     done
  531. else h=0
  532. fi
  533. echo "#define has_ftruncate $h /* Does ftruncate() work?  */"
  534.  
  535. : has_getuid
  536. cat >a.c <<'EOF'
  537. #include "a.h"
  538. #ifndef getuid
  539.     uid_t getuid();
  540. #endif
  541. int main() { exitmain(getuid()!=getuid()); }
  542. EOF
  543. $RM || exit
  544. if ($CL a.c $L && ./a.out) >&2
  545. then has_getuid=1
  546. else has_getuid=0
  547. fi
  548. echo "#define has_getuid $has_getuid /* Does getuid() work?  */"
  549.  
  550. : has_getpwuid
  551. case $has_getuid in
  552. 0)
  553.     a='/* ' z='*/ ' h=?;;
  554. *)
  555.     a= z=
  556.     cat >a.c <<'EOF'
  557. #include "a.h"
  558. int main() { exitmain(!getpwuid(0)); }
  559. EOF
  560.     $RM || exit
  561.     if ($CL a.c $L && ./a.out) >&2
  562.     then h=1
  563.     else h=0
  564.     fi
  565. esac
  566. echo "$a#define has_getpwuid $h $z/* Does getpwuid() work?  */"
  567.  
  568. : has_link
  569. cat >a.c <<'EOF'
  570. #include "a.h"
  571. int main() { exitmain(link("a.c","a.d") != 0); }
  572. EOF
  573. $RM a.d || exit
  574. if ($CL a.c $L && ./a.out && cmp a.c a.d) >&2
  575. then h=1
  576. else h=0
  577. fi
  578. rm -f a.d || exit
  579. echo "#define has_link $h /* Does link() work?  */"
  580.  
  581. : has_memcmp
  582. cat >a.c <<'EOF'
  583. #include "a.h"
  584. int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); }
  585. EOF
  586. $RM || exit
  587. if ($CL a.c $L && ./a.out) >&2
  588. then h=1
  589. else h=0
  590. fi
  591. echo "#define has_memcmp $h /* Does memcmp() work?  */"
  592.  
  593. : has_memcpy
  594. cat >a.c <<'EOF'
  595. #include "a.h"
  596. char a[3];
  597. int main() {
  598.     memcpy(a,"xy",3);
  599.     exitmain(strcmp(a,"xy")!=0);
  600. }
  601. EOF
  602. $RM || exit
  603. if ($CL a.c $L && ./a.out) >&2
  604. then h=1
  605. else h=0
  606. fi
  607. echo "#define has_memcpy $h /* Does memcpy() work?  */"
  608.  
  609. : has_memmove
  610. cat >a.c <<'EOF'
  611. #include "a.h"
  612. char a[4];
  613. int main() {
  614.     strcpy(a, "xy");
  615.     memmove(a+1, a, 3);
  616.     exitmain(strcmp(a,"xxy")!=0);
  617. }
  618. EOF
  619. $RM || exit
  620. if ($CL a.c $L && ./a.out) >&2
  621. then h=1
  622. else h=0
  623. fi
  624. echo "#define has_memmove $h /* Does memmove() work?  */"
  625.  
  626. : has_mmap, has_madvise
  627. cat >a.c <<'EOF'
  628. #define CHAR1 '#' /* the first character in this file */
  629. #include "a.h"
  630. #ifndef mmap
  631.     caddr_t mmap();
  632. #endif
  633. caddr_t a;
  634. struct stat b;
  635. #ifndef MADVISE_OK
  636. #    define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0)
  637. #endif
  638. int main()
  639. {
  640.     if (fstat(fileno(stdin), &b) != 0)
  641.         exitmain(1);
  642.     a = mmap(
  643.         (caddr_t)0, b.st_size, PROT_READ, MAP_SHARED,
  644.         fileno(stdin), (off_t)0
  645.     );
  646.     exitmain(
  647.         a == (caddr_t)-1  ||
  648.         !MADVISE_OK ||
  649.         *a != CHAR1  ||
  650.         munmap(a, b.st_size)  !=  0
  651.     );
  652. }
  653. EOF
  654. a=0 has_mmap=0
  655. $RM || exit
  656. if ($CL -DMADVISE_OK=1 a.c $L && ./a.out <a.c) >&2
  657. then
  658.     has_mmap=1
  659.     $RM || exit
  660.     ($CL a.c $L && ./a.out <a.c) >&2 && a=1
  661. fi
  662. echo "#define has_madvise $a /* Does madvise() work?  */"
  663. echo "#define has_mmap $has_mmap /* Does mmap() work on regular files?  */"
  664.  
  665. : has_rename, bad_a_rename, bad_b_rename
  666. cat >a.c <<'EOF'
  667. #include "a.h"
  668. int main() { exitmain(rename("a.a","a.b") != 0); }
  669. EOF
  670. echo a >a.a && $RM a.b || exit
  671. if ($CL a.c $L && ./a.out && test -f a.b) >&2
  672. then
  673.     h=1
  674.     rm -f a.a a.b &&
  675.     echo a >a.a && chmod -w a.a || exit
  676.     if ./a.out && test ! -f a.a && test -f a.b
  677.     then a=0
  678.     else a=1
  679.     fi
  680.     rm -f a.a a.b &&
  681.     echo a >a.a && echo b >a.b && chmod -w a.b || exit
  682.     if ./a.out && test ! -f a.a && test -f a.b
  683.     then b=0
  684.     else b=1
  685.     fi
  686.     rm -f a.a a.b || exit
  687. else h=0 a=0 b=0
  688. fi
  689. echo "#define has_rename $h /* Does rename() work?  */"
  690. echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable?  */"
  691. echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable?  */"
  692.  
  693. : void, VOID
  694. cat >a.c <<'EOF'
  695. #include "a.h"
  696. void f() {}
  697. int main() {f(); exitmain(0);}
  698. EOF
  699. if $CS a.c $LS >&2
  700. then
  701.     v='(void) '
  702. else
  703.     v=
  704.     echo 'typedef int void;'
  705. fi
  706. echo "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'.  */"
  707.  
  708. : has_seteuid
  709. case $has_getuid in
  710. 0)
  711.     a='/* ' z='*/ ' has_seteuid=?;;
  712. *)
  713.     a= z=
  714.     cat >a.c <<'EOF'
  715. #include "a.h"
  716. #ifndef geteuid
  717.     uid_t geteuid();
  718. #endif
  719. int main() {
  720. /* Guess, don't test.  Ugh.  Testing would require running conf.sh setuid.  */
  721. /* seteuid() isn't standardized yet, so the guess below may well be wrong.  */
  722. #if !_POSIX_VERSION || _POSIX_VERSION<=199009L&&!defined(sgi)&&!defined(__sgi__)&&!defined(sun)&&!defined(__sun__)
  723.     exitmain(1);
  724. #else
  725.     exitmain(seteuid(geteuid()) != 0);
  726. #endif
  727. }
  728. EOF
  729.     $RM || exit
  730.     if ($CL a.c $L && ./a.out) >&2
  731.     then has_seteuid=1
  732.     else has_seteuid=0
  733.     fi
  734. esac
  735. echo "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work?  See README.  */"
  736.  
  737. : has_setuid
  738. h=$has_seteuid
  739. case $h in
  740. 0)
  741.     cat >a.c <<'EOF'
  742. #include "a.h"
  743. #ifndef getuid
  744.     uid_t getuid();
  745. #endif
  746. int main() { exitmain(setuid(getuid()) != 0); }
  747. EOF
  748.     $RM || exit
  749.     ($CL a.c $L && ./a.out) >&2 && h=1
  750. esac
  751. echo "$a#define has_setuid $h $z/* Does setuid() exist?  */"
  752.  
  753. : has_signal, signal_args, signal_type, sig_zaps_handler
  754. cat >a.c <<'EOF'
  755. #include "a.h"
  756. #ifndef getpid
  757.     pid_t getpid();
  758. #endif
  759. #if !defined(signal) && declare_signal
  760.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  761. #endif
  762. signal_type nothing(i) int i; {}
  763. int main(argc, argv) int argc; char **argv;
  764. {
  765.     signal(SIGINT, nothing);
  766.     while (--argc)
  767.         kill(getpid(), SIGINT);
  768.     exitmain(0);
  769. }
  770. EOF
  771. for declare_signal in 1 0
  772. do
  773.     for signal_type in void int
  774.     do
  775.         for signal_args in 'P((int))' '()'
  776.         do
  777.             $RM || exit
  778.             ($CL \
  779.                 -Ddeclare_signal=$declare_signal \
  780.                 -Dsignal_args="$signal_args" \
  781.                 -Dsignal_type=$signal_type \
  782.                     a.c $L && ./a.out 1) >&2 && break
  783.         done && break
  784.     done && break
  785. done || {
  786.     echo >&2 "cannot deduce signal_args, signal_type"
  787.     exit 1
  788. }
  789. if ./a.out 1 2 >&2
  790. then z=0
  791. else z=1
  792. fi
  793. cat <<EOF
  794. #define has_signal $has_signal /* Does signal() work?  */
  795. #define signal_args $signal_args /* arguments of signal handlers */
  796. #define signal_type $signal_type /* type returned by signal handlers */
  797. #define sig_zaps_handler $z /* Must a signal handler reinvoke signal()?  */
  798. EOF
  799.  
  800. : has_sigaction
  801. cat >a.c <<'EOF'
  802. #include "a.h"
  803. #ifndef getpid
  804.     pid_t getpid();
  805. #endif
  806. static sig_atomic_t volatile gotsig;
  807. static void getsig(i) int i; { gotsig = 1; }
  808. int main(argc, argv) int argc; char **argv;
  809. {
  810.     struct sigaction s;
  811.     sigset_t t;
  812.     if (sigemptyset(&t) != 0  ||  sigaddset(&t, SIGINT) != 0)
  813.         exitmain(1);
  814.     if (sigaction(SIGINT, (struct sigaction const*)0, &s) != 0)
  815.         exitmain(1);
  816.     s.sa_handler = getsig;
  817.     s.sa_mask = t;
  818.     if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0)
  819.         exitmain(1);
  820.     kill(getpid(), SIGINT);
  821.     exitmain(gotsig != 1);
  822. }
  823. EOF
  824. $RM || exit
  825. if ($CL a.c $L && ./a.out) >&2
  826. then has_sigaction=1
  827. else has_sigaction=0
  828. fi
  829. echo "#define has_sigaction $has_sigaction /* Does struct sigaction work?  */"
  830.  
  831. : has_sigblock, sigmask
  832. a='/* ' z='*/ '
  833. b='/* ' y='*/ '
  834. case $has_sigaction in
  835. 1)
  836.     h=? n=?;;
  837. *)
  838.     a= z=
  839.     cat >a.c <<'EOF'
  840. #include "a.h"
  841. #include <signal.h>
  842. #if define_sigmask
  843. #    define sigmask(s) (1 << ((s)-1))
  844. #endif
  845. int main()
  846. {
  847.     sigblock(sigmask(SIGHUP));
  848.     exitmain(kill(getpid(), SIGHUP) != 0);
  849. }
  850. EOF
  851.     if $RM || exit; ($CL a.c $L && ./a.out) >&2
  852.     then h=1
  853.     elif $RM || exit; ($CL -Ddefine_sigmask=1 a.c $L && ./a.out) >&2
  854.     then h=1 b= y=
  855.     else h=0
  856.     fi
  857. esac
  858. echo "$a#define has_sigblock $h $z/* Does sigblock() work?  */"
  859. echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number.  */"
  860.  
  861. : has_sys_siglist
  862. cat >a.c <<'EOF'
  863. #include "a.h"
  864. #ifndef sys_siglist
  865.     extern char const *sys_siglist[];
  866. #endif
  867. int main() { exitmain(!sys_siglist[1][0]); }
  868. EOF
  869. $RM || exit
  870. if ($CL a.c $L && ./a.out) >&2
  871. then h=1
  872. else h=0
  873. fi
  874. echo "#define has_sys_siglist $h /* Does sys_siglist[] work?  */"
  875.  
  876. : fread_type, Fread, Fwrite
  877. cat >a.c <<'EOF'
  878. #define CHAR1 '#' /* the first character in this file */
  879. #include "a.h"
  880. #if !defined(fread) && declare_fread
  881.     fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  882. #endif
  883. int main()
  884. {
  885.     char b;
  886.     exitmain(!(
  887.         fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1  &&
  888.         b==CHAR1
  889.     ));
  890. }
  891. EOF
  892. for declare_fread in 1 0
  893. do
  894.     for fread_type in ssize_t size_t int unsigned
  895.     do
  896.         for freadarg_type in size_t ssize_t unsigned int
  897.         do
  898.             $RM || exit
  899.             (
  900.                 $CL \
  901.                     -Ddeclare_fread=$declare_fread \
  902.                     -Dfreadarg_type=$freadarg_type \
  903.                     -Dfread_type=$fread_type \
  904.                     a.c $L &&
  905.                 ./a.out <a.c
  906.             ) >&2 && break
  907.         done && break
  908.     done && break
  909. done || {
  910.     echo >&2 "cannot deduce fread types"
  911.     exit 1
  912. }
  913. cat <<EOF
  914. typedef $fread_type fread_type; /* type returned by fread() and fwrite() */
  915. typedef $freadarg_type freadarg_type; /* type of their size arguments */
  916. EOF
  917.  
  918. : malloc_type
  919. cat >a.c <<'EOF'
  920. #include "a.h"
  921. typedef void *malloc_type;
  922. #ifndef malloc
  923.     malloc_type malloc();
  924. #endif
  925. int main() { exitmain(!malloc(1)); }
  926. EOF
  927. if $CS a.c $LS >&2
  928. then t=void
  929. else t=char
  930. fi
  931. echo "typedef $t *malloc_type; /* type returned by malloc() */"
  932.  
  933. : has_getcwd
  934. cat >a.c <<'EOF'
  935. #include "a.h"
  936. #ifndef getcwd
  937.     char *getcwd();
  938. #endif
  939. char buf[10000];
  940. int main() { exitmain(!getcwd(buf,10000)); }
  941. EOF
  942. $RM || exit
  943. if ($CL a.c $L && ./a.out) >&2
  944. then has_getcwd=1
  945. else has_getcwd=0
  946. fi
  947. echo "#define has_getcwd $has_getcwd /* Does getcwd() work?  */"
  948.  
  949. : has_getwd
  950. case $has_getcwd in
  951. 1)
  952.     a='/* ' z='*/ ' h=?;;
  953. *)
  954.     a= z=
  955.     cat >a.c <<'EOF'
  956. #include "a.h"
  957. #include <sys/param.h>
  958. #ifndef getwd
  959.     char *getwd();
  960. #endif
  961. char buf[MAXPATHLEN];
  962. int main() { exitmain(!getwd(buf)); }
  963. EOF
  964.     $RM || exit
  965.     if ($CL a.c $L && ./a.out) >&2
  966.     then h=1
  967.     else h=0
  968.     fi
  969. esac
  970. echo "$a#define has_getwd $h $z/* Does getwd() work?  */"
  971.  
  972. : has_mktemp
  973. cat >a.c <<'EOF'
  974. #include "a.h"
  975. #ifndef mktemp
  976.     char *mktemp();
  977. #endif
  978. int main()
  979. {
  980.     char b[9];
  981.     strcpy(b, "a.XXXXXX");
  982.     exitmain(!mktemp(b));
  983. }
  984. EOF
  985. $RM || exit
  986. if ($CL a.c $L && ./a.out) >&2
  987. then h=1
  988. else h=0
  989. fi
  990. echo "#define has_mktemp $h /* Does mktemp() work?  */"
  991.  
  992. : has_NFS
  993. echo "#define has_NFS 1 /* Might NFS be used?  */"
  994.  
  995. : strchr
  996. cat >a.c <<'EOF'
  997. #include "a.h"
  998. #ifndef strchr
  999.     char *strchr();
  1000. #endif
  1001. int main() {exitmain(!strchr("abc", 'c'));}
  1002. EOF
  1003. $RM || exit
  1004. if ($CL a.c $L && ./a.out) >&2
  1005. then a='/* ' z='*/ '
  1006. else a= z=
  1007. fi
  1008. echo "$a#define strchr index $z/* Use old-fashioned name for strchr()?  */"
  1009.  
  1010. : strrchr
  1011. cat >a.c <<'EOF'
  1012. #include "a.h"
  1013. #ifndef strrchr
  1014.     char *strrchr();
  1015. #endif
  1016. int main() {exitmain(!strrchr("abc", 'c'));}
  1017. EOF
  1018. $RM || exit
  1019. if ($CL a.c $L && ./a.out) >&2
  1020. then a='/* ' z='*/ '
  1021. else a= z=
  1022. fi
  1023. echo "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()?  */"
  1024.  
  1025. : bad_unlink
  1026. cat >a.c <<'EOF'
  1027. #include "a.h"
  1028. int main() { exitmain(unlink("a.c") != 0); }
  1029. EOF
  1030. $RM && chmod -w a.c || exit
  1031. if $CL a.c $L >&2 && ./a.out >/dev/null && test ! -f a.c
  1032. then b=0
  1033. else b=1
  1034. fi
  1035. rm -f a.c || exit
  1036. echo "#define bad_unlink $b /* Does unlink() fail on unwritable files?  */"
  1037.  
  1038. : has_vfork, has_fork, has_spawn, has_wait, has_waitpid, RCS_SHELL
  1039. cat >a.c <<'EOF'
  1040. #include "a.h"
  1041. #ifndef getpid
  1042.     pid_t getpid();
  1043. #endif
  1044. #if TRY_VFORK
  1045. #    ifndef vfork
  1046.         pid_t vfork();
  1047. #    endif
  1048. #else
  1049. #    ifndef fork
  1050.         pid_t fork();
  1051. #    endif
  1052. #    undef vfork
  1053. #    define vfork fork
  1054. #endif
  1055. #if TRY_WAITPID
  1056. #    ifndef waitpid
  1057.         pid_t waitpid();
  1058. #    endif
  1059. #else
  1060. #    ifndef wait
  1061.         pid_t wait();
  1062. #    endif
  1063. #endif
  1064. pid_t child;
  1065. int status;
  1066. struct stat st;
  1067. int main()
  1068. {
  1069.     pid_t parent = getpid();
  1070.     if (!(child = vfork())) {
  1071.         /* Tickle vfork/compiler bug (e.g. sparc gcc -O (1.37.1).  */
  1072.         pid_t i = getpid(), j = getpid();
  1073.         if (i!=getpid() || j!=getpid())
  1074.             _exit(!i);
  1075.         /* Tickle file descriptor bug (e.g. IRIX 3.3).  */
  1076.         _exit(close(1) != 0);
  1077.     } else {
  1078. #        if TRY_WAITPID
  1079.             if (waitpid(child, &status, 0) != child)
  1080.                 exitmain(1);
  1081. #        else
  1082.             while (wait(&status) != child)
  1083.                 ;
  1084. #        endif
  1085.         /* Test for presence of bugs.  */
  1086.         exitmain(status  ||  parent != getpid()  ||  fstat(1,&st) != 0);
  1087.     }
  1088. }
  1089. EOF
  1090. $RM || exit
  1091. if ($CL -DTRY_VFORK=1 a.c $L && ./a.out) >&2
  1092. then has_vfork=1
  1093. else has_vfork=0
  1094. fi
  1095. echo "#define has_vfork $has_vfork /* Does vfork() work?  */"
  1096. h=$has_vfork
  1097. case $h in
  1098. 0)
  1099.     $RM || exit
  1100.     ($CL a.c $L && ./a.out) >&2 && h=1
  1101. esac
  1102. echo "#define has_fork $h /* Does fork() work?  */"
  1103. $RM || exit
  1104. if ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && ./a.out) >&2
  1105. then h=1
  1106. else h=0
  1107. fi
  1108. echo "#define has_spawn 0 /* Does spawn*() work?  */"
  1109. echo "#define has_wait 1 /* Does wait() work?  */"
  1110. echo "#define has_waitpid $h /* Does waitpid() work?  */"
  1111. echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */'
  1112.  
  1113. : has_vfprintf
  1114. cat >a.c <<'EOF'
  1115. #include "a.h"
  1116. #if has_prototypes
  1117. int p(char const*format,...)
  1118. #else
  1119. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1120. #endif
  1121. {
  1122.     int r;
  1123.     va_list args;
  1124.     vararg_start(args, format);
  1125.     r = vfprintf(stderr, format, args);
  1126.     va_end(args);
  1127.     return r;
  1128. }
  1129. int main() { exitmain(p("") != 0); }
  1130. EOF
  1131. $RM || exit
  1132. if ($CL a.c $L && ./a.out) >&2
  1133. then h=1
  1134. else h=0
  1135. fi
  1136. echo "#define has_vfprintf $h /* Does vfprintf() work?  */"
  1137.  
  1138. : has__doprintf, has__doprnt
  1139. case $h in
  1140. 1)
  1141.     h=? a='/* ' z='*/ ';;
  1142. *)
  1143.     a= z=
  1144.     cat >a.c <<'EOF'
  1145. #include "a.h"
  1146. #if has_prototypes
  1147. int p(char const*format,...)
  1148. #else
  1149. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1150. #endif
  1151. {
  1152.     va_list args;
  1153.     vararg_start(args, format);
  1154. #    if TRY__DOPRINTF
  1155.         _doprintf(stderr, format, args);
  1156. #    else
  1157.         _doprnt(format, args, stderr);
  1158. #    endif
  1159.     va_end(args);
  1160. }
  1161. int main() { p(""); exitmain(ferror(stderr) != 0); }
  1162. EOF
  1163.     $RM || exit
  1164.     if ($CL -DTRY__DOPRINTF=1 a.c $L && ./a.out) >&2
  1165.     then h=1
  1166.     else h=0
  1167.     fi
  1168. esac
  1169. echo "$a#define has__doprintf $h $z/* Does _doprintf() work?  */"
  1170. case $h in
  1171. 0)
  1172.     $RM || exit
  1173.     if ($CL a.c $L && ./a.out) >&2
  1174.     then h=1
  1175.     else h=0
  1176.     fi
  1177.     a= z=;;
  1178. *)
  1179.     h=? a='/* ' z='*/ '
  1180. esac
  1181. echo "$a#define has__doprnt $h $z/* Does _doprnt() work?  */"
  1182.  
  1183. : EXIT_FAILURE
  1184. cat >a.c <<'EOF'
  1185. #include "a.h"
  1186. int main() { exitmain(EXIT_FAILURE); }
  1187. EOF
  1188. $RM || exit
  1189. if $CL a.c $L >&2 && ./a.out
  1190. then a= z=
  1191. else a='/* ' z='*/ '
  1192. fi
  1193. echo "$a#undef EXIT_FAILURE $z/* Uncomment this if EXIT_FAILURE is broken.  */"
  1194.  
  1195. : large_memory
  1196. echo "#define large_memory $has_mmap /* Can main memory hold entire RCS files?  */"
  1197.  
  1198. : ULONG_MAX
  1199. cat >a.c <<'EOF'
  1200. #include "a.h"
  1201. #ifdef ULONG_MAX
  1202.     /*
  1203.      * "#if ULONG_MAX/10 <= 0" does not always work,
  1204.      * because some buggy implementations put casts in ULONG_MAX.
  1205.      */
  1206.     int main() { exitmain(ULONG_MAX/10 <= 0); }
  1207. #else
  1208.     int main() { exitmain(1); }
  1209. #endif
  1210. EOF
  1211. $RM || exit
  1212. if $CL a.c $L >&2 && ./a.out
  1213. then a='/* ' z='*/ '
  1214. else a= z=
  1215. fi
  1216. echo "$a#undef ULONG_MAX $z/* Uncomment this if ULONG_MAX is broken (e.g. < 0).  */"
  1217.  
  1218. : struct utimbuf
  1219. cat >a.c <<'EOF'
  1220. #include "a.h"
  1221. struct utimbuf s;
  1222. int main() { s.actime = s.modtime = 1; exitmain(utime("a.c", &s) != 0); }
  1223. EOF
  1224. $RM || exit
  1225. if ($CL a.c $L && ./a.out) >&2
  1226. then a='/* ' z=' */'
  1227. else a= z=
  1228. fi
  1229. echo "${a}struct utimbuf { time_t actime, modtime; };$z /* Uncomment this if needed.  */"
  1230.  
  1231. : CO
  1232. echo "#define CO \"${RCSPREFIX}co\" /* name of 'co' program */"
  1233.  
  1234. : COMPAT2
  1235. echo "#define COMPAT2 $COMPAT2 /* Are version 2 files supported?  */"
  1236.  
  1237. : DATEFORM
  1238. cat >a.c <<'EOF'
  1239. #include "a.h"
  1240. int main() { printf("%.2d", 1); exitmain(0); }
  1241. EOF
  1242. $RM && $CL a.c $L >&2 && r=`./a.out` || exit
  1243. case $r in
  1244. 01)    f=%.2d;;
  1245. *)    f=%02d
  1246. esac
  1247. echo "#define DATEFORM \"$f.$f.$f.$f.$f.${f}\" /* e.g. 01.01.01.01.01.01 */"
  1248.  
  1249. : DIFF
  1250. echo "#define DIFF \"${DIFF}\" /* name of 'diff' program */"
  1251.  
  1252. : DIFF3
  1253. echo "#define DIFF3 \"${DIFF3}\" /* name of 'diff3' program */"
  1254.  
  1255. echo "#define DIFF3_A $DIFF3_A /* Does diff3 have an -A option?  */"
  1256.  
  1257. echo "#define DIFF3_BIN $DIFF3_BIN /* Is diff3 user-visible (not the /usr/lib auxiliary)?  */"
  1258.  
  1259. : DIFF_FLAGS
  1260. dfs=
  1261. for df in $DIFF_FLAGS
  1262. do dfs="$dfs, \"${df}\""
  1263. done
  1264. echo "#define DIFF_FLAGS $dfs /* Make diff output suitable for RCS.  */"
  1265.  
  1266. : DIFF_L
  1267. echo "#define DIFF_L $DIFF_L /* Does diff -L work? */"
  1268.  
  1269. : DIFF_SUCCESS, DIFF_FAILURE, DIFF_TROUBLE
  1270. cat <<EOF
  1271. #define DIFF_SUCCESS $DIFF_SUCCESS /* DIFF status if no differences are found */
  1272. #define DIFF_FAILURE $DIFF_FAILURE /* DIFF status if differences are found */
  1273. #define DIFF_TROUBLE $DIFF_TROUBLE /* DIFF status if trouble */
  1274. EOF
  1275.  
  1276. : ED
  1277. echo "#define ED \"${ED}\" /* name of 'ed' program (used only if !DIFF3_BIN) */"
  1278.  
  1279. : MERGE
  1280. echo "#define MERGE \"${RCSPREFIX}merge\" /* name of 'merge' program */"
  1281.  
  1282. : '*SLASH*', ROOTPATH, TMPDIR, X_DEFAULT
  1283. case ${PWD-`pwd`} in
  1284. /*) # Posix
  1285.     SLASH=/
  1286.     qSLASH="'/'"
  1287.     SLASHes=$qSLASH
  1288.     isSLASH='#define isSLASH(c) ((c) == SLASH)'
  1289.     ROOTPATH='isSLASH((p)[0])'
  1290.     X_DEFAULT=",v$SLASH";;
  1291. ?:[/\\]*) # MS-DOS
  1292.     SLASH='\'
  1293.     qSLASH="'\\\\'"
  1294.     SLASHes="$qSLASH: case '/': case ':'"
  1295.     isSLASH='int isSLASH P((int));'
  1296.     ROOTPATH='((p)[0] && (p)[1]==':' && isSLASH((p)[2]))'
  1297.     X_DEFAULT="$SLASH,v";;
  1298. *)
  1299.     echo >&2 "cannot deduce SLASH"; exit 1
  1300. esac
  1301. cat <<EOF
  1302. #define TMPDIR "${SLASH}tmp" /* default directory for temporary files */
  1303. #define SLASH $qSLASH /* principal pathname separator */
  1304. #define SLASHes $SLASHes /* \`case SLASHes:' labels all pathname separators */
  1305. $isSLASH /* Is arg a pathname separator?  */
  1306. #define ROOTPATH(p) $ROOTPATH /* Is p an absolute pathname?  */
  1307. #define X_DEFAULT "$X_DEFAULT" /* default value for -x option */
  1308. EOF
  1309.  
  1310. : DIFF_ABSOLUTE
  1311. case $DIFF in
  1312. "$SLASH"*) a=1;;
  1313. *) a=0
  1314. esac
  1315. echo "#define DIFF_ABSOLUTE $a /* Is ROOTPATH(DIFF) true?  */"
  1316.  
  1317. : ALL_ABSOLUTE
  1318. a=1
  1319. for i in "$DIFF" "$DIFF3" "$ED" "$RCSPREFIX" "$SENDMAIL"/
  1320. do
  1321.     case $i in
  1322.     "$SLASH"* | "\"$SLASH"*) ;;
  1323.     *) a=0 break
  1324.     esac
  1325. done
  1326. echo "#define ALL_ABSOLUTE $a /* Are all subprograms absolute pathnames?  */"
  1327.  
  1328. : SENDMAIL
  1329. case $SENDMAIL in
  1330. '') a='/* ' z='*/ ';;
  1331. *) a= z=
  1332. esac
  1333. echo "$a#define SENDMAIL $SENDMAIL $z/* how to send mail */"
  1334.  
  1335. : TZ_must_be_set
  1336. echo "#define TZ_must_be_set 0 /* Must TZ be set for gmtime() to work?  */"
  1337.  
  1338.  
  1339. : standard function declarations
  1340.  
  1341. cat <<'EOF'
  1342.  
  1343.  
  1344.  
  1345. /* Adjust the following declarations as needed.  */
  1346.  
  1347.  
  1348. #if __GNUC__ && !__STRICT_ANSI__
  1349. #    define exiting volatile /* GCC extension: function cannot return */
  1350. #else
  1351. #    define exiting
  1352. #endif
  1353. EOF
  1354.  
  1355. cat >a.ha <<EOF
  1356.  
  1357. #if has_ftruncate
  1358.     int ftruncate P((int,off_t));
  1359. #endif
  1360.  
  1361. /* <sys/mman.h> */
  1362. #if has_madvise
  1363.     int madvise P((caddr_t,size_t,int));
  1364. #endif
  1365. #if has_mmap
  1366.     caddr_t mmap P((caddr_t,size_t,int,int,int,off_t));
  1367.     int munmap P((caddr_t,size_t));
  1368. #endif
  1369.  
  1370.  
  1371. /* Posix (ISO/IEC 9945-1: 1990 / IEEE Std 1003.1-1990) */
  1372. /* These definitions are for the benefit of non-Posix hosts, and */
  1373. /* Posix hosts that have Standard C compilers but traditional include files.  */
  1374. /* Unfortunately, mixed-up hosts are all too common.  */
  1375.  
  1376. /* <fcntl.h> */
  1377. #ifdef F_DUPFD
  1378.     int fcntl P((int,int,...));
  1379. #else
  1380.     int dup2 P((int,int));
  1381. #endif
  1382. #ifndef O_BINARY /* some non-Posix hosts need O_BINARY */
  1383. #    define O_BINARY 0 /* no effect on Posix */
  1384. #endif
  1385. #ifdef O_CREAT
  1386. #    define open_can_creat 1
  1387. #else
  1388. #    define open_can_creat 0
  1389. #    define O_RDONLY 0
  1390. #    define O_WRONLY 1
  1391. #    define O_RDWR 2
  1392. #    define O_CREAT 01000
  1393. #    define O_TRUNC 02000
  1394.     int creat P((char const*,mode_t));
  1395. #endif
  1396. #ifndef O_EXCL
  1397. #    define O_EXCL 0
  1398. #endif
  1399.  
  1400. /* <pwd.h> */
  1401. #if has_getpwuid
  1402.     struct passwd *getpwuid P((uid_t));
  1403. #endif
  1404.  
  1405. /* <signal.h> */
  1406. #if has_sigaction
  1407.     int sigaction P((int,struct sigaction const*,struct sigaction*));
  1408.     int sigaddset P((sigset_t*,int));
  1409.     int sigemptyset P((sigset_t*));
  1410. #else
  1411. #if has_sigblock
  1412.     /* BSD */
  1413.     int sigblock P((int));
  1414.     int sigmask P((int));
  1415.     int sigsetmask P((int));
  1416. #endif
  1417. #endif
  1418.  
  1419. /* <stdio.h> */
  1420. FILE *fdopen P((int,char const*));
  1421. int fileno P((FILE*));
  1422.  
  1423. /* <sys/stat.h> */
  1424. int chmod P((char const*,mode_t));
  1425. int fstat P((int,struct stat*));
  1426. int stat P((char const*,struct stat*));
  1427. mode_t umask P((mode_t));
  1428. #if has_fchmod
  1429.     int fchmod P((int,mode_t));
  1430. #endif
  1431. #ifndef S_IRUSR
  1432. #    ifdef S_IREAD
  1433. #        define S_IRUSR S_IREAD
  1434. #    else
  1435. #        define S_IRUSR 0400
  1436. #    endif
  1437. #    ifdef S_IWRITE
  1438. #        define S_IWUSR S_IWRITE
  1439. #    else
  1440. #        define S_IWUSR (S_IRUSR/2)
  1441. #    endif
  1442. #endif
  1443. #ifndef S_IRGRP
  1444. #    if has_getuid
  1445. #        define S_IRGRP (S_IRUSR / 0010)
  1446. #        define S_IWGRP (S_IWUSR / 0010)
  1447. #        define S_IROTH (S_IRUSR / 0100)
  1448. #        define S_IWOTH (S_IWUSR / 0100)
  1449. #    else
  1450.         /* single user OS -- not Posix or Unix */
  1451. #        define S_IRGRP 0
  1452. #        define S_IWGRP 0
  1453. #        define S_IROTH 0
  1454. #        define S_IWOTH 0
  1455. #    endif
  1456. #endif
  1457. #ifndef S_ISREG
  1458. #    define S_ISREG(n) (((n) & S_IFMT) == S_IFREG)
  1459. #endif
  1460.  
  1461. /* <sys/wait.h> */
  1462. #if has_wait
  1463.     pid_t wait P((int*));
  1464. #endif
  1465. #ifndef WEXITSTATUS
  1466. #    define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  1467. #    undef WIFEXITED /* Avoid 4.3BSD incompatibility with Posix.  */
  1468. #endif
  1469. #ifndef WIFEXITED
  1470. #    define WIFEXITED(stat_val) (!((stat_val) & 255))
  1471. #endif
  1472.  
  1473. /* <unistd.h> */
  1474. char *getlogin P((void));
  1475. int close P((int));
  1476. int isatty P((int));
  1477. int link P((char const*,char const*));
  1478. int open P((char const*,int,...));
  1479. int unlink P((char const*));
  1480. int _filbuf P((FILE*)); /* keeps lint quiet in traditional C */
  1481. int _flsbuf P((int,FILE*)); /* keeps lint quiet in traditional C */
  1482. long pathconf P((char const*,int));
  1483. ssize_t write P((int,void const*,size_t));
  1484. #ifndef STDIN_FILENO
  1485. #    define STDIN_FILENO 0
  1486. #    define STDOUT_FILENO 1
  1487. #    define STDERR_FILENO 2
  1488. #endif
  1489. #if has_fork
  1490. #    if !has_vfork
  1491. #        undef vfork
  1492. #        define vfork fork
  1493. #    endif
  1494.     pid_t vfork P((void)); /* vfork is nonstandard but faster */
  1495. #endif
  1496. #if has_getcwd || !has_getwd
  1497.     char *getcwd P((char*,size_t));
  1498. #else
  1499.     char *getwd P((char*));
  1500. #endif
  1501. #if has_getuid
  1502.     uid_t getuid P((void));
  1503. #endif
  1504. #if has_readlink
  1505.     ssize_t readlink P((char const*,char*,size_t)); /* BSD; not standard yet */
  1506. #endif
  1507. #if has_setuid
  1508. #    if !has_seteuid
  1509. #        undef seteuid
  1510. #        define seteuid setuid
  1511. #    endif
  1512.     int seteuid P((uid_t));
  1513.     uid_t geteuid P((void));
  1514. #endif
  1515. #if has_spawn
  1516.     int spawnv P((int,char const*,char*const*));
  1517. #    if ALL_ABSOLUTE
  1518. #        define spawn_RCS spawnv
  1519. #    else
  1520. #        define spawn_RCS spawnvp
  1521.         int spawnvp P((int,char const*,char*const*));
  1522. #    endif
  1523. #else
  1524.     int execv P((char const*,char*const*));
  1525. #    if ALL_ABSOLUTE
  1526. #        define exec_RCS execv
  1527. #    else
  1528. #        define exec_RCS execvp
  1529.         int execvp P((char const*,char*const*));
  1530. #    endif
  1531. #endif
  1532.  
  1533. /* utime.h */
  1534. int utime P((char const*,struct utimbuf const*));
  1535.  
  1536.  
  1537. /* Standard C library */
  1538. /* These definitions are for the benefit of hosts that have */
  1539. /* traditional C include files, possibly with Standard C compilers.  */
  1540. /* Unfortunately, mixed-up hosts are all too common.  */
  1541.  
  1542. /* <errno.h> */
  1543. extern int errno;
  1544.  
  1545. /* <limits.h> */
  1546. #ifndef ULONG_MAX
  1547.     /* This does not work in #ifs, but it's good enough for us.  */
  1548. #    define ULONG_MAX ((unsigned long)-1)
  1549. #endif
  1550.  
  1551. /* <signal.h> */
  1552. #if has_signal
  1553.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  1554. #endif
  1555.  
  1556. /* <stdio.h> */
  1557. FILE *fopen P((char const*,char const*));
  1558. fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  1559. fread_type fwrite P((void const*,freadarg_type,freadarg_type,FILE*));
  1560. int fclose P((FILE*));
  1561. int feof P((FILE*));
  1562. int ferror P((FILE*));
  1563. int fflush P((FILE*));
  1564. int fprintf P((FILE*,char const*,...));
  1565. int fputs P((char const*,FILE*));
  1566. int fseek P((FILE*,long,int));
  1567. int printf P((char const*,...));
  1568. int rename P((char const*,char const*));
  1569. int sprintf P((char*,char const*,...));
  1570. long ftell P((FILE*));
  1571. void clearerr P((FILE*));
  1572. void perror P((char const*));
  1573. #ifndef L_tmpnam
  1574. #    define L_tmpnam 32 /* power of 2 > sizeof("/usr/tmp/xxxxxxxxxxxxxxx") */
  1575. #endif
  1576. #ifndef SEEK_SET
  1577. #    define SEEK_SET 0
  1578. #endif
  1579. #if has_mktemp
  1580.     char *mktemp P((char*)); /* traditional */
  1581. #else
  1582.     char *tmpnam P((char*));
  1583. #endif
  1584. #if has_vfprintf
  1585.     int vfprintf P((FILE*,char const*,va_list));
  1586. #else
  1587. #if has__doprintf
  1588.     void _doprintf P((FILE*,char const*,va_list)); /* Minix */
  1589. #else
  1590.     void _doprnt P((char const*,va_list,FILE*)); /* BSD */
  1591. #endif
  1592. #endif
  1593.  
  1594. /* <stdlib.h> */
  1595. char *getenv P((char const*));
  1596. exiting void _exit P((int));
  1597. exiting void exit P((int));
  1598. malloc_type malloc P((size_t));
  1599. malloc_type realloc P((malloc_type,size_t));
  1600. void free P((malloc_type));
  1601. #ifndef EXIT_FAILURE
  1602. #    define EXIT_FAILURE 1
  1603. #endif
  1604. #ifndef EXIT_SUCCESS
  1605. #    define EXIT_SUCCESS 0
  1606. #endif
  1607. #if !has_fork && !has_spawn
  1608.     int system P((char const*));
  1609. #endif
  1610.  
  1611. /* <string.h> */
  1612. char *strcpy P((char*,char const*));
  1613. char *strchr P((char const*,int));
  1614. char *strrchr P((char const*,int));
  1615. int memcmp P((void const*,void const*,size_t));
  1616. int strcmp P((char const*,char const*));
  1617. size_t strlen P((char const*));
  1618. void *memcpy P((void*,void const*,size_t));
  1619. #if has_memmove
  1620.     void *memmove P((void*,void const*,size_t));
  1621. #endif
  1622.  
  1623. /* <time.h> */
  1624. time_t time P((time_t*));
  1625. EOF
  1626.  
  1627. cat >a.c <<'EOF'
  1628. #include "a.h"
  1629. #define a 0
  1630. #define b 1
  1631. #if h==a
  1632. #    include "a.ha"
  1633. #else
  1634. #    include "a.hb"
  1635. #endif
  1636. int main() { exitmain(0); }
  1637. EOF
  1638.  
  1639. # Comment out lines in a.ha that the compiler rejects.
  1640. # a.ha may not contain comments that cross line boundaries.
  1641. # Leave the result in a.h$h.
  1642. h=a l=1
  1643. U=`wc -l <a.ha | sed 's| ||g'`
  1644. commentOut='s|^[^#/][^/]*|/* & */|'
  1645.  
  1646. until  test $U -lt $l  ||  $CS -Dh=$h a.c $LS >&2
  1647. do
  1648.     case $h in
  1649.     a) i=b;;
  1650.     *) i=a
  1651.     esac
  1652.  
  1653.     # The compiler rejects some line in l..U.
  1654.     # Use binary search to set l to be the index of the first bad line in l..U.
  1655.     u=$U
  1656.     while test $l -lt $u
  1657.     do
  1658.         M=`expr '(' $l + $u ')' / 2`
  1659.         M1=`expr $M + 1`
  1660.         sed "$M1,\$$commentOut" a.h$h >a.h$i || exit
  1661.         if $CS -Dh=$i a.c $LS >&2
  1662.         then l=$M1
  1663.         else u=$M
  1664.         fi
  1665.     done
  1666.  
  1667.     # Comment out the bad line.
  1668.     sed "$l$commentOut" a.h$h >a.h$i || exit
  1669.  
  1670.     h=$i
  1671.     l=`expr $l + 1`
  1672. done
  1673.  
  1674. cat a.h$h
  1675.