]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/make-cygwin-cross.sh
release: 1.3.42
[lilypond.git] / buildscripts / make-cygwin-cross.sh
index 942d58e01f071ca22f6f309f7b5180a4259c7f92..73a1a40990cdcacf1a7c26996bbace2978c5ec30 100644 (file)
 #
 #  * all development tools to build a native LilyPond, see INSTALL.txt
 #
-#  * pre-release cygnus sources (and a binary) from:
+#  * RPM distribution of the cygwin pre-release sources, from:
 #
-#      ftp://sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485/
-#
-#          binutils/binutils-19990818-1-src.tar.gz
-#          bison/bison-src.tar.gz
-#          cygwin/cygwin-20000301.tar.gz
-#          flex/flex-src.tar.gz
-#          gcc/gcc-2.95.2-1-src.tar.gz
-#
-#      ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime/
-#
-#          bin-crtdll-2000-02-03.tar.gz  (mingw only)
+#      http://appel.dyndns.org/lilypond/gnu-windows/redhat/SRPMS/
 #
-#  * guile-1.3.4.tar.gz
+#    The tarballs were fetched from:
 #
-#  * lilypond-1.3.38.jcn1.tar.gz
-#
-#  * lots of disk space, ca 353MB
+#      ftp://sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485/
 #
 
 ################
 # config section
 ################
 
-target=cygwin
-#target=mingw
+TARGET_OS=cygwin
+#TARGET_OS=mingw32
 
-if [ $target = cygwin ]; then
+if [ $TARGET_OS = cygwin ]; then
        ROOT=/usr/src/cygwin-net-485
-       TARGET_ARCH=i686-pc-cygwin
+       TARGET_ARCH=i686
+       TARGET_VENDOR=pc
 else
        ROOT=/usr/src/mingw-net-485
-       TARGET_ARCH=i386-pc-mingw32
+       TARGET_ARCH=i386
+       TARGET_VENDOR=pc
 fi
+TARGET_PLATFORM=$TARGET_ARCH-$TARGET_VENDOR-$TARGET_OS
+
+ARCH=`uname -m`
+OS=`uname -s | tr '[A-Z]' '[a-z]'`
+VENDOR=gnu
+PLATFORM=$ARCH-$VENDOR-$OS
+
+#CROSS_TARGET_PLATFORM=$ARCH-x-$TARGET_PLATFORM
+CROSS_TARGET_PLATFORM=$PLATFORM-x-$TARGET_PLATFORM
+cto=$OS-x-cygwin
+tp=i686-cygwin
+
 PREFIX=$ROOT/usr
-NATIVE_PREFIX=/Cygnus/usr
+NATIVE_ROOT=/Cygnus
+NATIVE_PREFIX=$NATIVE_ROOT/usr
+CROSS_ROOT=$NATIVE_ROOT/$cto
+CROSS_PREFIX=$CROSS_ROOT/usr
 
 # urg
 DEVEL=/home/fred
-WWW=$DEVEL/WWW/lilypond/gnu-windows
-#WWW=/tmp
+distdir=$DEVEL/WWW/lilypond/gnu-windows/lily-w32
+#distdir=/tmp
 
 CYGWIN_SOURCE=$DEVEL/sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485
