]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/make-cygwin-cross.sh
patch::: 1.3.40.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=cygwin
30 #target=mingw
31
32 if [ $target = cygwin ]; then
33         ROOT=/usr/src/cygwin-net-485
34         TARGET_ARCH=i686-pc-cygwin
35 else
36         ROOT=/usr/src/mingw-net-485
37         TARGET_ARCH=i386-pc-mingw32
38 fi
39 PREFIX=$ROOT/usr
40 NATIVE_ROOT=/Cygnus
41 NATIVE_PREFIX=$NATIVE_ROOT/usr
42
43 # urg
44 DEVEL=/home/fred
45 distdir=$DEVEL/WWW/lilypond/gnu-windows/lily-w32
46 #distdir=/tmp
47
48 SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/redhat/SRPMS
49
50 ARCH=`uname -m`
51 OS=`uname -s | tr '[A-Z]' '[a-z]'`
52 HOST=$ARCH-gnu-$OS
53 CROSS_TARGET_ARCH=$ARCH-x-$TARGET_ARCH
54 cta=$ARCH-x-cygwin
55 ta=i686-cygwin
56
57 cygwin_binary=cygwin-20000301.tar.gz
58 mingw_binary=bin-crtdll-2000-02-03.tar.gz
59
60 #CYGWIN_DLL=cygwin1-net-485.dll
61 CYGWIN_DLL=cygwin1.dll
62 MINWG_DLL=mingwc10-net-485.dll
63
64
65 ################
66 # cross packages
67 ################
68
69 cross_rpm="
70 binutils-19990818
71 bison
72 flex
73 gcc-2.95.2
74 "
75
76 #guile_after_rpm='ln -f $NATIVE_PREFIX/bin/i686-redhat-cygwin-guile-config $NATIVE_PREFIX/bin/i686-pc-cygwin-guile-config'
77
78 lilypond_version=@TOPLEVEL_VERSION@
79
80 native_rpm="
81 rx-1.5
82 zlib-1.1.3
83 db-2.7.7
84 guile-1.3.4
85 rpm-3.0.4
86 lilypond-$lilypond_version
87 "
88
89 #######################
90 # end of config section
91 #######################
92
93 ###########
94 # functions
95 ###########
96
97 expand ()
98 {(
99
100         set -
101         string=`eval echo $\`eval echo "${1}${2}"\``
102         eval echo $string
103 )
104 }
105
106 find_path ()
107 {(
108         set -
109         expr=$1
110         source_path=${2:-$SOURCE_PATH}
111         path_list=`echo $source_path | sed 's/:/ /g'`
112
113         found=
114         for i in $path_list; do
115                 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
116                 if [ "$found" != "" ] && [ -e $found ]; then
117                         break
118                 fi
119         done
120         echo $found
121 )
122 }
123
124 build ()
125 {(
126         package=$1
127         name=`echo $package | sed 's/-.*//'`
128
129         if [ $type = "cross" ]; then
130                 target_arch=$CROSS_TARGET_ARCH
131                 a=$cta
132         else
133                 target_arch=$TARGET_ARCH
134                 a=$ta
135         fi
136
137         rpm_package=`find_path $name*.rpm "$topdir/RPMS/$cta:$topdir/RPMS/$ta"`
138         if [ "$rpm_package" != "" ]; then
139                 echo "$rpm_package: package exists"
140                 echo "$rpm_package: just updating db"
141                 rpm -ivv --justdb --ignoreos --ignorearch --nodeps --force\
142                         --dbpath $NATIVE_ROOT/var/lib/rpm \
143                         $topdir/RPMS/$a/$name*.rpm
144                 exit 0
145         fi
146
147         cd $topdir
148         found=`find_path $package*src.rpm`
149         if [ "$found" != "" ]; then
150                 rpm --root $NATIVE_ROOT -ivv $found || exit 1
151                 rpm --target=$target_arch -ba SPECS/$name*.spec || exit 1
152         else
153                 tarball=`/bin/ls -d1 SOURCES/$package*tar.gz 2>/dev/null | head -1`
154                 if [ "SPECS/$name.spec" != "" ] && [ "$tarball" != "" ]; then
155                         rpm --target=$target_arch -ba SPECS/$name.spec || exit 1
156                 else
157                         found=`find_path $package*tar.gz`
158                         if [ "$found" != "" ]; then
159                                 rpm --target=$target_arch -ta $found || exit 1
160                         else
161                                 echo "$package: no such rpm or tarball"
162                                 exit 1
163                         fi
164                 fi
165         fi
166         name=`echo $package | sed 's/-.*//'`
167
168         rpm -ivv --ignoreos --ignorearch --nodeps --force\
169                 --dbpath $NATIVE_ROOT/var/lib/rpm \
170                 $topdir/RPMS/$a/$name*.rpm
171 )
172 }
173
174 ##################
175 # end of functions
176 ##################
177
178 #######
179 # setup
180 #######
181
182 set -x
183 mkdir -p $ROOT
184 if [ ! -d $PREFIX/bin ]; then
185         mkdir -p $PREFIX
186         cd $PREFIX
187         mkdir -p include
188         mkdir -p $TARGET_ARCH
189         cd $TARGET_ARCH && ln -s ../include .
190         cd $ROOT
191         found=`find_path $cygwin_binary`
192         if [ "$found" = "" ]; then
193                 echo "$cygwin_binary: no such tarball"
194                 exit 1
195         fi
196         tar xzf $found
197         # urg, bug in gcc's cross-make configuration
198         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
199 else
200         echo "$PREFIX: already exists"
201         echo "$cygwin_binary: skipping"
202 fi
203
204 # mingw
205 if [ ! -d $PREFIX/$TARGET_ARCH ]; then
206         cd $PREFIX
207         found=`find_path $mingw_binary`
208         if [ "$found" = "" ]; then
209                 echo "$mingw_binary: no such tarball"
210                 exit 1
211         fi
212         tar xzf $found
213
214         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
215         rm -f include
216         mkdir -p $PREFIX/i386-mingw32/include
217         ln -s $PREFIX/i386-mingw32 $TARGET_ARCH
218         ln -s $PREFIX/$TARGET_ARCH/include .
219 fi
220
221 rm -f $NATIVE_ROOT
222 if [ ! -e $NATIVE_ROOT ]; then
223         ln -s $ROOT $NATIVE_ROOT || exit 1
224 fi
225
226 #mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
227 #mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
228
229 mkdir -p $ROOT/var/redhat
230 mkdir -p $PREFIX/src/redhat
231
232 native_config_site='$PREFIX/share/native-config.site'
233
234 ncs=`eval echo $native_config_site`
235 rm -f $ncs
236 mkdir -p `dirname $ncs`
237 cat > $ncs <<EOF
238 ac_cv_sizeof_int=4
239 ac_cv_sizeof_long=4
240 ac_cv_sys_restartable_syscalls=yes
241 ac_cv_sprintf_count=yes
242 ac_cv_spinlocks=no
243 db_cv_sprintf_count=yes
244 db_cv_spinlocks=no
245 EOF
246
247 cross_rpm_dir=$NATIVE_PREFIX/lib/rpm/$cta
248 cross_rpm_link=/usr/lib/rpm/$cta
249 mkdir -p $cross_rpm_dir
250 rm -f $cross_rpm_link
251 ln -s $NATIVE_PREFIX/lib/rpm/$cta $cross_rpm_link
252
253 native_rpm_dir=$NATIVE_PREFIX/lib/rpm/$ta
254 native_rpm_link=/usr/lib/rpm/$ta
255 mkdir -p $native_rpm_dir
256 rm -f $native_rpm_link
257 ln -s $NATIVE_PREFIX/lib/rpm/$ta $native_rpm_link
258
259 cross_macros=$cross_rpm_dir/macros
260 native_macros=$native_rpm_dir/macros
261
262 base_macros=$NATIVE_PREFIX/lib/rpm/base-macros
263 rm -f $base_macros
264 cat > $base_macros <<EOF
265 %root           /Cygnus
266 %_prefix        /Cygnus/usr
267 %prefix         /Cygnus/usr
268 %native_prefix  /Cygnus/usr
269
270 %_topdir        %{native_prefix}/src/redhat
271 %_sourcedir     %{native_prefix}/src/redhat/SOURCES
272 %_builddir      %{native_prefix}/src/redhat/BUILD
273 %_srcrpmdir     %{native_prefix}/src/redhat/SRPMS
274 %_rpmdir        %{native_prefix}/src/redhat/RPMS
275
276 #%DocDir                %{native_prefix}/doc
277 %DocDir         /Cygnus/usr/doc
278 %_defaultdocdir /Cygnus/usr/doc
279
280 %cygwin_dll     %{native_prefix}/bin/cygwin1.dll
281
282 %cflags         %{optflags}
283
284 %sourcedir      .
285 EOF
286
287 cp -f $base_macros $cross_macros
288 cat >> $cross_macros <<EOF
289 %_rpmfilename   %%{ARCH}-x-cygwin/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-x-cygwin.rpm
290
291 %config_site    %{nil}
292 %ldflags        %{nil}
293 %_target_platform $TARGET_ARCH
294
295 %configure      \
296   CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
297   %{sourcedir}/configure \
298   --host=%{_host} --target=%{_target_platform} --prefix=%{native_prefix}
299 EOF
300
301 cp -f $base_macros $native_macros
302 cat >> $native_macros <<EOF
303 %config_site    %{_prefix}/share/native-config.site
304 #%program_suffix .exe
305 %program_suffix %{nil}
306
307 #%_arch         i686-cygwin
308 #%_vendor       pc
309 #%_os           cygwin
310
311 %_rpmfilename   %%{ARCH}-cygwin/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-cygwin.rpm
312
313 %__find_provides        %{native_prefix}/lib/rpm/cygwin.prov
314 %__find_requires        %{native_prefix}/lib/rpm/cygwin.req
315
316 %ldflags        -L%{native_prefix}/lib %{cygwin_dll}
317 %configure      \
318   CFLAGS="%{cflags}" LDFLAGS="%{ldflags}" CONFIG_SITE=%{config_site} \
319   %{sourcedir}/configure --host=%{_host} --target=%{_target_platform} \
320   --prefix=%{native_prefix} --program-suffix=%{program_suffix}
321 EOF
322
323 rm -f $native_rpm_dir/cygwin.prov
324 cat > $native_rpm_dir/cygwin.prov <<EOF
325 #!/bin/sh
326 while read f ; do
327        f=\`echo $f | tr '[:upper:]' '[:lower:]'\`
328        case \$f in
329        *.dll)  basename \$f
330                ;;
331        esac
332 done | sort -u
333 EOF
334 chmod 755 $native_rpm_dir/cygwin.prov
335
336 rm -f $native_rpm_dir/cygwin.req
337 cat > $native_rpm_dir/cygwin.req <<EOF
338 #!/bin/sh
339
340 while read f ; do
341        case \$f in
342        *.dll|*.exe)    objdump -p $f | grep "DLL Name:" | cut -f3 -d" " | tr '[
343 upper:]' '[:lower:]'
344                        ;;
345        esac
346 done | sort -u
347
348 EOF
349 chmod 755 $native_rpm_dir/cygwin.req
350
351
352 set -x
353 type=rpm
354 rm -rf $NATIVE_ROOT/var/lib/rpm
355 mkdir -p $NATIVE_ROOT/var/lib/rpm
356 rpm --root $NATIVE_ROOT --initdb
357
358 topdir=$NATIVE_PREFIX/src/redhat
359 mkdir -p $topdir/{BUILD,RPMS/{$ta,$cta},SOURCES,SPECS,SRPMS}
360
361 ##############
362 # end of setup
363 ##############
364
365
366 PATH=$PREFIX/bin:$PATH
367
368 mkdir -p $PREFIX/src
369 cd $PREFIX/src
370 type=cross
371 for i in $cross_rpm; do
372         if build $i; then
373                 true
374         else
375                 echo "$i: rpm build failed"
376                 exit 1
377         fi
378 done
379
380 # urg, bug in binutil's cross-make install
381 (
382 cd $PREFIX/$TARGET_ARCH/bin
383 ln -f ../../bin/$TARGET_ARCH-objdump objdump
384 ln -f ../../bin/$TARGET_ARCH-objcopy objcopy
385 )
386 # urg, bug in gcc's cross-make install
387 (
388 cd $PREFIX/$TARGET_ARCH/bin
389 ln -f ../../bin/$TARGET_ARCH-gcc cc
390 ln -f ../../bin/$TARGET_ARCH-gcc gcc
391 ln -f ../../bin/$TARGET_ARCH-c++ c++
392 ln -f ../../bin/$TARGET_ARCH-g++ g++
393 )
394
395 PATH=$PREFIX/$TARGET_ARCH/bin:$PATH
396
397 cd $PREFIX/src
398 type=native
399 for i in $native_rpm; do
400         if build $i; then
401                 true
402         else
403                 echo "$i: rpm build failed"
404                 exit 1
405         fi
406 done
407
408 cd $NATIVE_PREFIX/src/redhat/BUILD
409
410 rm -f $distdir/$CYGWIN_DLL.gz
411 cd $distdir && cp -f $PREFIX/bin/$CYGWIN_DLL . && gzip -f $CYGWIN_DLL
412
413 rm -f $distdir/rpm2cpio.gz
414 cd $distdir && cp -f $PREFIX/bin/rpm2cpio . && gzip -f rpm2cpio
415
416
417 cat > $distdir/setup.sh <<EOF
418 #!/bin/bash
419 set -x
420 ROOT=/Cygnus
421 PREFIX=\$ROOT/usr
422 gunzip rpm2cpio.gz || exit 1
423 # currently, the cygwin1.dll's conflict.
424 # it's been reported one can't have both in PATH
425 dll=\$ROOT/net-485
426 mkdir -p \$dll
427 gzip -dc cygwin.dll.gz > \$dll/cygwin1.dll
428 here=\`pwd\`
429 cd \$ROOT/.. && (PATH=\$dll \$here/rpm2cpio \$here/rpm*.rpm ) | cpio -ivmd 
430 PATH=\$dll rpm --root=\$ROOT --initdb
431 cd \$here
432 for i in RPMS/$ta/*.rpm; do
433         PATH=\$dll rpm -ivv --ignoreos --ignorearch --nodeps --force\
434                   --dbpath \$ROOT/var/lib/rpm \
435                   \$i
436 done
437 EOF
438
439 cat > $distdir/setup.bat <<EOF
440 bash setup.sh
441 if errorlevel 0 goto exit
442 @echo "setup.bat: can't find bash"
443 @echo "setup.bat: please install usertools from"
444 @echo "setup.bat: http://sourceware.cygnus.com/cygwin/"
445 :exit
446 EOF
447
448 cat > $distdir/lilypond.sh <<EOF
449 #!/bin/bash
450 ROOT=/Cygnus
451 PREFIX=\$ROOT/usr
452 # currently, the cygwin1.dll's conflict.
453 # it's been reported one can't have both in PATH
454 dll=\$ROOT/net-485
455 PATH=\$dll \$ROOT/bin/lilypond \$*
456 EOF
457
458 cat > $distdir/midi2ly.sh <<EOF
459 #!/bin/bash
460 ROOT=/Cygnus
461 PREFIX=\$ROOT/usr
462 # currently, the cygwin1.dll's conflict.
463 # it's been reported one can't have both in PATH
464 dll=\$ROOT/net-485
465 PATH=\$dll \$ROOT/bin/midi2ly \$*
466 EOF
467
468 cat > $distdir/lilypond.bat <<EOF
469 bash lilypond.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
470 EOF
471
472 cat > $distdir/midi2ly.bat <<EOF
473 bash midi2ly.sh %1 %2 %3 %4 %5 %6 %7 %8 %9
474 EOF
475
476 distbase=`basename $distdir`
477 cd $distdir
478 rm -f RPMS
479 ln -s ../redhat/RPMS .
480
481 www=`dirname $distdir`
482 cd $www
483 for i in guile-1 rpm lilypond; do
484         rpm=`find_path $i*.rpm $distbase/RPMS/$ta`
485         dist_rpms="$dist_rpms $rpm"
486 done
487
488 rm -f $www/setup.zip
489 cd $www && zip setup.zip lily-w32 $distbase/* $dist_rpms