head	1.7;
access;
symbols
	V-0-2-4:1.6
	V-0-2-3:1.6
	V-0-2-2:1.6
	V-0-2-1:1.6
	V-0-2:1.5
	V-0-1:1.2;
locks; strict;
comment	@# @;


1.7
date	2001.01.18.07.18.02;	author wkoch;	state Exp;
branches;
next	1.6;

1.6
date	2000.03.27.15.47.59;	author wk;	state Exp;
branches;
next	1.5;

1.5
date	2000.03.27.11.26.43;	author wk;	state Exp;
branches;
next	1.4;

1.4
date	2000.03.20.16.12.34;	author wk;	state Exp;
branches;
next	1.3;

1.3
date	2000.03.20.15.33.08;	author wk;	state Exp;
branches;
next	1.2;

1.2
date	97.06.24.07.08.09;	author wk;	state Exp;
branches;
next	1.1;

1.1
date	97.06.23.15.07.40;	author wk;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Some restructuring for version 0.3
@
text
@#!/bin/sh
# Note: we expect a POSIX shell
# Configure the Mingw32/CPD cross platform development system

here=`pwd`
pgmname=$0

fatal () {
    echo "$pgmname: FATAL:" $* >&2
    exit 1;
}

chdir () {
    cd $1 || fatal "cannot cd to $1"
}


echo_n_init=no
echo_n () {
  if test "$echo_n_init" = "no"; then
    if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
      if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
	echo_n_n=
	echo_n_c='
'
      else
	echo_n_n='-n'
	echo_n_c=
      fi
    else
      echo_n_n=
      echo_n_c='\c'
    fi
    echo_n_init=yes
  fi
  echo $echo_n_n "${1}$echo_n_c"
}

#==========================
# read defaults
#==========================
if [ ! -r config.in ]; then
    echo "config.in does not exist!"
    exit 1
fi
. config.in
if [ -r config.cache ] ; then
    . config.cache 2>/dev/null
fi


CONFIG=config.new
CONFIG_MK=config.mk
rm -f $CONFIG $CONFIG_MK config.okay

cat << EOF > $CONFIG
#
# Automatically generated by ./Configure --- do not edit!
#
EOF

cat << EOF > $CONFIG_MK
#
# Automatically generated by ./Configure --- do not edit!
#
EOF

#==========================
# Some functions
#==========================

function write_mk () {
    value=$(eval echo "\$$1")
    echo "$1=$value" >> $CONFIG_MK
}

function prompt () {
    export $2
    default=$(eval echo "\$$2")
    echo_n "$1 [$default]: "
    read answer
    [ -z "$answer" ] && answer="$default"
    eval "$2"=\"$answer\"
    echo "$2"=\"$answer\" >> $CONFIG
}

function prompt_bool () {
    default="$2"
    [ "$default" = "" ] && default=n
    answer=""
    while [ "$answer" != n -a "$answer" != y ] ; do
	echo_n "$1 (y/n) [$default]: "
	read answer
	[ -z "$answer" ] && answer="$default"
    done
}

function make_abs () {
    a_path=$(eval echo "\$$1")
    if cd $a_path 2>/dev/null ; then
	a_path=`/bin/pwd`
	eval "$1"=\"$a_path\"
	chdir $here;
    fi
}

#===========================================================
# Start
#===========================================================

echo ""
echo "Mingw32/CPD Configuration Script"
echo ""

prompt "Where to install" MAINPREFIX
make_abs MAINPREFIX
if [ ! -d "$MAINPREFIX" ]; then
    fatal "Directory $MAINPREFIX does not exists"
fi
PREFIX=$MAINPREFIX/lib/mingw32-cpd
if [ ! -d "$PREFIX" ]; then
    mkdir -p $PREFIX
fi


prompt "Where is the gcc source" GCC_SRC_PATH
make_abs GCC_SRC_PATH
gcc_version_c_path="$GCC_SRC_PATH/version.c"
[ -f $gcc_version_c_path ] || gcc_version_c_path="$GCC_SRC_PATH/gcc/version.c"
if [ ! -f "$gcc_version_c_path" ]; then
    echo "gcc is not installed in $GCC_SRC_PATH"
    exit 1
fi
gcc_version=$(sed -e 's/.* "\([0-9.]*\).*/\1/' "$gcc_version_c_path")
case "$gcc_version" in
    2.7.2.1)
	;;
    2.95.[12])
	;;
    *)
	echo "Sorry, this is gcc version $gcc_version"
	echo "       which is not supported"
	exit 1;
	;;
