#!/bin/sh
# 
# +----------------------------------------------------------------------+
# | PHP HTML Embedded Scripting Language Version 3.0                     |
# +----------------------------------------------------------------------+
# | Copyright (c) 1997,1998 PHP Development Team (See Credits file)      |
# +----------------------------------------------------------------------+
# | This program is free software; you can redistribute it and/or modify |
# | it under the terms of the GNU General Public License as published by |
# | the Free Software Foundation; either version 2 of the License, or    |
# | (at your option) any later version.                                  |
# |                                                                      |
# | This program is distributed in the hope that it will be useful,      |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
# | GNU General Public License for more details.                         |
# |                                                                      |
# | You should have received a copy of the GNU General Public License    |
# | along with this program; if not, write to the Free Software          |
# | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            |
# +----------------------------------------------------------------------+
# | Authors: Stig Sther Bakken <ssb@guardian.no>                        |
# | Updated By: Jim Winstead <jimw@php.net>                              |
# |             Ariel Shkedi <ars@ziplink.net> or <as@altavista.net>     |
# +----------------------------------------------------------------------+
# 
# $Id: setup,v 1.27 1998/03/31 21:44:32 ars Exp $

if [ "$1" = "-q" ]; then
    quiet_mode=on
    shift
fi

if echo '\c' | grep -s c >/dev/null 2>&1
then
    ECHO_N="echo -n"
    ECHO_C=""
else
    ECHO_N="echo"
    ECHO_C='\c'
fi

echo '
  ***************************************************************************
  *                                                                         *
  *  Welcome to the PHP 3.0 setup script.  Use this script if you do not    *
  *  want or know how to use the configure program.  See the INSTALL file   *
  *  for further installation instructions.                                 *
  *                                                                         *
  *  You will now be asked a series of questions for your installation.     *
  *  For each question, your options will be shown in parantheses, and      *
  *  for some a default value is listed shown in brackets.                  *
  *                                                                         *
  ***************************************************************************
'

display_prompt()
{
    prm=$1
    shift
    typ=$1
    shift
    def=$1
    shift
    $ECHO_N "$prm $ECHO_C"
    case $typ in
	yesno) $ECHO_N "(yes/no) $ECHO_C";;
        yesnodir) $ECHO_N "(\`yes', \`no' or dir) $ECHO_C";;
        dir) $ECHO_N "(dir) $ECHO_C";;
    esac
    if test "$typ" = "yesnodir"; then
	set $def
	def=$1
    fi
    $ECHO_N "[$def] : $ECHO_C"
}

