]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/make-cygwin-cross.sh
patch::: 1.3.41.jcn2
[lilypond.git] / buildscripts / make-cygwin-cross.sh
1 #!@BASH@
2 # make-cygwin-cross
3 #
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).
8 #
9 # Besides being a handy script for me, currently this mainly serves
10 # as documentation for cross-building lilypond.
11 #
12 # To use this script, you need
13 #
14 #  * all development tools to build a native LilyPond, see INSTALL.txt
15 #
16 #  * RPM distribution of the cygwin pre-release sources, from:
17 #
18 #      http://appel.dyndns.org/lilypond/gnu-windows/redhat/SRPMS/
19 #
20 #    The tarballs were fetched from:
21 #
22 #      ftp://sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485/
23 #
24
25 ################
26 # config section
27 ################
28
29 TARGET_OS=cygwin
30 #TARGET_OS=mingw32
31
32 if [ $TARGET_OS = cygwin ]; then
33         ROOT=/usr/src/cygwin-net-485
34         TARGET_ARCH=i686
35         TARGET_VENDOR=pc
36 else
37         ROOT=/usr/src/mingw-net-485
38         TARGET_ARCH=i386
39         TARGET_VENDOR=pc
40 fi
41 TARGET_PLATFORM=$TARGET_ARCH-$TARGET_VENDOR-$TARGET_OS
42
43 ARCH=`uname -m`
44 OS=`uname -s | tr '[A-Z]' '[a-z]'`
45 VENDOR=gnu
46 PLATFORM=$ARCH-$VENDOR-$OS
47
48 #CROSS_TARGET_PLATFORM=$ARCH-x-$TARGET_PLATFORM
49 CROSS_TARGET_PLATFORM=$PLATFORM-x-$TARGET_PLATFORM
50 cto=$OS-x-cygwin
51 tp=i686-cygwin
52
53 PREFIX=$ROOT/usr
54 NATIVE_ROOT=/Cygnus
55 NATIVE_PREFIX=$NATIVE_ROOT/usr
56 CROSS_ROOT=$NATIVE_ROOT/$cto
57 CROSS_PREFIX=$CROSS_ROOT/usr
58
59 # urg
60 DEVEL=/home/fred
61 distdir=$DEVEL/WWW/lilypond/gnu-windows/lily-w32
62 #distdir=/tmp
63
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
68
69 cygwin_binary=cygwin-20000301.tar.gz
70 mingw_binary=bin-crtdll-2000-02-03.tar.gz
71
72 #CYGWIN_DLL=cygwin1-net-485.dll
73 CYGWIN_DLL=cygwin1.dll
74 MINWG_DLL=mingwc10-net-485.dll
75
76
77 ################
78 # cross packages
79 ################
80
81 cross_rpm="
82 binutils-19990818
83 gcc-2.95.2
84 bison
85 flex
86 "
87
88 # binutils installs ok, but forgets these two
89 binutils_after_rpm='
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
94 '
95 # burp.  gcc doesn't install any of these
96 gcc_after_rpm='
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++
102 '
103
104 guile_after_rpm='cp -f $NATIVE_PREFIX/bin/*guile-config $CROSS_PREFIX/$TARGET_PLATFORM/bin'
105
106 lilypond_version=@TOPLEVEL_VERSION@
107
108 native_rpm="
109 rx-1.5
110 zlib-1.1.3
111 db-2.7.7
112 guile-1.3.4
113 rpm-3.0.4
114 lilypond-$lilypond_version
115 "
116
117 #######################
118 # end of config section
119 #######################
120
121 ###########
122 # functions
123 ###########
124
125 expand ()
126 {(
127
128         set -
129         string=`eval echo $\`eval echo "${1}${2}"\``
130         eval echo $string
131 )
132 }
133
134 find_path ()
135 {(
136         set -
137         expr=$1
138         source_path=${2:-$SOURCE_PATH}
139         path_list=`echo $source_path | sed 's/:/ /g'`
140
141         found=
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
145                         break
146                 fi
147         done
148         echo $found
149 )
150 }
151
152 build ()
153 {(
154         package=$1
155         name=`echo $package | sed 's/-.*//'`
156
157         if [ $type = "cross" ]; then
158                 target_platform=$CROSS_TARGET_PLATFORM
159                 a=$cto
160         else
161                 target_platform=$TARGET_PLATFORM
162                 a=$tp
163         fi
164
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
173                 exit 0
174         fi
175
176         cd $topdir
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
181         else
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
185                 else
186                         found=`find_path $package*tar.gz`
187                         if [ "$found" != "" ]; then
188                                 rpm --target=$target_platform -ta $found || exit 1
189                         else
190                                 echo "$package: no such rpm or tarball"
191                                 exit 1
192                         fi
193                 fi
194         fi
195         name=`echo $package | sed 's/-.*//'`
196
197         rpm -ivv --ignoreos --ignorearch --nodeps --force\
198                 --dbpath $NATIVE_ROOT/var/lib/rpm \
199                 $topdir/RPMS/$a/$name*.rpm
200         #urg
201         name_after_rpm="`expand $name _after_rpm`"
202         `eval $name_after_rpm` || exit 1
203 )
204 }
205
206 ##################
207 # end of functions
208 ##################
209
210 #######
211 # setup
212 #######
213
214 set -x
215 mkdir -p $ROOT
216 if [ ! -d $PREFIX/bin ]; then
217         mkdir -p $PREFIX
218         cd $PREFIX
219
220         ## is this still necessary?
221         mkdir -p include lib
222         mkdir -p $TARGET_PLATFORM
223         cd $TARGET_PLATFORM && ln -s ../include .
224
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 .
231         
232         cd $ROOT
233         found=`find_path $cygwin_binary`
234         if [ "$found" = "" ]; then
235                 echo "$cygwin_binary: no such tarball"
236                 exit 1
237         fi
238         tar xzf $found
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
242 else
243         echo "$PREFIX: already exists"
244         echo "$cygwin_binary: skipping"
245 fi
246
247 # mingw
248 if [ ! -d $PREFIX/$TARGET_PLATFORM ]; then
249         cd $PREFIX
250         found=`find_path $mingw_binary`
251         if [ "$found" = "" ]; then
252                 echo "$mingw_binary: no such tarball"
253                 exit 1
254         fi
255         tar xzf $found
256
257         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_PLATFORM/2.95.2
258         rm -f include
259         mkdir -p $PREFIX/i386-mingw32/include
260         ln -s $PREFIX/i386-mingw32 $TARGET_PLATFORM
261         ln -s $PREFIX/$TARGET_PLATFORM/include .
262 fi
263
264 rm -f $NATIVE_ROOT
265 if [ ! -e $NATIVE_ROOT ]; then
266         ln -s $ROOT $NATIVE_ROOT || exit 1
267 fi
268
269 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
270 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
271
272 mkdir -p $ROOT/var/redhat
273 mkdir -p $PREFIX/src/redhat
274
275 native_config_site='$PREFIX/share/native-config.site'
276
277 ncs=`eval echo $native_config_site`
278 rm -f $ncs
279 mkdir -p `dirname $ncs`
280 cat > $ncs <<EOF
281 ac_cv_sizeof_int=4
282 ac_cv_sizeof_long=4
283 ac_cv_sys_restartable_syscalls=yes
284 ac_cv_sprintf_count=yes
285 ac_cv_spinlocks=no
286 db_cv_sprintf_count=yes
287 db_cv_spinlocks=no
288 EOF
289
290 #URG, stupid RPM
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
297
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
303
304 cross_macros=$cross_rpm_dir/macros
305 native_macros=$native_rpm_dir/macros
306
307 base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
308 rm -f $base_macros
309 cat > $base_macros <<EOF
310 %native_prefix  /Cygnus/usr
311
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
317
318 #%DocDir                %{native_prefix}/doc
319 %DocDir         /Cygnus/usr/doc
320 %_docdir        /Cygnus/usr/doc
321 %_defaultdocdir /Cygnus/usr/doc
322
323 %cygwin_dll     %{native_prefix}/bin/cygwin1.dll
324
325 %__install      /bin/install
326
327 %cflags         %{optflags}
328 %cppflags       %{nil}
329
330 %sourcedir      .
331 EOF
332
333 cp -f $base_macros $cross_macros
334 cat >> $cross_macros <<EOF
335
336 %cross_prefix   /Cygnus/$cto/usr
337 %root           /Cygnus/$cto
338 %_rootbindir    /Cygnus/$cto/bin
339 #_usr           /Cygnus/$cto/usr
340 %_prefix        /Cygnus/$cto/usr
341 %prefix         /Cygnus/$cto/usr
342
343 %_rpmfilename   $cto/%%{NAME}-%%{VERSION}-%%{RELEASE}.$cto.rpm
344
345 %config_site    %{nil}
346
347 %cppflags       %{nil}
348 %cflags         %{nil}
349 %ldflags        %{nil}
350 %_target_platform $TARGET_PLATFORM
351
352 #% configure    \
353 #  %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
354 %configure      \
355   CPPFLAGS="%{cppflags}" CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
356   %{sourcedir}/configure \
357   --host=%{_host} --target=%{_target_platform} --prefix=%{cross_prefix} -v
358 EOF
359
360 cp -f $base_macros $native_macros
361 cat >> $native_macros <<EOF
362
363 %root           /Cygnus
364 %_rootbindir    /Cygnus/bin
365 #_usr           /Cygnus/usr
366 %_prefix        /Cygnus/usr
367 %prefix         /Cygnus/usr
368
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}
373
374 #%_arch         i686-cygwin
375 #%_vendor       pc
376 #%_os           cygwin
377
378 %_rpmfilename   %%{ARCH}-$TARGET_OS/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-$TARGET_OS.rpm
379
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/*
384
385 %cppflags       -I%{native_prefix}/include
386 %cflags         %{optflags} %{cppflags}
387 %ldflags        -L%{native_prefix}/lib %{cygwin_dll}
388
389 #%configure     \
390 #  %{?__libtoolize:[ -f configure.in ] \&\& %{__libtoolize} --copy --force}; \
391
392 %configure      \
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}
397 EOF
398
399 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.prov
400 cat > $NATIVE_PREFIX/lib/rpm/cygwin.prov <<EOF
401 #!/bin/sh
402 while read f ; do
403        f=\`echo \$f | tr '[:upper:]' '[:lower:]'\`
404        case \$f in
405        *.dll)  basename \$f
406                ;;
407        esac
408 done | sort -u
409 EOF
410 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.prov
411
412 rm -f $NATIVE_PREFIX/lib/rpm/cygwin.req
413 cat > $NATIVE_PREFIX/lib/rpm/cygwin.req <<EOF
414 #!/bin/sh
415
416 while read f ; do
417        case \$f in
418        *.dll|*.exe)    objdump -p \$f | grep "DLL Name:" | cut -f3 -d" " | tr '[:upper:]' '[:lower:]'
419                        ;;
420        esac
421 done | sort -u
422
423 EOF
424 chmod 755 $NATIVE_PREFIX/lib/rpm/cygwin.req
425
426 rm -f $NATIVE_PREFIX/bin/fix-suffixes
427 cat > $NATIVE_PREFIX/bin/fix-suffixes <<EOF
428 #!/bin/sh
429 ## duh, rename executables,
430 ## for people that use a dumb shell instead of bash
431
432
433 if [ \$# -le 0 ]; then
434         echo "Usage: fix-suffixes [FILE]..."
435         exit 2
436 fi
437
438 fix_extension ()
439 {
440         path=\$1
441         ext=\$2
442         expr="\$3"
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
450                 fi
451         fi
452 }
453
454 for i in \`/bin/ls -d1 \$*\`; do
455         fix_extension \$i .exe '.*Windows.*\(executable\).*'
456         fix_extension \$i .py '.*\(python\).*'
457 done
458
459 EOF
460 chmod 755 $NATIVE_PREFIX/bin/fix-suffixes
461 set -x
462 type=rpm
463 rm -rf $NATIVE_ROOT/var/lib/rpm
464 mkdir -p $NATIVE_ROOT/var/lib/rpm
465 rpm --root $NATIVE_ROOT --initdb
466
467 topdir=$NATIVE_PREFIX/src/redhat
468 mkdir -p $topdir/{BUILD,RPMS/{$tp,$cto},SOURCES,SPECS,SRPMS}
469
470 ##############
471 # end of setup
472 ##############
473
474 OLDPATH=$PATH
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
478
479 mkdir -p $PREFIX/src
480 cd $PREFIX/src
481 type=cross
482 for i in $cross_rpm; do
483         if build $i; then
484                 true
485         else
486                 echo "$i: rpm build failed"
487                 exit 1
488         fi
489 done
490
491 PATH=$CROSS_PREFIX/$TARGET_PLATFORM/bin:$PATH
492
493 cd $PREFIX/src
494 type=native
495 for i in $native_rpm; do
496         if build $i; then
497                 true
498         else
499                 echo "$i: rpm build failed"
500                 exit 1
501         fi
502 done
503
504 ##############
505 # Distribution
506 ##############
507
508 PATH=$OLDPATH
509
510 mkdir -p $distdir
511 rm -f $distdir/$CYGWIN_DLL.gz
512 cd $distdir && cp -f $PREFIX/bin/$CYGWIN_DLL . && gzip -f $CYGWIN_DLL
513
514 rm -f $distdir/rpm.gz
515 cd $distdir && cp -f `/bin/ls -d1 $ROOT/bin/rpm* |head -1` rpm && gzip -f rpm
516
517
518 cat > $distdir/setup.sh <<EOF
519 #!/bin/bash
520 set -x
521 ROOT=/Cygnus
522 PREFIX=\$ROOT/usr
523 gunzip rpm.gz || exit 1
524 #dll=\$ROOT/net-485
525 #mkdir -p \$dll
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
532 echo > rpmrc
533 mkdir -p \$ROOT/var/lib
534 mkdir -p \$ROOT/bin
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 \\
539         RPMS/$tp/*.$tp.rpm
540 done
541 EOF
542
543 cat > $distdir/setup.bat <<EOF
544 del dll olddll
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
557 copy < olddll 
558 copy < newdll 
559 bash setup.sh
560 if not errorlevel 0 goto nobash
561 goto :exit
562 :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/"
566 :exit
567 EOF
568
569 cat > $distdir/lilypond.sh <<EOF
570 #!/bin/bash
571 ROOT=/Cygnus
572 PREFIX=\$ROOT/usr
573 \$ROOT/bin/lilypond \$*
574 EOF
575
576 cat > $distdir/midi2ly.sh <<EOF
577 #!/bin/bash
578 ROOT=/Cygnus
579 PREFIX=\$ROOT/usr
580 \$ROOT/bin/midi2ly \$*
581 EOF
582
583 cat > $distdir/lilypond.bat <<EOF
584 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
585 EOF
586
587 cat > $distdir/midi2ly.bat <<EOF
588 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
589 EOF
590
591 distbase=`basename $distdir`
592 cd $distdir
593 rm -f RPMS
594 ln -s ../redhat/RPMS .
595
596 www=`dirname $distdir`
597 cd $www
598 for i in guile-1 rpm lilypond; do
599         rpm=`find_path $i*.rpm $distbase/RPMS/$tp`
600         dist_rpms="$dist_rpms $rpm"
601 done
602
603 rm -f $www/setup.zip
604 cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms
605
606
607 # make small zip dist available
608 #
609 zipdir=$www/zip
610 mkdir -p $zipdir
611
612 rm -f $zipdir/$CYGWIN_DLL.zip
613 cd $ROOT/bin && zip $zipdir/$CYGWIN_DLL.zip $CYGWIN_DLL
614
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"
619         else
620                 base=`basename $found`
621                 package=`echo $base | sed "s/\.$tp.rpm//"`
622                 dir=/tmp/$i-rpm2zip
623                 rm -rf $dir
624                 mkdir -p $dir
625                 cd $dir || exit 1
626                 rpm2cpio $found | cpio -id
627                 zip -ry $zipdir/$package.zip .
628                 rm -rf $dir
629         fi
630 done