esac

prompt "Where is the binutils source" BINUTILS_SRC_PATH
make_abs BINUTILS_SRC_PATH
if [ -f "$BINUTILS_SRC_PATH/bfd/VERSION" ]; then
    bfd_version=$(cat "$BINUTILS_SRC_PATH/bfd/VERSION")
elif [ -f "$BINUTILS_SRC_PATH/bfd/configure.in" ]; then
    bfd_version=$(sed -n '/AM_INIT_AUTOMAKE/ s/.*, *\([0-9.]*\).*/\1/p' \
		    < "$BINUTILS_SRC_PATH/bfd/configure.in")
else
    echo "binutils are not installed in $BINUTILS_SRC_PATH"
    exit 1
fi


case "$bfd_version" in
    2.8.1)
	;;
    2.9.1)
	;;
    *)
	echo "Sorry, these are binutils version $bfd_version"
	echo "       but we need version 2.8.1 or 2.9.1"
	exit 1;
	;;
esac


#------------------------------------
# Write some constants
#------------------------------------

write_mk GCCVER
write_mk CPDVER
write_mk TARGET
write_mk MAINPREFIX
write_mk PREFIX
write_mk GCC_SRC_PATH
write_mk BINUTILS_SRC_PATH
#write_mk WINDOWS32API_SRC_PATH

echo "GCC=${PREFIX}/${TARGET}/bin/gcc" >> $CONFIG_MK
echo "LD=${PREFIX}/${TARGET}/bin/ld" >> $CONFIG_MK
echo "AS=${PREFIX}/${TARGET}/bin/as" >> $CONFIG_MK
echo "AR=${PREFIX}/${TARGET}/bin/ar" >> $CONFIG_MK
echo "NM=${PREFIX}/${TARGET}/bin/nm" >> $CONFIG_MK
echo "RANLIB=${PREFIX}/${TARGET}/bin/ranlib" >> $CONFIG_MK
echo "DLLTOOL=${PREFIX}/${TARGET}/bin/dlltool" >> $CONFIG_MK
echo "INSTALL=install" >> $CONFIG_MK

echo "" >> $CONFIG
echo "" >> $CONFIG_MK
mv $CONFIG config.cache


#----------------------------------
# apply patches to the GNU packages
#----------------------------------

# we are going to build them in a subdirectory
[ -d $here/binutils-build ] || mkdir $here/binutils-build
[ -d $here/gcc-build ] || mkdir $here/gcc-build

if [ -f $here/patches/binutils-${bfd_version}.diff ]; then
    if [ -f "$here/binutils-build.src/mingw32-cpd-$CPDVER.stamp" ] ; then
	echo "Fine, binutils are already patched"
    else
	echo "Patching in binutils-build"
        [ -d $here/binutils-build.src ] || mkdir $here/binutils-build.src
        chdir $here/binutils-build.src
        ( cd $BINUTILS_SRC_PATH && tar cf - . ) | tar xf - 
	patch -p1 < $here/patches/binutils-${bfd_version}.diff || fatal "patch failed"
        touch "mingw32-cpd-$CPDVER.stamp" 
	chdir $here
   fi
fi


if [ -f $here/patches/gcc-${gcc_version}.diff ]; then
    if [ -f "$here/gcc-build.src/mingw32-cpd-$CPDVER.stamp" ] ; then
	echo "Fine, gcc is already patched"
    else
	echo "Patching in gcc-build.src"
        # first create copies and then patch
        # ooos: we cant do tha because the Makefile sometimes uses
        # paths to the orginal src and does not relay on the VPATH feature.
        # So, lets copy the whole source 
        #files=`awk <$here/patches/gcc-${gcc_version}.diff '
        #         /^diff / {sub(/^[^\/]*\//,"",$NF); print $NF}
        #        '`
        #for i in $files; do
        #   mkdir -p $here/gcc-build/`dirname $i`
        #   cat $GCC_SRC_PATH/$i >$here/gcc-build/$i
        #one
        [ -d $here/gcc-build.src ] || mkdir $here/gcc-build.src
        chdir $here/gcc-build.src
        ( cd $GCC_SRC_PATH && tar cf - . ) | tar xf - 
	patch  -p1 < $here/patches/gcc-${gcc_version}.diff || fatal "patch failed"
        # need some additional fixes
        for i in gcc/config/i386/mingw32.h gcc/config/i386/crtdll.h ; do
            [ -f "$i" ] || fatal "$i not found"
            sed \
            -e "s,-D__MINGW32_CPD__=[0-9]*,-D__MINGW32_CPD__=${CPDVER_AGE},"\
            -e "s,/usr/local,${PREFIX},g"  $i >$i.tmp && mv $i.tmp $i 
         done
        touch "mingw32-cpd-$CPDVER.stamp" 
	chdir $here
    fi
