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@
115 lilypond-$lilypond_version
118 #######################
119 # end of config section
120 #######################
130 string=`eval echo $\`eval echo "${1}${2}"\``
139 source_path=${2:-$SOURCE_PATH}
140 path_list=`echo $source_path | sed 's/:/ /g'`
143 for i in $path_list; do
144 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
145 if [ "$found" != "" ] && [ -e $found ]; then
156 name=`echo $package | sed 's/-.*//'`
158 if [ $type = "cross" ]; then
159 target_platform=$CROSS_TARGET_PLATFORM
162 target_platform=$TARGET_PLATFORM
166 rpm_package=`find_path $name*.rpm "$topdir/RPMS/$cto:$topdir/RPMS/$tp"`
167 if [ "$rpm_package" != "" ]; then
168 echo "$rpm_package: package exists"
169 #echo "$rpm_package: refreshing installation only"
170 echo "$rpm_package: just updating rpm database"
171 rpm -ivv --justdb --ignoreos --ignorearch --nodeps --force\
172 --dbpath $NATIVE_ROOT/var/lib/rpm \
173 $topdir/RPMS/$a/$name*.rpm
178 found=`find_path $package*src.rpm`
179 if [ "$found" != "" ]; then
180 rpm --root $NATIVE_ROOT -ivv $found || exit 1
181 rpm --target=$target_platform -ba SPECS/$name*.spec || exit 1
183 tarball=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
184 if [ "$name.spec" != "" ] && [ "$tarball" != "" ]; then
185 rpm --target=$target_platform -ba SPECS/$name.spec || exit 1
187 found=`find_path $package*tar.gz`
188 if [ "$found" != "" ]; then
189 rpm --target=$target_platform -ta $found || exit 1
191 echo "$package: no such rpm or tarball"
196 name=`echo $package | sed 's/-.*//'`
198 rpm -ivv --ignoreos --ignorearch --nodeps --force\
199 --dbpath $NATIVE_ROOT/var/lib/rpm \
200 $topdir/RPMS/$a/$name*.rpm
202 name_after_rpm="`expand $name _after_rpm`"
203 `eval $name_after_rpm` || exit 1
217 if [ ! -d $PREFIX/bin ]; then
221 ## is this still necessary?
223 mkdir -p $TARGET_PLATFORM
224 cd $TARGET_PLATFORM && ln -s ../include .
226 mkdir -p $CROSS_PREFIX/$TARGET_PLATFORM
227 cd $CROSS_PREFIX/$TARGET_PLATFORM
228 ln -s $NATIVE_PREFIX/{include,lib} .
229 #ln -s $NATIVE_PREFIX/{include,lib} .
230 #ln -s $NATIVE_PREFIX/include .
231 #ln -s $CROSS_PREFIX/bin .
234 found=`find_path $cygwin_binary`
235 if [ "$found" = "" ]; then
236 echo "$cygwin_binary: no such tarball"
240 # urg, bug in gcc's cross-make configuration
241 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
242 mkdir -p $CROSS_PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
244 echo "$PREFIX: already exists"
245 echo "$cygwin_binary: skipping"
249 if [ ! -d $PREFIX/$TARGET_PLATFORM ]; then
251 found=`find_path $mingw_binary`
252 if [ "$found" = "" ]; then
253 echo "$mingw_binary: no such tarball"
258 mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
260 mkdir -p $PREFIX/i386-mingw32/include
261 ln -s $PREFIX/i386-mingw32 $TARGET_PLATFORM
262 ln -s $PREFIX/$TARGET_PLATFORM/include .
266 if [ ! -e $NATIVE_ROOT ]; then
267 ln -s $ROOT $NATIVE_ROOT || exit 1
270 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
271 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
273 mkdir -p $ROOT/var/redhat
274 mkdir -p $PREFIX/src/redhat
276 native_config_site='$PREFIX/share/native-config.site'
278 ncs=`eval echo $native_config_site`
280 mkdir -p `dirname $ncs`
283 ac_cv_sizeof_char_p=4
287 ac_cv_sizeof_double=8
288 ac_cv_sys_restartable_syscalls=no
289 ac_cv_sprintf_count=yes
291 db_cv_sprintf_count=yes
293 ac_cv_func_getpgrp_void=yes
294 ac_cv_func_setvbuf_reversed=no
296 # urg, lots of stuff goes wrong when configuring bash??
298 ac_cv_header_libintl_h=no
299 ac_cv_header_termcap_h=no
300 ac_cv_func_mkfifo=yes
301 bash_cv_dup2_broken=no
302 bash_cv_opendir_not_robust=no
304 bash_cv_printf_declared=yes
305 bash_cv_sbrk_declared=yes
306 bash_cv_signal_vintage=posix
307 bash_cv_speed_t_in_sys_types=no
308 bash_cv_struct_timeval=yes
309 bash_cv_struct_winsize_header=ioctl_h
310 bash_cv_sys_errlist=yes
311 bash_cv_sys_named_pipes=missing
312 bash_cv_func_strcoll_broken=no
313 bash_cv_must_reinstall_sighandlers=no
314 bash_cv_getcwd_calls_popen=no
315 bash_cv_func_sigsetjmp=missing
316 bash_cv_job_control_missing=present
317 bash_cv_sys_restartable_syscalls=no
318 bash_cv_getenv_redef=yes
319 bash_cv_sys_siglist=no
320 bash_cv_type_rlimit=long
321 bash_cv_ulimit_maxfds=no
322 bash_cv_decl_under_sys_siglist=no
323 bash_cv_under_sys_siglist=no
327 rpm_ct=$ARCH-$TARGET_OS
328 cross_rpm_dir=$CROSS_PREFIX/lib/rpm/$rpm_ct
329 cross_rpm_link=/usr/lib/rpm/$rpm_ct
330 mkdir -p $cross_rpm_dir
331 rm -f $cross_rpm_link
332 ln -s $cross_rpm_dir $cross_rpm_link
334 native_rpm_dir=$NATIVE_PREFIX/lib/rpm/$tp
335 native_rpm_link=/usr/lib/rpm/$tp
336 mkdir -p $native_rpm_dir
337 rm -f $native_rpm_link
338 ln -s $native_rpm_dir $native_rpm_link
340 cross_macros=$cross_rpm_dir/macros
341 native_macros=$native_rpm_dir/macros
343 base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
345 cat > $base_macros <<EOF
346 %native_prefix /Cygnus/usr
348 %_topdir %{native_prefix}/src/redhat
349 %_sourcedir %{native_prefix}/src/redhat/SOURCES
350 %_builddir %{native_prefix}/src/redhat/BUILD
351 %_srcrpmdir %{native_prefix}/src/redhat/SRPMS
352 %_rpmdir %{native_prefix}/src/redhat/RPMS
354 #%DocDir %{native_prefix}/doc
355 %DocDir /Cygnus/usr/doc
356 %_docdir /Cygnus/usr/doc
357 %_defaultdocdir /Cygnus/usr/doc
359 %cygwin_dll %{native_prefix}/bin/cygwin1.dll
361 %__install /bin/install
369 cp -f $base_macros $cross_macros
370 cat >> $cross_macros <<EOF
372 %cross_prefix /Cygnus/$cto/usr
374 %_rootbindir /Cygnus/$cto/bin
375 #_usr /Cygnus/$cto/usr
376 %_prefix /Cygnus/$cto/usr
377 %prefix /Cygnus/$cto/usr
379 %_rpmfilename $cto/%%{NAME}-%%{VERSION}-%%{RELEASE}.$cto.rpm
386 %_target_platform $TARGET_PLATFORM
389 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
391 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
392 %{sourcedir}/configure \
393 --host=%{_host} --target=%{_target_platform} --prefix=%{cross_prefix} -v
396 cp -f $base_macros $native_macros
397 cat >> $native_macros <<EOF
400 %_rootbindir /Cygnus/bin
405 %config_site %{_prefix}/share/native-config.site
406 # won't work: scripts and stuff are .exe too
407 #%program_suffix .exe
408 %program_suffix %{nil}
414 %_rpmfilename %%{ARCH}-$TARGET_OS/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-$TARGET_OS.rpm
416 %__find_provides %{native_prefix}/lib/rpm/cygwin.prov
417 %__find_requires %{native_prefix}/lib/rpm/cygwin.req
418 %__fix_suffixes %{native_prefix}/bin/fix-suffixes
419 %fix_suffixes %{__fix_suffixes} \$RPM_BUILD_ROOT%{_rootbindir}/* \$RPM_BUILD_ROOT%{native_prefix}/bin/*
421 %cppflags -I%{native_prefix}/include
422 %cflags %{optflags} %{cppflags}
423 %ldflags -L%{native_prefix}/lib %{cygwin_dll}
426 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
429 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
430 %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
431 --prefix=%{native_prefix} --program-prefix=
432 # --prefix=%{native_prefix} --program-suffix=%{program_suffix}
435 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.prov
436 cat > $NATIVE_PREFIX/lib/rpm/cygwin.prov <<EOF
439 f=\`echo \$f | tr '[:upper:]' '[:lower:]'\`
446 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.prov
448 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.req
449 cat > $NATIVE_PREFIX/lib/rpm/cygwin.req <<EOF
454 *.dll|*.exe) objdump -p \$f | grep "DLL Name:" | cut -f3 -d" " | tr '[:upper:]' '[:lower:]'
460 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.req
462 rm -f $NATIVE_PREFIX/bin/fix-suffixes
463 cat > $NATIVE_PREFIX/bin/fix-suffixes <<EOF
465 ## duh, rename executables,
466 ## for people that use a dumb shell instead of bash
469 if [ \$# -le 0 ]; then
470 echo "Usage: fix-suffixes [FILE]..."
479 dir=\`dirname \$path\`
480 file=\`basename \$path\`
481 base=\`basename \$file \$ext\`
482 if [ \$base\$ext != \$file ]; then
483 type="\`file \$path\`"
484 if expr "\$type" : "\$expr"; then
485 mv -f \$path \$dir/\$base\$ext
490 for i in \`/bin/ls -d1 \$*\`; do
491 fix_extension \$i .exe '.*Windows.*\(executable\).*'
492 fix_extension \$i .py '.*\(python\).*'
496 chmod 755 $NATIVE_PREFIX/bin/fix-suffixes
499 rm -rf $NATIVE_ROOT/var/lib/rpm
500 mkdir -p $NATIVE_ROOT/var/lib/rpm
501 rpm --root $NATIVE_ROOT --initdb
503 topdir=$NATIVE_PREFIX/src/redhat
504 mkdir -p $topdir/{BUILD,RPMS/{$tp,$cto},SOURCES,SPECS,SRPMS}
511 # building x-gcc requires to have x-ar in path
512 # x-gcc will find $prefix/x/bin/as by itself
513 PATH=$CROSS_PREFIX/bin:$PATH
518 for i in $cross_rpm; do
522 echo "$i: rpm build failed"
527 PATH=$CROSS_PREFIX/$TARGET_PLATFORM/bin:$PATH
531 for i in $native_rpm; do
535 echo "$i: rpm build failed"
548 cat > $distdir/setup.sh <<EOF
553 gunzip rpm.gz || exit 1
556 #gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
557 ## this won't work: must be done outside of cygwin
558 #old_dll=\`which cygwin1.dll\`
559 #mv -f \$old_dll \$old_dll.orig\$\$
560 #gunzip cygwin1.dll.gz
561 #cp -f cygwin1.dll \$old_dll
563 mkdir -p \$ROOT/var/lib
565 rem # touch \$ROOT/bin/rpm \$ROOT/bin/rpm.exe
566 echo > \$ROOT/bin/rpm; echo > \$ROOT/bin/rpm.exe
567 ./rpm --root \$ROOT --rcfile rpmrc --initdb
568 ./rpm --root \$ROOT --rcfile rpmrc --nodeps --ignorearch --ignoreos -Uhv \\
569 RPMS/$tp/rpm-*.$tp.rpm \\
574 cat > $distdir/setup.bat <<EOF
576 rem # old_dll=\`which cygwin1.dll\`
577 rem # urg, should dist bash too, then we don't need usertools!
578 rem # cp -f \`which bash\` /bin;
579 bash -c 'mkdir -p /bin;
580 cp -f bash /bin/bash.exe;
581 cp -f /bin/bash /bin/sh.exe;
582 dll=\`which cygwin1.dll\`;
583 wdll=\`./cygpath -w \$dll\`;
584 echo cygwin1.dll \$wdll > newdll; echo \$wdll \$wdll.orig\$\$ > olddll'
585 if not errorlevel 0 goto nobash
586 rem # mv -f \$old_dll \$old_dll.orig\$\$
587 rem # gunzip cygwin1.dll.gz
588 rem # cp -f cygwin1.dll \$old_dll
592 if not errorlevel 0 goto nobash
595 @echo "setup.bat: can't find bash"
596 rem # @echo "setup.bat: please install usertools from"
597 rem # @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
601 cat > $distdir/lilypond.sh <<EOF
605 \$ROOT/bin/lilypond \$*
608 cat > $distdir/midi2ly.sh <<EOF
612 \$ROOT/bin/midi2ly \$*
615 cat > $distdir/lilypond.bat <<EOF
616 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
619 cat > $distdir/midi2ly.bat <<EOF
620 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
625 cp -f $PREFIX/bin/$CYGWIN_DLL
627 cp -f `/bin/ls -d1 $ROOT/bin/rpm* |head -1` rpm
630 cp -f `/bin/ls -d1 $ROOT/bin/bash* |head -1` bash
633 cp -f `/bin/ls -d1 $ROOT/bin/cygpath* |head -1` cygpath
635 distbase=`basename $distdir`
637 ln -s ../redhat/RPMS .
639 www=`dirname $distdir`
641 for i in bash-2 guile-1 rpm-3 lilypond; do
642 rpm=`find_path $i*.rpm $distbase/RPMS/$tp`
643 dist_rpms="$dist_rpms $rpm"
647 cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms
649 # make small zip dist available
654 rm -f $zipdir/$CYGWIN_DLL.zip
655 cd $ROOT/bin && zip $zipdir/$CYGWIN_DLL.zip $CYGWIN_DLL
657 for i in bash-2 guile-1 rpm-3 lilypond; do
658 found=`find_path $i*.rpm $distdir/RPMS/$tp`
659 if [ "$found" = "" ]; then
660 echo "$i: no such .rpm"
662 base=`basename $found`
663 package=`echo $base | sed "s/\.$tp.rpm//"`
668 rpm2cpio $found | cpio -id
669 zip -ry $zipdir/$package.zip .