#!/bin/sh
#
#	Configuration.
#

# parameters:

# Version number of Boehm-GC library comes with w3m.
# version number: JMMAAA  J: major MM: minor AAA: alpha
#   Alpha number of non-alpha version is 255.
# version 4.14alpha1 => 414002
mygcversion=500002

#
set `uname -a`
sysname=$1
sysversion=$3
host=$2
platform=`uname -m`

sysversion1=`echo $sysversion | awk -F. '{print $1}'`
sysversion2=`echo $sysversion | awk -F. '{print $2}'`
sysversion3=`echo $sysversion | awk -F. '{print $3}'`

echo $sysname $sysversion1 $sysversion2 $sysversion3 /$platform at $host

if [ -f config.param ] ; then
	confhost=`awk 'NR==1{print $4}' config.param`
	if [ $confhost = $host ] ; then
          . ./config.param
	fi
fi

echo "# Configuretion at $host" > config.param

if [ -z "`echo -n aho | grep n`" ] ; then
Echo()
{
	echo -n "$*"
}
else
Echo()
{
	echo "$*\c"
}
fi


do_sigtest()
{
  echo "#include <signal.h>" > _zmachdep.c
  if [ $2 = void ]; then
    echo "$1 _handler($2) {}" >> _zmachdep.c
  else
    echo "$1 _handler($2 x) {}" >> _zmachdep.c
  fi
  echo "int main() { $1 (*hdl)($2); hdl = signal(SIGINT,_handler); return 0; }" >> _zmachdep.c
  $cc $cflags -o _zmachdep _zmachdep.c > _zwarning 2>&1 
  stat=$?
  warning=`cat _zwarning`
  /bin/rm -f _zwarning
}

readdir() { 
  read __dir
  _dir=`echo $__dir|sed -e "s;^~;$HOME;"`
}

#--------------------------------------------------------------
if [ -n "$USER" ]; then
	user=$USER
elif [ -n "$LOGNAME" ]; then
	user=$LOGNAME
else
	Echo "Who are you? "
	read user
fi

echo "%"
echo "% Hello $user. Let's start configuration process for w3m."
echo "% Please answer some questions."
echo "%"

if [ -n "`echo $sysname | grep CYGWIN`" ]; then
  sysname="CYGWIN"
fi

special_sys=''
case $sysname in
  aix | AIX )
    special_sys="#define AIX"
  ;;
  CYGWIN )
    special_sys="#define CYGWIN"
  ;;
  NetBSD )
# Newer NetBSD system doesn't define 'unix' symbol anymore, but GC library
# requires it.
    special_sys="#define unix"
  ;;
esac

if [ -z "$def_bindir" ]; then
  def_bindir="/usr/local/bin"
fi
echo "Which directory do you want to put the binary?"
Echo "(default: $def_bindir) "
readdir
bindir=$_dir
if [ -z "$bindir" ]; then
  bindir=$def_bindir
fi
echo "def_bindir=$bindir" >> config.param

if [ -z "$def_helpdir" ]; then
  def_helpdir="/usr/local/lib"
fi
echo "Which directory do you want to put the helpfile?"
Echo "(default: $def_helpdir) "
readdir
helpdir=$_dir
if [ -z "$helpdir" ]; then
  helpdir=$def_helpdir
fi
echo "def_helpdir=$helpdir" >> config.param

echo "Which language do you prefer?"
echo "  1 - Japanese (charset ISO-2022-JP, EUC-JP, Shift_JIS)"
echo "  2 - English (charset US_ASCII, ISO-8859-1, etc.)"
if [ "$pref_lang" = 2 ]; then
  Echo '[2]? '
  def_lg=2
else
  Echo '[1]? '
  def_lg=1
fi
while :
do
  read lg_ans
  if [ -z "$lg_ans" ]; then
    lg_ans=$def_lg
  elif [ "$lg_ans" != 1 -a "$lg_ans" != 2 ]; then
    echo "Please choose 1 or 2."
    continue
  else
    :
  fi
  break