fi

# Now get the GCC version
[ -f gcc-build.src/gcc/version.c ] \
     || fatal "gcc-build.src/gcc/version.c not found"
GCCVER=`sed -n < gcc-build.src/gcc/version.c '
/version_string/ s/[^"]*"\([^ "]*\).*/\1/p
'`
[ -z "$GCCVER" ] && fatal "gcc version not found"
write_mk GCCVER

#------------------------------------
# Configure the GNU packages
#------------------------------------

prompt_bool "Next step ist to configure gcc and binutils. Okay" y
if [ "$answer" = "n" ]; then
    echo "No? So you can't continue"
    exit 1
fi


cd $here/binutils-build
if [ -f ../binutils-build.src/configure ]; then
  tmp=../binutils-build.src
else
  tmp=`cd $BINUTILS_SRC_PATH; pwd`
fi
$tmp/configure --target=${TARGET} --prefix=$PREFIX || fatal "configure failed"


cd $here/gcc-build
if [ -f ../gcc-build.src/configure ]; then
  tmp=../gcc-build.src
else
  tmp=`cd $GCC_SRC_PATH; pwd`
fi
$tmp/configure --target=${TARGET} --with-gnu-as \
	    --with-gnu-ld --prefix=$PREFIX || fatal "configure failed"
cd $here


#========================
# mark configure complete
#========================
touch config.okay

## end of configure script ###
@


1.6
log
@.
@
text
@d115 6
a120 2
prompt "Where to install" PREFIX
make_abs PREFIX
d122 1
a122 1
    fatal "Directory $PREFIX does not exists"
d125 1
a145 1
GCCVER=${gcc_version}wk1
a171 20
prompt "Where is the windows32api source" WINDOWS32API_SRC_PATH
make_abs WINDOWS32API_SRC_PATH
if [ ! -f "$WINDOWS32API_SRC_PATH/Version" ]; then
    echo "windows32api source is not installed in $WINDOWS32API_SRC_PATH"
    exit 1
fi
cat >mk.$$.tmp <<EOF
include \$(X)
.PHONY: all
all:
	echo \$(WINDOWS32_API_VERSION)
EOF
api_version=$(make -rsf mk.$$.tmp X=$WINDOWS32API_SRC_PATH/Version)
rm mk.$$.tmp
if [ "$api_version" != "0.1.1" ]; then
    echo "Sorry, this is the windows32api version $api_version"
    echo "       but we need version 0.1.1"
    exit 1;
fi

d180 1
d184 1
a184 1
write_mk WINDOWS32API_SRC_PATH
d204 4
d209 10
a218 13
   if [ -f "$BINUTILS_SRC_PATH/PATCHED-FOR-MINGW32-CPD" ]; then
       echo "Fine, binutils are already patched"
   else
       prompt_bool "Next step is to patch binutils. Okay" y
       if [ "$answer" = "n" ]; then
	   echo "No? So you can't continue"
	   exit 1
       fi
       echo "Patching $BINUTILS_SRC_PATH"
       chdir $BINUTILS_SRC_PATH ; chdir ..
       patch -sl -p0 < $here/patches/binutils-${bfd_version}.diff || fatal "patch failed"
       touch "$BINUTILS_SRC_PATH/PATCHED-FOR-MINGW32-CPD"
       chdir $here
d224 1
a224 2
    grep -q $GCCVER "$gcc_version_c_path"
    if [ $? = 0 ] ; then
d227 24
a250 8
	prompt_bool "Next step is to patch gcc. Okay" y
	if [ "$answer" = "n" ]; then
	    echo "No? So you can't continue"
	    exit 1
	fi
	echo "Patching $GCC_SRC_PATH"
	chdir $GCC_SRC_PATH ; chdir ..
	patch -sl -p0 < $here/patches/gcc-${gcc_version}.diff || fatal "patch failed"
d255 9
a267 3
[ -d $here/binutils-build ] || mkdir $here/binutils-build
[ -d $here/gcc-build ] || mkdir $here/gcc-build