-MINGW_SOURCE=$DEVEL/ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime
-SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/patches:$DEVEL/usr/src/lilypond/Documentation/ntweb:$MINGW_SOURCE
-
-HOST=`uname -m`-gnu-`uname -s | tr '[A-Z]' '[a-z]'`
+cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
+cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs | sed s'/\$/:/g'`
+SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/redhat/SRPMS:$cygwin_source_path
 
 cygwin_binary=cygwin-20000301.tar.gz
 mingw_binary=bin-crtdll-2000-02-03.tar.gz
@@ -74,61 +78,40 @@ MINWG_DLL=mingwc10-net-485.dll
 # cross packages
 ################
 
-cross_packages="
+cross_rpm="
 binutils-19990818
 gcc-2.95.2
-flex
 bison
+flex
 "
-not_yet_needed="
-cygwin-2000301
-"
-
-cross_configure='--prefix=$PREFIX --target=$TARGET_ARCH'
-gcc_make='LANGUAGES="c++"'
-cygwin_make='-k || true'
-
 
-#################
-# native packages
-#################
-
-# Typically, we install native packages under
-#
-#   /Cygnus/usr/package-x.y.z
-#
-# so that's how we configure them.
-#
-native_configure='--target=$TARGET_ARCH --build=$TARGET_ARCH --host=$HOST --oldincludedir=$PREFIX/include --prefix=$NATIVE_PREFIX/$package'
-
-guile_patch='guile-1.3.4-gnu-windows.patch'
-if [ $target = mingw ]; then
-       guile_patch1='guile-1.3.4-mingw.patch'
-       guile_cflags='-I $PREFIX/$TARGET_ARCH/include -I $PREFIX/i686-pc-cygwin/include'
-fi
-guile_configure='--enable-sizeof-int=4 --enable-sizeof-long=4 --enable-restartable-syscalls=yes'
-guile_make='oldincludedir=$PREFIX/include'
-
-# We need to get guile properly installed for cross-development, ie
-# at our prefix: $PREFIX.  When packaging, the prefix we configured
-# for, will be used.
-#
-guile_install='prefix=$PREFIX'
+# binutils installs ok, but forgets these two
+binutils_after_rpm='
+cd $CROSS_PREFIX/$TARGET_PLATFORM/bin \;
+ln -f ../../bin/$TARGET_PLATFORM-objdump objdump \;
+ln -f ../../bin/$TARGET_PLATFORM-objcopy objcopy \;
+mv -f ld ld-in-path-breaks-libtool
+'
+# burp.  gcc doesn't install any of these
+gcc_after_rpm='
+cd $CROSS_PREFIX/$TARGET_PLATFORM/bin \;
+ln -f ../../bin/$TARGET_PLATFORM-gcc cc \;
+ln -f ../../bin/$TARGET_PLATFORM-gcc gcc \;
+ln -f ../../bin/$TARGET_PLATFORM-c++ c++ \;
+ln -f ../../bin/$TARGET_PLATFORM-g++ g++
+'
+
+guile_after_rpm='cp -f $NATIVE_PREFIX/bin/*guile-config $CROSS_PREFIX/$TARGET_PLATFORM/bin'
 
 lilypond_version=@TOPLEVEL_VERSION@
-if [ $target = mingw ]; then
-       lilypond_cflags='-I $PREFIX/$TARGET_ARCH/include -I $PREFIX/i686-pc-cygwin/include'
-fi
-lilypond_ldflags='-L$PREFIX/lib -lguile $PREFIX/bin/$CYGWIN_DLL'
-#lilypond_configure='--prefix=$lilypond_prefix'
-## URG, help2man: doesn't know about cross-compilation.
-#lilypond_make='-k || make -k || true'
-lilypond_patch=lilypond-manpages.patch
-# Don't install lilypond
-lilypond_install='--just-print'
-
-native_packages="
+
+native_rpm="
+rx-1.5
+zlib-1.1.3
+db-2.7.7
 guile-1.3.4
+bash-2.03
+rpm-3.0.4
 lilypond-$lilypond_version
 "
 
@@ -136,42 +119,15 @@ lilypond-$lilypond_version
 # end of config section
 #######################
 
-cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
-cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs`
-source_path=`echo $SOURCE_PATH:$cygwin_source_path | sed 's/:/ /g'`
-
 ###########
 # functions
 ###########
 
-untar ()
-{(
-       set -x
-       tarball=$1
-       dest_dir=$2
-
-       first_dir=`tar tzf $tarball | head -1`
-       src_dir=`dirname $first_dir`
-
-       if [ "$src_dir" = "src" -o "$src_dir" = "./src" \
-         -o "$src_dir" = "." ]; then
-               src_dir=$first_dir
-       fi
-
-       tar xzf $tarball
-
-       if [ "$src_dir" != "$dest_dir" -a "$src_dir" != "$dest_dir/" ]; then
-               mv $src_dir $dest_dir
-               rm -rf ./$first_dir
-       fi
-)
-}
-
 expand ()
 {(
 
        set -
-       string=`eval echo $\`eval echo ${1}${2}\``
+       string=`eval echo $\`eval echo "${1}${2}"\``
        eval echo $string
 )
 }