done 
echo "pref_lang='$lg_ans'" >> config.param
if [ $lg_ans = 1 ]; then
  use_lang="#define LANG JA"
  lang=ja
else
  use_lang="#define LANG EN"
  lang=en
fi


if [ $lang = ja ]; then
  echo "Input your display kanji code."
  echo "	S - Shift JIS"
  echo "	E - EUC-JP"
  echo '	j - JIS: ESC $@ - ESC (J'
  echo '	N - JIS: ESC $B - ESC (J'
  echo '	n - JIS: ESC $B - ESC (B'
  echo '	m - JIS: ESC $@ - ESC (B'
  echo ''
  while :
  do
	if [ -n "$def_dcode" ] ; then
		Echo "(default: $def_dcode) "
	fi
	Echo "Which? "
	read ncode
	if [ -n "$def_dcode"  -a -z "$ncode" ] ; then
		ncode=$def_dcode
	fi
	if [ -z "`echo $ncode | grep '[SEjNnm]'`" ] ; then
		Echo "Illegal code. Try again."
		continue
	fi
	break
  done
  echo "def_dcode=$ncode" >> config.param
else
  ncode=x
fi

echo "Do you want to use Lynx-like key binding?"
if [ "$lynx_key" = y ]; then
  Echo '[y]? '
  read ks_ans
  if [ "$ks_ans" = 'n' ]; then
    lynx_key=n
  fi
else
  Echo '[n]? '
  read ks_ans
  if [ "$ks_ans" = 'y' ]; then
    lynx_key=y
  else
    lynx_key=n
  fi
fi
echo "lynx_key=$lynx_key" >> config.param
if [ $lynx_key = y ]; then
  keymap_file="keybind_lynx"
else
  keymap_file="keybind"
fi

if [ $lang = ja ]; then
  if [ "$lynx_key" = y ]; then
    helpfile="w3mhelp-lynx_ja.html"
  else
    helpfile="w3mhelp_ja.html"
  fi
else
  if [ "$lynx_key" = y ]; then
    helpfile="w3mhelp-lynx_en.html"
  else  
    helpfile="w3mhelp_en.html"
  fi
fi

if [ $lang = ja ]; then
  echo "Do you want to use 2-byte character for table border, item, etc."
  if [ "$kanji_symbols" = n ]; then
    Echo '[n]? '
    read ks_ans
    if [ "$ks_ans" = 'y' ]; then
      kanji_symbols=y
    fi
  else
    Echo '[y]? '
    read ks_ans
    if [ "$ks_ans" = 'n' ]; then
      kanji_symbols=n
    else
      kanji_symbols=y
    fi
  fi
  echo "kanji_symbols=$kanji_symbols" >> config.param
fi
if [ "$kanji_symbols" = y ]; then
  def_kanji_symbols="#define KANJI_SYMBOLS"
else
  def_kanji_symbols="#undef KANJI_SYMBOLS"
fi

echo "Do you want to use color ESC sequence for kterm/pxvt "
if [ "$use_color" = n ]; then
  Echo '[n]? '
  read ks_ans
  if [ "$ks_ans" = 'y' ]; then
    use_color='y'
  fi
else
  Echo '[y]? '
  read ks_ans
  if [ "$ks_ans" = 'n' ]; then
    use_color='n'
  else
    use_color='y'
  fi
fi
echo "use_color=$use_color" >> config.param
if [ $use_color = y ]; then
  def_color="#define COLOR"
else
  def_color="#undef COLOR"
fi

echo "Do you want to use mouse?"
echo "  (It requires xterm/kterm)"
if [ "$use_mouse" = y ]; then
  Echo '[y]? '
  read ks_ans
  if [ "$ks_ans" = 'n' ]; then
    use_mouse='n'
  fi
else
  Echo '[n]? '
  read ks_ans
  if [ "$ks_ans" = 'y' ]; then
    use_mouse='y'
  else
    use_mouse='n'
  fi
fi
echo "use_mouse=$use_mouse" >> config.param
if [ $use_mouse = y ]; then
  def_mouse="#define MOUSE"