a274 1
tmp=`cd $BINUTILS_SRC_PATH; pwd`
d276 5
d283 1
a283 1
tmp=`cd $GCC_SRC_PATH; pwd`
d285 5
@


1.5
log
@builds again.
@
text
@d17 22
d80 1
a80 1
    /bin/echo "$1 [$default]: \c"
d92 1
a92 1
	/bin/echo "$1 (y/n) [$default]: \c"
@


1.4
log
@.
@
text
@d101 3
a103 1
if [ ! -f "$GCC_SRC_PATH/version.c" ]; then
d107 1
a107 1
gcc_version=$(sed -e 's/.* "\([0-9.]*\).*/\1/' "$GCC_SRC_PATH/version.c")
d216 1
a216 1
    grep -q $GCCVER "$GCC_SRC_PATH/version.c"
@


1.3
log
@Quite old changes
@
text
@a28 1
GCCVER=${GNU_GCCVER}-dd9jn-${CPDVER}
d106 12
a117 5
if [ "$gcc_version" != "${GNU_GCCVER}" ]; then
    echo "Sorry, this is gcc version $gcc_version"
    echo "       but we need version ${GNU_GCCVER}"
    exit 1;
fi
a168 1
write_mk GNU_GCCVER
d195 15
a209 13
if [ -f "$BINUTILS_SRC_PATH/PATCHED-FOR-MINGW32-CPD" ]; then
    echo "Fine, binutils are already patched"
else
    prompt_bool "Next step is to patch binutils. Okay" y
    if [ "$answer" = "n" ]; then
	echo "No? So you can't continue"
	exit 1
    fi
    echo "Patching $BINUTILS_SRC_PATH"
    chdir $BINUTILS_SRC_PATH ; chdir ..
    patch -sl -p0 < $here/patches/binutils-$bfd_version.diff || fatal "patch failed"
    touch "$BINUTILS_SRC_PATH/PATCHED-FOR-MINGW32-CPD"
    chdir $here
d213 14
a226 8
grep -q $GCCVER "$GCC_SRC_PATH/version.c"
if [ $? = 0 ] ; then
    echo "Fine, gcc is already patched"
else
    prompt_bool "Next step is to patch gcc. Okay" y
    if [ "$answer" = "n" ]; then
	echo "No? So you can't continue"
	exit 1
a227 4
    echo "Patching $GCC_SRC_PATH"
    chdir $GCC_SRC_PATH ; chdir ..
    patch -sl -p0 < $here/patches/gcc-2.7.2.1.diff || fatal "patch failed"
    chdir $here
d234 3
a242 2
cd $BINUTILS_SRC_PATH
./configure --target=${TARGET} --prefix=$PREFIX || fatal "configure failed"
d244 7
a250 2
cd $GCC_SRC_PATH
./configure --target=${TARGET} --with-gnu-as \
@


1.2
log
@modified config scripts
@
text
@d2 1
d5 1
a5 1
here=$(pwd)
d80 1
a80 1
	a_path=$(/bin/pwd)
d115 6
a120 1
if [ ! -f "$BINUTILS_SRC_PATH/bfd/VERSION" ]; then
d124 13
a136 6
bfd_version=$(cat "$BINUTILS_SRC_PATH/bfd/VERSION")
if [ "$bfd_version" != "2.8.1" ]; then
    echo "Sorry, these are binutils version $bfd_version"
    echo "       but we need version 2.8.1"
    exit 1;
fi
d185 1
d190 1
a190 2
grep -q mingw32 "$BINUTILS_SRC_PATH/configure"
if [ $? = 0 ] ; then
d200 2
a201 1
    patch -sl -p0 < $here/patches/binutils-2.8.1.diff || fatal "patch failed"
@


1.1
log
@First check in
@
text
@d19 5
a25 6
else
    if [ ! -r config.in ]; then
	echo "config.in does not exist!"
	exit 1
    fi
    . config.in
d50 1
a50 1
function write_value () {
a51 1
    echo "$1"=\"$value\" >> $CONFIG
d62 1
a62 1
    write_value $2
d76 9
d94 1
d100 1
d113 1
d126 1
d150 8
a157 4
write_value GNU_GCCVER
write_value GCCVER
write_value CPDVER
write_value TARGET
d187 1
a187 1
    patch -sl < $here/patches/binutils-2.8.1.diff || fatal "patch failed"
d203 1
a203 1
    patch -sl < $here/patches/gcc-2.7.2.1.diff || fatal "patch failed"
@