define_option()
{
    if test "$#" != "5"; then
        echo "wrong number of arguments to define_option" >&2
        return
    fi
    name=$1
    shift
    prompt=$1
    shift
    type=$1
    shift
    default=$1
    shift
    docstring=$1
    optname=`echo $name | sed -e 's/[^a-zA-Z0-9_]/_/g'`
    options="$options $optname"
    eval "option_name_$optname='$name'"
    eval "option_prompt_$optname='$prompt'"
    eval "option_type_$optname='$type'"
    eval "option_default_$optname='$default'"
    eval "option_docstring_$optname='$docstring'"
    answer=""
    if [ "$quiet_mode" != "on" ]; then
	show_help "$optname" "$type" "$default"
    fi
    while test "$answer" = ""; do
        display_prompt "$prompt" "$type" "$default"
    	read answer
    	test -t || echo $answer # Echo the answer if it did not come
    				# from a terminal.
	if test "$type" = "yesnodir"; then
	    set $default
	    if test "$1" = "yes"; then
		if test "$answer" = ""; then
		    answer=yes
		fi
	    fi
	    case "$answer" in
	        */*) ;;
		[Yy]*) dir=$2
		       shift
		       shift
		       $ECHO_N "Enter $@ directory [$dir] : $ECHO_C"
		       read answer
		       test -t || echo $answer
		       if test "$answer" = ""; then
			   answer=$dir
		       fi
		       ;;
	    esac
	fi
    	if test "$answer" = ""; then
	    if test "$type" = "yesnodir"; then
		set $default
		answer=$1
	    else
		answer=$default
	    fi
        elif test "$answer" = "?"; then
	    show_help "$optname" "$type" "$default"
            answer=""
    	fi
    done
    if test "$type" = "yesnodir"; then
	set $default
	if test $1 = "yes"; then
	    case "$answer" in
		"$2")  answer=yes;;
		[Yy]*) answer=yes;;
		[Nn]*) answer=no;;
	    esac
	else
	    case "$answer" in
		[Yy]*) answer=$2;;
		[Nn]*) answer=no;;
	    esac
        fi
    elif test "$type" = "yesno"; then
	case "$answer" in
	    [Yy]*) answer=yes;;
	    [Nn]*) answer=no;;
	esac
    fi
    eval "option_value_$optname='$answer'"
}

show_help()
{
    echo ''
    ( eval "echo \$option_docstring_$1" ;
      if test "$2" = "yesnodir"; then
	  set $3
          echo "If you answer \`yes', the default directory is \`$2'."
      fi ) | fmt
    echo ''
}

generate_config_command()
{
    configure_options=""
    for optname in $options; do
	eval "name=\$option_name_$optname"
	eval "value=\$option_value_$optname"
	eval "default=\$option_default_$optname"
	set $default
	if test "$value" != "$1"; then
	    if test "$value" != "$2"; then
		configure_options="$configure_options --$name=$value"
	    else
		configure_options="$configure_options --$name"
	    fi
	fi
    done
    echo "./configure$configure_options"
}

# now define all the options

define_option with-apache 'Build as an Apache module?' yesnodir \
    'no /usr/local/etc/httpd Apache base install' \
'    Whether to build PHP as an Apache module.  If you are running
    Apache, building PHP as a module will give better performance and
    security. If you answer no PHP will be built as a CGI program.
    The CGI version also enables Apache users to run different PHP3-enabled
    pages under different user-ids.'

define_option with-fhttpd 'Build as an fhttpd module?' yesnodir \
    'no /usr/local/src/fhttpd fhttpd sources' \
'    Whether to build PHP as fhttpd module.  If you are running
    fhttpd, building PHP as a module will give better performance,
    more control and remote execution capability. If you answer no
    PHP will be built as a CGI program. More info about fhttpd can be
    found at http://phobos.illtel.denver.co.us/pub/fhttpd/.'

define_option with-oracle 'Oracle support?' yesnodir \
    "no $oradir Oracle home" \
'    Whether to build PHP with Oracle support.  Has been confirmed to
    work with Oracle versions 7.0 to 7.3.  If you have not set up your
    Oracle environment, enter what $ORACLE_HOME is usually set to here.
    More info about Oracle can be found at http://www.oracle.com/.'

define_option with-iodbc 'iODBC support?' yesnodir \
    'no /usr/local iODBC install' \
'    Whether to build PHP with iODBC support.  This feature was first
    developed for iODBC Driver Manager, a freely redistributable ODBC
    driver manager which runs under many flavors of UNIX.
    More info about iODBC can be found on the FreeODBC Pages at 
    http://users.ids.net/~bjepson/freeODBC/.'

define_option with-adabas 'Adabas D support?' yesnodir \
    'no /usr/local Adabas D install root' \
'    Whether to build with Adabas D support.
    More info about Adabas D can be found at http://www.adabas.com/.'

define_option with-sybase 'Sybase support?' yesnodir \
    'no /home/sybase Sybase install' \
'     Whether to build PHP with Sybase support (DBLib only).
     More info about Sybase can be found at http://www.sybase.com/.'

define_option with-sybase-ct 'Sybase-CT support?' yesnodir \
    'no /home/sybase Sybase-CT install' \
'     Whether to build PHP with Sybase-CT support.'

define_option with-mysql 'MySQL support?' yesnodir \
    'no /usr/local MySQL install' \
'    Whether to build PHP with MySQL support.
    More info about MySQL can be found at http://www.tcx.se/.'

define_option with-msql 'mSQL support?' yesnodir \
    'no /usr/local/Hughes mSQL install' \
'    Whether to build PHP with mSQL support.  PHP supports both mSQL 1.0 and
    mSQL 2.0.  However, if you build PHP with mSQL 1.0 libraries, you will
    only be able to access mSQL 1.0 databases, ditto for mSQL 2.0.
    More info about mSQL can be found at http://www.hughes.com.au/.'

define_option with-pgsql 'PostgreSQL support?' yesnodir \
    'no /usr/local/pgsql PostgreSQL base install' \
'    Whether to build PHP with PostgreSQL support.
    More info about PostgreSQL can be found at
    http://www.postgreSQL.org/.'

define_option with-solid 'Solid support?' yesnodir \
    'no /usr/local/solid Solid install' \
'     Whether to build PHP with Solid support.
     More information about Solid can be found at http://www.solidtech.com/.'

define_option with-ldap 'LDAP support?' yesnodir \
    'no /usr/local/ldap LDAP base install' \
'     Whether to build with LDAP (Lightweight Directory Access Protocol)
     support.
     More information about LDAP can be found in RFC1777 and RFC1778.'

define_option with-velocis 'Velocis support?' yesnodir \
    'no /usr/local/velocis Velocis install' \
'     Whether to build PHP with Velocis support.
     More information about Velocis can be found at http://www.raima.com/.'

if test "$option_value_with_iodbc" != "no" -o \
        "$option_value_with_solid" != "no" -o \
        "$option_value_with_adabas" != "no" -o \
        "$option_value_with_velocis" != "no"
then
define_option enable-unified-odbc 'Enable unified ODBC support?' yesno yes \
'    Whether to enabled the unified ODBC support.  This is a database
    module that compiles with the C API of several DBMSes that happen to
    use ODBC as their C-API.  Has been tested with iODBC, Solid and Adabas
    D.  Requires that one (and only one) of these modules is enabled.'
fi

define_option with-dbase 'dBase support? ' yesno no \
'    Whether to use the bundled dbase library.'

define_option with-filepro 'filePro support? ' yesno no \
'    Whether to use the bundled filePro library.  Read-access only.'

define_option with-config-file-path 'Default config directory?' yesnodir \
    'yes /usr/local/lib Configuration file' \
'    Directory where the PHP3 configuration file (php3.ini) is
    located.'

# systems should be system's
define_option with-system-regex 'Use the system regex library?' yesno no \
"    Whether to use the systems regular expression library rather than
    the bundled one. If you are building PHP3 as a server module, you must
    use the same library when building PHP3 as when linking the server.
    Enable this if the systems library provides special features you need.
    It is recommended that you use the bundled library if possible."

define_option enable-debug 'Compile with debug information?' yesno yes \
'    Whether to enable debug information.  Answering "no" here will make
    PHP run faster, but it will be harder to trace bugs.  You are 
    encouraged to leave debugging on while PHP 3.0 is in alpha and 
    beta state.'

define_option enable-safe-mode 'Enable safe mode by default?' yesno no \
"    Whether to enable PHP safe mode.  This imposes several
    restrictions on what PHP can do, such as opening only files within
    the document root.  Read the Security chapter of the documentation
    for more information.  CGI users should always enable secure mode.
    This only sets the default, it may be enabled or disabled in the
    configuration file later. "

# broken configure.in doesn't check apache (bug?)
#if test "$option_value_with_apache" != "no"; then
#  defexecdir="$option_value_with_apache/php-bin"
#else
  defexecdir=/usr/local/bin
#fi

define_option with-exec-dir 'Default safe mode exec dir?' dir "$defexecdir" \
"    The directory where executables that may be run from safe mode
    are located."

define_option enable-track-vars 'Enable variable tracking by default?' yesno \
    no \
'    Enable the HTTP_GET_VARS, HTTP_POST_VARS and HTTP_COOKIE_VARS arrays by
    default (can be turned on or off in the configuration file).'

define_option enable-magic-quotes 'Enable magic quotes by default?' yesno no \
'    Whether to magic quotes by default. This can be changed in the
    configuration file.'

define_option enable-debugger 'Enable PHP remote debugger?' yesno no \
"    Whether to enable PHP remote debugging support.  This feature
    is still under development."

define_option enable-bcmath 'Enable bc style precision math functions' yesno \
    no \
'    Enables bc style arbitrary precision math functions.'

# configure.in only checks these if it's a cgi so setup does the same
if test "$option_value_with_apache" = "no"; then
# outputing the bank line isn't really possible, but it would be nice
define_option enable-force-cgi-redirect 'Enable redirect checking?' yesno no \
'    When using PHP as a CGI binary, this will make PHP always first check
    that it is used by redirection (for example under Apache, by using
    Action directives). This makes sure that the PHP binary cannot be used
    to bypass standard web server authentication procedures by calling it
    directly, like http://my.host/cgi-bin/php/secret/doc.html. This
    example accesses http://my.host/secret/doc.html but does not honour
    any security settings enforced by httpd for directory /secret.

    Not enabling this option disables the check and enables bypassing
    httpd security and authentication settings. Do this only if your server
    software is unable to indicate that a safe redirection was done and
    all your files under your document root and user directories may be
    accessed by anyone. (See the doc_root and user_dir options in the
    configuartion file).'

define_option enable-discard-path 'Enable discard path?' yesno no \
'    If this is enabled, the PHP CGI binary can safely be placed outside
     of the web tree and people will not be able to circumvent .htaccess
     security.'
fi

define_option enable-memory-limit 'Enable memory limit?' yesno no \
'    Compile with memory limit support.'

define_option enable-short-tags 'Allow short tag by default?' yesno yes \
"    Whether to enable the short form of the PHP HTML embed tags.
    The short form is \"<? code; ?>\", while the long form is
    \"<?php code; ?>\".  If you plan on using XML on your site, you
    should disable the short form. This is the default and can be overriden
    in the configuration file."

define_option enable-url-fopen-wrapper 'Enable URL fopen wrappers?' yesno yes \
"    Enable the URL-aware fopen wrapper that allows accessing files via http
    or ftp."

# only the cgi version of PHP is installed to bindir
if test "$option_value_with_apache" = "no"; then
define_option bindir 'Install php in:' dir "/usr/local/bin" \
"    Directory where PHP should be installed."
fi

echo '

  ***************************************************************************
  *                                                                         *
  *                      Running configure...                               *
  *                                                                         *
  ***************************************************************************
'
if test ! -f configure; then
    autoconf
fi

command=`generate_config_command`
mv do-conf do-conf.bak > /dev/null 2>&1
echo $command > do-conf
chmod +x do-conf
echo $command
eval $command

echo '
  ***************************************************************************
  *                                                                         *
  *  Configuration options were saved in do-conf, if desired you can        *
  *  edit this file and then run it. Run ./configure --help for a list      *
  *  of options.                                                            *
  *                                                                         *
  *  Read the INSTALL file for more information and for help in             *
  *  configuring apache. See the web site at: http://www.php.net/ for       *
  *  documentation and more. If desired copy the php3.ini-dist file to      *
  *  your config directory/php3.ini and edit it.                            *
  *                                                                         *
  ***************************************************************************
'