else
  def_mouse="#undef MOUSE"
fi

echo "Do you want to use popup menu?"
if [ "$use_menu" = n ]; then
  Echo '[n]? '
  read ks_ans
  if [ "$ks_ans" = 'y' ]; then
    use_menu='y'
  fi
else
  Echo '[y]? '
  read ks_ans
  if [ "$ks_ans" = 'n' ]; then
    use_menu='n'
  else
    use_menu='y'
  fi
fi
echo "use_menu=$use_menu" >> config.param
if [ $use_menu = y ]; then
  def_menu="#define MENU"
else
  def_menu="#undef MENU"
fi

echo "Do you want to use matrix in rendering table?"
if [ "$use_matrix" = n ]; then
  Echo '[n]? '
  read ks_ans
  if [ "$ks_ans" = 'y' ]; then
    use_matrix='y'
  fi
else
  Echo '[y]? '
  read ks_ans
  if [ "$ks_ans" = 'n' ]; then
    use_matrix='n'
  else
    use_matrix='y'
  fi
fi
echo "use_matrix=$use_matrix" >> config.param
if [ $use_matrix = y ]; then
  def_matrix="#define MATRIX 1"
else
  def_matrix="#undef MATRIX"
fi


if [ -z "$ded" ] ; then ded=`./which \vi` ; fi
if [ -n  "`echo $ded | grep 'no'`" ] ; then ded=vi ; fi
echo "Input your favorite editor program."
Echo "(Default: $ded) "
readdir
editor=$_dir
if [ -z "$editor" ] ; then editor="$ded" ; fi
echo "ded='$editor'" >> config.param

if [ -z "$dmail" ] ; then 
  if ./which \mailx > /dev/null
  then
    dmail=`./which \mailx` 
  else
    dmail=`./which \mail`
  fi
  if [ -n  "`echo $dmail | grep 'no'`" ] ; then dmail=mailx ; fi
fi
echo "Input your favorite mailer program."
Echo "(Default: $dmail) "
readdir
mailer=$_dir
if [ -z "$mailer" ] ; then mailer="$dmail" ; fi
echo "dmail='$mailer'" >> config.param


if [ -z "$dbrowser" ] ; then 
  if ./which netscape > /dev/null
  then
    dbrowser=`./which netscape` 
  elif ./which iexplore > /dev/null
  then
    dbrowser=`./which iexplore`
  else
    dbrowser=`./which lynx`
  fi
  if [ -n  "`echo $dbrowser | grep 'no'`" ] ; then dbrowser=netscape ; fi
fi
echo "Input your favorite external browser program."
Echo "(Default: $dbrowser) "
readdir
brz=$_dir
if [ -z "$brz" ] ; then brz="$dbrowser" ; fi
echo "dbrowser='$brz'" >> config.param

if [ -z "$dcc" ] ; then 
  if ./which gcc >/dev/null
  then
    dcc=gcc
  else
    dcc=cc
  fi
fi
echo "Input your favorite C-compiler."
Echo "(Default: $dcc) "
read cc
if [ -z "$cc" ] ; then cc="$dcc" ; fi
echo "dcc='$cc'" >> config.param

if [ -z "$dcflags" ] ; then dcflags=-g ; fi
echo "Input your favorite C flags."
Echo "(Default: $dcflags) "
read cflags
if [ -z "$cflags" ] ; then cflags="$dcflags" ; fi
echo "dcflags='$cflags'" >> config.param

bsdinclude=''
if [ ! -f /usr/include/netinet/in.h ] ; then
	if [ -f /usr/include/bsd/netinet/in.h ] ; then
		bsdinclude='-I/usr/include/bsd'
	elif [ -f /usr/bsdinclude/netinet/in.h ] ; then
		bsdinclude='-I/usr/bsdinclude'
	else
		echo "It seems you don't have some include files for networking."
	fi
fi

termlib=''
cat > _zmachdep.c << EOF
main()
{
  char bp[100];
  tgetent(bp,getenv("TERM"));
}
EOF

