1#! /bin/sh
2#
3# If these # comments don't work, trim them.  Don't worry about any
4# other shell scripts, Configure will trim # comments from them for you.
5#
6# (If you are trying to port this package to a machine without sh, I'd
7# suggest you cut out the prototypical config.h from the end of this
8# file and edit it to reflect your system.  Some packages may include
9# samples of config.h for certain machines, so you might look for one
10# of those.)
11#
12# Yes, you may rip this off to use in other distribution packages.
13# (Note: this Configure script was generated automatically.  Rather than
14# working with this copy of Configure, you may wish to get metaconfig.
15# Write to ram@educ.emse.fr (Raphael Manfredi) and I will send you
16# my version which slightly differs from the original written by
17# Larry Wall.)
18
19# $Id: Configure,v 4.0.1.1 91/10/10 18:39:55 cek Exp Locker: cek $
20
21: save PATH defined by user
22user_path=$PATH
23
24: sanity checks
25PATH='.:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin'
26PATH=$PATH:'/usr/5bin:/etc:/usr/gnu/bin:/usr/new:/usr/new/bin:/usr/nbin'
27PATH=$PATH:'/sys5.3/bin:/sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/ucb'
28PATH=$PATH:'/bsd4.3/usr/bin:/usr/bsd'
29export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
30
31#FreeBSD's ports don't want to be interactive
32#if test ! -t 0; then
33#    echo "Say 'sh Configure', not 'sh <Configure'"
34#    exit 1
35#fi
36
37(alias) >/dev/null 2>&1 && \
38    echo "(I see you are using the Korn shell.  Some ksh's blow up on Configure," && \
39    echo "especially on exotic machines.  If yours does, try the Bourne shell instead.)"
40
41if test ! -d ../UU; then
42    if test ! -d UU; then
43	mkdir UU
44    fi
45    cd UU
46fi
47
48case "$1" in
49-d) shift; fastread='yes';;
50esac
51
52d_eunice=''
53d_xenix=''
54d_bsd=''
55define=''
56eunicefix=''
57loclist=''
58expr=''
59awk=''
60sed=''
61echo=''
62cat=''
63chgrp=''
64chmod=''
65chown=''
66rm=''
67mv=''
68cp=''
69tail=''
70tr=''
71mkdir=''
72sort=''
73uniq=''
74grep=''
75trylist=''
76test=''
77inews=''
78egrep=''
79more=''
80pg=''
81Mcc=''
82vi=''
83mail=''
84bison=''
85cpp=''
86perl=''
87Log=''
88Header=''
89Id=''
90bin=''
91contains=''
92cppstdin=''
93cppminus=''
94d_bzero=''
95d_cbrt=''
96d_index=''
97d_memset=''
98d_popen=''
99d_rusage=''
100d_times=''
101clocktype=''
102i_string=''
103strings=''
104i_sysresrc=''
105i_systypes=''
106i_time=''
107i_systime=''
108i_systimek=''
109timeincl=''
110inhdr=''
111inlibc=''
112libs=''
113models=''
114split=''
115small=''
116medium=''
117large=''
118huge=''
119ccflags=''
120ldflags=''
121cc=''
122cppflags=''
123optimize=''
124n=''
125c=''
126orderlib=''
127ranlib=''
128package=''
129randfunc=''
130mrand=''
131seedfunc=''
132nrandbits=''
133spitshell=''
134shsharp=''
135sharpbang=''
136startsh=''
137sysman=''
138voidflags=''
139defvoidused=''
140yacc=''
141d_urt=''
142urtinc=''
143urtlib=''
144i_stdlib=''
145libc=''
146mkdep=''
147CONFIG=''
148: set package name
149package=rayshade
150
151echo " "
152echo "Beginning of configuration questions for $package kit."
153: Eunice requires " " instead of "", can you believe it
154echo " "
155
156define='define'
157undef='undef'
158: change the next line if compiling for Xenix/286 on Xenix/386
159xlibpath='/usr/lib/386 /lib/386'
160libpth='/usr/lib /usr/local/lib /usr/lib/large /lib '$xlibpth' /lib/large'
161libpth=$libpth' /usr/lib/small /lib/small'
162smallmach='pdp11 i8086 z8000 i80286 iAPX286'
163rmlist='ark[1-9]isdone ark[1-9][0-9]isdone'
164trap 'echo " "; rm -f $rmlist; exit 1' 1 2 3 15
165
166: We must find out about Eunice early
167eunicefix=':'
168if test -f /etc/unixtovms; then
169    eunicefix=/etc/unixtovms
170fi
171if test -f /etc/unixtovms.exe; then
172    eunicefix=/etc/unixtovms.exe
173fi
174
175if ls blurfl >/dev/null 2>&1; then
176	if awk '' blurfl >/dev/null 2>&1; then
177		check='cat'
178	else
179		check='awk ""'
180	fi
181else
182	check='ls'
183fi
184
185: Now test for existence of everything in MANIFEST
186if test -f ../MANIFEST; then
187	echo "First let's make sure your kit is complete.  Checking..."
188	: some grep do not return a proper exit status
189	grep '^---' ../MANIFEST > .grepmani 2>/dev/null
190	if test -s .grepmani; then
191(cd ..; eval $check `awk '!/^.*\/$/{if (b) print $1}
192/^---/{b=1}' MANIFEST` || kill $$) >/dev/null
193	else
194(cd ..; eval $check `awk '!/^.*\/$/{print $1}' MANIFEST` || kill $$) >/dev/null
195	fi
196	echo "Looks good..."
197else
198	echo "No MANIFEST found. Hope your kit is complete !"
199fi
200rm -f .grepmani
201
202pth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/5bin"
203pth=$pth" /usr/lbin /etc /usr/new /usr/new/bin /usr/nbin /usr/gnu/bin"
204pth=$pth" /usr/plx /vol/local/bin /usr/lib /lib /usr/local/lib"
205pth=$pth" /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/bin"
206pth=$pth" /bsd4.3/usr/ucb /usr/bsd"
207: add PATH from user
208pth=$pth" "`echo $user_path | sed -e 's/:/ /g'`
209inclwanted=''
210defvoidused=15
211libswanted='m malloc c_s'
212defvoidused=11
213: some greps do not return status, grrr.
214echo "grimblepritz" >grimble
215if grep blurfldyick grimble >/dev/null 2>&1 ; then
216    contains=contains
217elif grep grimblepritz grimble >/dev/null 2>&1 ; then
218    contains=grep
219else
220    contains=contains
221fi
222rm -f grimble
223: the following should work in any shell
224case "$contains" in
225contains*)
226    echo " "
227    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
228    cat >contains <<'EOSS'
229grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
230EOSS
231chmod +x contains
232esac
233
234: see if sh knows # comments
235echo " "
236echo "Checking your sh to see if it knows about # comments..."
237if sh -c '#' >/dev/null 2>&1 ; then
238	echo "Your sh handles # comments correctly."
239	shsharp=true
240	spitshell=cat
241	echo " "
242	echo "Okay, let's see if #! works on this system..."
243	echo "#!/bin/echo hi" > try
244	$eunicefix try
245	chmod +x try
246	try > today
247	if $contains hi today >/dev/null 2>&1; then
248		echo "It does."
249		sharpbang='#!'
250	else
251		echo "#! /bin/echo hi" > try
252		$eunicefix try
253		chmod +x try
254		try > today
255		if test -s today; then
256			echo "It does."
257			sharpbang='#! '
258		else
259			echo "#!/bin/cat" > try
260			$eunicefix try
261			chmod +x try
262			try >today
263			if test -s today; then
264				echo "It does, without processing parameters."
265				sharpbang='#!'
266			else
267				echo "It doesn't."
268				sharpbang=': use '
269			fi
270		fi
271	fi
272else
273	echo "Your sh doesn't grok # comments--I will strip them later on."
274	shsharp=false
275	echo "exec grep -v '^[ 	]*#'" >spitshell
276	chmod +x spitshell
277	$eunicefix spitshell
278	spitshell=`pwd`/spitshell
279	echo "I presume that if # doesn't work, #! won't work either!"
280	sharpbang=': use '
281fi
282rm -f try today
283
284: figure out how to guarantee sh startup
285echo " "
286echo "Checking out how to guarantee sh startup..."
287startsh=$sharpbang'/bin/sh'
288echo "Let's see if '$startsh' works..."
289cat >try <<EOSS
290$startsh
291set abc
292test "$?abc" != 1
293EOSS
294
295chmod +x try
296$eunicefix try
297if try; then
298    echo "Yup, it does."
299else
300    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
301fi
302rm -f try
303
304: first determine how to suppress newline on echo command
305echo " "
306echo "Checking echo to see how to suppress newlines..."
307(echo "hi there\c" ; echo " ") >.echotmp
308if $contains c .echotmp >/dev/null 2>&1 ; then
309    echo "...using -n."
310    n='-n'
311    c=''
312else
313    cat <<'EOM'
314...using \c
315EOM
316    n=''
317    c='\c'
318fi
319echo $n "The star should be here-->$c"
320echo '*'
321rm -f .echotmp
322
323: now set up to do reads with possible shell escape and default assignment
324cat <<EOSC >myread
325case "\$fastread" in
326yes) ans=''; echo " " ;;
327*) ans='!';;
328esac
329while expr "X\$ans" : "X!" >/dev/null; do
330    read ans
331    case "\$ans" in
332    !)
333	sh
334	echo " "
335	echo $n "\$rp $c"
336	;;
337    !*)
338	set \`expr "X\$ans" : "X!\(.*\)\$"\`
339	sh -c "\$*"
340	echo " "
341	echo $n "\$rp $c"
342	;;
343    esac
344done
345rp='Your answer:'
346case "\$ans" in
347'') ans="\$dflt";;
348esac
349EOSC
350
351: general instructions
352cat <<EOH
353 
354This installation shell script will examine your system and ask you questions
355to determine how the $package package should be installed.  If you get stuck
356on a question, you may use a ! shell escape to start a subshell or execute
357a command.  Many of the questions will have default answers in square
358brackets--typing carriage return will give you the default.
359
360On some of the questions which ask for file or directory names you are
361allowed to use the ~name construct to specify the login directory belonging
362to "name", even if you don't have a shell which knows about that.  Questions
363where this is allowed will be marked "(~name ok)".
364
365EOH
366rp="[Type carriage return to continue]"
367echo $n "$rp $c"
368. myread
369cat <<EOH
370
371Much effort has been expended to ensure that this shell script will run on
372any Unix system. If despite that it blows up on you, your best bet is to edit
373Configure and run it again. Also, let me (rayshade-request@cs.princeton.edu)
374know how I blew it. If you can't run Configure for some reason, you'll have
375to generate a config.sh file by hand.
376
377This installation script affects things in two ways:
3781) it may do direct variable substitutions on some of the files included
379   in this kit.
3802) it builds a config.h file for inclusion in C programs.  You may edit
381   any of these files as the need arises after running this script.
382
383If you make a mistake on a question, there is no easy way to back up to it
384currently.  The easiest thing to do is to edit config.sh and rerun all the
385SH files.  Configure will offer to let you do this before it runs the SH files.
386
387EOH
388rp="[Type carriage return to continue]"
389echo $n "$rp $c"
390. myread
391
392: get old answers, if there is a config file out there
393if test -f ../config.sh; then
394    echo " "
395    dflt=y
396    rp="I see a config.sh file.  Did Configure make it on THIS system? [$dflt]"
397    echo $n "$rp $c"
398    . myread
399    case "$ans" in
400    n*|N*) echo "OK, I'll ignore it.";;
401    *)  echo "Fetching default answers from your old config.sh file..."
402	tmp="$n"
403	ans="$c"
404        . ../config.sh
405	n="$tmp"
406	c="$ans"
407	;;
408    esac
409fi
410
411: find out where common programs are
412echo " "
413echo "Locating common programs..."
414cat <<EOSC >loc
415$startsh
416case \$# in
4170) exit 1;;
418esac
419thing=\$1
420shift
421dflt=\$1
422shift
423for dir in \$*; do
424    case "\$thing" in
425    .)
426	if test -d \$dir/\$thing; then
427	    echo \$dir
428	    exit 0
429	fi
430	;;
431    *)
432	if test -f \$dir/\$thing; then
433	    echo \$dir/\$thing
434	    exit 0
435	elif test -f \$dir/\$thing.exe; then
436	    : on Eunice apparently
437	    echo \$dir/\$thing
438	    exit 0
439	fi
440	;;
441    esac
442done
443echo \$dflt
444exit 1
445EOSC
446chmod +x loc
447$eunicefix loc
448loclist="
449cat
450echo
451expr
452grep
453rm
454sed
455sort
456uniq
457"
458trylist="
459bison
460cpp
461test
462"
463for file in $loclist; do
464    xxx=`loc $file $file $pth`
465    eval $file=$xxx
466    eval _$file=$xxx
467    case "$xxx" in
468    /*)
469	echo $file is in $xxx.
470	;;
471    *)
472	echo "I don't know where $file is.  I hope it's in everyone's PATH."
473	;;
474    esac
475done
476echo " "
477echo "Don't worry if any of the following aren't found..."
478ans=offhand
479for file in $trylist; do
480    xxx=`loc $file $file $pth`
481    eval $file=$xxx
482    eval _$file=$xxx
483    case "$xxx" in
484    /*)
485	echo $file is in $xxx.
486	;;
487    *)
488	echo "I don't see $file out there, $ans."
489	ans=either
490	;;
491    esac
492done
493case "$egrep" in
494egrep)
495    echo "Substituting grep for egrep."
496    egrep=$grep
497    ;;
498esac
499case "$test" in
500test)
501    echo "Hopefully test is built into your sh."
502    ;;
503/bin/test)
504    if sh -c "PATH= test true" >/dev/null 2>&1; then
505	echo "Using the test built into your sh."
506	test=test
507    fi
508    ;;
509*)
510    test=test
511    ;;
512esac
513case "$echo" in
514echo)
515    echo "Hopefully echo is built into your sh."
516    ;;
517/bin/echo)
518    echo " "
519    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
520    $echo $n "hi there$c" >foo1
521    echo $n "hi there$c" >foo2
522    if cmp foo1 foo2 >/dev/null 2>&1; then
523	echo "They are compatible.  In fact, they may be identical."
524    else
525	case "$n" in
526	'-n') n='' c='\c' ans='\c' ;;
527	*) n='-n' c='' ans='-n' ;;
528	esac
529	cat <<FOO
530They are not compatible!  You are probably running ksh on a non-USG system.
531I'll have to use /bin/echo instead of the builtin, since Bourne shell doesn't
532have echo built in and we may have to run some Bourne shell scripts.  That
533means I'll have to use $ans to suppress newlines now.  Life is ridiculous.
534
535FOO
536	rp="The star should be here-->"
537	$echo $n "$rp$c"
538	$echo "*"
539    fi
540    $rm -f foo1 foo2
541    ;;
542*)
543    : cross your fingers
544    echo=echo
545    ;;
546esac
547rmlist="$rmlist loc"
548
549: Looking for optional libraries
550echo " "
551echo "Checking for optional libraries..."
552dflt=''
553case "$libswanted" in
554'') libswanted='c_s';;
555esac
556for thislib in $libswanted; do
557    case "$thislib" in
558    dbm) thatlib=ndbm;;
559    *_s) thatlib=NONE;;
560    *) thatlib="${thislib}_s";;
561    *) thatlib=NONE;;
562    esac
563    xxx=`loc lib$thislib.a X /usr/lib /usr/local/lib /lib`
564    if $test -f $xxx; then
565	echo "Found -l$thislib."
566	case "$dflt" in
567	*-l$thislib*|*-l$thatlib*);;
568	*) dflt="$dflt -l$thislib";;
569	esac
570    else
571	xxx=`loc lib$thislib.a X $libpth`
572	if $test -f $xxx; then
573	    echo "Found $xxx."
574	    case "$dflt" in
575	    *$xxx*);;
576	    *) dflt="$dflt $xxx";;
577	    esac
578	else
579	    xxx=`loc Slib$thislib.a X $xlibpth`
580	    if $test -f $xxx; then
581		echo "Found -l$thislib."
582		case "$dflt" in
583		*-l$thislib*|*-l$thatlib*);;
584		*) dflt="$dflt -l$thislib";;
585		esac
586	    else
587		echo "No -l$thislib."
588	    fi
589	fi
590    fi
591done
592set X $dflt
593shift
594dflt="$*"
595case "$libs" in
596'') dflt="$dflt";;
597*) dflt="$libs";;
598esac
599case "$dflt" in
600'') dflt='none';;
601esac
602
603$cat <<EOM
604 
605Some versions of Unix support shared libraries, which make
606executables smaller but make load time slightly longer.
607
608On some systems, mostly newer Unix System V's, the shared library
609is included by putting the option "-lc_s" as the last thing on the
610cc command line when linking.  Other systems use shared libraries
611by default.  There may be other libraries needed to compile $package
612on your machine as well.  If your system needs the "-lc_s" option,
613include it here.  Include any other special libraries here as well.
614Say "none" for none.
615EOM
616
617echo " "
618rp="Any additional libraries? [$dflt]"
619$echo $n "$rp $c"
620. myread
621case "$ans" in
622none) ans='';
623esac
624libs="$ans"
625
626: get list of predefined functions in a handy place
627echo " "
628case "$libc" in
629'') libc=unknown;;
630esac
631case "$libpth" in
632'') libpth='/lib /usr/lib /usr/local/lib';;
633esac
634case "$libs" in
635*-lc_s*) libc=`loc libc_s.a $libc $libpth`
636esac
637libnames='';
638case "$libs" in
639'') ;;
640*)  for thislib in $libs; do
641	case "$thislib" in
642	-l*) thislib=`expr X$thislib : 'X-l\(.*\)'`
643	    try=`loc lib$thislib.a blurfl/dyick $libpth`
644	    if test ! -f $try; then
645		try=`loc lib$thislib blurfl/dyick $libpth`
646		if test ! -f $try; then
647		    try=`loc $thislib blurfl/dyick $libpth`
648		    if test ! -f $try; then
649			try=`loc Slib$thislib.a blurfl/dyick $xlibpth`
650			if test ! -f $try; then
651			    try=''
652			fi
653		    fi
654		fi
655	    fi
656	    libnames="$libnames $try"
657	    ;;
658	*) libnames="$libnames $thislib" ;;
659	esac
660    done
661    ;;
662esac
663set /usr/ccs/lib/libc.so
664test -f $1 || set /usr/lib/libc.a
665test -f $1 || set /usr/lib/libc.so
666test -f $1 || set /usr/lib/libc.so.[0-9]*
667eval set \$$#
668if test -f "$1"; then
669    echo "Your shared C library is in $1."
670    libc="$1"
671elif test -f /lib/libc && test -f /lib/clib; then
672    echo "Your C library is in both /lib/clib and /lib/libc."
673    libc='/lib/clib /lib/libc'
674	if test -f /lib/syslib; then
675		echo "(Your math library is in /lib/syslib.)"
676		libc="$libc /lib/syslib"
677	fi
678elif test -f $libc; then
679    echo "Your C library is in $libc, like you said before."
680elif test -f /lib/libc.a; then
681    echo "Your C library is in /lib/libc.a.  You're normal."
682    libc=/lib/libc.a
683else
684    ans=`loc libc.a blurfl/dyick $libpth`
685    if test ! -f "$ans"; then
686	ans=`loc Slibc.a blurfl/dyick $xlibpth`
687    fi
688    if test ! -f "$ans"; then
689	ans=`loc Mlibc.a blurfl/dyick $xlibpth`
690    fi
691    if test ! -f "$ans"; then
692	ans=`loc Llibc.a blurfl/dyick $xlibpth`
693    fi
694    if test ! -f "$ans"; then
695	ans=`loc libc blurfl/dyick $libpth`
696    fi
697    if test ! -f "$ans"; then
698	ans=`loc clib blurfl/dyick $libpth`
699    fi
700    if test ! -f "$ans"; then
701         ans=`loc libsys_s.a blurfl/dyick $libpth`
702    fi
703    if test -f "$ans"; then
704	echo "Your C library is in $ans, of all places."
705	libc=$ans
706    else
707	cat <<EOM
708 
709I can't seem to find your C library.  I've looked in the following places:
710
711	$libpth
712
713None of these seems to contain your C library.  What is the full name
714EOM
715	dflt=None
716	$echo $n "of your C library? $c"
717	rp='C library full name?'
718	. myread
719	libc="$ans"
720    fi
721fi
722echo " "
723set `echo $libc $libnames | tr ' ' '\012' | sort | uniq`
724$echo $n "Extracting names from $* for later perusal...$c"
725nm $* 2>/dev/null >libc.tmp
726$grep printf libc.tmp > libc.ptf
727com="$sed -n -e 's/^.* [ADTS]  *_[_.]*//p' -e 's/^.* [ADTS] //p'"
728eval "$com <libc.ptf >libc.list"
729if $contains '^printf$' libc.list >/dev/null 2>&1; then
730	:
731else
732	com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'"
733	eval "$com <libc.ptf >libc.list"
734fi
735if $contains '^printf$' libc.list >/dev/null 2>&1; then
736	:
737else
738	com="$sed -n -e '/|Undef/d' -e '/|Proc/s/ .*//p'"
739	eval "$com <libc.ptf >libc.list"
740fi
741if $contains '^printf$' libc.list >/dev/null 2>&1; then
742	:
743else
744	com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'"
745	eval "$com <libc.ptf >libc.list"
746fi
747if $contains '^printf$' libc.list >/dev/null 2>&1; then
748	:
749else
750	com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'"
751	eval "$com <libc.ptf >libc.list"
752fi
753if $contains '^printf$' libc.list >/dev/null 2>&1; then
754	:
755else
756	com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'"
757	eval "$com <libc.ptf >libc.list"
758fi
759if $contains '^printf$' libc.list >/dev/null 2>&1; then
760	:
761else
762	com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'"
763	eval "$com <libc.ptf >libc.list"
764fi
765if $contains '^printf$' libc.list >/dev/null 2>&1; then
766	eval "$com <libc.tmp >libc.list"
767	echo "done"
768else
769	echo " "
770	echo "nm didn't seem to work right."
771	echo "Trying ar instead..."
772	if ar t $libc > libc.tmp; then
773		for thisname in $libnames; do
774			ar t $thisname >>libc.tmp
775		done
776		$sed -e 's/\.o$//' < libc.tmp > libc.list
777		echo "Ok."
778	else
779		echo "ar didn't seem to work right."
780		echo "Maybe this is a Cray...trying bld instead..."
781		if bld t $libc | $sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
782			for thisname in $libnames; do
783				bld t $libnames | \
784				$sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
785				ar t $thisname >>libc.tmp
786			done
787			echo "Ok."
788		else
789			echo "That didn't work either.  Giving up."
790			exit 1
791		fi
792	fi
793fi
794
795: define an in-header-list? function
796inhdr='echo " ";
797xxx=`loc $1 x /usr/include /usr/local/include $inclwanted`;
798if $test -f $xxx;
799then echo "<$1> found."; eval "$2=$define";
800else echo "No <$1> found."; eval "$2=$undef"; fi'
801
802: see if sys/types.h has to be included
803set sys/types.h i_systypes
804eval $inhdr
805
806: see if times exists
807echo " "
808if $contains '^times$' libc.list >/dev/null 2>&1; then
809    echo 'times() found.'
810    d_times="$define"
811	case "$clocktype" in
812	'')
813		if $contains 'clock_t;' /usr/include/sys/types.h >/dev/null 2>&1 ; then
814			dflt='clock_t';
815		elif $contains 'clock_t;' /usr/include/sys/times.h >/dev/null 2>&1; then
816			dflt='clock_t';
817		else
818			dflt='long';
819		fi
820		;;
821	*)  dflt="$clocktype"
822		;;
823	esac
824	cont=true
825	echo " "
826	rp="What type is returned by times() on this sytem? [$dflt]"
827	$echo $n "$rp $c"
828	. myread
829	clocktype="$ans"
830else
831    echo 'times() not found, hope that will do.'
832    d_times="$undef"
833	clocktype='int'
834fi
835
836: set up shell script to do ~ expansion
837cat >filexp <<EOSS
838$startsh
839: expand filename
840case "\$1" in
841 ~/*|~)
842    echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
843    ;;
844 ~*)
845    if $test -f /bin/csh; then
846	/bin/csh -f -c "glob \$1"
847	echo ""
848    else
849	name=\`$expr x\$1 : '..\([^/]*\)'\`
850	dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
851	if $test ! -d "\$dir"; then
852	    me=\`basename \$0\`
853	    echo "\$me: can't locate home directory for: \$name" >&2
854	    exit 1
855	fi
856	case "\$1" in
857	*/*)
858	    echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
859	    ;;
860	*)
861	    echo \$dir
862	    ;;
863	esac
864    fi
865    ;;
866*)
867    echo \$1
868    ;;
869esac
870EOSS
871chmod +x filexp
872$eunicefix filexp
873
874: determine where manual pages are on this system
875echo " "
876case "$sysman" in
877	'') sysman=`loc . /usr/local/man/man1 /usr/man/man1 /usr/man/mann /usr/man/manl /usr/man/local/man1 /usr/man/u_man/man1 /usr/share/man/man1 /usr/catman/u_man/man1 /usr/man/l_man/man1 /usr/local/man/u_man/man1 /usr/local/man/l_man/man1 /usr/man/man.L`
878    ;;
879esac
880if test -d "$sysman"; then
881	echo "System manual is in $sysman."
882fi
883
884: make some quick guesses about what we are up against
885echo " "
886$echo $n "Hmm...  $c"
887cat /usr/include/signal.h /usr/include/sys/signal.h >foo 2>/dev/null
888if test `echo abc | tr a-z A-Z` = Abc ; then
889	if $contains SIGTSTP foo >/dev/null 2>&1 ; then
890	echo "Looks kind of like an USG system with BSD features, but we'll see..."
891		echo exit 0 >bsd
892		echo exit 0 >usg
893		echo exit 1 >v7
894	else
895    echo "Looks kind of like an USG system, but we'll see..."
896		echo exit 1 >bsd
897		echo exit 0 >usg
898		echo exit 1 >v7
899	fi
900	d_bsd="$undef"
901elif $contains SIGTSTP foo >/dev/null 2>&1 ; then
902    echo "Looks kind of like a BSD system, but we'll see..."
903	d_bsd="$define"
904    echo exit 0 >bsd
905    echo exit 1 >usg
906    echo exit 1 >v7
907else
908    echo "Looks kind of like a Version 7 system, but we'll see..."
909	d_bsd="$undef"
910    echo exit 1 >bsd
911    echo exit 1 >usg
912    echo exit 0 >v7
913fi
914case "$eunicefix" in
915*unixtovms*)
916    cat <<'EOI'
917There is, however, a strange, musty smell in the air that reminds me of
918something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
919EOI
920    echo "exit 0" >eunice
921    eunicefix=unixtovms
922    d_eunice="$define"
923: it so happens the Eunice I know will not run shell scripts in Unix format
924	;;
925*)
926    echo " "
927    echo "Congratulations.  You aren't running Eunice."
928    eunicefix=':'
929    d_eunice="$undef"
930    echo "exit 1" >eunice
931	;;
932esac
933if test -f /xenix; then
934    echo "Actually, this looks more like a XENIX system..."
935    echo "exit 0" >xenix
936	d_xenix="$define"
937else
938    echo " "
939    echo "It's not Xenix..."
940    echo "exit 1" >xenix
941	d_xenix="$undef"
942fi
943chmod +x xenix
944$eunicefix xenix
945if test -f /venix; then
946    echo "Actually, this looks more like a VENIX system..."
947    echo "exit 0" >venix
948else
949    echo " "
950    if xenix; then
951	: null
952    else
953	echo "Nor is it Venix..."
954    fi
955    echo "exit 1" >venix
956fi
957chmod +x bsd usg v7 eunice venix
958$eunicefix bsd usg v7 eunice venix
959rm -f foo
960rmlist="$rmlist bsd usg v7 eunice venix xenix"
961
962: see what memory models we can support
963case "$models" in
964'')
965    cat >pdp11.c <<'EOP'
966main() {
967#ifdef pdp11
968    exit(0);
969#else
970    exit(1);
971#endif
972}
973EOP
974	cc -o pdp11 pdp11.c >/dev/null 2>&1
975	if pdp11 2>/dev/null; then
976		dflt='unsplit split'
977	else
978		ans=`loc . X /lib/small /lib/large /usr/lib/small /usr/lib/large /lib/medium /usr/lib/medium /lib/huge`
979		case "$ans" in
980		X) dflt='none';;
981		*) if $test -d /lib/small || $test -d /usr/lib/small; then
982				dflt='small'
983			else
984				dflt=''
985			fi
986			if $test -d /lib/medium || $test -d /usr/lib/medium; then
987				dflt="$dflt medium"
988			fi
989			if $test -d /lib/large || $test -d /usr/lib/large; then
990				dflt="$dflt large"
991			fi
992			if $test -d /lib/huge || $test -d /usr/lib/huge; then
993				dflt="$dflt huge"
994			fi
995		esac
996	fi;;
997*) dflt="$models";;
998esac
999$cat <<EOM
1000
1001Some systems have different model sizes.  On most systems they are called
1002small, medium, large, and huge.  On the PDP11 they are called unsplit and
1003split.  If your system doesn't support different memory models, say "none".
1004If you wish to force everything to one memory model, say "none" here and
1005put the appropriate flags later when it asks you for other cc and ld flags.
1006Venix systems may wish to put "none" and let the compiler figure things out.
1007(In the following question multiple model names should be space separated.)
1008
1009EOM
1010rp="Which models are supported? [$dflt]"
1011$echo $n "$rp $c"
1012. myread
1013models="$ans"
1014
1015case "$models" in
1016none)
1017	small=''
1018	medium=''
1019	large=''
1020	huge=''
1021	unsplit=''
1022	split=''
1023	;;
1024*split)
1025	case "$split" in
1026	'') if $contains '\-i' $mansrc/ld.1 >/dev/null 2>&1 || \
1027			 $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1; then
1028			dflt='-i'
1029		else
1030			dflt='none'
1031		fi;;
1032	*) dflt="$split";;
1033	esac
1034	rp="What flag indicates separate I and D space? [$dflt]"
1035	$echo $n "$rp $c"
1036	. myread
1037	case "$ans" in
1038	none) ans='';;
1039	esac
1040	split="$ans"
1041	unsplit='';;
1042*large*|*small*|*medium*|*huge*)
1043	case "$model" in
1044	*large*)
1045		case "$large" in
1046		'') dflt='-Ml';;
1047		*) dflt="$large";;
1048		esac
1049	rp="What flag indicates large model? [$dflt]"
1050	$echo $n "$rp $c"
1051	. myread
1052	case "$ans" in
1053	none) ans='';
1054	esac
1055	large="$ans";;
1056	*) large='';;
1057	esac
1058	case "$model" in
1059	*huge*) case "$huge" in
1060		'') dflt='-Mh';;
1061		*) dflt="$huge";;
1062		esac
1063		rp="What flag indicates huge model? [$dflt]"
1064		$echo $n "$rp $c"
1065		. myread
1066		case "$ans" in
1067		none) ans='';
1068		esac
1069		huge="$ans";;
1070    *) huge="$large";;
1071	esac
1072	case "$model" in
1073	*medium*) case "$medium" in
1074		'') dflt='-Mm';;
1075		*) dflt="$medium";;
1076		esac
1077		rp="What flag indicates medium model? [$dflt]"
1078		$echo $n "$rp $c"
1079		. myread
1080		case "$ans" in
1081		none) ans='';
1082		esac
1083		medium="$ans";;
1084    *) medium="$large";;
1085	esac
1086	case "$model" in
1087	*small*) case "$small" in
1088		'') dflt='none';;
1089		*) dflt="$small";;
1090		esac
1091		rp="What flag indicates small model? [$dflt]"
1092		$echo $n "$rp $c"
1093		. myread
1094		case "$ans" in
1095		none) ans='';
1096		esac
1097		small="$ans";;
1098	*) small='';;
1099	esac
1100	;;
1101*)
1102	echo "Unrecognized memory models--you may have to edit Makefile.SH"
1103	;;
1104esac
1105
1106: see if we need a special compiler
1107echo " "
1108if usg; then
1109    case "$cc" in
1110    '')
1111	case "$Mcc" in
1112	/*) dflt='Mcc'
1113	    ;;
1114	*)
1115	    case "$large" in
1116	    -M*)
1117		dflt='cc'
1118		;;
1119	    *)
1120		if $contains '\-M' $mansrc/cc.1 >/dev/null 2>&1 ; then
1121		    dflt='cc -M'
1122		else
1123		    dflt='cc'
1124		fi
1125		;;
1126	    esac
1127	    ;;
1128	esac
1129	;;
1130    *)  dflt="$cc";;
1131    esac
1132    $cat <<'EOM'
1133
1134On some systems the default C compiler will not resolve multiple global
1135references that happen to have the same name.  On some such systems the
1136"Mcc" command may be used to force these to be resolved.  On other systems
1137a "cc -M" command is required.  (Note that the -M flag on other systems
1138indicates a memory model to use!)  If you have the Gnu C compiler, you
1139might wish to use that instead.  What command will force resolution on
1140EOM
1141	$echo $n "this system? [$dflt] $c"
1142	rp="Command to resolve multiple refs? [$dflt]"
1143	. myread
1144	cc="$ans"
1145else
1146	case "$cc" in
1147	'') dflt=cc;;
1148	*) dflt="$cc";;
1149	esac
1150	rp="Use which C compiler? [$dflt]"
1151	$echo $n "$rp $c"
1152	. myread
1153	cc="$ans"
1154fi
1155case "$cc" in
1156gcc*) cpp=`loc gcc-cpp $cpp $pth`;;
1157esac
1158
1159: determine optimize, if desired, or use for debug flag also
1160case "$optimize" in
1161' ') dflt="none";;
1162'') dflt="-O";;
1163*) dflt="$optimize";;
1164esac
1165cat <<EOH
1166
1167Some C compilers have problems with their optimizers, by default, $package
1168compiles with the -O flag to use the optimizer.  Alternately, you might
1169want to use the symbolic debugger, which uses the -g flag (on traditional
1170Unix systems).  Either flag can be specified here.  To use neither flag,
1171specify the word "none".
1172  
1173EOH
1174rp="What optimizer/debugger flag should be used? [$dflt]"
1175$echo $n "$rp $c"
1176. myread
1177optimize="$ans"
1178case "$optimize" in
1179'none') optimize=" ";;
1180esac
1181
1182case "$ccflags" in
1183'') case "$cc" in
1184	*gcc*) dflt='-fpcc-struct-return';;
1185	*) dflt='';;
1186	esac
1187	;;
1188*) dflt="$ccflags";;
1189esac
1190for thisincl in $inclwanted; do
1191	if $test -d $thisincl; then
1192		case "$dflt" in
1193		*$thisincl*);;
1194		*) dflt="$dflt -I$thisincl";;
1195		esac
1196	fi
1197done
1198case "$optimize" in
1199-g*)
1200	case "$dflt" in
1201	*DEBUG*);;
1202	*) dflt="$dflt -DDEBUG";;
1203	esac
1204	;;
1205esac
1206if $contains 'LANGUAGE_C' /usr/include/signal.h >/dev/null 2>&1; then
1207	case "$dflt" in
1208	*LANGUAGE_C*);;
1209	*) dflt="$dflt -DLANGUAGE_C";;
1210	esac
1211fi
1212case "$dflt" in
1213'') dflt=none;;
1214esac
1215cat <<EOH
1216
1217Your C compiler may want other flags.  For this question you should
1218include -I/whatever and -DWHATEVER flags and any other flags used by
1219the C compiler, but you should NOT include libraries or ld flags like
1220-lwhatever.  To use no flags, specify the word "none".
1221  
1222EOH
1223rp="Any additional cc flags? [$dflt]"
1224$echo $n "$rp $c"
1225. myread
1226case "$ans" in
1227none) ans='';
1228esac
1229ccflags="$ans"
1230
1231: the following weeds options from ccflags that are of no interest to cpp
1232cppflags="$ccflags"
1233case "$cc" in
1234*gcc*) cppflags="$cppflags -D__GNUC__";;
1235esac
1236case "$cppflags" in
1237'');;
1238*)  set X $cppflags
1239	cppflags=''
1240	for flag do
1241		case $flag in
1242		-D*|-I*) cppflags="$cppflags $flag";;
1243		esac
1244	done
1245	case "$cppflags" in
1246	*-*)  echo "(C preprocessor flags: $cppflags)";;
1247	esac
1248	;;
1249esac
1250
1251case "$ldflags" in
1252'') if venix; then
1253		dflt='-i -z'
1254	else
1255		dflt='none'
1256	fi
1257	;;
1258*) dflt="$ldflags";;
1259esac
1260echo " "
1261rp="Any additional ld flags (NOT including libraries)? [$dflt]"
1262$echo $n "$rp $c"
1263. myread
1264case "$ans" in
1265none) ans='';
1266esac
1267ldflags="$ans"
1268rmlist="$rmlist pdp11"
1269
1270: see how we invoke the C preprocessor
1271echo " "
1272echo "Now, how can we feed standard input to your C preprocessor..."
1273cat <<'EOT' >testcpp.c
1274#define ABC abc
1275#define XYZ xyz
1276ABC.XYZ
1277EOT
1278echo 'Maybe "'"$cc"' -E" will work...'
1279$cc -E <testcpp.c >testcpp.out 2>&1
1280if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1281    echo "Yup, it does."
1282    cppstdin="$cc -E"
1283    cppminus='';
1284else
1285    echo 'Nope, maybe "'$cpp'" will work...'
1286    $cpp <testcpp.c >testcpp.out 2>&1
1287    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1288	echo "Yup, it does."
1289	cppstdin="$cpp"
1290	cppminus='';
1291    else
1292	echo 'No such luck...maybe "'$cpp' -" will work...'
1293	$cpp - <testcpp.c >testcpp.out 2>&1
1294	if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1295	    echo "It works!"
1296	    cppstdin="$cpp"
1297	    cppminus='-';
1298	else
1299	    echo 'Nixed again...maybe "'"$cc"' -E -" will work...'
1300	    $cc -E - <testcpp.c >testcpp.out 2>&1
1301	    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1302		echo "Hooray, it works!  I was beginning to wonder."
1303		cppstdin="$cc -E"
1304		cppminus='-';
1305	    else
1306		echo 'Nope...maybe "'"$cc"' -P" will work...'
1307		$cc -P <testcpp.c >testcpp.out 2>&1
1308		if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1309		    echo "Yup, that does."
1310		    cppstdin="$cc -P"
1311		    cppminus='';
1312		else
1313		    echo 'Nope...maybe "'"$cc"' -P -" will work...'
1314		    $cc -P - <testcpp.c >testcpp.out 2>&1
1315		    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1316			echo "Yup, that does."
1317			cppstdin="$cc -P"
1318			cppminus='-';
1319		    else
1320			echo 'Hmm...perhaps you already told me...'
1321			case "$cppstdin" in
1322			'') ;;
1323			*) $cppstdin $cppminus <testcpp.c >testcpp.out 2>&1;;
1324			esac
1325			if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1326			    echo "Hooray, you did!  I was beginning to wonder."
1327			else
1328			    echo 'Uh-uh.  Time to get fancy...'
1329			    cd ..
1330			    echo 'Trying (cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c)'
1331			    echo 'cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c' >cppstdin
1332			    chmod 755 cppstdin
1333			    cppstdin=`pwd`/cppstdin
1334			    cppminus='';
1335			    cd UU
1336			    $cppstdin <testcpp.c >testcpp.out 2>&1
1337			    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1338				echo "Eureka!."
1339			    else
1340				dflt=blurfl
1341				$echo $n "No dice.  I can't find a C preprocessor.  Name one: $c"
1342				rp='Name a C preprocessor:'
1343				. myread
1344				cppstdin="$ans"
1345				$cppstdin <testcpp.c >testcpp.out 2>&1
1346				if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
1347				    echo "OK, that will do."
1348				else
1349				    echo "Sorry, I can't get that to work.  Go find one."
1350				    exit 1
1351				fi
1352			    fi
1353			fi
1354		    fi
1355		fi
1356	    fi
1357	fi
1358    fi
1359fi
1360rm -f testcpp.c testcpp.out
1361
1362: define an is-in-libc? function and set rmlist
1363inlibc='echo " ";
1364if $contains "^$1\$" libc.list >/dev/null 2>&1;
1365then echo "$1() found."; eval "$2=$define";
1366else echo "$1() not found."; eval "$2=$undef"; fi'
1367
1368rmlist="$rmlist libc.tmp libc.list"
1369
1370: see if memset exists
1371set memset d_memset
1372eval $inlibc
1373
1374: see if bzero exists
1375echo " "
1376if $contains '^bzero$' libc.list >/dev/null 2>&1; then
1377    echo 'bzero() found.'
1378    d_bzero="$undef"
1379elif $test $d_memset = "$define" ; then
1380	echo "bzero() not found -- Will use memset() instead."
1381	d_bzero="$define"
1382else
1383	echo "bzero() not found."
1384	d_bzero="$define"
1385fi
1386
1387: see if cbrt exists
1388set cbrt d_cbrt
1389eval $inlibc
1390
1391: see which of string.h or strings.h is needed
1392echo " "
1393strings=`loc string.h "" /usr/include $inclwanted`
1394i_string="$undef"
1395if $test -r "$strings"; then
1396	echo "Using <string.h> instead of <strings.h>."
1397	if bsd; then
1398		echo "(Actually, this looks more like it were an USG system)"
1399	fi
1400	i_string="$define"
1401else
1402	strings=`loc strings.h "" /usr/include $inclwanted`
1403	if $test -r "$strings"; then
1404		echo "Using <strings.h> instead of <string.h>."
1405		if usg; then
1406			echo "(Actually, this looks more like it were a BSD system)"
1407		fi
1408	else
1409		echo "No string header found--You'll surely have problems."
1410	fi
1411fi
1412
1413: index or strchr
1414echo " "
1415case "$d_index" in
1416n) dflt=n;;
1417*) dflt=y;;
1418esac
1419if $contains '^index$' libc.list >/dev/null 2>&1 ; then
1420	if $contains '^strchr$' libc.list >/dev/null 2>&1 ; then
1421		if $contains strchr "$strings" >/dev/null 2>&1 ; then
1422			if $contains index "$strings" >/dev/null 2>&1 ; then
1423				echo "Your system has both index() and strchr(). I use index() instead."
1424				d_index="$define"
1425			else
1426				d_index="$define"
1427				echo "strchr() found."
1428			fi
1429		else
1430			d_index="$undef"
1431			echo "index() found."
1432		fi
1433	else
1434		d_index="$undef"
1435		echo "index() found."
1436	fi
1437else
1438	if $contains '^strchr$' libc.list >/dev/null 2>&1 ; then
1439		d_index="$define"
1440		echo "strchr() found."
1441	else
1442		echo "No index() or strchr() found!"
1443		d_index="$undef"
1444	fi
1445fi
1446
1447: see if popen exists
1448set popen d_popen
1449eval $inlibc
1450
1451: see if sys/resource.h has to be included
1452set sys/resource.h i_sysresrc
1453eval $inhdr
1454
1455: see if we should include time.h, sys/time.h, or both
1456cat <<'EOM'
1457
1458Testing to see if we should include <time.h>, <sys/time.h> or both.
1459I'm now running the test program...
1460EOM
1461$cat >try.c <<'EOCP'
1462#include <sys/types.h>
1463#ifdef I_TIME
1464#include <time.h>
1465#endif
1466#ifdef I_SYSTIME
1467#ifdef SYSTIMEKERNEL
1468#define KERNEL
1469#endif
1470#include <sys/time.h>
1471#endif
1472main()
1473{
1474    struct tm foo;
1475#ifdef S_TIMEVAL
1476    struct timeval bar;
1477#endif
1478    if (foo.tm_sec == foo.tm_sec)
1479	exit(0);
1480#ifdef S_TIMEVAL
1481    if (bar.tv_sec == bar.tv_sec)
1482	exit(0);
1483#endif
1484    exit(1);
1485}
1486EOCP
1487flags=''
1488for s_timeval in '-DS_TIMEVAL' ''; do
1489    for i_systimek in '' '-DSYSTIMEKERNEL'; do
1490	for i_time in '' '-DI_TIME'; do
1491	    for i_systime in '-DI_SYSTIME' ''; do
1492		case "$flags" in
1493		'') echo Trying $i_time $i_systime $i_systimek $s_timeval
1494		    if $cc $ccflags \
1495			    $i_time $i_systime $i_systimek $s_timeval \
1496			    try.c -o try >/dev/null 2>&1 ; then
1497			set X $i_time $i_systime $i_systimek $s_timeval
1498			shift
1499			flags="$*"
1500			echo Succeeded with $flags
1501		    fi
1502		    ;;
1503		esac
1504	    done
1505	done
1506    done
1507done
1508timeincl=''
1509case "$flags" in
1510*SYSTIMEKERNEL*) i_systimek="$define"
1511	timeincl='/usr/include/sys/time.h'
1512	echo "We'll include <sys/time.h> with KERNEL defined.";;
1513*) i_systimek="$undef";;
1514esac
1515case "$flags" in
1516*I_TIME*) i_time="$define"
1517	timeincl='/usr/include/time.h'
1518	echo "We'll include <time.h>.";;
1519*) i_time="$undef";;
1520esac
1521case "$flags" in
1522*I_SYSTIME*) i_systime="$define"
1523	timeincl='/usr/include/sys/time.h'
1524	echo "We'll include <sys/time.h>.";;
1525*) i_systime="$undef";;
1526esac
1527$rm -f try.c try
1528
1529: see if getrusage exists
1530echo " "
1531if $contains getrusage libc.list >/dev/null 2>&1; then
1532    echo 'getrusage() found.'
1533    d_rusage="$define"
1534else
1535    echo 'getrusage() not found--cpu accounting may be less accurate.'
1536    d_rusage="$undef"
1537fi
1538
1539
1540: determine if we want to use the URT
1541case "$urtinc" in
1542'')
1543    dflt='none'
1544    ;;
1545*)  dflt=`echo $urtinc | $sed -e 's/-I//'`
1546    ;;
1547esac
1548
1549echo " "
1550echo "$package works best when linked with the Utah Raster Toolkit."
1551echo "If you don't have the URT, $package will compile, but with many"
1552
1553$cat << EOT
1554useful features disabled.
1555
1556In addition to providing a library for reading and writing compact
1557image files, the URT offers a host of useful image-maniuplation tools.
1558You are strongly encouraged to get a copy.
1559
1560If you do not have a copy of the URT, answer 'none' below.
1561
1562EOT
1563
1564rp="What directory holds the Utah Raster Toolkit include files? [$dflt]"
1565$echo $n "$rp $c"
1566. myread
1567case "$ans" in
1568'none')
1569    urtinc=''
1570    urtlib=''
1571    d_urt="$undef"
1572    ;;
1573*)
1574    urtinc="$ans"
1575    d_urt="$define"
1576    case "$urtlib" in
1577    '')
1578        dflt=`$echo $urtinc | $sed -e 's/include/lib\/librle.a/g'`
1579        if test ! -f "$dflt"; then
1580            dflt="/usr/local/lib/librle.a"
1581        fi
1582        ;;
1583    *)
1584        dflt="$urtlib"
1585        ;;
1586    esac
1587    echo " "
1588    rp="Where is the Utah Raster Toolkit library? [$dflt]"
1589    $echo $n "$rp $c"
1590    . myread
1591    urtlib="$ans"
1592    urtinc="-I$urtinc"
1593    ;;
1594esac
1595: see if this is a stdlib.h
1596echo " "
1597if $test -r /usr/include/stdlib.h ; then
1598    i_stdlib="$define"
1599    echo "<stdlib.h> found."
1600else
1601    i_stdlib="$undef"
1602fi
1603
1604: How can we generate normalized random numbers ?
1605echo " "
1606case "$randfunc" in
1607'')
1608	if $contains "^drand48\$" libc.list >/dev/null 2>&1; then
1609		dflt="drand48"
1610		echo "Good, found drand48()."
1611	elif $contains "^random\$" libc.list >/dev/null 2>&1; then
1612		dflt="random"
1613		echo "OK, found random()."
1614	else
1615		dflt="rand"
1616		echo "Yick, looks like I have to use rand()."
1617	fi
1618	echo " "
1619	;;
1620*)
1621	dflt="$randfunc"
1622	;;
1623esac
1624cont=true
1625while $test "$cont"; do
1626	rp="Use which function to generate random numbers? [$dflt]"
1627	$echo $n "$rp $c"
1628	. myread
1629	if $test "$ans" = "$dflt"; then
1630		: null
1631	else
1632		nrandbits=''
1633	fi
1634	randfunc="$ans"
1635	if $contains "^$ans\$" libc.list >/dev/null 2>&1; then
1636		cont=''
1637	else
1638		dflt=n
1639		rp="Function $ans does not exists. Use that name anyway? [$dflt]"
1640		$echo $n "$rp $c"
1641		. myread
1642		dflt=rand
1643		case "$ans" in
1644			[yY]*) cont='';;
1645		esac
1646	fi
1647	case "$cont" in
1648	'')
1649		case "$randfunc" in
1650		drand48)
1651			mrand="drand48()"
1652			seedfunc="srand48"
1653			;;
1654		rand*)
1655			case "$nrandbits" in
1656			'')
1657			echo "Checking to see how many bits your $randfunc() function produces..."
1658			$cat >try.c <<EOCP
1659#include <stdio.h>
1660main()
1661{
1662	register int i;
1663	register unsigned long tmp;
1664	register unsigned long max = 0L;
1665	extern long random();
1666
1667	for (i=1000; i; i--) {
1668		tmp = (unsigned long)$randfunc();
1669		if (tmp > max) max = tmp;
1670	}
1671	for (i=0; max; i++)
1672		max /= 2;
1673	printf("%d\n",i);
1674}
1675EOCP
1676			if $cc try.c -o try >/dev/null 2>&1 ; then
1677			dflt=`try`
1678			else
1679			dflt='?'
1680			echo "(I can't seem to compile the test program...)"
1681			fi
1682			;;
1683			*)
1684				dflt="$nrandbits"
1685				;;
1686			esac
1687			rp="How many bits does your $randfunc() function produce? [$dflt]"
1688			$echo $n "$rp $c"
1689			. myread
1690			nrandbits="$ans"
1691			$rm -f try.c try
1692			mrand="($randfunc() / (double) ((1 << $nrandbits) -1))"
1693			seedfunc="srand"
1694			;;
1695		*)
1696			dflt="31"
1697			rp="How many bits does your $randfunc() function produce? [$dflt]"
1698			$echo $n "$rp $c"
1699			. myread
1700			nrandbits="$ans"
1701			seedfunc="s$randfunc"
1702			mrand="($randfunc() / (double) ((1 << $nrandbits) -1))"
1703			if $contains "^$seedfunc\$" libc.list >/dev/null 2>&1; then
1704				echo "(Using $seedfunc() to seed random generator)"
1705			else
1706				echo "(Warning: no $seedfunc() to seed random generator)"
1707				seedfunc=rand
1708			fi
1709			;;
1710		esac
1711		;;
1712	esac
1713done
1714
1715: check for void type
1716echo " "
1717$cat <<EOM
1718Checking to see how well your C compiler groks the void type...
1719
1720  Support flag bits are:
1721    1: basic void declarations.
1722    2: arrays of pointers to functions returning void.
1723    4: operations between pointers to and addresses of void functions.
1724    8: generic void pointers.
1725
1726EOM
1727case "$voidflags" in
1728'')
1729    $cat >try.c <<'EOCP'
1730#if TRY & 1
1731void main() {
1732#else
1733main() {
1734#endif
1735	extern void moo();	/* function returning void */
1736	void (*goo)();		/* ptr to func returning void */
1737#if TRY & 8
1738	void *hue;		/* generic ptr */
1739#endif
1740#if TRY & 2
1741	void (*foo[10])();
1742#endif
1743
1744#if TRY & 4
1745	if(goo == moo) {
1746		exit(0);
1747	}
1748#endif
1749	exit(0);
1750}
1751EOCP
1752    if $cc -S -DTRY=$defvoidused try.c >.out 2>&1 ; then
1753		voidflags=$defvoidused
1754		echo "It appears to support void."
1755		if $contains warning .out >/dev/null 2>&1; then
1756			echo "However, you might get some warnings that look like this:"
1757			$cat .out
1758		fi
1759    else
1760		echo "Hmm, your compiler has some difficulty with void.  Checking further..."
1761		if $cc -S -DTRY=1 try.c >/dev/null 2>&1 ; then
1762			echo "It supports 1..."
1763			if $cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then
1764				echo "It also supports 2..."
1765				if $cc -S -DTRY=7 try.c >/dev/null 2>&1 ; then
1766					voidflags=7
1767					echo "And it supports 4 but not 8 definitely."
1768				else
1769					echo "It doesn't support 4..."
1770					if $cc -S -DTRY=11 try.c >/dev/null 2>&1 ; then
1771						voidflags=11
1772						echo "But it supports 8."
1773					else
1774						voidflags=3
1775						echo "Neither does it support 8."
1776					fi
1777				fi
1778			else
1779				echo "It does not support 2..."
1780				if $cc -S -DTRY=13 try.c >/dev/null 2>&1 ; then
1781					voidflags=13
1782					echo "But it supports 4 and 8."
1783				else
1784					if $cc -S -DTRY=5 try.c >/dev/null 2>&1 ; then
1785						voidflags=5
1786						echo "And it supports 4 but haven't heard about 8."
1787					else
1788						echo "However it supports 8 but not 4."
1789					fi
1790				fi
1791			fi
1792		else
1793			echo "There is no support at all for void."
1794			voidflags=0
1795		fi
1796    fi
1797esac
1798dflt="$voidflags";
1799rp="Your void support flags add up to what? [$dflt]"
1800$echo $n "$rp $c"
1801. myread
1802voidflags="$ans"
1803$rm -f try.* .out
1804
1805: preserve RCS keywords in files with variable substitution, grrr
1806Log='$Log'
1807Header='$Header'
1808Id='$Id'
1809
1810: determine where public executables go
1811case "$bin" in
1812'')
1813    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
1814    ;;
1815*)  dflt="$bin"
1816    ;;
1817esac
1818cont=true
1819while $test "$cont" ; do
1820    echo " "
1821    rp="Where do you want to put the public executables? (~name ok) [$dflt]"
1822    $echo $n "$rp $c"
1823    . myread
1824    bin="$ans"
1825    bin=`filexp $bin`
1826    if test -d $bin; then
1827	cont=''
1828    else
1829	dflt=n
1830	rp="Directory $bin doesn't exist.  Use that name anyway? [$dflt]"
1831	$echo $n "$rp $c"
1832	. myread
1833	dflt=''
1834	case "$ans" in
1835	y*) cont='';;
1836	esac
1837    fi
1838done
1839
1840: find out how to generate dependencies
1841echo " "
1842echo "Checking how to generate makefile dependencies on your machine..."
1843toplev=`cd ..;pwd`
1844ccinc="-I. -I$toplev -I$toplev/libray -I$toplev/libshade $urtinc"
1845$cat >dep.c <<'EOCP'
1846#include "dep.h"
1847EOCP
1848$cat >dep.h <<'EOCP'
1849
1850EOCP
1851case "$mkdep" in
1852'')
1853	;;
1854*)
1855	if test -x "$mkdep" &&
1856		$mkdep dep.c >dep.out 2>/dev/null &&
1857		$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
1858	then
1859		echo "$mkdep works."
1860	else
1861		mkdep=
1862	fi
1863esac
1864
1865case "$mkdep" in
1866'')
1867	$spitshell > ../mkdep <<EOM
1868$startsh
1869for srcfile
1870do
1871	$cpp -M $ccinc $cppflags \$srcfile
1872done
1873EOM
1874	mkdep=$toplev/mkdep
1875	chmod +x $mkdep
1876	$eunicefix $mkdep
1877	if $mkdep dep.c >dep.out 2>/dev/null &&
1878		$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
1879	then
1880		echo "Looks like we can use $cpp -M."
1881	else
1882		mkdep=
1883	fi
1884	;;
1885esac
1886
1887case "$mkdep" in
1888'')
1889	$spitshell >../mkdep <<EOS
1890$startsh
1891for srcfile
1892do
1893	case "\$srcfile" in
1894	*.c) c='.c';;
1895	*.y) c='.y';;
1896	*.l) c='.l';;
1897	esac
1898	filebase=\`basename \$srcfile \$c\`
1899	< \$srcfile $cpp $cppminus $cppflags $ccinc | \\
1900	$sed -e '/^# *[0-9]/!d' \\
1901		-e 's/^.*"\(.*\)".*\$/'\$filebase'.o: \1/' \\
1902		-e 's|: \./|: |' \\
1903		-e 's|: *$|: '\$srcfile'|' | \\
1904	$grep -v '^#' | $sort | $uniq
1905done
1906EOS
1907	mkdep=$toplev/mkdep
1908	chmod +x $mkdep
1909	$eunicefix $mkdep
1910	if $mkdep dep.c >dep.out 2>/dev/null &&
1911		$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
1912	then
1913		echo "A shell script using $cpp does the trick."
1914	else
1915		echo "$cpp doesn't seem to be any use at all."
1916		$spitshell >../mkdep <<EOS
1917$startsh
1918for srcfile
1919do
1920	case "\$srcfile" in
1921	*.c) c='.c';;
1922	*.y) c='.y';;
1923	*.l) c='.l';;
1924	esac
1925	filebase=\`basename \$srcfile \$c\`
1926	echo \$filebase.o: \$srcfile
1927	$grep '^#[  ]*include' \$srcfile /dev/null |
1928	$sed -e 's/#[   ]*include[  ]*//' \\
1929		-e 's,<\(.*\)>,"/usr/include/\1",' \\
1930		-e 's/:[^"]*"\([^"]*\)".*/: \1/' \\
1931		-e 's/\.c:/\.o:/'
1932done
1933EOS
1934		mkdep=$toplev/mkdep
1935		chmod +x $mkdep
1936		$eunicefix $mkdep
1937		if $mkdep dep.c >dep.out 2>/dev/null &&
1938		    $contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
1939		then
1940			cat << EOM
1941
1942I can use a script with grep instead, but it will make some incorrect
1943dependencies, since it doesn't understand about conditional compilation.
1944Moreover, some dependencies may be missing, because scanning won't be
1945a recursive process.
1946If you have a program which generates makefile dependencies, you may want
1947to use it.  If not, you can use the script and edit the Makefile by hand
1948if you need to.
1949EOM
1950		else
1951			mkdep=
1952			cat << EOM
1953
1954I can't seem to generate makefile dependencies at all!  Perhaps you have a
1955program that does?  If you don't, you might look at the mkdep script to
1956see if you can create one which works.
1957EOM
1958		fi
1959	fi
1960esac
1961cont=true
1962dflt="$mkdep"
1963while $test "$cont" ; do
1964	echo " "
1965rp="Name of program to make makefile dependencies? [$dflt]"
1966$echo $n "$rp $c"
1967. myread
1968mkdep="$ans"
1969mkdep=`filexp $mkdep`
1970if test -f "$mkdep"; then
1971	cont=''
1972else
1973	dflt=n
1974	rp="$mkdep doesn't exist.  Use that name anyway? [$dflt]"
1975	$echo $n "$rp $c"
1976	. myread
1977	dflt=''
1978	case "$ans" in
1979	y*) cont='';;
1980	esac
1981fi
1982done
1983$rm -f dep.c dep.h dep.o dep.out
1984: see if ar generates random libraries by itself
1985echo " "
1986echo "Checking how to generate random libraries on your machine..."
1987ar rc ran.a /dev/null
1988if ar ts ran.a >/dev/null 2>&1; then
1989	echo "ar appears to generate random libraries itself."
1990	orderlib=false
1991	ranlib=":"
1992else
1993	if test -f /usr/bin/ranlib; then
1994		ranlib=/usr/bin/ranlib
1995	elif test -f /bin/ranlib; then
1996		ranlib=/bin/ranlib
1997	fi
1998
1999	if test -n "$ranlib"; then
2000		echo "your system has $ranlib; we'll use that."
2001		orderlib=false
2002	else
2003		echo "your system doesn't seem to support random libraries"
2004		echo "so we'll use lorder and tsort to order the libraries."
2005		orderlib=true
2006		ranlib=":"
2007	fi
2008fi
2009
2010: determine compiler compiler
2011case "$bison" in
2012/*) dflt="bison -y";;
2013*) case "$yacc" in
2014		'') dflt=yacc;;
2015		*)  dflt="$yacc";;
2016	esac
2017	;;
2018esac
2019cont=true
2020    echo " "
2021rp="Which compiler compiler (yacc or bison -y) will you use? [$dflt]"
2022$echo $n "$rp $c"
2023. myread
2024case "$ans" in
2025'') ans="$dflt";;
2026*bis*) ans="bison -y";;
2027*yac*) ans="yacc";;
2028esac
2029yacc="$ans"
2030
2031echo " "
2032echo "End of configuration questions."
2033echo " "
2034
2035: create config.sh file
2036echo " "
2037if test -d ../UU; then
2038    cd ..
2039fi
2040echo "Creating config.sh..."
2041$spitshell <<EOT >config.sh
2042$startsh
2043# config.sh
2044# This file was produced by running the Configure script.
2045
2046d_eunice='$d_eunice'
2047d_xenix='$d_xenix'
2048d_bsd='$d_bsd'
2049define='$define'
2050eunicefix='$eunicefix'
2051loclist='$loclist'
2052expr='$expr'
2053awk='$awk'
2054sed='$sed'
2055echo='$echo'
2056cat='$cat'
2057chgrp='$chgrp'
2058chmod='$chmod'
2059chown='$chown'
2060rm='$rm'
2061mv='$mv'
2062cp='$cp'
2063tail='$tail'
2064tr='$tr'
2065mkdir='$mkdir'
2066sort='$sort'
2067uniq='$uniq'
2068grep='$grep'
2069trylist='$trylist'
2070test='$test'
2071inews='$inews'
2072egrep='$egrep'
2073more='$more'
2074pg='$pg'
2075Mcc='$Mcc'
2076vi='$vi'
2077mail='$mail'
2078bison='$bison'
2079cpp='$cpp'
2080perl='$perl'
2081Log='$Log'
2082Header='$Header'
2083Id='$Id'
2084bin='$bin'
2085contains='$contains'
2086cppstdin='$cppstdin'
2087cppminus='$cppminus'
2088d_bzero='$d_bzero'
2089d_cbrt='$d_cbrt'
2090d_index='$d_index'
2091d_memset='$d_memset'
2092d_popen='$d_popen'
2093d_rusage='$d_rusage'
2094d_times='$d_times'
2095clocktype='$clocktype'
2096i_string='$i_string'
2097strings='$strings'
2098i_sysresrc='$i_sysresrc'
2099i_systypes='$i_systypes'
2100i_time='$i_time'
2101i_systime='$i_systime'
2102i_systimek='$i_systimek'
2103timeincl='$timeincl'
2104inhdr='$inhdr'
2105inlibc='$inlibc'
2106libs='$libs'
2107models='$models'
2108split='$split'
2109small='$small'
2110medium='$medium'
2111large='$large'
2112huge='$huge'
2113ccflags='$ccflags'
2114ldflags='$ldflags'
2115cc='$cc'
2116cppflags='$cppflags'
2117optimize='$optimize'
2118n='$n'
2119c='$c'
2120orderlib='$orderlib'
2121ranlib='$ranlib'
2122package='$package'
2123randfunc='$randfunc'
2124mrand='$mrand'
2125seedfunc='$seedfunc'
2126nrandbits='$nrandbits'
2127spitshell='$spitshell'
2128shsharp='$shsharp'
2129sharpbang='$sharpbang'
2130startsh='$startsh'
2131sysman='$sysman'
2132voidflags='$voidflags'
2133defvoidused='$defvoidused'
2134yacc='$yacc'
2135d_urt='$d_urt'
2136urtinc='$urtinc'
2137urtlib='$urtlib'
2138i_stdlib='$i_stdlib'
2139libc='$libc'
2140mkdep='$mkdep'
2141CONFIG=true
2142EOT
2143
2144CONFIG=true
2145
2146echo " "
2147dflt=''
2148fastread=''
2149echo "If you didn't make any mistakes, then just type a carriage return here."
2150rp="If you need to edit config.sh, do it as a shell escape here:"
2151$echo $n "$rp $c"
2152. UU/myread
2153case "$ans" in
2154'') ;;
2155*) : in case they cannot read
2156    eval $ans;;
2157esac
2158. ./config.sh
2159
2160echo " "
2161echo "Doing variable substitutions on .SH files..."
2162if test -f MANIFEST; then
2163	set x `awk '{print $1}' <MANIFEST | $grep '\.SH'`
2164else
2165	set x `find . -name "*.SH" -print`
2166fi
2167shift
2168case $# in
21690) set x *.SH; shift;;
2170esac
2171if test ! -f $1; then
2172    shift
2173fi
2174for file in $*; do
2175    case "$file" in
2176    */*)
2177	dir=`$expr X$file : 'X\(.*\)/'`
2178	file=`$expr X$file : 'X.*/\(.*\)'`
2179	(cd $dir && . $file)
2180	;;
2181    *)
2182	. $file
2183	;;
2184    esac
2185done
2186if test -f config.h.SH; then
2187    if test ! -f config.h; then
2188	: oops, they left it out of MANIFEST, probably, so do it anyway.
2189	. config.h.SH
2190    fi
2191fi
2192
2193if $contains '^depend:' Makefile >/dev/null 2>&1; then
2194    dflt=n
2195    $cat <<EOM
2196
2197Now you need to generate make dependencies by running "make depend".
2198You might prefer to run it in background: "make depend > makedepend.out &"
2199It can take a while, so you might not want to run it right now.
2200
2201EOM
2202    rp="Run make depend now? [$dflt]"
2203    $echo $n "$rp $c"
2204    . UU/myread
2205    case "$ans" in
2206    y*) make depend
2207	echo "Now you must run a make."
2208	;;
2209    *)  echo "You must run 'make depend' then 'make'."
2210	;;
2211    esac
2212elif test -f Makefile; then
2213    echo " "
2214    echo "Now you must run a make."
2215else
2216    echo "Done."
2217fi
2218
2219$rm -f kit*isdone
2220: the following is currently useless
2221cd UU && $rm -f $rmlist
2222: since this removes it all anyway
2223cd .. && $rm -rf UU
2224: end of Configure
2225