@@ -180,10 +136,13 @@ find_path ()
 {(
        set -
        expr=$1
+       source_path=${2:-$SOURCE_PATH}
+       path_list=`echo $source_path | sed 's/:/ /g'`
+
        found=
-       for i in $source_path; do
+       for i in $path_list; do
                found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
-               if [ -e "$found" ]; then
+               if [ "$found" != "" ] && [ -e $found ]; then
                        break
                fi
        done
@@ -191,117 +150,86 @@ find_path ()
 )
 }
 
-fix_extension ()
-{
-       file=$1
-       ext=$2
-       expr="$3"
-       base=`basename $file $ext`
-       if [ $base$ext != $i ]; then
-               type="`file $file`"
-               if expr "$type" : "$expr"; then
-                       mv -f $file $base$ext
-               fi
-       fi
-}
-
 build ()
 {(
        package=$1
-       set -
-       if [ -d $package ]; then
-               echo "$package: directory exists"
-               echo "$package: skipping"
-               exit 0
-       fi
-
         name=`echo $package | sed 's/-.*//'`
-        name_cflags=`expand $name _cflags`
-        name_ldflags=`expand $name _ldflags`
-        name_configure=`expand $name _configure`
-        type_configure=`expand $type _configure`
-        name_make=`expand $name _make`
-        name_install=`expand $name _install`
-
-       found=`find_path $package*src.tar.gz`
-       if [ "$found" = "" ]; then
-               found=`find_path $package.tar.gz`
-       fi
-       if [ "$found" = "" ]; then
-               found=`find_path $name*tar.gz`
+
+       if [ $type = "cross" ]; then
+               target_platform=$CROSS_TARGET_PLATFORM
+               a=$cto
+       else
+               target_platform=$TARGET_PLATFORM
+               a=$tp
        fi
-       if [ "$found" = "" ]; then
-               echo "$package: no such tarball"
-               exit 1
+
+       rpm_package=`find_path $name*.rpm "$topdir/RPMS/$cto:$topdir/RPMS/$tp"`
+       if [ "$rpm_package" != "" ]; then
+               echo "$rpm_package: package exists"
+               #echo "$rpm_package: refreshing installation only"
+               echo "$rpm_package: just updating rpm database"
+               rpm -ivv --justdb --ignoreos --ignorearch --nodeps --force\
+                       --dbpath $NATIVE_ROOT/var/lib/rpm \
+                       $topdir/RPMS/$a/$name*.rpm
+               exit 0
        fi
-       
-       untar $found $package
-       patch=`expand $name _patch`
-       count=0
-       while [ "x$patch" != "x" ]; do
-               (
-               cd $package
-               found=`find_path $patch`
-               if [ "$found" = "" ]; then
-                       echo "$patch: no such file"
-                       exit 1
+
+       cd $topdir
+       found=`find_path $package*src.rpm`
+       if [ "$found" != "" ]; then
+               rpm --root $NATIVE_ROOT -ivv $found || exit 1
+               rpm --target=$target_platform -ba SPECS/$name*.spec || exit 1
+       else
+               tarball=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
+               if [ "$name.spec" != "" ] && [ "$tarball" != "" ]; then
+                       rpm --target=$target_platform -ba SPECS/$name.spec || exit 1
+               else
+                       found=`find_path $package*tar.gz`
+                       if [ "$found" != "" ]; then
+                               rpm --target=$target_platform -ta $found || exit 1
+                       else
+                               echo "$package: no such rpm or tarball"
+                               exit 1
+                       fi
                fi
-               patch -p1 -E < $found
-               )
-               count=`expr $count + 1`
-               patch=`expand $name _patch$count`
-       done
-       set -x
-       mkdir $type-$package
-       cd $type-$package
-
-       rm -f config.cache
-       CFLAGS="$name_cflags" LDFLAGS="$name_ldflags" ../$package/configure $type_configure $name_configure || exit 1
-       make $name_make || exit 1
-       make install $name_install || exit 1
+       fi
+       name=`echo $package | sed 's/-.*//'`
+
+       rpm -ivv --ignoreos --ignorearch --nodeps --force\
+               --dbpath $NATIVE_ROOT/var/lib/rpm \
+               $topdir/RPMS/$a/$name*.rpm
+       #urg
+        name_after_rpm="`expand $name _after_rpm`"
+       `eval $name_after_rpm` || exit 1
 )
 }
 