TERM_LIBS='termcap termlib terminfo mytinfo curses ncurses'

for lib in $TERM_LIBS
do
  for libdir in /lib /usr/lib /usr/local/lib /usr/ucblib /usr/ccslib /usr/ccs/lib
  do
    if [ -f $libdir/lib$lib.a -o -f $libdir/lib$lib.so ] ; then 
      # check if the lib works...
      Echo "Terminal library -l$lib found at $libdir, "
      if $cc $cflags -o _zmachdep _zmachdep.c -l$lib > /dev/null 2>&1
      then
        echo "and it seems to work."
        termlib=-l$lib
      else
        echo "but it doesn't seem to work."
      fi
    fi
  done
done
if [ -z "$termlib" ]; then
  Echo "termcap/curses library not found; I hope -ltermcap works."
  termlib='-ltermcap'
fi
echo "Which terminal library do you want to use?"
Echo "(default: $termlib) "
dtermlib=$termlib
read termlib
if [ -z "$termlib" ]; then
  termlib=$dtermlib
fi

extlib=''
for lib in bsd BSD socket nsl
do
  for libdir in /lib /usr/lib /usr/local/lib /usr/ucblib /usr/ccslib /usr/ccs/lib
  do
    if [ -f $libdir/lib$lib.a ] ; then 
      extlib="$extlib -l$lib"
    fi
  done
done
if [ $sysname = "HP-UX" ]; then
  extlib="$extlib -ldld"
fi
if [ -n "$extlib" ]; then
  echo additional library found: $extlib
fi

gclib=''
gcinclude=''
gctarget=''
for libdir in /lib /usr/lib /usr/local/lib /usr/ucblib /usr/ccslib /usr/ccs/lib ${HOME}/lib
do
  if [ -f $libdir/libgc.a -o -f $libdir/libgc.so ] ; then 
    echo $libdir/libgc found
    gclib="-lgc"
  fi
done
for inc in /usr/include /usr/include/gc /usr/local/include /usr/local/include/gc ${HOME}/include
do
  if [ -f $inc/gc.h ]; then
    echo $inc/gc.h found
    gcinclude=$inc
  fi
done

if [ -n "$gclib" -a -n "$gcinclude" ]; then
  Echo GC library found on your system...
  cat > _zmachdep.c << EOF
#include <gc.h>
main()
{
  extern unsigned GC_version;
  printf("%d%02d%03d\n",(GC_version>>16)&0xff,(GC_version>>8)&0xff,GC_version&0xff);
}
EOF
  if $cc $cflags -I$gcinclude -o _zmachdep _zmachdep.c $gclib > /dev/null 2>&1
  then
    echo "and it seems to work."
    gcversion=`./_zmachdep`
    echo "GC_version is $gcversion."    
    if [ $gcversion -lt $mygcversion ]; then
      echo "GC library on your system seems to be old."
      Echo "Do you want to use GC library comes with w3m?[y] "
      read ans
      if [ "$ans" = 'n' -o "$ans" = 'N' ]; then
        cflags="$cflags -I$gcinclude"
      else
        cflags="$cflags -I./gc"
        gclib="gc/gc.a"
        gctarget=$gclib
      fi
    else
      cflags="$cflags -I$gcinclude"
    fi
  else
    echo "but it doesn't seem to work."
    cflags="$cflags -I./gc"
    gclib="gc/gc.a"
    gctarget=$gclib
  fi
else
  cflags="$cflags -I./gc"
  gclib="gc/gc.a"
  gctarget=$gclib
fi

