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 rpm_package
=`find_path $package*.rpm "$topdir/RPMS/$cto:$topdir/RPMS/$tp"`
168 if [ "$rpm_package" != "" ]; then
169 echo "$rpm_package: package exists"
170 #echo "$rpm_package: refreshing installation only"
171 echo "$rpm_package: just updating rpm database"
172 rpm
-ivv --justdb --ignoreos --ignorearch --nodeps --force\
173 --dbpath $NATIVE_ROOT/var
/lib
/rpm \
174 $topdir/RPMS
/$a/$name*.rpm
179 found
=`find_path $package*src.rpm`
180 if [ "$found" != "" ]; then
181 rpm
--root $NATIVE_ROOT -ivv $found ||
exit 1
182 rpm
--target=$target_platform -ba SPECS
/$name*.spec ||
exit 1
184 tarball
=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
185 if [ "$name.spec" != "" ] && [ "$tarball" != "" ]; then
186 rpm
--target=$target_platform -ba SPECS
/$name.spec ||
exit 1
188 found
=`find_path $package*tar.gz`
189 if [ "$found" != "" ]; then
190 rpm
--target=$target_platform -ta $found ||
exit 1
192 echo "$package: no such rpm or tarball"
197 name
=`echo $package | sed 's/-.*//'`
199 rpm
-ivv --ignoreos --ignorearch --nodeps --force\
200 --dbpath $NATIVE_ROOT/var
/lib
/rpm \
201 $topdir/RPMS
/$a/$name*.rpm
203 name_after_rpm
="`expand $name _after_rpm`"
204 `eval $name_after_rpm` ||
exit 1
218 if [ ! -d $PREFIX/bin
]; then
222 ## is this still necessary?
224 mkdir
-p $TARGET_PLATFORM
225 cd $TARGET_PLATFORM && ln -s ..
/include .
227 mkdir
-p $CROSS_PREFIX/$TARGET_PLATFORM
228 cd $CROSS_PREFIX/$TARGET_PLATFORM
229 ln -s $NATIVE_PREFIX/{include
,lib
} .
230 #ln -s $NATIVE_PREFIX/{include,lib} .
231 #ln -s $NATIVE_PREFIX/include .
232 #ln -s $CROSS_PREFIX/bin .
235 found
=`find_path $cygwin_binary`
236 if [ "$found" = "" ]; then
237 echo "$cygwin_binary: no such tarball"
241 # urg, bug in gcc's cross-make configuration
242 mkdir
-p $PREFIX/lib
/gcc-lib
/$TARGET_PLATFORM/2.95.2
243 mkdir
-p $CROSS_PREFIX/lib
/gcc-lib
/$TARGET_PLATFORM/2.95.2
245 echo "$PREFIX: already exists"
246 echo "$cygwin_binary: skipping"
250 if [ ! -d $PREFIX/$TARGET_PLATFORM ]; then
252 found
=`find_path $mingw_binary`
253 if [ "$found" = "" ]; then
254 echo "$mingw_binary: no such tarball"
259 mkdir
-p $PREFIX/lib
/gcc-lib
/$TARGET_PLATFORM/2.95.2
261 mkdir
-p $PREFIX/i386-mingw32
/include
262 ln -s $PREFIX/i386-mingw32
$TARGET_PLATFORM
263 ln -s $PREFIX/$TARGET_PLATFORM/include .
267 if [ ! -e $NATIVE_ROOT ]; then
268 ln -s $ROOT $NATIVE_ROOT ||
exit 1
271 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
272 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
274 mkdir
-p $ROOT/var
/redhat
275 mkdir
-p $PREFIX/src
/redhat
277 native_config_site
='$PREFIX/share/native-config.site'
279 ncs
=`eval echo $native_config_site`
281 mkdir
-p `dirname $ncs`
284 ac_cv_sizeof_char_p=4
288 ac_cv_sizeof_double=8
289 ac_cv_sys_restartable_syscalls=no
290 ac_cv_sprintf_count=yes
292 db_cv_sprintf_count=yes
294 ac_cv_func_getpgrp_void=yes
295 ac_cv_func_setvbuf_reversed=no
297 # urg, lots of stuff goes wrong when configuring bash??
299 ac_cv_header_libintl_h=no
300 ac_cv_header_termcap_h=no
301 ac_cv_func_mkfifo=yes
302 bash_cv_dup2_broken=no
303 bash_cv_opendir_not_robust=no
305 bash_cv_printf_declared=yes
306 bash_cv_sbrk_declared=yes
307 bash_cv_signal_vintage=posix
308 bash_cv_speed_t_in_sys_types=no
309 bash_cv_struct_timeval=yes
310 bash_cv_struct_winsize_header=ioctl_h
311 bash_cv_sys_errlist=yes
312 bash_cv_sys_named_pipes=missing
313 bash_cv_func_strcoll_broken=no
314 bash_cv_must_reinstall_sighandlers=no
315 bash_cv_getcwd_calls_popen=no
316 bash_cv_func_sigsetjmp=missing
317 bash_cv_job_control_missing=present
318 bash_cv_sys_restartable_syscalls=no
319 bash_cv_getenv_redef=yes
320 bash_cv_sys_siglist=no
321 bash_cv_type_rlimit=long
322 bash_cv_ulimit_maxfds=no
323 bash_cv_decl_under_sys_siglist=no
324 bash_cv_under_sys_siglist=no
328 rpm_ct
=$ARCH-$TARGET_OS
329 cross_rpm_dir
=$CROSS_PREFIX/lib
/rpm
/$rpm_ct
330 cross_rpm_link
=/usr
/lib
/rpm
/$rpm_ct
331 mkdir
-p $cross_rpm_dir
332 rm -f $cross_rpm_link
333 ln -s $cross_rpm_dir $cross_rpm_link
335 native_rpm_dir
=$NATIVE_PREFIX/lib
/rpm
/$tp
336 native_rpm_link
=/usr
/lib
/rpm
/$tp
337 mkdir
-p $native_rpm_dir
338 rm -f $native_rpm_link
339 ln -s $native_rpm_dir $native_rpm_link
341 cross_macros
=$cross_rpm_dir/macros
342 native_macros
=$native_rpm_dir/macros
344 base_macros
=$NATIVE_PREFIX/lib
/rpm
/base-macros
346 cat > $base_macros <<EOF
347 %native_prefix /Cygnus/usr
349 %_topdir %{native_prefix}/src/redhat
350 %_sourcedir %{native_prefix}/src/redhat/SOURCES
351 %_builddir %{native_prefix}/src/redhat/BUILD
352 %_srcrpmdir %{native_prefix}/src/redhat/SRPMS
353 %_rpmdir %{native_prefix}/src/redhat/RPMS
355 #%DocDir %{native_prefix}/doc
356 %DocDir /Cygnus/usr/doc
357 %_docdir /Cygnus/usr/doc
358 %_defaultdocdir /Cygnus/usr/doc
360 %cygwin_dll %{native_prefix}/bin/cygwin1.dll
362 %__install /bin/install
370 cp -f $base_macros $cross_macros
371 cat >> $cross_macros <<EOF
373 %cross_prefix /Cygnus/$cto/usr
375 %_rootbindir /Cygnus/$cto/bin
376 #_usr /Cygnus/$cto/usr
377 %_prefix /Cygnus/$cto/usr
378 %prefix /Cygnus/$cto/usr
380 %_rpmfilename $cto/%%{NAME}-%%{VERSION}-%%{RELEASE}.$cto.rpm
387 %_target_platform $TARGET_PLATFORM
390 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
392 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
393 %{sourcedir}/configure \
394 --host=%{_host} --target=%{_target_platform} --prefix=%{cross_prefix} -v
397 cp -f $base_macros $native_macros
398 cat >> $native_macros <<EOF
401 %_rootbindir /Cygnus/bin
406 %config_site %{_prefix}/share/native-config.site
407 # won't work: scripts and stuff are .exe too
408 #%program_suffix .exe
409 %program_suffix %{nil}
415 %_rpmfilename %%{ARCH}-$TARGET_OS/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-$TARGET_OS.rpm
417 %__find_provides %{native_prefix}/lib/rpm/cygwin.prov
418 %__find_requires %{native_prefix}/lib/rpm/cygwin.req
419 %__fix_suffixes %{native_prefix}/bin/fix-suffixes
420 %fix_suffixes %{__fix_suffixes} \$RPM_BUILD_ROOT%{_rootbindir}/* \$RPM_BUILD_ROOT%{native_prefix}/bin/*
422 %cppflags -I%{native_prefix}/include
423 %cflags %{optflags} %{cppflags}
424 %ldflags -L%{native_prefix}/lib %{cygwin_dll}
427 # %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
430 CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
431 %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
432 --prefix=%{native_prefix} --program-prefix=
433 # --prefix=%{native_prefix} --program-suffix=%{program_suffix}
436 rm -f $NATIVE_PREFIX/lib
/rpm
/cygwin.prov
437 cat > $NATIVE_PREFIX/lib
/rpm
/cygwin.prov
<<EOF
440 f=\`echo \$f | tr '[:upper:]' '[:lower:]'\`
447 chmod 755 $NATIVE_PREFIX/lib
/rpm
/cygwin.prov
449 rm -f $NATIVE_PREFIX/lib
/rpm
/cygwin.req
450 cat > $NATIVE_PREFIX/lib
/rpm
/cygwin.req
<<EOF
455 *.dll|*.exe) objdump -p \$f | grep "DLL Name:" | cut -f3 -d" " | tr '[:upper:]' '[:lower:]'
461 chmod 755 $NATIVE_PREFIX/lib
/rpm
/cygwin.req
463 rm -f $NATIVE_PREFIX/bin
/fix-suffixes
464 cat > $NATIVE_PREFIX/bin
/fix-suffixes
<<EOF
466 ## duh, rename executables,
467 ## for people that use a dumb shell instead of bash
470 if [ \$# -le 0 ]; then
471 echo "Usage: fix-suffixes [FILE]..."
480 dir=\`dirname \$path\`
481 file=\`basename \$path\`
482 base=\`basename \$file \$ext\`
483 if [ \$base\$ext != \$file ]; then
484 type="\`file \$path\`"
485 if expr "\$type" : "\$expr"; then
486 mv -f \$path \$dir/\$base\$ext
491 for i in \`/bin/ls -d1 \$*\`; do
492 fix_extension \$i .exe '.*Windows.*\(executable\).*'
493 fix_extension \$i .py '.*\(python\).*'
497 chmod 755 $NATIVE_PREFIX/bin
/fix-suffixes
500 rm -rf $NATIVE_ROOT/var
/lib
/rpm
501 mkdir
-p $NATIVE_ROOT/var
/lib
/rpm
502 rpm
--root $NATIVE_ROOT --initdb
504 topdir
=$NATIVE_PREFIX/src
/redhat
505 mkdir
-p $topdir/{BUILD
,RPMS
/{$tp,$cto},SOURCES
,SPECS
,SRPMS
}
512 # building x-gcc requires to have x-ar in path
513 # x-gcc will find $prefix/x/bin/as by itself
514 PATH
=$CROSS_PREFIX/bin
:$PATH
519 for i
in $cross_rpm; do
523 echo "$i: rpm build failed"
528 PATH
=$CROSS_PREFIX/$TARGET_PLATFORM/bin
:$PATH
532 for i
in $native_rpm; do
536 echo "$i: rpm build failed"
549 cat > $distdir/setup.sh
<<EOF
554 # gunzip rpm.gz || exit 1
557 #gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
558 ## this won't work: must be done outside of cygwin
559 #old_dll=\`which cygwin1.dll\`
560 #mv -f \$old_dll \$old_dll.orig\$\$
561 #gunzip cygwin1.dll.gz
562 #cp -f cygwin1.dll \$old_dll
564 # mkdir -p \$ROOT/var/lib
565 # mkdir -p \$ROOT/bin
566 rem # touch \$ROOT/bin/rpm \$ROOT/bin/rpm.exe
567 echo > \$ROOT/bin/rpm; echo > \$ROOT/bin/rpm.exe
568 ./rpm --root \$ROOT --rcfile rpmrc --initdb
569 ./rpm --root \$ROOT --rcfile rpmrc --nodeps --ignorearch --ignoreos -Uhv \\
570 RPMS/$tp/rpm-*.$tp.rpm \\
575 cat > $distdir/setup.bat
<<EOF
577 rem # old_dll=\`which cygwin1.dll\`
578 rem # urg, should dist bash too, then we don't need usertools!
579 rem # but this gets ugly, we could really use:
581 rem # cp, cygpath, gunzip, mv, mkdir, touch
583 rem # ie, fileutils, gzip, (cygpath?)
585 rem # cp -f \`which bash\` /bin;
587 rem # cp -f bash /bin/bash.exe;
588 rem # cp -f /bin/bash /bin/sh.exe;
590 copy bash \\bin\\bash.exe
591 copy bash \\bin\\sh.exe
595 mkdir \\Cygnus\\var\\lib
597 dll=\`type -p cygwin1.dll\`;
598 wdll=\`./cygpath -w \$dll\`;
599 wdll=\${wdll:-\\Cygnus\\bin};
600 echo cygwin1.dll \$wdll > newdll; echo \$wdll \$wdll.orig\$\$ > olddll'
601 if not errorlevel 0 goto nobash
602 rem # mv -f \$old_dll \$old_dll.orig\$\$
603 rem # gunzip cygwin1.dll.gz
604 rem # cp -f cygwin1.dll \$old_dll
608 if not errorlevel 0 goto nobash
609 attrib +s \\Cygnus\\usr\\share\\lilypond\\cmtfm
612 @echo "setup.bat: can't find bash"
613 rem # @echo "setup.bat: please install usertools from"
614 rem # @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
618 cat > $distdir/lilypond.sh
<<EOF
622 \$ROOT/bin/lilypond \$*
625 cat > $distdir/midi2ly.sh
<<EOF
629 \$ROOT/bin/midi2ly \$*
632 cat > $distdir/lilypond.bat
<<EOF
633 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
636 cat > $distdir/midi2ly.bat
<<EOF
637 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
642 cp -f $PREFIX/bin
/$CYGWIN_DLL .
644 cp -f `/bin/ls -d1 $ROOT/bin/rpm* |head -1` rpm
647 cp -f `/bin/ls -d1 $ROOT/bin/bash* |head -1` bash
650 cp -f `/bin/ls -d1 $PREFIX/bin/cygpath* |head -1` cygpath
652 distbase
=`basename $distdir`
654 ln -s ..
/redhat
/RPMS .
656 www
=`dirname $distdir`
658 for i
in bash-2 guile-1 rpm-3 lilypond-
$lilypond_version; do
659 rpm
=`find_path $i*.rpm $distbase/RPMS/$tp`
660 dist_rpms
="$dist_rpms $rpm"
663 rm -f $www/setup
*.
zip
664 cd $www && zip setup-lilypond-
$lilypond_version.
zip lily-w32
$distbase/* $dist_rpms
666 # make small zip dist available
671 rm -f $zipdir/$CYGWIN_DLL.
zip
672 cd $ROOT/bin
&& zip $zipdir/$CYGWIN_DLL.
zip $CYGWIN_DLL
674 for i
in bash-2 guile-1 rpm-3 lilypond-
$lilypond_version; do
675 found
=`find_path $i*.rpm $distdir/RPMS/$tp`
676 if [ "$found" = "" ]; then
677 echo "$i: no such .rpm"
679 base
=`basename $found`
680 package
=`echo $base | sed "s/\.$tp.rpm//"`
685 rpm2cpio
$found |
cpio -id
686 zip -ry $zipdir/$package.
zip .