-## urg, let's hope Cygnus uses rpm for packaging its next release
-pack ()
-{(
-       set -
-       package=$1
-        name=`echo $package | sed 's/-.*//'`
-        name_pack_install=`expand $name _pack_install`
-       install_root=/tmp/$package-install
-       install_prefix=$install_root/$NATIVE_PREFIX/$package
-
-       set -x
-       rm -rf $install_root
-       mkdir -p $install_prefix
-
-       cd $PREFIX/src/$type-$package || exit 1
-       make install prefix=$install_prefix $name_pack_install
-
-        ## duh, rename executables,
-       ## for people that use a dumb shell instead of bash
-       cd $install_prefix/bin &&
-       for i in `/bin/ls -d1 *`; do
-               fix_extension $i .exe '.*Windows.*\(executable\).*'
-               fix_extension $i .py '.*\(python\).*'
-       done
-
-        rm -f $WWW/$package.zip
-        cd $install_root && zip -r $WWW/$package.zip .$NATIVE_PREFIX
-)
-}
 ##################
 # end of functions
 ##################
 
-#
+#######
 # setup
-#
+#######
 
 set -x
 mkdir -p $ROOT
-if [ ! -d $PREFIX ]; then
+if [ ! -d $PREFIX/bin ]; then
+       mkdir -p $PREFIX
+       cd $PREFIX
+
+       ## is this still necessary?
+       mkdir -p include lib
+       mkdir -p $TARGET_PLATFORM
+       cd $TARGET_PLATFORM && ln -s ../include .
+
+       mkdir -p $CROSS_PREFIX/$TARGET_PLATFORM
+       cd $CROSS_PREFIX/$TARGET_PLATFORM
+       ln -s $NATIVE_PREFIX/{include,lib} .
+       #ln -s $NATIVE_PREFIX/{include,lib} .
+       #ln -s $NATIVE_PREFIX/include .
+       #ln -s $CROSS_PREFIX/bin .
+       
        cd $ROOT
        found=`find_path $cygwin_binary`
        if [ "$found" = "" ]; then
@@ -310,20 +238,15 @@ if [ ! -d $PREFIX ]; then
        fi
        tar xzf $found
        # urg, bug in gcc's cross-make configuration
-       mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
-
-       cd $PREFIX
-
-       # urg, bug in gcc's cross-make configuration
-       rm -f include
-       ln -s $PREFIX/$TARGET_ARCH/include .
+       mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
+       mkdir -p $CROSS_PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
 else
        echo "$PREFIX: already exists"
        echo "$cygwin_binary: skipping"
 fi
 
 # mingw
-if [ ! -d $PREFIX/$TARGET_ARCH ]; then
+if [ ! -d $PREFIX/$TARGET_PLATFORM ]; then
        cd $PREFIX
        found=`find_path $mingw_binary`
        if [ "$found" = "" ]; then
@@ -332,52 +255,428 @@ if [ ! -d $PREFIX/$TARGET_ARCH ]; then
        fi
        tar xzf $found
 
-       mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
+       mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
        rm -f include
        mkdir -p $PREFIX/i386-mingw32/include
-       ln -s $PREFIX/i386-mingw32 $TARGET_ARCH
-       ln -s $PREFIX/$TARGET_ARCH/include .
+       ln -s $PREFIX/i386-mingw32 $TARGET_PLATFORM
+       ln -s $PREFIX/$TARGET_PLATFORM/include .
 fi
 