# Apply patch.
if [ $gclib = "gc/gc.a" ]; then
  patchfile=""
  case "$platform:$sysname"
  in
  [Aa]lpha:Linux)
    patchfile=Patches/alpha ;;
  [Ss]parc:Linux|sun4*:Linux)
      if [ $sysversion1 = 2 -a $sysversion2 = 2 ]
      then
        patchfile=Patches/linux2.2sparc
      fi
      ;;
  *:HP-UX)
    if [ $sysversion2 = 11 ]
    then
      patchfile=Patches/hpux11
    fi
    ;;
  macppc:NetBSD)
    patchfile = Patches/macppc
    ;;
  R3000:*System_V*|R4000:UNIX_SYSV|R4000:UNIX_SV)
    # EWS-4800
    patchfile=Patches/ews4800
    ;;
  esac

  if [ -n "$patchfile" -a -f "$patchfile" ]; then
    patch -p0 < $patchfile
    echo "dpatch='$patch'" >> config.param
  fi
fi


echo "Input additional LD flags other than listed above, if any:"
if [ -n "$dldflags" ]; then
  Echo "(default: $dldflags) : "
else
  Echo ": "
fi
read ldflags
if [ -z "$ldflags" ]; then
  ldflags=$dldflags
fi
echo "dldflags='$ldflags'" >> config.param

echo "Checking machine dependency."

