1#!/bin/sh
2#
3# Guess values for system-dependant variables and create `Makefile'.
4# Can be distributed according to GPL.
5#
6# Usage:
7#   configure -ask		(ask all questions)
8#
9# As soon as some other option is specified, configure
10# will not ask questions. Other options:
11#
12#   configure -d[efault]	(language=en, +fhs)
13#   configure -confdir DIR	(directory to hold man.conf)
14#   configure +suid/sgid	(make man suid or sgid)
15#   configure +lang cs,da,de,el,en,es,fi,fr,hr,it,ko,nl,pl,pt,ro,sl
16#                               (language(s) as given)
17#				("all" will specify all available languages)
18#				("none" will disable NLS support)
19#   configure +fhs		(follow FHS: use /var/cache/man)
20#   configure +fsstnd		(follow FSSTND: use /var/catman)
21#
22LANGUAGES="bg,cs,da,de,el,en,es,fi,fr,hr,it,ja,ko,nl,pl,pt,ro,ru,sl"
23LANGOPT="+lang {$LANGUAGES|all|none}"
24#
25# Some people prefer "-irs", but probably only when they have a broken setup.
26# (Indeed, -r may cause the terminal to get into funny states.
27# Very inconvenient. For viewing pages in strange locales, set LC_*.)
28#
29DEFAULTLESSOPT="-is"
30#
31# Note that not creating any cat directories (/var/cache/man or so)
32# and not making man suid or sgid is recommended.
33# This avoids security problems, the fact that different users have
34# different window sizes and different character sets, etc.
35# Formatting is fast enough today.
36
37trap 'rm -f conftest conftest.c; exit 1' 1 3 15
38
39set +u # Make sure unset variables are ok.
40
41if [ $# = 0 ]; then
42  echo "Usage: configure -ask"
43  echo "   or: configure [-d|-default] [-confdir DIR] [+suid] [+sgid] \\"
44  echo "                 [+fhs|+fsstnd|+traditional] [+lang none|all|LANGUAGES]"
45  echo "   where LANGUAGES is a substring of $LANGUAGES".
46  echo
47  echo 'The default "configure -d" is equivalent to "configure +fhs +lang en".'
48  echo 'The option +suid will make man suid to a user "man". Create this first.'
49  echo 'The option +sgid will make man sgid to a group "man". Create this first.'
50  echo 'The options +fhs, +fsstnd, +traditional will make man use'
51  echo ' /var/cache/man, /var/catman and /usr/man/cat?, respectively.'
52  echo 'It is recommended not to use suid/sgid and not to keep cat pages.'
53  echo 'The -confdir option specifies where man.conf lives (default /usr/share/misc).'
54  echo
55  exit 1
56fi
57
58default=true
59usenls=true
60
61for arg in $*; do
62  if [ x$setlang = xtrue ]
63  then
64    case $arg in
65      none)
66	usenls=false
67	;;
68      all)
69	languages="??"
70	;;
71      *)
72	languages=`echo $arg | sed -e 's/,/ /g'`
73    esac
74    setlang=false
75  elif [ x$setconfdir = xtrue ]
76  then
77    confdir=$arg
78    confexplicit=1
79    setconfdir=false
80  else
81    # help people used to GNU-style --options
82    # e.g. --enable-suid, --disable-suid, --prefix
83    case $arg in
84      --enable-*)
85          arg=`echo $arg | sed -e 's/--enable-/+/'`
86	  ;;
87      --disable-*)
88          arg=`echo $arg | sed -e 's/--disable-/-/'`
89	  ;;
90      --*)
91          arg=`echo $arg | sed -e 's/--/-/'`
92    esac
93    case $arg in
94      -default | -d)
95	  usefhs=true
96	  ;;
97      -ask | -a)
98	  default=
99	  ;;
100      -prefix=*)
101	  prefix=`echo $arg | sed -e 's/-prefix=//'`
102	  ;;
103      -bindir=*)
104          bindir=`echo $arg | sed -e 's/-bindir=//'`
105	  ;;
106      -confdir=*)
107          confdir=`echo $arg | sed -e 's/-confdir=//'`
108	  confexplicit=1
109	  ;;
110      -confdir)
111          setconfdir=true;
112          ;;
113      -confprefix=*)
114          confprefix=`echo $arg | sed -e 's/-confprefix=//'`
115	  ;;
116      -mandir=*)
117          mandir=`echo $arg | sed -e 's/-mandir=//'`
118	  manexplicit=1
119	  ;;
120      -sbindir=*)
121          sbindir=`echo $arg | sed -e 's/-sbindir=//'`
122	  ;;
123      +lang)
124	  setlang=true
125	  ;;
126      +suid)
127	  suid=true
128	  ;;
129      -suid)
130	  suid=false
131	  ;;
132      +sgid)
133	  sgid=true
134	  ;;
135      -sgid)
136	  sgid=false
137	  ;;
138      +traditional)
139          usefsstnd=false
140          usefhs=false
141          ;;
142      +fsstnd)
143	  usefsstnd=true
144	  ;;
145      -fsstnd)
146	  usefsstnd=false
147          ;;
148      +fhs)
149	  usefhs=true
150	  ;;
151      -fhs)
152          usefhs=false
153          ;;
154      -compatibility_mode_for_colored_groff)
155          set_compatibility_mode_for_colored_groff=true;
156	  ;;
157      *)
158  echo "Usage: configure -ask"
159  echo "   or: configure [-d|-default] [-confdir DIR] [+suid] [+sgid] \\"
160  echo "                 [+fhs|+fsstnd|+traditional] [+lang all|LANGUAGES]"
161  echo "       where LANGUAGES is a substring of $LANGUAGES".
162  echo
163  echo 'The default "configure -d" is equivalent to "configure +fhs +lang en".'
164  echo 'The option +suid will make man suid to a user "man". Create this first.'
165  echo 'The option +sgid will make man sgid to a group "man". Create this first.'
166  echo 'The options +fhs, +fsstnd, +traditional will make man use'
167  echo ' /var/cache/man, /var/catman and /usr/man/cat?, respectively.'
168  echo 'The -confdir option specifies where man.conf lives (default /usr/share/misc).'
169  exit 1
170	  ;;
171    esac
172  fi
173done
174
175# Default installation paths
176#
177# prefix="/usr/local" or "/usr"
178# confprefix="/usr/local" or "/usr" or "/etc"
179# 
180# The configuration file has various names and pathnames in the
181# various distributions, such as /usr/share/misc/man.conf,
182# /usr/lib/man.conf, /etc/man.config.
183# The FHS wants it in /usr/share/misc
184# All documentation assumes "man.conf" - in case you invent some other name
185# (why?), also man pages and other docs need to be patched.
186if [ -z "${prefix}" ]; then prefix="/usr"; fi
187if [ -z "${confprefix}" ]; then confprefix=${prefix}; fi
188if [ -z "${bindir}" ]; then bindir="${prefix}/bin"; fi
189if [ -z "${sbindir}" ]; then sbindir="${prefix}/sbin"; fi
190if [ -z "${mandir}" ]; then mandir="${prefix}/man"; fi
191
192if [ -z "$manexplicit" -a x"$usefhs" = xtrue ]; then
193  mandir="${prefix}/share/man"
194fi
195if [ -z "$confexplicit" ]; then
196  confdir="${confprefix}/lib"
197  if [ x"$usefhs" = xtrue ]; then
198    confdir="${confprefix}/share/misc"
199  fi
200fi
201conffilename="man.conf"
202
203if test "$RANDOM" = "$RANDOM"; then
204  # Plain old Bourne shell.
205  echo checking for gcc
206  test -z "$CC" -a -n "`gcc 2>&1`" && CC="gcc -O"
207else
208  # ksh, bash or zsh.  ksh and zsh write "command not found" to stderr.
209  echo checking for gcc
210  test -z "$CC" && type gcc && CC="gcc -O"
211fi
212
213CC=${CC-cc}
214BUILD_CC=${BUILD_CC-${CC}}
215INSTALL=${INSTALL-install}
216INCLUDEDIR=${INCLUDEDIR-/usr/include}
217
218rm -f conftest conftest.c
219compile="$CC $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1"
220
221# Check for various header files.
222
223echo checking for ANSI C header files
224echo "#include <stdlib.h>
225#include <string.h>
226main() { exit(0); strerror(0); }" > conftest.c
227eval $compile
228if test -s conftest && ./conftest 2>/dev/null; then
229  DEFS="$DEFS -DSTDC_HEADERS"
230fi
231rm -f conftest conftest.c
232
233echo checking for POSIX.1 header files
234echo "#include <unistd.h>
235main() {
236#ifdef _POSIX_VERSION
237exit(0);
238#else
239exit(1);
240#endif
241}" > conftest.c
242eval $compile
243if test -s conftest && ./conftest 2>/dev/null; then
244  DEFS="$DEFS -DPOSIX"
245fi
246rm -f conftest conftest.c
247
248echo checking for BSD string and memory functions
249echo "#include <strings.h>
250main() { exit(0); rindex(0, 0); bzero(0, 0); }" > conftest.c
251eval $compile
252if test -s conftest && ./conftest 2>/dev/null; then :
253  else DEFS="$DEFS -DUSG"
254fi
255rm -f conftest conftest.c
256
257echo checking whether sys/types.h defines uid_t
258echo '#include <sys/types.h>
259main() { uid_t x; exit(0); }' > conftest.c
260eval $compile
261if test -s conftest && ./conftest 2>/dev/null; then :
262else
263  uid_t=`awk '/pw_uid;/ {print $1}' $INCLUDEDIR/pwd.h`
264  DEFS="$DEFS -Duid_t=${uid_t} -Dgid_t=${uid_t}"
265fi
266rm -f conftest conftest.c
267
268echo checking for Xenix
269if test -f /xenix; then
270  LIBS="$LIBS -lx"
271  case "$DEFS" in
272  *SYSNDIR*) ;;
273  *) LIBS="-ldir $LIBS" ;; # Make sure -ldir precedes any -lx.
274  esac
275fi
276
277echo checking how to get alloca
278echo '
279#ifdef __GNUC__
280#define alloca __builtin_alloca
281#else
282#ifdef sparc
283#include <alloca.h>
284#else
285#ifdef _AIX
286 #pragma alloca
287#else
288char *alloca ();
289#endif
290#endif
291#endif
292main() { char *p = (char *) alloca(1); exit(0); }' > conftest.c
293eval $compile
294if test -s conftest && ./conftest 2>/dev/null; then :
295elif test -d /usr/ucblib; then LIBS="$LIBS -L/usr/ucblib -lucb"
296elif test -f /usr/lib/libPW.a; then LIBS="$LIBS -lPW"
297else DEFS="$DEFS -DALLOCA_MISSING"
298fi
299rm -f conftest conftest.c
300
301if [ $usenls = true ]; then
302  echo checking for nls
303  echo '#include <nl_types.h>
304  main() {nl_catd catfd; exit(0); }' > conftest.c
305  eval $compile
306  if test -s conftest && ./conftest 2>/dev/null; then :
307  else
308    usenls=false
309  fi
310  rm -f conftest conftest.c
311fi
312
313if [ $usenls = false ]; then
314  DEFS="$DEFS -DNONLS"
315fi
316
317echo checking for getopt.h
318echo '#define _GNU_SOURCE
319#include <getopt.h>
320#include <stdio.h>
321struct option long_opts[] = { { "", no_argument, NULL, 0 } };
322main() { exit(0); }' > conftest.c
323eval $compile
324if test -s conftest && ./conftest 2>/dev/null; then
325  manpathoption="--path"
326else
327  manpathoption="-w"
328  DEFS="$DEFS -DNOGETOPT"
329fi
330rm -f conftest conftest.c
331
332# first determine how to suppress newline on echo command (stolen from
333# Perl's Configure) ...
334
335echo "Checking echo to see how to suppress newlines..."
336(echo "hi there\c" ; echo " ") >conftest
337if grep c conftest >/dev/null 2>&1 ; then
338    echo "...using -n."
339    n='-n'
340    c=''
341else
342    cat <<'EOM'
343...using \c
344EOM
345    n=''
346    c='\c'
347fi
348rm -f conftest
349
350# Ask the installer where various things are located.
351# (A separate variable is needed since various shells do
352# word-splitting at different moments, which means that
353#   for i in /bin:/usr/bin:$PATH
354# does not work everywhere.)
355# Some people might prefer having $PATH first in PREPATH
356PREPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH
357IFS0="$IFS"
358IFS=":$IFS"
359for i in $PREPATH
360do
361  case $i in
362    /*)
363      DEFPATH="$DEFPATH $i"
364      ;;
365  esac
366done
367IFS="$IFS0"
368
369if [ x$default = x ]; then
370  echo ""
371  echo $n "Do you have the nroff source for man pages?  [yes] $c"
372  ans=
373  while [ x$ans = x ]
374  do
375    read yesno
376    if test "$yesno" = "" || test "$yesno" = "yes"
377    then
378      ans=true
379    elif test "$yesno" = "no"
380    then
381      ans=false
382    else
383      echo "You must enter yes or no"
384    fi
385  done
386else
387  echo ""
388  echo "Assuming you want to be able to handle the nroff source for man pages."
389  ans=true
390fi
391
392if test "$ans" = "false"
393then
394  for i in more less cmp cat awk gawk mawk
395  do
396    eval F$i="missing"
397    for j in $DEFPATH
398    do
399      if test -f $j/$i
400      then
401	eval F$i=$j/$i
402	break
403      fi
404    done
405  done
406  troff=""
407  nroff=""
408  jnroff=""
409  eqn=""
410  neqn=""
411  jneqn=""
412  tbl=""
413  col=""
414  vgrind=""
415  refer=""
416  grap=""
417  pic=""
418  if test $Fless = "missing"
419  then
420    pager="$Fmore"
421  else
422    pager="$Fless $DEFAULTLESSOPT"
423  fi
424  if test $Fawk = "missing"
425  then
426    Fawk="$Fgawk"
427  fi
428  if test $Fawk = "missing"
429  then
430    Fawk="$Fmawk"
431  fi
432  cmp="$Fcmp -s"
433  cat="$Fcat"
434  awk="$Fawk"
435
436  FILTERS="pager cmp cat awk"
437else
438  for i in nroff groff geqn gtbl col vgrind grefer grap gpic more less lynx cmp cat awk gawk mawk
439  do
440    eval F$i="missing"
441    for j in $DEFPATH
442    do
443      if test -f $j/$i
444      then
445	eval F$i=$j/$i
446	break
447      fi
448    done
449  done
450  for i in eqn tbl refer pic
451  do
452    if test `eval echo \\$Fg$i` = "missing"
453    then
454      for j in $DEFPATH
455      do
456        if test -f $j/$i
457        then
458	  eval Fg$i=$j/$i
459	  break
460        fi
461      done
462    fi
463  done
464# -Tlatin1 is bad when utf8 is used, but needed for groff, not for nroff
465# Hmm - also needed for nroff, to prevent double conversion on uxterm
466  if test $Fgroff = "missing"
467  then
468    if test $Fnroff = "missing"
469    then
470      nroff="nroff -Tlatin1 -mandoc"
471    else
472      nroff="$Fnroff -Tlatin1 -mandoc"
473    fi
474    troff="troff -mandoc"
475    echo "Warning: could not find groff"
476  else
477    nroff="$Fgroff -Wall -mtty-char -Tascii -mandoc"
478    troff="$Fgroff -Tps -mandoc"
479    jnroff="$Fgroff -Tnippon -mandocj"
480  fi
481  eqn="$Fgeqn -Tps"
482  neqn="$Fgeqn -Tascii"
483  jneqn="$Fgeqn -Tnippon"
484  tbl="$Fgtbl"
485  col="$Fcol"
486  vgrind="$Fvgrind"
487  refer="$Fgrefer"
488  grap="$Fgrap"
489  pic="$Fgpic"
490  if test $Fless = "missing"
491  then
492    pager="$Fmore"
493  else
494    pager="$Fless $DEFAULTLESSOPT"
495  fi
496  if test $Flynx = "missing"
497  then
498    browser=$pager
499    htmlpager=$Fcat
500  else
501    browser="$Flynx"
502    htmlpager="$Flynx -dump"
503  fi
504  if test $Fawk = "missing"
505  then
506    Fawk="$Fgawk"
507  fi
508  if test $Fawk = "missing"
509  then
510    Fawk="$Fmawk"
511  fi
512  cmp="$Fcmp -s"
513  cat="$Fcat"
514  awk="$Fawk"
515
516  FILTERS="troff nroff jnroff eqn neqn jneqn tbl col vgrind refer grap pic pager browser htmlpager cmp cat awk"
517fi
518
519# Note: older nroff gives an error message for -c
520# Do this only when you have troff 1.18.1 or so.
521if [ "x$set_compatibility_mode_for_colored_groff" = "xtrue" ]; then
522    troff="$troff -c"
523    nroff="$nroff -c"
524    jnroff="$jnroff -c"
525fi
526
527if [ x$default = x ]; then
528  echo ""
529  echo "If you don't have one of the following programs, enter \`missing'."
530  echo "It's best to enter absolute pathnames so that man won't have to"
531  echo "depend on the user's path to work properly.  Default values are"
532  echo "given in square brackets.  The answers given are only checked to"
533  echo "see if the programs exist, not to see see if the given flags are"
534  echo "correct."
535  
536  for filter in $FILTERS
537  do
538    found=false
539    while test "$found" = "false"
540    do
541      echo ""
542      echo $n "$filter command to use [`eval echo \\$$filter`] $c"
543      read tmp
544      if test -n "$tmp"
545      then
546        if test "$tmp" = "missing"
547        then
548          if test "$filter" = "pager"
549          then
550            found=false
551            echo "You must have a pager!"
552          else
553            found=true
554            eval $filter=""
555          fi
556        elif test -f `echo $tmp | awk '{print $1}'`
557        then
558          found=true
559          eval $filter=\""$tmp"\"
560        else
561          found=false
562          echo ""
563          echo "`echo $tmp | awk '{print $1}'` doesn't seem to exist!  Try again or enter \`missing'"
564        fi
565      elif test `eval echo \\$$filter | awk '{print $1}'` = "missing"
566      then
567        found=true
568        eval $filter=""
569      elif test -f `eval echo \\$$filter | awk '{print $1}'`
570      then
571        found=true
572      else
573        found=false
574        echo ""
575        echo "`eval echo \\$$filter | awk '{print $1}'` doesn't seem to exist!  Try again or enter \`missing'"
576      fi
577    done
578  done
579else
580  echo ""
581  echo "Assuming the following ways to invoke the various commands and filters":
582  for filter in $FILTERS
583  do
584    echo "$filter command:	`eval echo \\$$filter`"
585    if test `eval echo \\$$filter | awk '{print $1}'` = "missing"
586    then
587      eval $filter=""
588    fi
589  done
590fi
591
592case $nroff in
593  *roff*)
594    echo ""
595    echo "It seems that no col is needed, since you use groff."
596    pcol=
597    nocol="# " ;;
598  *)
599    pcol=$col
600    nocol= ;;
601esac
602  
603fhs="# "
604fsstnd="# "
605FHSDIR=/var/cache/man
606FSSTNDDIR=/var/catman
607if [ x$usefhs = x -a x$usefsstnd = x ]; then
608  if [ x$default = x ]; then
609    echo ""
610    echo $n "Do you want to put the cat pages under $FHSDIR ? [no] $c"
611    ans=
612    while [ x$ans = x ]
613    do
614      read yesno
615      if test "$yesno" = "" || test "$yesno" = "no"
616      then
617        ans=false
618      elif test "$yesno" = "yes"
619      then
620        ans=true
621      else
622        echo "You must enter yes or no"
623      fi
624    done
625    if [ $ans = true ]; then
626      fhs=
627    else
628      echo $n "Do you want to put the cat pages under $FSSTNDDIR ? [no] $c"
629      ans=
630      while [ x$ans = x ]
631      do
632        read yesno
633        if test "$yesno" = "" || test "$yesno" = "no"
634        then
635          ans=false
636        elif test "$yesno" = "yes"
637        then
638          ans=true
639        else
640          echo "You must enter yes or no"
641        fi
642      done
643      if [ $ans = true ]; then
644        fsstnd=
645      fi
646    fi
647  else
648    echo ""
649    if [ -d $FHSDIR ]; then
650      echo "Using $FHSDIR for cat pages, following FHS."
651      fhs=
652    elif [ -d $FSSTNDDIR ]; then
653      echo "Using $FSSTNDDIR for cat pages, following FSSTND."
654      fsstnd=
655    else
656      echo "Using /usr/man/cat* (if that exists) for cat pages."
657    fi
658  fi
659else
660  if [ x$usefsstnd = xtrue ]; then
661    fsstnd=
662  elif [ x$usefhs = xtrue ]; then
663    fhs=
664  fi
665fi
666
667# How should man be installed?
668
669if [ x$default = x ]; then
670  for d in bindir sbindir mandir confdir
671  do
672    case $d in
673      bindir)
674        echo ""
675        echo $n "Where should executables be installed?  [${bindir}] $c" ;;
676      sbindir)
677        echo ""
678        echo $n "Where should makewhatis be installed?  [${sbindir}] $c" ;;
679      confdir)
680        echo ""
681        echo $n "Where should $conffilename be installed?  [${confdir}] $c" ;;
682      mandir)
683        echo ""
684        echo $n "Where should man pages be installed? [${mandir}] $c" ;;
685    esac
686    dd=`eval echo \\$$d`
687    dir=$prefix/$dd
688    ok=false
689    while test "$ok" = "false"
690    do
691      read tmpdir
692      if test "$tmpdir" = "" && test "$dir" != ""
693      then
694        if test -d $dir
695        then
696          ok=true
697          eval $d=$dir
698        else
699          echo ""
700          echo "$dir doesn't seem to exist!  Try again!"
701        fi
702      elif test -d "$tmpdir"
703      then
704        ok=true
705        eval $d=$tmpdir
706        newprefix=`echo $tmpdir | sed -e "s:/$dd::"`
707        if test "$tmpdir" = "$newprefix/$dd"
708        then
709          prefix=$newprefix
710        fi
711      else
712        ok=false
713        echo ""
714        echo "$tmpdir doesn't seem to exist!  Try again!"
715      fi
716    done
717  done
718
719  tmpext=1
720  echo ""
721  echo $n "What extension should installed man(1) pages have? [${tmpext}] $c"
722  read man1ext
723  if test "$man1ext" = ""; then man1ext=$tmpext; fi
724
725  tmpext=5
726  echo ""
727  echo $n "What extension should installed man(5) pages have? [${tmpext}] $c"
728  read man5ext
729  if test "$man5ext" = ""; then man5ext=$tmpext; fi
730
731  tmpext=8
732  echo ""
733  echo $n "What extension should installed man(8) pages have? [${tmpext}] $c"
734  read man8ext
735  if test "$man8ext" = ""; then man8ext=$tmpext; fi
736else
737  echo ""
738  echo "Assuming that binaries go to $bindir, the configuration file"
739  echo "goes to $confdir, makewhatis to $sbindir, and the man pages"
740  echo "to $mandir/man*."
741  man1ext=1
742  man5ext=5
743  man8ext=8
744fi
745
746if [ x$default = x ]; then
747  echo ""
748  echo $n "Do you want to install non-english man pages? [no] $c"
749  ok=false
750  while test "$ok" = "false"
751  do
752    read yesno
753    if test "$yesno" = "" || test "$yesno" = "no"
754    then
755      ok=true
756      ans=false
757    elif test "$yesno" = "yes"
758    then
759      ok=true
760      ans=true
761    else
762      ok=false
763      echo "You must enter yes or no"
764    fi
765  done
766else
767  if [ "x$languages" = x ]; then
768    echo ""
769    echo "Assuming that you do not want to install non-english man pages."
770  fi
771  ans=false
772fi
773
774if test "$ans" = "true"
775then
776  cd man
777  languages=""
778  for i in ??; do
779    langname=`cat $i.txt`
780    echo $n "Install $langname pages? [no] $c"
781    ok=false
782    while test "$ok" = "false"
783    do
784      read yesno
785      if test "$yesno" = "" || test "$yesno" = "no"
786      then
787        ok=true
788        ans=false
789      elif test "$yesno" = "yes"
790      then
791        ok=true
792        ans=true
793      else
794        ok=false
795        echo "You must enter yes or no"
796      fi
797    done
798    if test "$ans" = "true"
799    then
800      languages="$languages $i"
801    fi
802  done
803  cd ..
804  if [ "x$languages" = x ]; then echo "Not installing any man pages, then."; fi
805else
806  if [ "x$languages" = x ]
807  then
808    languages="en"
809  fi
810fi
811
812if [ "x$languages" != x -a "x$languages" != xen ]
813then
814  DEF_NLSPATH="/usr/share/locale/%L/%N:/usr/lib/locale/%N/%L"
815  deflocalepath=`echo $NLSPATH:$DEF_NLSPATH | sed 's/:/ /g'`
816  for i in $deflocalepath; do
817    if [ x$deflocale = x ]; then
818      tstdir=`echo $i | sed -e 's/%N//; s/%L//'`
819      if [ -d "$tstdir" ]; then
820	deflocale=$i
821#      else
822#	tstdir=`echo $i | sed -e 's/%N/*/; s/%L/*/'`
823#	if [ -d "$tstdir" ]; then
824#	  deflocale=$i
825#	fi
826      fi
827    fi
828  done
829  if [ x$deflocale = x ]; then
830    deflocale="/usr/lib/locale/%N/%L"
831  fi
832  if [ x$default = x ]; then
833    echo ""
834    echo $n "Do you want to install non-english message catalogs for man? [yes] $c"
835    ok=false
836    while test "$ok" = "false"
837    do
838      read yesno
839      if test "$yesno" = "" || test "$yesno" = "yes"
840      then
841        ok=true
842        ans=true
843      elif test "$yesno" = "no"
844      then
845        ok=true
846        ans=false
847      else
848        ok=false
849        echo "You must enter yes or no"
850      fi
851    done
852    if [ $ans = true ]; then
853      echo $n "Where? [$deflocale] $c"
854      read locale
855      if [ x$locale = x ]; then
856        locale=$deflocale
857      fi
858    else
859      locale=
860    fi
861  else
862    locale=$deflocale
863  fi
864  echo
865  echo "Using localedir $locale"
866fi
867
868if [ x$suid = x -a x$sgid = x ]; then
869  if [ x$default = x ]; then
870    echo ""
871    echo "Do you want to install man setuid or setgid to some user"
872    echo $n "who owns all the formatted man pages?  [no] $c"
873    ok=false
874    while test "$ok" = "false"
875    do
876      read yesno
877      if test "$yesno" = "" || test "$yesno" = "no"
878      then
879        ok=true
880        ans=false
881      elif test "$yesno" = "yes"
882      then
883        ok=true
884        ans=true
885      else
886        ok=false
887        echo "You must enter yes or no"
888      fi
889    done
890  else
891    echo "Assuming that you do not want man to be suid or sgid."
892    echo "(But you can always do _chown man man; chmod 04555 man_ later.)"
893    ans=false
894  fi
895else
896  ans=true
897fi
898
899if test "$ans" = "true"
900then
901  # prefer uid/gid man above root, but prefer not to give man the
902  # ability to write into its own binary; never install man suid root
903
904  if [ x$sgid = x ]; then
905    man_user=man
906    man_mode=4555
907    if grep -q '^man:' /etc/group >/dev/null 2>/dev/null;
908    then
909      man_group=man
910    else
911      man_group=root
912    fi
913    if grep -q '^man:' /etc/passwd >/dev/null 2>/dev/null;
914    then
915      :
916    else
917      echo "Warning: you still have to create a user \"man\""
918    fi
919  else
920    man_user=root
921    man_group=man
922    man_mode=2555
923    if grep -q '^man:' /etc/group >/dev/null 2>/dev/null;
924    then
925      :
926    else
927      echo "Warning: you still have to create a group \"man\""
928    fi
929  fi
930  if [ x$default = x ]; then
931    echo ""
932    echo $n "What owner should man have? [${man_user}] $c"
933    read user
934    if test "$user" != ""; then man_user=$user; fi
935    echo ""
936    echo $n "What group should man have? [${man_group}] $c"
937    read group
938    if test "$group" != ""; then man_group=$group; fi
939    echo ""
940    echo $n "What mode should the installed man have? [${man_mode}] $c"
941    read mode
942    if test "$mode" != ""; then man_mode=$mode; fi
943  fi
944  man_install_flags="-m $man_mode -o $man_user -g $man_group"
945fi
946
947# What sections do we anticipate?
948
949tmpsections="1 1p 8 2 3 3p 4 5 6 7 9 0p tcl n l p o"
950
951if [ x$default = x ]; then
952  echo ""
953  echo "Enter the man page sections your system uses, separated by"
954  echo "spaces, and in the order they should be searched."
955  echo $n "[${tmpsections}] $c"
956  read sects
957  if test "$sects" != ""; then tmpsections="$sects"; fi
958else
959  echo
960  echo "Setting the default section search order to $tmpsections."
961fi
962
963for sect in $tmpsections
964do
965  if [ x$sections = x ]; then
966    sections=$sect
967  else
968    sections=$sections:$sect
969  fi
970done
971
972if test "$nroff" != ""
973then
974  if [ x$default = x ]; then
975    echo ""
976    echo $n "Compress formatted pages? [yes] $c"
977    ok=false
978    while test "$ok" = "false"
979    do
980      read yesno
981      if test "$yesno" = "" || test "$yesno" = "yes"
982      then
983        ok=true
984        ans=true
985      elif test "$yesno" = "no"
986      then
987        ok=true
988        ans=false
989      else
990        ok=false
991        echo "You must enter yes or no"
992      fi
993    done
994  else
995    echo ""
996    echo "Assuming that formatted pages should be compressed."
997    ans=true
998  fi
999
1000  if test "$ans" = "true"
1001  then
1002    DO_COMPRESSION=true
1003    compress=
1004    for i in bzip2 gzip bzip tzip pack compress freeze yabba
1005    do
1006      eval F$i=missing
1007      for j in $DEFPATH
1008      do
1009        if test -f $j/$i
1010        then
1011	  eval F$i=$j/$i
1012	  if [ x$compress = x ]; then compress=$j/$i; fi
1013	  break
1014        fi
1015      done
1016    done
1017
1018    if [ x$default = x ]; then
1019      echo ""
1020      echo "What program should be used to compress the formatted pages?"
1021      echo $n "Note that it must work as a filter! [${compress}] $c"
1022      found=false
1023      while test "$found" = "false"
1024      do
1025        read tmp
1026        if test -n "$tmp"
1027        then
1028          if test -f `echo $tmp | awk '{print $1}'`
1029          then
1030            found=true
1031            compress=$tmp
1032          else
1033            found=false
1034            echo ""
1035            echo "`echo $tmp | awk '{print $1}'` doesn't seem to exist!  Try again!"
1036          fi
1037        elif test -f `echo "$compress" | awk '{print $1}'`
1038        then
1039          found=true
1040        else
1041          found=false
1042          echo ""
1043          echo "`echo "$compress" | awk '{print $1}'` doesn't seem to exist!  Try again!"
1044        fi
1045      done
1046    else
1047      if [ x$compress = x ]
1048      then
1049	DO_COMPRESSION=false
1050	echo "Could not find any compression programs."
1051      else
1052        echo "Using $compress for compression."
1053      fi
1054    fi
1055
1056    case $compress in
1057      *bzip2*) ext=".bz2" ;;
1058      *gzip*) ext=".gz" ;;
1059      *bzip*) ext=".bz" ;;
1060      *tzip*) ext=".tz" ;;
1061      *pack*) ext=".z" ;;
1062      *compress*) ext=".Z" ;;
1063      *freeze*) ext=".F" ;;
1064      *yabba*) ext=".Y" ;;
1065      *) ext="" ;;
1066    esac
1067    if [ x$default = x ]; then
1068      echo ""
1069      echo "What extension should be added to"
1070      if test "$ext" = ""
1071      then
1072        echo "compressed files?"
1073      else
1074        echo $n "compressed files?  [${ext}] $c"
1075      fi
1076      ok=false
1077      while test "$ok" = "false"
1078      do
1079        read tmp_ext
1080        if test "$tmp_ext" = "" && test "$ext" != ""
1081        then
1082          ok=true
1083          compress_ext=$ext
1084        elif test "$tmp_ext" != ""
1085        then
1086          ok=true
1087          compress_ext=$tmp_ext
1088        fi
1089      done
1090    else
1091      compress_ext=$ext
1092    fi
1093  else
1094    DO_COMPRESSION=false
1095  fi
1096fi
1097
1098# unconditionally handle uncompression
1099UNCOMPRESSORS="gunzip bzip2 pcat zcat fcat unyabba"
1100for i in $UNCOMPRESSORS
1101do
1102  eval F$i=missing
1103  for j in $DEFPATH
1104  do
1105    if test -f $j/$i
1106    then
1107      eval F$i=$j/$i
1108      break
1109    fi
1110  done
1111done
1112gunzip=missing
1113if [ $Fgunzip != missing ]; then
1114  gunzip="$Fgunzip -c"
1115fi
1116bzip2=missing
1117if [ $Fbzip2 != missing ]; then
1118  bzip2="$Fbzip2 -c -d"
1119fi
1120pcat="$Fpcat"
1121zcat="$Fzcat"
1122fcat="$Ffcat"
1123unyabba="$Funyabba"
1124
1125if [ x$default = x ]; then
1126  echo ""
1127  echo "Now let us look at programs for uncompressing compressed man pages."
1128  echo ""
1129  echo "If you don't have one of the following programs, enter \`missing'."
1130  echo "It's best to enter absolute pathnames so that man won't have to"
1131  echo "depend on the user's path to work properly.  Default values are"
1132  echo "given in square brackets.  The answers given are only checked to"
1133  echo "see if the programs exist, not to see see if the given flags are"
1134  echo "correct."
1135  for filter in $UNCOMPRESSORS
1136  do
1137    found=false
1138    while test "$found" = "false"
1139    do
1140      echo ""
1141      case $filter in
1142	gunzip)
1143	  echo "Command to use for .gz files (standard gzip)"
1144	  echo $n "[`eval echo \\$$filter`] $c" ;;
1145	bzip2)
1146	  echo "Command to use for .bz2 files (standard bzip2)"
1147	  echo $n "[`eval echo \\$$filter`] $c" ;;
1148        pcat)
1149          echo "Command to use for .z files (pack/unpack)"
1150          echo $n "[`eval echo \\$$filter`] $c" ;;
1151        zcat)
1152          echo "Command to use for .Z files (standard compress)"
1153          echo $n "[`eval echo \\$$filter`] $c" ;;
1154        fcat)
1155          echo "Command to use for .F files (freeze/melt from net posting)"
1156          echo $n "[`eval echo \\$$filter`] $c" ;;
1157        unyabba)
1158          echo "Command to use for .Y files (yabba/unyabba from net posting)"
1159          echo $n "[`eval echo \\$$filter`] $c" ;;
1160        esac
1161      read tmp
1162      if test -n "$tmp"
1163      then
1164        if test "$tmp" = "missing"
1165        then
1166          found=true
1167          eval $filter=""
1168        elif test -f `echo $tmp | awk '{print $1}'`
1169        then
1170          found=true
1171          eval $filter=\""$tmp"\"
1172        else
1173          found=false
1174          echo ""
1175          echo "`echo $tmp | awk '{print $1}'` doesn't seem to exist!  Try again or enter \`missing'"
1176        fi
1177      elif test `eval echo \\$$filter | awk '{print $1}'` = "missing"
1178      then
1179        found=true
1180        eval $filter=""
1181      elif test -f `eval echo \\$$filter | awk '{print $1}'`
1182      then
1183        found=true
1184      else
1185        found=false
1186        echo ""
1187        echo "`eval echo \\$$filter | awk '{print $1}'` doesn't seem to exist!  Try again or enter \`missing'"
1188      fi
1189    done
1190  done
1191else
1192  echo ""
1193  echo "Assuming the following ways to invoke the various decompressors:"
1194  for filter in $UNCOMPRESSORS
1195  do
1196    echo "$filter command:   	`eval echo \\$$filter`"
1197    if test `eval echo \\$$filter | awk '{print $1}'` = "missing"
1198    then
1199      eval $filter=""
1200    fi
1201  done
1202fi
1203
1204# set $decompress to the program that decompresses things
1205# with the $compress_ext extension.
1206case $compress_ext in
1207  .gz) decompress=$gunzip ;;
1208  .bz2) decompress=$bzip2 ;;
1209  .z) decompress=$pcat ;;
1210  .Z) decompress=$zcat ;;
1211  .F) decompress=$fcat ;;
1212  .Y) decompress=$unyabba ;;
1213  *) decompress= ;;
1214esac
1215
1216if test "$DO_COMPRESSION" = "true"
1217then
1218  DEFS="$DEFS -DDO_COMPRESS"
1219fi
1220
1221man=$bindir/man
1222apropos=$bindir/apropos
1223whatis=$bindir/whatis
1224man2dvi=$bindir/man2dvi
1225makewhatis=$sbindir/makewhatis
1226man_config_dir=$confdir
1227man_config_file=$confdir/$conffilename
1228
1229if [ x$locale = x ]; then
1230  sed -e 's/%.*//' < Makefile.in > Makefile
1231else
1232  sed -e 's/%//' < Makefile.in > Makefile
1233fi
1234
1235# some definitions to avoid extensive quoting in the script below
1236allargs='$@'
1237infiles='$infiles'
1238infile='$infile'
1239cb='$cb'
1240cs='$cs'
1241ce='$ce'
1242mancomment='.\\\"'
1243
1244# Note: the script below only works when none of the variables
1245# contains a comma.
1246version=`cat version`
1247
1248cat > conf_script << EOS
1249#!/bin/sh
1250infiles=$allargs
1251trap 'rm -f $infiles; exit 1' 1 3 15
1252
1253# echo ""
1254for infile in $infiles
1255do
1256  case $infile in
1257  *.h)
1258    cb="/*"; cs=" *"; ce=" */";;
1259  *.1|*.5|*.8|*.man)
1260    cb=$mancomment; cs=$mancomment; ce=$mancomment;;
1261  *)
1262    cb="#"; cs="#"; ce="#";;
1263  esac
1264  echo "$cb"                                                    > $infile
1265  echo "$cs Generated automatically from $infile.in by the"     >> $infile
1266  echo "$cs configure script."                                  >> $infile
1267  echo "$ce"                                                    >> $infile
1268  echo "Creating $infile from $infile.in"
1269  sed -e '
1270s,@version@,$version,
1271s,@CC@,$CC,
1272s,@BUILD_CC@,$BUILD_CC,
1273s,@INSTALL@,$INSTALL,
1274s,@DEFS@,$DEFS,
1275s,@LIBS@,$LIBS,
1276s,@LIBOBJS@,$LIBOBJS,
1277s,@troff@,$troff,
1278s,@nroff@,$nroff,
1279s,@jnroff@,$jnroff,
1280s,@eqn@,$eqn,
1281s,@neqn@,$neqn,
1282s,@jneqn@,$jneqn,
1283s,@tbl@,$tbl,
1284s,@nocol@,$nocol,
1285s,@pcol@,$pcol,
1286s,@col@,$col,
1287s,@vgrind@,$vgrind,
1288s,@refer@,$refer,
1289s,@grap@,$grap,
1290s,@pic@,$pic,
1291s,@fcat@,$fcat,
1292s,@pcat@,$pcat,
1293s,@zcat@,$zcat,
1294s,@gunzip@,$gunzip,
1295s,@bzip2@,$bzip2,
1296s,@unyabba@,$unyabba,
1297s,@compress@,$compress,
1298s,@compress_ext@,$compress_ext,
1299s,@decompress@,$decompress,
1300s,@pager@,$pager,
1301s,@browser@,$browser,
1302s,@htmlpager@,$htmlpager,
1303s,@cmp@,$cmp,
1304s,@cat@,$cat,
1305s,@awk@,$awk,
1306s,@bindir@,$bindir,
1307s,@sbindir@,$sbindir,
1308s,@mandir@,$mandir,
1309s,@locale@,$locale,
1310s,@fhs@,$fhs,
1311s,@fsstnd@,$fsstnd,
1312s,@man1ext@,$man1ext,g
1313s,@man5ext@,$man5ext,g
1314s,@man8ext@,$man8ext,g
1315s,@man_install_flags@,$man_install_flags,
1316s,@man_user@,$man_user,
1317s,@languages@,$languages,
1318s,@man@,$man,
1319s,@apropos@,$apropos,
1320s,@whatis@,$whatis,
1321s,@man2dvi@,$man2dvi,
1322s,@makewhatis@,$makewhatis,
1323s,@man_config_dir@,$man_config_dir,
1324s,@man_config_file@,$man_config_file,
1325s,@manpathoption@,$manpathoption,
1326s/@sections@/$sections/
1327' $infile.in >> $infile
1328done
1329EOS
1330
1331chmod +x conf_script
1332
1333echo ""
1334echo 'Created Makefile and conf_script. Now do "make" and "make install".'
1335echo ""
1336