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