-if [ ! -e $NATIVE_PREFIX ]; then
-       ln -s $ROOT /Cygnus || exit 1
+rm -f $NATIVE_ROOT
+if [ ! -e $NATIVE_ROOT ]; then
+       ln -s $ROOT $NATIVE_ROOT || exit 1
 fi
 
+#mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
+#mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
+
+mkdir -p $ROOT/var/redhat
+mkdir -p $PREFIX/src/redhat
+
+native_config_site='$PREFIX/share/native-config.site'
+
+ncs=`eval echo $native_config_site`
+rm -f $ncs
+mkdir -p `dirname $ncs`
+cat > $ncs <<EOF
+ac_cv_c_bigendian=no
+ac_cv_sizeof_char_p=4
+ac_cv_sizeof_int=4
+ac_cv_sizeof_long=4
+ac_cv_sizeof_float=4
+ac_cv_sizeof_double=8
+ac_cv_sys_restartable_syscalls=no
+ac_cv_sprintf_count=yes
+ac_cv_spinlocks=no
+db_cv_sprintf_count=yes
+db_cv_spinlocks=no
+ac_cv_func_getpgrp_void=yes
+ac_cv_func_setvbuf_reversed=no
+ac_cv_lib_intl=no
+# urg, lots of stuff goes wrong when configuring bash??
+ac_cv_exeext=.exe
+ac_cv_header_libintl_h=no
+ac_cv_header_termcap_h=no
+ac_cv_func_mkfifo=yes
+bash_cv_dup2_broken=no
+bash_cv_opendir_not_robust=no
+bash_cv_pgrp_pipe=no
+bash_cv_printf_declared=yes
+bash_cv_sbrk_declared=yes
+bash_cv_signal_vintage=posix
+bash_cv_speed_t_in_sys_types=no
+bash_cv_struct_timeval=yes
+bash_cv_struct_winsize_header=ioctl_h
+bash_cv_sys_errlist=yes
+bash_cv_sys_named_pipes=missing
+bash_cv_func_strcoll_broken=no
+bash_cv_must_reinstall_sighandlers=no
+bash_cv_getcwd_calls_popen=no
+bash_cv_func_sigsetjmp=missing
+bash_cv_job_control_missing=present
+bash_cv_sys_restartable_syscalls=no
+bash_cv_getenv_redef=yes
+bash_cv_sys_siglist=no
+bash_cv_type_rlimit=long
+bash_cv_ulimit_maxfds=no
+bash_cv_decl_under_sys_siglist=no
+bash_cv_under_sys_siglist=no
+EOF
+
+#URG, stupid RPM
+rpm_ct=$ARCH-$TARGET_OS
+cross_rpm_dir=$CROSS_PREFIX/lib/rpm/$rpm_ct
+cross_rpm_link=/usr/lib/rpm/$rpm_ct
+mkdir -p $cross_rpm_dir
+rm -f $cross_rpm_link
+ln -s $cross_rpm_dir $cross_rpm_link
+
+native_rpm_dir=$NATIVE_PREFIX/lib/rpm/$tp
+native_rpm_link=/usr/lib/rpm/$tp
+mkdir -p $native_rpm_dir
+rm -f $native_rpm_link
+ln -s $native_rpm_dir $native_rpm_link
+
+cross_macros=$cross_rpm_dir/macros
+native_macros=$native_rpm_dir/macros
+
+base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
+rm -f $base_macros
+cat > $base_macros <<EOF
+%native_prefix /Cygnus/usr
+
+%_topdir       %{native_prefix}/src/redhat
+%_sourcedir    %{native_prefix}/src/redhat/SOURCES
+%_builddir     %{native_prefix}/src/redhat/BUILD
+%_srcrpmdir    %{native_prefix}/src/redhat/SRPMS
+%_rpmdir       %{native_prefix}/src/redhat/RPMS
+
+#%DocDir               %{native_prefix}/doc
+%DocDir                /Cygnus/usr/doc
+%_docdir       /Cygnus/usr/doc
+%_defaultdocdir /Cygnus/usr/doc
+
+%cygwin_dll    %{native_prefix}/bin/cygwin1.dll
+
+%__install     /bin/install
+
+%cflags                %{optflags}
+%cppflags      %{nil}
+
+%sourcedir     .
+EOF
+
+cp -f $base_macros $cross_macros
+cat >> $cross_macros <<EOF
+
+%cross_prefix  /Cygnus/$cto/usr
+%root          /Cygnus/$cto
+%_rootbindir    /Cygnus/$cto/bin
+#_usr           /Cygnus/$cto/usr
+%_prefix       /Cygnus/$cto/usr
+%prefix                /Cygnus/$cto/usr
+
+%_rpmfilename  $cto/%%{NAME}-%%{VERSION}-%%{RELEASE}.$cto.rpm
+
+%config_site   %{nil}
+
+%cppflags      %{nil}
+%cflags                %{nil}
+%ldflags       %{nil}
+%_target_platform $TARGET_PLATFORM
+
+#% configure   \
+#  %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
+%configure     \
+  CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
+  %{sourcedir}/configure \
+  --host=%{_host} --target=%{_target_platform} --prefix=%{cross_prefix} -v
+EOF
+
+cp -f $base_macros $native_macros
+cat >> $native_macros <<EOF
+
+%root          /Cygnus
+%_rootbindir    /Cygnus/bin
+#_usr           /Cygnus/usr
+%_prefix       /Cygnus/usr
+%prefix                /Cygnus/usr
+
+%config_site   %{_prefix}/share/native-config.site
+# won't work: scripts and stuff are .exe too
+#%program_suffix .exe
+%program_suffix %{nil}
+
+#%_arch                i686-cygwin
+#%_vendor      pc
+#%_os          cygwin
+
+%_rpmfilename  %%{ARCH}-$TARGET_OS/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-$TARGET_OS.rpm
+
+%__find_provides       %{native_prefix}/lib/rpm/cygwin.prov
+%__find_requires       %{native_prefix}/lib/rpm/cygwin.req
+%__fix_suffixes                %{native_prefix}/bin/fix-suffixes
+%fix_suffixes  %{__fix_suffixes} \$RPM_BUILD_ROOT%{_rootbindir}/* \$RPM_BUILD_ROOT%{native_prefix}/bin/*
+
+%cppflags      -I%{native_prefix}/include
+%cflags                %{optflags} %{cppflags}
+%ldflags       -L%{native_prefix}/lib %{cygwin_dll}
+
+#%configure    \
+#  %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
+
+%configure     \
+  CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
+  %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
+  --prefix=%{native_prefix} --program-prefix=
+#  --prefix=%{native_prefix} --program-suffix=%{program_suffix}
+EOF
+
+rm -f $NATIVE_PREFIX/lib/rpm/cygwin.prov
+cat > $NATIVE_PREFIX/lib/rpm/cygwin.prov <<EOF
+#!/bin/sh
+while read f ; do
+       f=\`echo \$f | tr '[:upper:]' '[:lower:]'\`
+       case \$f in
+       *.dll)  basename \$f
+               ;;
+       esac
+done | sort -u
+EOF
+chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.prov
+
+rm -f $NATIVE_PREFIX/lib/rpm/cygwin.req
+cat > $NATIVE_PREFIX/lib/rpm/cygwin.req <<EOF
+#!/bin/sh
+
+while read f ; do
+       case \$f in
+       *.dll|*.exe)    objdump -p \$f | grep "DLL Name:" | cut -f3 -d" " | tr '[:upper:]' '[:lower:]'
+                       ;;
+       esac
+done | sort -u
+
+EOF
+chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.req
+
+rm -f $NATIVE_PREFIX/bin/fix-suffixes
+cat > $NATIVE_PREFIX/bin/fix-suffixes <<EOF
+#!/bin/sh
+## duh, rename executables,
+## for people that use a dumb shell instead of bash
+
+
+if [ \$# -le 0 ]; then
+       echo "Usage: fix-suffixes [FILE]..."
+       exit 2
+fi
+
+fix_extension ()
+{
+        path=\$1
+        ext=\$2
+        expr="\$3"
+       dir=\`dirname \$path\`
+        file=\`basename \$path\`
+        base=\`basename \$file \$ext\`
+        if [ \$base\$ext != \$file ]; then
+                type="\`file \$path\`"
+                if expr "\$type" : "\$expr"; then
+                        mv -f \$path \$dir/\$base\$ext
+                fi
+        fi
+}
+
+for i in \`/bin/ls -d1 \$*\`; do
+       fix_extension \$i .exe '.*Windows.*\(executable\).*'
+       fix_extension \$i .py '.*\(python\).*'
+done
+
+EOF
+chmod 755 $NATIVE_PREFIX/bin/fix-suffixes
+set -x
+type=rpm
+rm -rf $NATIVE_ROOT/var/lib/rpm
+mkdir -p $NATIVE_ROOT/var/lib/rpm
+rpm --root $NATIVE_ROOT --initdb
+
+topdir=$NATIVE_PREFIX/src/redhat
+mkdir -p $topdir/{BUILD,RPMS/{$tp,$cto},SOURCES,SPECS,SRPMS}
+
+##############
+# end of setup
+##############
+
+OLDPATH=$PATH
+# building x-gcc requires to have x-ar in path
+# x-gcc will find $prefix/x/bin/as by itself
+PATH=$CROSS_PREFIX/bin:$PATH
+
 mkdir -p $PREFIX/src
 cd $PREFIX/src
-PATH=$PATH:$PREFIX/bin
-
 type=cross
-for i in $cross_packages; do
+for i in $cross_rpm; do
        if build $i; then
                true
        else
-               echo "$i: build failed"
+               echo "$i: rpm build failed"
                exit 1
        fi
 done
 
-# urg, bug in gcc's cross-make install
-mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
-mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
-ln -f $PREFIX/bin/$TARGET_ARCH-gcc $PREFIX/$TARGET_ARCH/bin/cc 
-ln -f $PREFIX/bin/$TARGET_ARCH-c++ $PREFIX/$TARGET_ARCH/bin/c++
-ln -f $PREFIX/bin/$TARGET_ARCH-g++ $PREFIX/$TARGET_ARCH/bin/g++
-
-PATH=$PREFIX/$TARGET_ARCH/bin:$PREFIX/bin:$PATH 
+PATH=$CROSS_PREFIX/$TARGET_PLATFORM/bin:$PATH
 
-mkdir -p $PREFIX/src
 cd $PREFIX/src
-
-set -x
 type=native
-for i in $native_packages; do
+for i in $native_rpm; do
        if build $i; then
-               pack $i
-               continue
+               true
+       else
+               echo "$i: rpm build failed"
+               exit 1
+       fi
+done
+
+##############
+# Distribution
+##############
+
+PATH=$OLDPATH
+
+mkdir -p $distdir
+
+cat > $distdir/setup.sh <<EOF
+#!/bin/bash
+set -x
+ROOT=/Cygnus
+PREFIX=\$ROOT/usr
+gunzip rpm.gz || exit 1
+#dll=\$ROOT/net-485
+#mkdir -p \$dll
+#gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
+## this won't work: must be done outside of cygwin
+#old_dll=\`which cygwin1.dll\`
+#mv -f \$old_dll \$old_dll.orig\$\$
+#gunzip cygwin1.dll.gz
+#cp -f cygwin1.dll \$old_dll
+echo > rpmrc
+mkdir -p \$ROOT/var/lib
+mkdir -p \$ROOT/bin
+rem # touch \$ROOT/bin/rpm \$ROOT/bin/rpm.exe
+echo > \$ROOT/bin/rpm; echo > \$ROOT/bin/rpm.exe
+./rpm --root \$ROOT --rcfile rpmrc --initdb
+./rpm --root \$ROOT --rcfile rpmrc --nodeps --ignorearch --ignoreos -Uhv \\
+       RPMS/$tp/rpm-*.$tp.rpm \\
+       RPMS/$tp/*.$tp.rpm
+done
+EOF
+
+cat > $distdir/setup.bat <<EOF
+del dll olddll
+rem # old_dll=\`which cygwin1.dll\`
+rem # urg, should dist bash too, then we don't need usertools!
+rem #  cp -f \`which bash\` /bin;
+bash -c 'mkdir -p /bin;
+       cp -f bash /bin/bash.exe;
+       cp -f /bin/bash /bin/sh.exe;
+       dll=\`which cygwin1.dll\`;
+       wdll=\`./cygpath -w \$dll\`;
+       echo cygwin1.dll \$wdll > newdll; echo \$wdll \$wdll.orig\$\$ > olddll'
+if not errorlevel 0 goto nobash
+rem # mv -f \$old_dll \$old_dll.orig\$\$
+rem # gunzip cygwin1.dll.gz
+rem # cp -f cygwin1.dll \$old_dll
+copy < olddll 
+copy < newdll 
+bash setup.sh
+if not errorlevel 0 goto nobash
+goto :exit
+:nobash
+@echo "setup.bat: can't find bash"
+rem # @echo "setup.bat: please install usertools from"
+rem # @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
+:exit
+EOF
+
+cat > $distdir/lilypond.sh <<EOF
+#!/bin/bash
+ROOT=/Cygnus
+PREFIX=\$ROOT/usr
+\$ROOT/bin/lilypond \$*
+EOF
+
+cat > $distdir/midi2ly.sh <<EOF
+#!/bin/bash
+ROOT=/Cygnus
+PREFIX=\$ROOT/usr
+\$ROOT/bin/midi2ly \$*
+EOF
+
+cat > $distdir/lilypond.bat <<EOF
+bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
+EOF
+
+cat > $distdir/midi2ly.bat <<EOF
+bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
+EOF
+
+cd $distdir
+rm -f $CYGWIN_DLL.gz
+cp -f $PREFIX/bin/$CYGWIN_DLL
+rm -f rpm.gz
+cp -f `/bin/ls -d1 $ROOT/bin/rpm* |head -1` rpm
+
+rm -f bash.gz
+cp -f `/bin/ls -d1 $ROOT/bin/bash* |head -1` bash
+
+rm -f cygpath.gz
+cp -f `/bin/ls -d1 $ROOT/bin/cygpath* |head -1` cygpath
+
+distbase=`basename $distdir`
+rm -f RPMS
+ln -s ../redhat/RPMS .
+
+www=`dirname $distdir`
+cd $www
+for i in bash-2 guile-1 rpm-3 lilypond; do
+       rpm=`find_path $i*.rpm $distbase/RPMS/$tp`
+       dist_rpms="$dist_rpms $rpm"
+done
+
+rm -f $www/setup.zip
+cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms
+
+# make small zip dist available
+#
+zipdir=$www/zip
+mkdir -p $zipdir
+
+rm -f $zipdir/$CYGWIN_DLL.zip
+cd $ROOT/bin && zip $zipdir/$CYGWIN_DLL.zip $CYGWIN_DLL
+
+for i in bash-2 guile-1 rpm-3 lilypond; do
+       found=`find_path $i*.rpm $distdir/RPMS/$tp`
+       if [ "$found" = "" ]; then
+               echo "$i: no such .rpm"
+       else
+               base=`basename $found`
+               package=`echo $base | sed "s/\.$tp.rpm//"`
+               dir=/tmp/$i-rpm2zip
+               rm -rf $dir
+               mkdir -p $dir
+               cd $dir || exit 1
+               rpm2cpio $found | cpio -id
+               zip -ry $zipdir/$package.zip .
+               rm -rf $dir
        fi
-       exit 1
 done
 
-rm -f $WWW/$CYGWIN_DLL.zip
-cd $PREFIX/bin && zip $WWW/$CYGWIN_DLL.zip $CYGWIN_DLL
+cd $distdir
+gzip -f $CYGWIN_DLL
+gzip -f rpm
+gzip -f bash
+gzip -f cygpath
+
+
+
+