configure 6.79 KB
Newer Older
1 2 3
#!/bin/sh

# Zope configure script
4
# $Id$
5 6 7 8 9

#####################################################################
#                    BEGIN EDITABLE PARAMETERS                      #
#####################################################################

10
# Place the Zope major version number below.
11
ZOPE_VERS=2.9
12

13 14
# Place the optimal target version number for Zope (as returned by sys.version)
# below
15
TARGET="2.4.3"
16 17

# Order a list of "acceptable" python version numbers (as returned by
18 19 20
# sys.version) below in "best" to "worst" order, not including the
# target version.  Up to six acceptable python versions are allowed.
# Do not include the target version number in this list!
21
ACCEPTABLE="2.4.1 2.4.2."
22 23 24

# provide the executable names for all the acceptable versions
# (and the target version) below
25
EXENAMES="python python2 python2.4"
26 27 28 29 30 31 32 33

#####################################################################
#                    END EDITABLE PARAMETERS                        #
#####################################################################

# where are we?
HERE=`dirname $0`

Chris McDonough's avatar
Chris McDonough committed
34 35 36
# should we be quiet?
QUIET=""

37 38 39
usage()
{
    echo
40
    echo "configure [--help] [--quiet] [--with-python=path] [--prefix=path] "
41
    echo "          [--ignore-largefile] [--ignore-zlib] [--optimize]"
42 43 44 45 46
    echo
    echo " Creates a Makefile suitable for building and installing Zope"
    echo
    echo " Options: "
    echo "  --help              shows usage and quits"
47
    echo "  --quiet             suppress nonessential output"
48 49 50
    echo "  --with-python       specify a path to a Python interpreter to use"
    echo "  --prefix            specify an installation path for binary data"
    echo "  --ignore-largefile  ignore large file support warnings"
51
    echo "  --ignore-expat      ignore warnings about expat/pyexpat"
52
    echo "  --ignore-zlib       ignore warnings about zlib"
Chris McDonough's avatar
Chris McDonough committed
53
    echo "  --optimize          optimize compiled Python bytecode"
54
    echo "  --no-compile        Dont compile Python bytecode"
55 56
    echo
    echo " Given no options, configure will search your PATH for a suitable"
57
    echo " Python interpreter and will use '/opt/Zope-$ZOPE_VERS' as a prefix."
58 59 60 61 62 63 64 65 66
    echo
}

