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 = cygwin ]; then
33 ROOT=/usr/src/cygwin-net-485
34 TARGET_ARCH=i686-pc-cygwin
36 ROOT=/usr/src/mingw-net-485
37 TARGET_ARCH=i386-pc-mingw32
41 NATIVE_PREFIX=$NATIVE_ROOT/usr
45 distdir=$DEVEL/WWW/lilypond/gnu-windows/lily-w32
48 SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/redhat/SRPMS
51 OS=`uname -s | tr '[A-Z]' '[a-z]'`
53 CROSS_TARGET_ARCH=$ARCH-x-$TARGET_ARCH
57 cygwin_binary=cygwin-20000301.tar.gz
58 mingw_binary=bin-crtdll-2000-02-03.tar.gz
60 #CYGWIN_DLL=cygwin1-net-485.dll
61 CYGWIN_DLL=cygwin1.dll
62 MINWG_DLL=mingwc10-net-485.dll
77 cd $PREFIX/$TARGET_ARCH/bin \;
78 ln -f ../../bin/$TARGET_ARCH-ar ar \;
79 ln -f ../../bin/$TARGET_ARCH-as as \;
80 ln -f ../../bin/$TARGET_ARCH-dlltool dlltool \;
81 ln -f ../../bin/$TARGET_ARCH-ld ld \;
82 ln -f ../../bin/$TARGET_ARCH-nm nm \;
83 ln -f ../../bin/$TARGET_ARCH-objdump objdump \;
84 ln -f ../../bin/$TARGET_ARCH-objcopy objcopy \;
85 ln -f ../../bin/$TARGET_ARCH-ranlib ranlib \;
86 ln -f ../../bin/$TARGET_ARCH-strip strip \;
88 rm -f ar as dlltool ld nm objdump objcopy ranlib strip \;
91 cd $PREFIX/$TARGET_ARCH/bin \;
92 ln -f ../../bin/$TARGET_ARCH-gcc cc \;
93 ln -f ../../bin/$TARGET_ARCH-gcc gcc \;
94 ln -f ../../bin/$TARGET_ARCH-c++ c++ \;
95 ln -f ../../bin/$TARGET_ARCH-g++ g++
98 #guile_after_rpm='ln -f $NATIVE_PREFIX/bin/i686-redhat-cygwin-guile-config $NATIVE_PREFIX/bin/i686-pc-cygwin-guile-config'
100 lilypond_version=@TOPLEVEL_VERSION@
108 lilypond-$lilypond_version
111 #######################
112 # end of config section
113 #######################
123 string=`eval echo $\`eval echo "${1}${2}"\``
132 source_path=${2:-$SOURCE_PATH}
133 path_list=`echo $source_path | sed 's/:/ /g'`
136 for i in $path_list; do
137 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
138 if [ "$found" != "" ] && [ -e $found ]; then
149 name=`echo $package | sed 's/-.*//'`
151 if [ $type = "cross" ]; then
152 target_arch=$CROSS_TARGET_ARCH
155 target_arch=$TARGET_ARCH
159 rpm_package=`find_path $name*.rpm "$topdir/RPMS/$cta:$topdir/RPMS/$ta"`
160 if [ "$rpm_package" != "" ]; then
161 echo "$rpm_package: package exists"
162 echo "$rpm_package: just updating db"
163 rpm -ivv --justdb --ignoreos --ignorearch --nodeps --force\
164 --dbpath $NATIVE_ROOT/var/lib/rpm \
165 $topdir/RPMS/$a/$name*.rpm
170 found=`find_path $package*src.rpm`
171 if [ "$found" != "" ]; then
172 rpm --root $NATIVE_ROOT -ivv $found || exit 1
173 rpm --target=$target_arch -ba SPECS/$name*.spec || exit 1
175 tarball=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
176 if [ "SPECS/$name.spec" != "" ] && [ "$tarball" != "" ]; then
177 rpm --target=$target_arch -ba SPECS/$name.spec || exit 1
179 found=`find_path $package*tar.gz`
180 if [ "$found" != "" ]; then
181 rpm --target=$target_arch -ta $found || exit 1
183 echo "$package: no such rpm or tarball"
188 name=`echo $package | sed 's/-.*//'`
190 rpm -ivv --ignoreos --ignorearch --nodeps --force\
191 --dbpath $NATIVE_ROOT/var/lib/rpm \
192 $topdir/RPMS/$a/$name*.rpm
194 name_after_rpm="`expand $name _after_rpm`"
195 `eval $name_after_rpm` || exit 1
209 if [ ! -d $PREFIX/bin ]; then
213 mkdir -p $TARGET_ARCH
214 cd $TARGET_ARCH && ln -s ../include .
216 found=`find_path $cygwin_binary`
217 if [ "$found" = "" ]; then
218 echo "$cygwin_binary: no such tarball"
222 # urg, bug in gcc's cross-make configuration
223 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
225 echo "$PREFIX: already exists"
226 echo "$cygwin_binary: skipping"
230 if [ ! -d $PREFIX/$TARGET_ARCH ]; then
232 found=`find_path $mingw_binary`
233 if [ "$found" = "" ]; then
234 echo "$mingw_binary: no such tarball"
239 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
241 mkdir -p $PREFIX/i386-mingw32/include
242 ln -s $PREFIX/i386-mingw32 $TARGET_ARCH
243 ln -s $PREFIX/$TARGET_ARCH/include .
247 if [ ! -e $NATIVE_ROOT ]; then
248 ln -s $ROOT $NATIVE_ROOT || exit 1
251 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
252 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
254 mkdir -p $ROOT/var/redhat
255 mkdir -p $PREFIX/src/redhat
257 native_config_site='$PREFIX/share/native-config.site'
259 ncs=`eval echo $native_config_site`
261 mkdir -p `dirname $ncs`
265 ac_cv_sys_restartable_syscalls=yes
266 ac_cv_sprintf_count=yes
268 db_cv_sprintf_count=yes
273 cross_rpm_dir=$NATIVE_PREFIX/lib/rpm/$mcta
274 cross_rpm_link=/usr/lib/rpm/$mcta
275 mkdir -p $cross_rpm_dir
276 rm -f $cross_rpm_link
277 ln -s $NATIVE_PREFIX/lib/rpm/$mcta $cross_rpm_link
279 native_rpm_dir=$NATIVE_PREFIX/lib/rpm/$ta
280 native_rpm_link=/usr/lib/rpm/$ta
281 mkdir -p $native_rpm_dir
282 rm -f $native_rpm_link
283 ln -s $NATIVE_PREFIX/lib/rpm/$ta $native_rpm_link
285 cross_macros=$cross_rpm_dir/macros
286 native_macros=$native_rpm_dir/macros
288 base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
290 cat > $base_macros <<EOF
292 %_rootbindir /Cygnus/bin
296 %native_prefix /Cygnus/usr
298 %_topdir %{native_prefix}/src/redhat
299 %_sourcedir %{native_prefix}/src/redhat/SOURCES
300 %_builddir %{native_prefix}/src/redhat/BUILD
301 %_srcrpmdir %{native_prefix}/src/redhat/SRPMS
302 %_rpmdir %{native_prefix}/src/redhat/RPMS
304 #%DocDir %{native_prefix}/doc
305 %DocDir /Cygnus/usr/doc
306 %_docdir /Cygnus/usr/doc
307 %_defaultdocdir /Cygnus/usr/doc
309 %cygwin_dll %{native_prefix}/bin/cygwin1.dll
316 cp -f $base_macros $cross_macros
317 cat >> $cross_macros <<EOF
318 %_rpmfilename %%{ARCH}-x-cygwin/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-x-cygwin.rpm
322 %_target_platform $TARGET_ARCH
323 %program_prefix $TARGET_ARCH-
326 CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
327 %{sourcedir}/configure \
328 --host=%{_host} --target=%{_target_platform} --prefix=%{native_prefix} \
329 --program-prefix=%{program_prefix}
332 cp -f $base_macros $native_macros
333 cat >> $native_macros <<EOF
334 %config_site %{_prefix}/share/native-config.site
335 #%program_suffix .exe
336 %program_suffix %{nil}
342 %_rpmfilename %%{ARCH}-cygwin/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-cygwin.rpm
344 %__find_provides %{native_prefix}/lib/rpm/cygwin.prov
345 %__find_requires %{native_prefix}/lib/rpm/cygwin.req
347 %ldflags -L%{native_prefix}/lib %{cygwin_dll}
349 CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
350 %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
351 --prefix=%{native_prefix} --program-suffix=%{program_suffix}
354 rm -f $native_rpm_dir/cygwin.prov
355 cat > $native_rpm_dir/cygwin.prov <<EOF
358 f=\`echo $f | tr '[:upper:]' '[:lower:]'\`
365 chmod 755 $native_rpm_dir/cygwin.prov
367 rm -f $native_rpm_dir/cygwin.req
368 cat > $native_rpm_dir/cygwin.req <<EOF
373 *.dll|*.exe) objdump -p $f | grep "DLL Name:" | cut -f3 -d" " | tr '[
380 chmod 755 $native_rpm_dir/cygwin.req
385 rm -rf $NATIVE_ROOT/var/lib/rpm
386 mkdir -p $NATIVE_ROOT/var/lib/rpm
387 rpm --root $NATIVE_ROOT --initdb
389 topdir=$NATIVE_PREFIX/src/redhat
390 mkdir -p $topdir/{BUILD,RPMS/{$ta,$cta},SOURCES,SPECS,SRPMS}
397 PATH=$PREFIX/bin:$PATH
402 for i in $cross_rpm; do
406 echo "$i: rpm build failed"
411 PATH=$PREFIX/$TARGET_ARCH/bin:$PATH
415 for i in $native_rpm; do
419 echo "$i: rpm build failed"
431 rm -f $distdir/$CYGWIN_DLL.gz
432 cd $distdir && cp -f $PREFIX/bin/$CYGWIN_DLL . && gzip -f $CYGWIN_DLL
434 rm -f $distdir/rpm.gz
435 cd $distdir && cp -f $ROOT/bin/rpm . && gzip -f rpm
438 cat > $distdir/setup.sh <<EOF
443 gunzip rpm.gz || exit 1
446 #gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
447 ## this won't work: must be done outside of cygwin
448 #old_dll=\`which cygwin1.dll\`
449 #mv -f \$old_dll \$old_dll.orig\$\$
450 #gunzip cygwin1.dll.gz
451 #cp -f cygwin1.dll \$old_dll
453 mkdir -p \$ROOT/var/lib
455 echo > \$ROOT/bin/rpm
456 ./rpm --root \$ROOT --rcfile rpmrc --initdb
457 ./rpm --root \$ROOT --rcfile rpmrc --nodeps --ignorearch --ignoreos -Uhv \\
458 RPMS/$ta/rpm-*.$ta.rpm \\
463 cat > $distdir/setup.bat <<EOF
465 #old_dll=\`which cygwin1.dll\`
466 bash -c 'dll=\`which cygwin1.dll\`;
467 wdll=\`cygpath -w \$dll\`;
468 echo cygwin1.dll \$wdll > newdll; echo \$wdll \$wdll.orig\$\$ > olddll'
469 if not errorlevel 0 goto nobash
470 #mv -f \$old_dll \$old_dll.orig\$\$
471 #gunzip cygwin1.dll.gz
472 gunzip cygwin1.dll.gz
473 #cp -f cygwin1.dll \$old_dll
477 if not errorlevel 0 goto nobash
480 @echo "setup.bat: can't find bash"
481 @echo "setup.bat: please install usertools from"
482 @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
486 cat > $distdir/lilypond.sh <<EOF
490 \$ROOT/bin/lilypond \$*
493 cat > $distdir/midi2ly.sh <<EOF
497 \$ROOT/bin/midi2ly \$*
500 cat > $distdir/lilypond.bat <<EOF
501 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
504 cat > $distdir/midi2ly.bat <<EOF
505 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
508 distbase=`basename $distdir`
511 ln -s ../redhat/RPMS .
513 www=`dirname $distdir`
515 for i in guile-1 rpm lilypond; do
516 rpm=`find_path $i*.rpm $distbase/RPMS/$ta`
517 dist_rpms="$dist_rpms $rpm"
521 cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms
524 # make small zip dist available
529 rm -f $zipdir/$CYGWIN_DLL.zip
530 cd $ROOT/bin && zip $zipdir/$CYGWIN_DLL.zip $CYGWIN_DLL
532 for i in guile-1 rpm lilypond; do
533 found=`find_path $i*.rpm $distdir/RPMS/$ta`
534 if [ "$found" = "" ]; then
535 echo "$i: no such .rpm"
537 base=`basename $found`
538 package=`echo $base | sed "s/\.$ta.rpm//"`
543 rpm2cpio $found | cpio -id
544 zip -ry $zipdir/$package.zip .