#!/bin/sh

# Configuration script, must be called from the top directory
# Peter Guntert, 28-07-2000

program=$1

# ---- System type ----

system="?"
while [ "$system" = "?" ]; do
  system=`etc/identify`
#  system=unknown
  echo "System type (? for a list) [$system]: " | awk '{printf("%s",$0)}'
  read answer; if [ "$answer" ]; then system=$answer; fi
  if [ "$system" != "?" ]; then
    system=`awk 'BEGIN { s="?" }
                 /^#*SYSTEM *= */ { if ($3==sys) { s=$3 }}
                 END { print s }' sys=$system etc/config.in`
  fi
  if [ "$system" = "?" ]; then
    echo "Supported systems:"
    awk '/^#*SYSTEM *= */ { print "   " $3 }' etc/config.in
  fi
done

# ---- Configuration file ----

awk '/# Configuration file for / { 
       print $0 ", created by \"make config\"."; next }
     NF==0 { if (on==1) exit;
             if (off==1) off=2;
             n=NR; on=0 
             if (m==NR-1) cmt=s }
     /^# Machine-specific parameters/ { off=1; cmt="" }
     /^# .*/ { if (n==NR-1) { m=NR; s=$0 }}
     /^#*SYSTEM *= */ { if ($3==sys) { on=1; print ""
                          if (cmt!="") { print cmt; print "" }}}
     /^#[A-Z][A-Z0-9_]* *=/ { if (on==1) { print substr($0,2); next; }}
     { if (off!=2) print $0 }' sys=$system etc/config.in > etc/config
