Configure script

Pavel Roskin proski
Mon Mar 3 17:51:19 PST 2003


Hello!

Is there any interest in having a Configure script for HostAP (like the
one in linux-wlan-ng)?

I started writing it.  The preliminary version is attached.  What needs to
be done:

1) Load the previous configuration as defaults.
2) Rewrite the output files only if the configuration is successful.
3) Change the build system to use config.mk and config.h is they are
present.
4) Add all configurable parameters.

I just want to know if this script will be used once it's finished.

I'm subscribed in no-mail mode, make sure to keep me in cc: if you want me
to read your e-mails.

-- 
Regards,
Pavel Roskin
-------------- next part --------------
#! /bin/sh

# Ask user for configurable parameters.
# (C) Pavel Roskin (proski at gnu.org)
#
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License version 2 as 
# published by the Free Software Foundation. See README and COPYING for 
# more details. 

function echo_n () {
  echo $ECHO_N "$@$ECHO_C"
}


function die () {
  echo "ERROR: $@" 2>&1
  echo "ERROR: Configuration unsuccessful" 2>&1
  exit 1
}


# Write data to configuration file
# Arguments:
# $1 - variable, $2 - value, $3 - config file type.
# Variable from $1 is also assigned the value from $2.
function write_data () {
  case "$3" in
  make)
    echo "$1 = $2" >>config.mk ;;
  header)
    echo "#define $1 $2" >>config.h ;;
  *)
    die "Invalid configuration file" ;;
  esac
  eval "$1=$2"
}


# Write disabled (commented out) data to configuration file
# Arguments:
# $1 - variable, $2 - value, $3 - config file type.
# Variable from $1 is also assigned the value from $2.
function write_disabled_data () {
  case "$3" in
  make)
    echo "# $1 = $2" >>config.mk ;;
  header)
    echo "/* #define $1 $2 */" >>config.h ;;
  *)
    die "Invalid configuration file" ;;
  esac
  eval "$1=$2"
}


# Ask user for a free form string.
# Arguments:
# $1 - message, $2 - default value, $3 - variable, $4 - config file type.
# Variable from $3 is assigned the value entered by the user.
function ask() {
  echo_n "$1 [$2] "
  read i
  if test -z "$i"; then
    i="$2"
  fi

  write_data "$3" "$i" "$4"
}

# Ask user for a boolean value.
# Arguments:
# $1 - message, $2 - default value, $3 - variable, $4 - config file type.
# Variable from $3 is assigned the value entered by the user.
function askbool() {
  case "$2" in
  y) c="[Y/n]" ;;
  n) c="[y/N]" ;;
  *) die "Invalid default for $3"
  esac

  i=
  while test -z "$i"; do
    echo_n "$1 $c "
    read i
    case "x$i" in
    xy) ;;
    xn) ;;
    x) i="$2" ;;
    *) i=""; echo "Invalid input" ;;
    esac
  done

  if test "$i" = "y"; then
    write_data "$3" "1" "$4"
  else
    write_disabled_data "$3" "1" "$4"
  fi
}

# Figure out how to turn off newline in echo.  From Autoconf.
case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
  *c*,-n*) ECHO_N= ECHO_C=' 
' ;;
  *c*,*  ) ECHO_N=-n ECHO_C= ;;
  *)       ECHO_N= ECHO_C='\c' ;;
esac

echo "# Generated by Configure" >config.mk
echo >>config.mk
echo "/* Generated by Configure */" >config.h
echo >>config.h

ask "Linux source directory" "/usr/src/linux" KERNEL_PATH make

test -d $KERNEL_PATH || die "Cannot find Linux source directory"
test -f $KERNEL_PATH/.config || die "Linux source directory is not configured"
. $KERNEL_PATH/.config

if test -z "$CONFIG_PCMCIA"; then
  ask "Path to the PCMCIA sources" "/usr/src/pcmcia" PCMCIA_PATH make
fi

askbool "Build PCMCIA Card Services driver" "y" BUILD_PCMCIA make

if test -n "$CONFIG_PCI"; then
  askbool "Build PLX9052 based PCI driver" "n" BUILD_PLX make
  askbool "Build native PCI driver" "n" BUILD_PCI make
fi

ask "Target root directory (empty to install locally)" "" DESTDIR make

askbool "Enable hostapd support" "n" PRISM2_HOSTAPD header
askbool "Enable firmware download" "n" PRISM2_DOWNLOAD_SUPPORT header



More information about the Hostap mailing list