# bootstrap ourselves by finding a Python interpreter if necessary
get_python() {
    OLDIFS="$IFS"
    IFS=":"
    FOUND=""
    VERSION=""
67
    FOUNDLIST=""
Chris McDonough's avatar
Chris McDonough committed
68 69
    out "Testing for an acceptable Python interpreter..."
    out ""
70 71 72 73
    for DIR in $PATH; do
        IFS="$OLDIFS"
        for EXECUTABLE in $EXENAMES; do
            FULL="$DIR/$EXECUTABLE"
74
            if [ -x "$FULL" -a ! -d "$FULL" ]; then
75 76 77
                CMD="import string,sys;a=string.split(sys.version)[0]"
		# Strip trailing + from version number
		CMD="$CMD;a=(a[-1]=='+')and(a[:-1])or(a);print a"
Chris McDonough's avatar
Chris McDonough committed
78
                VERSION=`"$FULL" -c "$CMD"`
Chris McDonough's avatar
Chris McDonough committed
79
                out "  Python version $VERSION found at $FULL"
80 81 82 83 84 85 86
                if [ "$VERSION" = "$TARGET" ]; then
                    FOUND="$FULL"
                    FOUNDVERSION=$VERSION
                    break 2
                else
                    i=1;
                    for ACC in $ACCEPTABLE; do
Chris McDonough's avatar
Chris McDonough committed
87
                        i=`expr $i + 1`
88
			for SLOT in $FOUNDLIST; do
Chris McDonough's avatar
Chris McDonough committed
89
                            if [ $SLOT -eq $i ]; then
90 91 92 93 94 95 96 97 98
                                # slot "i" already populated.  This means we've
                                # already found this particular version of
                                # python.  Continue the for ACC in 
                                # $ACCEPTABLE loop and don't overwrite the
                                # one we already found (interpreters first
                                # on the path win).
                                continue 2
                            fi
                        done
99
                        if [ "$VERSION" = "$ACC" ]; then
100
                            FOUNDLIST="$FOUNDLIST $i"
101 102 103 104 105 106 107 108 109
                            eval "FOUND$i=$FULL"
                            eval "FOUNDVERSION$i=$VERSION"
                        fi
                    done
                fi
            fi
        done
    done
    if [ "$VERSION" = "$TARGET" ]; then
Chris McDonough's avatar
Chris McDonough committed
110
        out ""
Christian Theune's avatar
Christian Theune committed
111
        out "  The optimum Python version ($TARGET) was found at $FOUND."
112 113
    elif [ -z "$FOUND1" ] && [ -z "$FOUND2" ] && [ -z "$FOUND3" ] &&
         [ -z "$FOUND4" ] && [ -z "$FOUND5" ] && [ -z "$FOUND6" ] ; then
Chris McDonough's avatar
Chris McDonough committed
114 115
        out ""
        out "  No suitable Python version found.  You should install"
116 117 118 119
        out "  Python version $TARGET before continuing."
        if [ "$ACCEPTABLE" ]; then
            out "  Versions $ACCEPTABLE also work, but not as optimally."
        fi
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        exit 1
    else
        if   [ -n "$FOUND1" ]; then
            FOUND=$FOUND1
            FOUNDVERSION=$FOUNDVERSION1
        elif [ -n "$FOUND2" ]; then
            FOUND=$FOUND2
            FOUNDVERSION=$FOUNDVERSION2
        elif [ -n "$FOUND3" ]; then
            FOUND=$FOUND3
            FOUNDVERSION=$FOUNDVERSION3
        elif [ -n "$FOUND4" ]; then
            FOUND=$FOUND4
            FOUNDVERSION=$FOUNDVERSION4
        elif [ -n "$FOUND5" ]; then
            FOUND=$FOUND5
            FOUNDVERSION=$FOUNDVERSION5
        elif [ -n "$FOUND6" ]; then
            FOUND=$FOUND6
            FOUNDVERSION=$FOUNDVERSION6
        fi
Chris McDonough's avatar
Chris McDonough committed
141 142 143 144 145 146 147 148 149 150
        out ""
        out "  !! WARNING !! "
        out "  An acceptable, but non-optimal Python version ($FOUNDVERSION) "
        out "  was found at '$FOUND'."
        out "  But consider installing version '$TARGET' before running "
        out "  'make'.  If this isn't the Python version or interpreter "
        out "  instance you wish to use, you may specify a Python interpreter"
        out "  manually by rerunning the ./configure script with the "
        out "  '--with-python' option."
    fi
Fred Drake's avatar
Fred Drake committed
151
    out ""
Chris McDonough's avatar
Chris McDonough committed
152 153 154
}

out() {
155
    
156 157
    if [ -z "$QUIET" ]; then
        echo $1
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    fi
}

NEWOPTS=""

for OPT in $@; do
    case "$OPT" in
    --h* | -h*)
        usage
        exit 0
        ;;
    --with-python=*)
        # pop this argument from the arglist, it is not valid to
        # pass this along to the Python configurator.
        shift;
        FOUND=`echo $OPT | sed -e 's/--with-python\=//'`
        # use eval to do tilde expansion below
        eval "FOUND='$FOUND'"
Chris McDonough's avatar
Chris McDonough committed
176 177 178
        out ""
        out "Using Python interpreter at $FOUND"
        ;;
179 180 181 182 183 184 185 186
    --with-python)
	# in case someone passed in a --with-python without a value,
        # we raise an error instead of passing it along to configure.py
        # (which would raise an inscrutable error were it to receive this
        # option).
        out "--with-python argument requires an option"
	exit 1
        ;;
Chris McDonough's avatar
Chris McDonough committed
187 188 189
    --quiet* | -q*)
        QUIET="true"
        NEWOPTS="$NEWOPTS $OPT"
190 191 192 193 194 195 196
        ;;
    *)
        NEWOPTS="$NEWOPTS $OPT"
        ;;
    esac
done

Chris McDonough's avatar
Chris McDonough committed
197 198 199
out ""
out "Configuring Zope installation"
out ""
200 201 202 203 204 205 206

if [ -z "$FOUND" ]; then
    get_python
fi

# run the Python configurator
"$FOUND" "$HERE/inst/configure.py" $NEWOPTS