####### strcasecmp
cat > _zmachdep.c << EOF
#include <string.h>
main()
{
  int i;
  i = strcasecmp("abc","def");
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have strcasecmp()."
  strcasecmp_flg="#define STRCASECMP"
else
  echo "You don't have strcasecmp()."
  strcasecmp_flg="#undef STRCASECMP"
fi

####### strchr
cat > _zmachdep.c << EOF
#include <string.h>
main()
{
  char *p, *q = "abc";
  p = strchr(q,'c');
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have strchr()."
  strchr_flg="#define STRCHR"
else
  echo "You don't have strchr()."
  strchr_flg="#undef STRCHR"
fi

####### strerror
cat > _zmachdep.c << EOF
main()
{
  int i;
  i = strerror(0);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have strerror()."
  strerror_flg="#define STRERROR"
else
  echo "You don't have strerror()."
  strerror_flg="#undef STRERROR"
fi


####### sys_errlist
cat > _zmachdep.c << EOF
main()
{
  extern char sys_errlist[];
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have sys_errlist[]."
  syserrlist_flg="#define SYS_ERRLIST"
else
  echo "You don't have sys_errlist[]."
  syserrlist_flg="#undef SYS_ERRLIST"
fi

####### bcopy
cat > _zmachdep.c << EOF
main()
{
  char x[1],y[1];
  bzero(x,1);
  bcopy(x,y,1);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have bcopy()."
  bcopy_flg="#undef NOBCOPY"
else
  echo "You don't have bcopy()."
  bcopy_flg="#define NOBCOPY"
fi

####### getdtablesize
cat > _zmachdep.c << EOF
main()
{
  getdtablesize();
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have getdtablesize()."
  getdtablesize_flg="#define GETDTABLESIZE"
else
  echo "You don't have getdtablesize()."
  getdtablesize_flg="#undef GETDTABLESIZE"
fi

####### getcwd
cat > _zmachdep.c << EOF
#include <sys/param.h>
#include <unistd.h>
main()
{
  char path[MAXPATHLEN];
  getcwd(path,MAXPATHLEN);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have getcwd()."
  getcwd_flg="#define GETCWD"
else
  echo "You don't have getcwd()."
  getcwd_flg="#undef GETCWD"
fi

####### getwd
cat > _zmachdep.c << EOF
main()
{
  char path[64];
  getwd(path);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have getwd()."
  getwd_flg="#define GETWD"
else
  echo "You don't have getwd()."
  getwd_flg="#undef GETWD"
fi

####### setenv
cat > _zmachdep.c << EOF
#include <stdlib.h>
main()
{
  setenv("HOGE","hoge",1);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have setenv()."
  setenv_flg="#define HAVE_SETENV"
else
  echo "You don't have setenv()."
  setenv_flg="#undef HAVE_SETENV"
fi

####### putenv
cat > _zmachdep.c << EOF
#include <stdlib.h>
main()
{
  putenv("HOGE=hoge");
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have putenv()."
  putenv_flg="#define HAVE_PUTENV"
else
  echo "You don't have putenv()."
  putenv_flg="#undef HAVE_PUTENV"
fi

####### qsort
cat > _zmachdep.c << EOF
#include <stdlib.h>
int cmp() {return 1;}
main()
{
  char s[2];
  qsort(s,2,1,cmp);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have qsort()."
  qsort_flg="#define HAVE_QSORT"
else
  echo "You don't have qsort()."
  qsort_flg="#undef HAVE_QSORT"
fi

####### sigsetjmp
cat > _zmachdep.c << EOF
#include <setjmp.h>
main()
{
  jmp_buf env;
  if (sigsetjmp(env,1) != 0) {
    exit(0);
  }
  siglongjmp(env,1);
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "You have sigsetjmp()."
  setjmp_def="#define SETJMP(env) sigsetjmp(env,1)"
  longjmp_def="#define LONGJMP(env,val) siglongjmp(env,val)"
  jmpbuf_def="#define JMP_BUF sigjmp_buf"
else
  echo "You don't have sigsetjmp()."
  setjmp_def="#define SETJMP(env) setjmp(env)"
  longjmp_def="#define LONGJMP(env,val) longjmp(env)"
  jmpbuf_def="#define JMP_BUF jmp_buf"
fi

####### fclose
cat > _zmachdep.c << EOF
#include <stdio.h>
#include <stdlib.h>
main()
{
  void (*c)() = fclose;
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "fclose() is declared."
  fclose_dcl=''
else
  echo "fclose() is not declared."
  fclose_dcl='void fclose(FILE*);'
fi

####### pclose
cat > _zmachdep.c << EOF
#include <stdio.h>
#include <stdlib.h>
main()
{
  void (*c)() = pclose;
}
EOF
if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
then
  echo "pclose() is declared."
  pclose_dcl=''
else
  echo "pclose() is not declared."
  pclose_dcl='void pclose(FILE*);'
fi

####### termios/termio/sgtty
term_if='#define SGTTY'
if [ $sysname = "HP-UX" ]; then
	echo "Your OS is HP-UX; using termio"
	term_if="#define TERMIO"
elif [ $sysname = "CYGWIN" ]; then
	echo "Your OS is CYGWIN; using termios"
	term_if="#define TERMIOS"
elif [ -r /usr/include/termios.h ]; then
	echo "You have termios."
	term_if='#define TERMIOS'
elif [ -r /usr/include/termio.h ]; then
	echo "You have termio."
	term_if='#define TERMIO'
elif [ -r /usr/include/sgtty.h ]; then
	echo "You have sgtty."
	term_if='#define SGTTY'
else
	echo "Do you have tty interface? I can't find one but I hope sgtty works..."
fi

####### dirent/direct
dir_if=''
if [ $sysname = "CYGWIN" ]; then
	echo "Your OS is CYGWIN; using dirent.h"
	dir_if='#define DIRENT'
elif [ -r /usr/include/dirent.h ]; then
	echo "You have dirent.h."
	dir_if='#define DIRENT'
elif [ -r /usr/include/sys/dir.h ]; then
	echo "You have sys/dir.h."
	dir_if=''
else
	echo "Do you have directory interface? I can't find one but I hope sys/dir.h works..."
fi

# check signal handler

do_sigtest int int
if [ $stat = 0 -a -z "$warning" ]
then
  echo 'signal handler is int handler(int).'
  sig_type='typedef int MySignalHandler;'
  sig_arg='#define SIGNAL_ARG int _dummy'
  sig_arglist='#define SIGNAL_ARGLIST 0'
  sig_return='#define SIGNAL_RETURN return 0'
else
  do_sigtest int void
  if [ $stat = 0 -a -z "$warning" ]
  then
    echo 'signal handler is int handler(void).'
    sig_type='typedef int MySignalHandler;'
    sig_arg='#define SIGNAL_ARG void'
    sig_arglist='#define SIGNAL_ARGLIST'
    sig_return='#define SIGNAL_RETURN return 0'
  else
    do_sigtest void int
    if [ $stat = 0 -a -z "$warning" ]
    then
      echo 'signal handler is void handler(int).'
      sig_type='typedef void MySignalHandler;'
      sig_arg='#define SIGNAL_ARG int _dummy'
      sig_arglist='#define SIGNAL_ARGLIST 0'
      sig_return='#define SIGNAL_RETURN return'
    else
      do_sigtest void void
      if [ $stat = 0 -a -z "$warning" ]
      then
        echo 'signal handler is void handler(void).'
      else
        echo 'I could not find the type of signal handler. I hope void handler(void) works.'
      fi
      sig_type='typedef void MySignalHandler;'
      sig_arg='#define SIGNAL_ARG void'
      sig_arglist='#define SIGNAL_ARGLIST'
      sig_return='#define SIGNAL_RETURN return'
    fi
  fi
fi

# check for float.h
cat > _zmachdep.c << EOF
#include <float.h>
main()
{
  ;
}
EOF
if $cc $cflags -c _zmachdep.c > /dev/null 2>&1
then
  echo "You have float.h."
  no_float_h='#undef NO_FLOAT_H'
else
  no_float_h='#define NO_FLOAT_H 1'
fi

/bin/rm -f _zmachdep _zmachdep.c _zmachdep.o
echo "------------ Configuration done ------------"
echo "Extracting config.h"
if [ $sysname = "CYGWIN" ]; then
  extension='.exe'
else
  extension=
fi

cat > config.h << END_OF_CONFIG_H
/*
 * Configuration for w3m
 */

#ifndef _CONFIGURED_
#define _CONFIGURED_

/* User Configuration */

/* 
   If you define DICT, you can use dictionary look-up function
   in w3m. See README.dict for detail.
*/
#undef DICT

/*
   If you define USE_MARK, you can use set-mark (C-SPC),
   goto-next-mark (ESC p), goto-next-mark (ESC n) and
   mark-by-regexp (").
*/
#undef USE_MARK

/*
   If you want to use IPv6, define this symbol.
 */
#undef INET6

/**********************************************************/
#ifdef makefile_parameter

BIN_DIR = $bindir
HELP_DIR = $helpdir
HELP_FILE = $helpfile
SYS_LIBRARIES = $extlib $termlib
LOCAL_LIBRARIES = $ldflags
CC = $cc
MYCFLAGS = $cflags $bsdinclude
KEYBIND_SRC = $keymap_file.c
KEYBIND_OBJ = $keymap_file.o
EXT=$extension
GCLIB=$gclib
GCTARGET=$gctarget
#else
$special_sys

#define DISPLAY_CODE '$ncode'

#define JA 0
#define EN 1
$use_lang
$def_kanji_symbols
$def_color
$def_mouse
$def_menu

#define DEF_EDITOR "$editor"
#define DEF_MAILER "$mailer"
#define DEF_EXT_BROWSER "$brz"
#define HELP_FILE "$helpdir/w3mhelp.html"
#define BOOKMARK "~/.w3m/bookmark.html"
#define KEYMAP_FILE  "~/.w3m/keymap"
#define MENU_FILE    "~/.w3m/menu"
#define USER_MAILCAP "~/.mailcap"
#define SYS_MAILCAP  "/etc/mailcap"

$term_if
$dir_if
$strcasecmp_flg
$strchr_flg
$strerror_flg
$syserrlist_flg
$bcopy_flg
$getdtablesize_flg
$getcwd_flg
$getwd_flg
$setenv_flg
$putenv_flg
$qsort_flg
$fclose_dcl
$pclose_dcl
$setjmp_def
$longjmp_def
$jmpbuf_def

$sig_type
$sig_arg
$sig_arglist
$sig_return

#undef TABLE_EXPAND
#define NOWRAP 1
#define NEW_FORM 1
$def_matrix
$no_float_h

#endif /* makefile_parameter */
#endif /* _CONFIGURED_ */

END_OF_CONFIG_H

echo ''
echo 'config.h is created. See config.h for further configuration.'
echo ''
echo 'Configuration done. Just type "make".'
