4 # Build and install cross-development tools for cygwin package
5 # (binutils, compiler, flex, bison).
6 # Using this cross-development enviroment, build and install
7 # native cygwin packages (guile, lilypond).
9 # Besides being a handy script for me, currently this mainly serves
10 # as documentation for cross-building lilypond.
12 # To use this script, you need
14 # * all development tools to build a native LilyPond, see INSTALL.txt
16 # * RPM distribution of the cygwin pre-release sources, from:
18 # http://appel.dyndns.org/lilypond/gnu-windows/redhat/SRPMS/
20 # The tarballs were fetched from:
22 # ftp://sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485/
32 if [ $TARGET_OS = cygwin ]; then
33 ROOT=/usr/src/cygwin-net-485
37 ROOT=/usr/src/mingw-net-485
41 TARGET_PLATFORM=$TARGET_ARCH-$TARGET_VENDOR-$TARGET_OS
44 OS=`uname -s | tr '[A-Z]' '[a-z]'`
46 PLATFORM=$ARCH-$VENDOR-$OS
48 #CROSS_TARGET_PLATFORM=$ARCH-x-$TARGET_PLATFORM
49 CROSS_TARGET_PLATFORM=$PLATFORM-x-$TARGET_PLATFORM
55 NATIVE_PREFIX=$NATIVE_ROOT/usr
56 CROSS_ROOT=$NATIVE_ROOT/$cto
57 CROSS_PREFIX=$CROSS_ROOT/usr
61 distdir=$DEVEL/WWW/lilypond/gnu-windows/lily-w32
64 CYGWIN_SOURCE=$DEVEL/sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485
65 cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
66 cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs | sed s'/\$/:/g'`
67 SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/redhat/SRPMS:$cygwin_source_path
69 cygwin_binary=cygwin-20000301.tar.gz
70 mingw_binary=bin-crtdll-2000-02-03.tar.gz
72 #CYGWIN_DLL=cygwin1-net-485.dll
73 CYGWIN_DLL=cygwin1.dll
74 MINWG_DLL=mingwc10-net-485.dll
88 # binutils installs ok, but forgets these two
90 cd $CROSS_PREFIX/$TARGET_PLATFORM/bin \;
91 ln -f ../../bin/$TARGET_PLATFORM-objdump objdump \;
92 ln -f ../../bin/$TARGET_PLATFORM-objcopy objcopy \;
93 mv -f ld ld-in-path-breaks-libtool
95 # burp. gcc doesn't install any of these
97 cd $CROSS_PREFIX/$TARGET_PLATFORM/bin \;
98 ln -f ../../bin/$TARGET_PLATFORM-gcc cc \;
99 ln -f ../../bin/$TARGET_PLATFORM-gcc gcc \;
100 ln -f ../../bin/$TARGET_PLATFORM-c++ c++ \;
101 ln -f ../../bin/$TARGET_PLATFORM-g++ g++
104 guile_after_rpm='cp -f $NATIVE_PREFIX/bin/*guile-config $CROSS_PREFIX/$TARGET_PLATFORM/bin'
106 lilypond_version=@TOPLEVEL_VERSION@
114 lilypond-$lilypond_version
117 #######################
118 # end of config section
119 #######################
129 string=`eval echo $\`eval echo "${1}${2}"\``
138 source_path=${2:-$SOURCE_PATH}
139 path_list=`echo $source_path | sed 's/:/ /g'`
142 for i in $path_list; do
143 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
144 if [ "$found" != "" ] && [ -e $found ]; then
155 name=`echo $package | sed 's/-.*//'`
157 if [ $type = "cross" ]; then
158 target_platform=$CROSS_TARGET_PLATFORM
161 target_platform=$TARGET_PLATFORM
165 rpm_package=`find_path $name*.rpm "$topdir/RPMS/$cto:$topdir/RPMS/$tp"`
166 if [ "$rpm_package" != "" ]; then
167 echo "$rpm_package: package exists"
168 #echo "$rpm_package: refreshing installation only"
169 echo "$rpm_package: just updating rpm database"
170 rpm -ivv --justdb --ignoreos --ignorearch --nodeps --force\
171 --dbpath $NATIVE_ROOT/var/lib/rpm \
172 $topdir/RPMS/$a/$name*.rpm
177 found=`find_path $package*src.rpm`
178 if [ "$found" != "" ]; then
179 rpm --root $NATIVE_ROOT -ivv $found || exit 1
180 rpm --target=$target_platform -ba SPECS/$name*.spec || exit 1
182 tarball=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
183 if [ "$name.spec" != "" ] && [ "$tarball" != "" ]; then
184 rpm --target=$target_platform -ba SPECS/$name.spec || exit 1
186 found=`find_path $package*tar.gz`
187 if [ "$found" != "" ]; then
188 rpm --target=$target_platform -ta $found || exit 1
190 echo "$package: no such rpm or tarball"
195 name=`echo $package | sed 's/-.*//'`
197 rpm -ivv --ignoreos --ignorearch --nodeps --force\
198 --dbpath $NATIVE_ROOT/var/lib/rpm \
199 $topdir/RPMS/$a/$name*.rpm
201 name_after_rpm="`expand $name _after_rpm`"
202 `eval $name_after_rpm` || exit 1
216 if [ ! -d $PREFIX/bin ]; then
220 ## is this still necessary?
222 mkdir -p $TARGET_PLATFORM
223 cd $TARGET_PLATFORM && ln -s ../include .
225 mkdir -p $CROSS_PREFIX/$TARGET_PLATFORM
226 cd $CROSS_PREFIX/$TARGET_PLATFORM
227 ln -s $NATIVE_PREFIX/{include,lib} .
228 #ln -s $NATIVE_PREFIX/{include,lib} .
229 #ln -s $NATIVE_PREFIX/include .
230 #ln -s $CROSS_PREFIX/bin .
233 found=`find_path $cygwin_binary`
234 if [ "$found" = "" ]; then
235 echo "$cygwin_binary: no such tarball"
239 # urg, bug in gcc's cross-make configuration
240 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
241 mkdir -p $CROSS_PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
243 echo "$PREFIX: already exists"
244 echo "$cygwin_binary: skipping"
248 if [ ! -d $PREFIX/$TARGET_PLATFORM ]; then
250 found=`find_path $mingw_binary`
251 if [ "$found" = "" ]; then
252 echo "$mingw_binary: no such tarball"
257 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
259 mkdir -p $PREFIX/i386-mingw32/include
260 ln -s $PREFIX/i386-mingw32 $TARGET_PLATFORM
261 ln -s $PREFIX/$TARGET_PLATFORM/include .
265 if [ ! -e $NATIVE_ROOT ]; then
266 ln -s $ROOT $NATIVE_ROOT || exit 1
269 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
270 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
272 mkdir -p $ROOT/var/redhat
273 mkdir -p $PREFIX/src/redhat
275 native_config_site='$PREFIX/share/native-config.site'
277 ncs=`eval echo $native_config_site`
279 mkdir -p `dirname $ncs`
283 ac_cv_sys_restartable_syscalls=yes
284 ac_cv_sprintf_count=yes
286 db_cv_sprintf_count=yes
291 rpm_ct=$ARCH-$TARGET_OS
292 cross_rpm_dir=$CROSS_PREFIX/lib/rpm/$rpm_ct
293 cross_rpm_link=/usr/lib/rpm/$rpm_ct
294 mkdir -p $cross_rpm_dir
295 rm -f $cross_rpm_link
296 ln -s $cross_rpm_dir $cross_rpm_link
298 native_rpm_dir=$NATIVE_PREFIX/lib/rpm/$tp
299 native_rpm_link=/usr/lib/rpm/$tp
300 mkdir -p $native_rpm_dir
301 rm -f $native_rpm_link
302 ln -s $native_rpm_dir $native_rpm_link
304 cross_macros=$cross_rpm_dir/macros
305 native_macros=$native_rpm_dir/macros
307 base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
309 cat > $base_macros <<EOF
310 %native_prefix /Cygnus/usr
312 %_topdir %{native_prefix}/src/redhat
313 %_sourcedir %{native_prefix}/src/redhat/SOURCES
314 %_builddir %{native_prefix}/src/redhat/BUILD
315 %_srcrpmdir %{native_prefix}/src/redhat/SRPMS
316 %_rpmdir %{native_prefix}/src/redhat/RPMS
318 #%DocDir %{native_prefix}/doc
319 %DocDir /Cygnus/usr/doc
320 %_docdir /Cygnus/usr/doc
321 %_defaultdocdir /Cygnus/usr/doc
323 %cygwin_dll %{native_prefix}/bin/cygwin1.dll
325 %__install /bin/install
333 cp -f $base_macros $cross_macros
334 cat >> $cross_macros <<EOF
336 %cross_prefix /Cygnus/$cto/usr
338 %_rootbindir /Cygnus/$cto/bin
339 #_usr /Cygnus/$cto/usr
340 %_prefix /Cygnus/$cto/usr
341 %prefix /Cygnus/$cto/usr
343 %_rpmfilename $cto/%%{NAME}-%%{VERSION}-%%{RELEASE}.$cto.rpm
350 %_target_platform $TARGET_PLATFORM
353 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
355 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
356 %{sourcedir}/configure \
357 --host=%{_host} --target=%{_target_platform} --prefix=%{cross_prefix} -v
360 cp -f $base_macros $native_macros
361 cat >> $native_macros <<EOF
364 %_rootbindir /Cygnus/bin
369 %config_site %{_prefix}/share/native-config.site
370 # won't work: scripts and stuff are .exe too
371 #%program_suffix .exe
372 %program_suffix %{nil}
378 %_rpmfilename %%{ARCH}-$TARGET_OS/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-$TARGET_OS.rpm
380 %__find_provides %{native_prefix}/lib/rpm/cygwin.prov
381 %__find_requires %{native_prefix}/lib/rpm/cygwin.req
382 %__fix_suffixes %{native_prefix}/bin/fix-suffixes
383 %fix_suffixes %{__fix_suffixes} \$RPM_BUILD_ROOT%{_rootbindir}/* \$RPM_BUILD_ROOT%{native_prefix}/bin/*
385 %cppflags -I%{native_prefix}/include
386 %cflags %{optflags} %{cppflags}
387 %ldflags -L%{native_prefix}/lib %{cygwin_dll}
390 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
393 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
394 %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
395 --prefix=%{native_prefix} --program-prefix=
396 # --prefix=%{native_prefix} --program-suffix=%{program_suffix}
399 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.prov
400 cat > $NATIVE_PREFIX/lib/rpm/cygwin.prov <<EOF
403 f=\`echo \$f | tr '[:upper:]' '[:lower:]'\`
410 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.prov
412 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.req
413 cat > $NATIVE_PREFIX/lib/rpm/cygwin.req <<EOF
418 *.dll|*.exe) objdump -p \$f | grep "DLL Name:" | cut -f3 -d" " | tr '[:upper:]' '[:lower:]'
424 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.req
426 rm -f $NATIVE_PREFIX/bin/fix-suffixes
427 cat > $NATIVE_PREFIX/bin/fix-suffixes <<EOF
429 ## duh, rename executables,
430 ## for people that use a dumb shell instead of bash
433 if [ \$# -le 0 ]; then
434 echo "Usage: fix-suffixes [FILE]..."
443 dir=\`dirname \$path\`
444 file=\`basename \$path\`
445 base=\`basename \$file \$ext\`
446 if [ \$base\$ext != \$file ]; then
447 type="\`file \$path\`"
448 if expr "\$type" : "\$expr"; then
449 mv -f \$path \$dir/\$base\$ext
454 for i in \`/bin/ls -d1 \$*\`; do
455 fix_extension \$i .exe '.*Windows.*\(executable\).*'
456 fix_extension \$i .py '.*\(python\).*'
460 chmod 755 $NATIVE_PREFIX/bin/fix-suffixes
463 rm -rf $NATIVE_ROOT/var/lib/rpm
464 mkdir -p $NATIVE_ROOT/var/lib/rpm
465 rpm --root $NATIVE_ROOT --initdb
467 topdir=$NATIVE_PREFIX/src/redhat
468 mkdir -p $topdir/{BUILD,RPMS/{$tp,$cto},SOURCES,SPECS,SRPMS}
475 # building x-gcc requires to have x-ar in path
476 # x-gcc will find $prefix/x/bin/as by itself
477 PATH=$CROSS_PREFIX/bin:$PATH
482 for i in $cross_rpm; do
486 echo "$i: rpm build failed"
491 PATH=$CROSS_PREFIX/$TARGET_PLATFORM/bin:$PATH
495 for i in $native_rpm; do
499 echo "$i: rpm build failed"
511 rm -f $distdir/$CYGWIN_DLL.gz
512 cd $distdir && cp -f $PREFIX/bin/$CYGWIN_DLL . && gzip -f $CYGWIN_DLL
514 rm -f $distdir/rpm.gz
515 cd $distdir && cp -f `/bin/ls -d1 $ROOT/bin/rpm* |head -1` rpm && gzip -f rpm
518 cat > $distdir/setup.sh <<EOF
523 gunzip rpm.gz || exit 1
526 #gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
527 ## this won't work: must be done outside of cygwin
528 #old_dll=\`which cygwin1.dll\`
529 #mv -f \$old_dll \$old_dll.orig\$\$
530 #gunzip cygwin1.dll.gz
531 #cp -f cygwin1.dll \$old_dll
533 mkdir -p \$ROOT/var/lib
535 touch \$ROOT/bin/rpm \$ROOT/bin/rpm.exe
536 ./rpm --root \$ROOT --rcfile rpmrc --initdb
537 ./rpm --root \$ROOT --rcfile rpmrc --nodeps --ignorearch --ignoreos -Uhv \\
538 RPMS/$tp/rpm-*.$tp.rpm \\
543 cat > $distdir/setup.bat <<EOF
545 rem # old_dll=\`which cygwin1.dll\`
546 bash -c 'mkdir -p /bin;
547 cp -f \`which bash\` /bin;
548 cp -f /bin/bash /bin/sh.exe;
549 dll=\`which cygwin1.dll\`;
550 wdll=\`cygpath -w \$dll\`;
551 echo cygwin1.dll \$wdll > newdll; echo \$wdll \$wdll.orig\$\$ > olddll'
552 if not errorlevel 0 goto nobash
553 rem # mv -f \$old_dll \$old_dll.orig\$\$
554 rem # gunzip cygwin1.dll.gz
555 gunzip cygwin1.dll.gz
556 rem # cp -f cygwin1.dll \$old_dll
560 if not errorlevel 0 goto nobash
563 @echo "setup.bat: can't find bash"
564 @echo "setup.bat: please install usertools from"
565 @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
569 cat > $distdir/lilypond.sh <<EOF
573 \$ROOT/bin/lilypond \$*
576 cat > $distdir/midi2ly.sh <<EOF
580 \$ROOT/bin/midi2ly \$*
583 cat > $distdir/lilypond.bat <<EOF
584 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
587 cat > $distdir/midi2ly.bat <<EOF
588 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
591 distbase=`basename $distdir`
594 ln -s ../redhat/RPMS .
596 www=`dirname $distdir`
598 for i in guile-1 rpm lilypond; do
599 rpm=`find_path $i*.rpm $distbase/RPMS/$tp`
600 dist_rpms="$dist_rpms $rpm"
604 cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms
607 # make small zip dist available
612 rm -f $zipdir/$CYGWIN_DLL.zip
613 cd $ROOT/bin && zip $zipdir/$CYGWIN_DLL.zip $CYGWIN_DLL
615 for i in guile-1 rpm lilypond; do
616 found=`find_path $i*.rpm $distdir/RPMS/$tp`
617 if [ "$found" = "" ]; then
618 echo "$i: no such .rpm"
620 base=`basename $found`
621 package=`echo $base | sed "s/\.$tp.rpm//"`
626 rpm2cpio $found | cpio -id
627 zip -ry $zipdir/$package.zip .