]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/make-cygwin-cross.sh
patch::: 1.3.38.jcn4
[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 #  * pre-release cygnus sources (and a binary) from:
17 #
18 #      ftp://sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485/
19 #
20 #          binutils/binutils-19990818-1-src.tar.gz
21 #          bison/bison-src.tar.gz
22 #          cygwin/cygwin-20000301.tar.gz
23 #          flex/flex-src.tar.gz
24 #          gcc/gcc-2.95.2-1-src.tar.gz
25 #
26 #      ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime/
27 #
28 #          bin-crtdll-2000-02-03.tar.gz  (mingw only)
29 #
30 #  * guile-1.3.4.tar.gz
31 #
32 #  * lilypond-1.3.38.jcn1.tar.gz
33 #
34 #  * lots of disk space, ca 353MB
35 #
36
37 ################
38 # config section
39 ################
40
41 target=cygwin
42 #target=mingw
43
44 if [ $target = cygwin ]; then
45         ROOT=/usr/src/cygwin-net-485
46         TARGET_ARCH=i686-pc-cygwin
47 else
48         ROOT=/usr/src/mingw-net-485
49         TARGET_ARCH=i386-pc-mingw32
50 fi
51 PREFIX=$ROOT/usr
52 NATIVE_PREFIX=/Cygnus/usr
53
54 # urg
55 DEVEL=/home/fred
56 WWW=$DEVEL/WWW/lilypond/gnu-windows
57 #WWW=/tmp
58
59 CYGWIN_SOURCE=$DEVEL/sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485
60 MINGW_SOURCE=$DEVEL/ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime
61 SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/patches:$DEVEL/usr/src/lilypond/Documentation/ntweb:$MINGW_SOURCE
62
63 HOST=`uname -m`-gnu-`uname -s | tr '[A-Z]' '[a-z]'`
64
65 cygwin_binary=cygwin-20000301.tar.gz
66 mingw_binary=bin-crtdll-2000-02-03.tar.gz
67
68 #CYGWIN_DLL=cygwin1-net-485.dll
69 CYGWIN_DLL=cygwin1.dll
70 MINWG_DLL=mingwc10-net-485.dll
71
72
73 ################
74 # cross packages
75 ################
76
77 cross_packages="
78 binutils-19990818
79 gcc-2.95.2
80 flex
81 bison
82 "
83 not_yet_needed="
84 cygwin-2000301
85 "
86
87 cross_configure='--prefix=$PREFIX --target=$TARGET_ARCH'
88 gcc_make='LANGUAGES="c++"'
89 cygwin_make='-k || true'
90
91
92 #################
93 # native packages
94 #################
95
96 # Typically, we install native packages under
97 #
98 #   /Cygnus/usr/package-x.y.z
99 #
100 # so that's how we configure them.
101 #
102 native_configure='--target=$TARGET_ARCH --build=$TARGET_ARCH --host=$HOST --oldincludedir=$PREFIX/include --prefix=$NATIVE_PREFIX/$package --program-suffix='
103
104 guile_patch='guile-1.3.4-gnu-windows.patch'
105 if [ $target = mingw ]; then
106         guile_patch1='guile-1.3.4-mingw.patch'
107         guile_cflags='-I $PREFIX/$TARGET_ARCH/include -I $PREFIX/i686-pc-cygwin/include'
108 fi
109 guile_ldflags='-L$PREFIX/lib $PREFIX/bin/$CYGWIN_DLL'
110 guile_configure='--enable-sizeof-int=4 --enable-sizeof-long=4 --enable-restartable-syscalls=yes'
111 guile_make='oldincludedir=$PREFIX/include'
112
113 # We need to get guile properly installed for cross-development, ie
114 # at our prefix: $PREFIX.  When packaging, the prefix we configured
115 # for, will be used.
116 #
117 guile_install='prefix=$PREFIX'
118
119 lilypond_version=@TOPLEVEL_VERSION@
120 if [ $target = mingw ]; then
121         lilypond_cflags='-I $PREFIX/$TARGET_ARCH/include -I $PREFIX/i686-pc-cygwin/include'
122 fi
123 lilypond_ldflags='-L$PREFIX/lib -lguile $PREFIX/bin/$CYGWIN_DLL'
124 #lilypond_configure='--prefix=$lilypond_prefix'
125 ## URG, help2man: doesn't know about cross-compilation.
126 #lilypond_make='-k || make -k || true'
127 lilypond_patch=lilypond-manpages.patch
128 # Don't install lilypond
129 lilypond_install='--just-print'
130
131 native_packages="
132 guile-1.3.4
133 lilypond-$lilypond_version
134 "
135
136 #######################
137 # end of config section
138 #######################
139
140 cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
141 cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs`
142 source_path=`echo $SOURCE_PATH:$cygwin_source_path | sed 's/:/ /g'`
143
144 ###########
145 # functions
146 ###########
147
148 untar ()
149 {(
150         set -x
151         tarball=$1
152         dest_dir=$2
153
154         first_dir=`tar tzf $tarball | head -1`
155         src_dir=`dirname $first_dir`
156
157         if [ "$src_dir" = "src" -o "$src_dir" = "./src" \
158           -o "$src_dir" = "." ]; then
159                 src_dir=$first_dir
160         fi
161
162         tar xzf $tarball
163
164         if [ "$src_dir" != "$dest_dir" -a "$src_dir" != "$dest_dir/" ]; then
165                 mv $src_dir $dest_dir
166                 rm -rf ./$first_dir
167         fi
168 )
169 }
170
171 expand ()
172 {(
173
174         set -
175         string=`eval echo $\`eval echo ${1}${2}\``
176         eval echo $string
177 )
178 }
179
180 find_path ()
181 {(
182         set -
183         expr=$1
184         found=
185         for i in $source_path; do
186                 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
187                 if [ -e "$found" ]; then
188                         break
189                 fi
190         done
191         echo $found
192 )
193 }
194
195 fix_extension ()
196 {
197         file=$1
198         ext=$2
199         expr="$3"
200         base=`basename $file $ext`
201         if [ $base$ext != $i ]; then
202                 type="`file $file`"
203                 if expr "$type" : "$expr"; then
204                         mv -f $file $base$ext
205                 fi
206         fi
207 }
208
209 build ()
210 {(
211         package=$1
212         set -
213         if [ -d $package ]; then
214                 echo "$package: directory exists"
215                 echo "$package: skipping"
216                 exit 0
217         fi
218
219         name=`echo $package | sed 's/-.*//'`
220         name_cflags=`expand $name _cflags`
221         name_ldflags=`expand $name _ldflags`
222         name_configure=`expand $name _configure`
223         type_configure=`expand $type _configure`
224         name_make=`expand $name _make`
225         name_install=`expand $name _install`
226
227         found=`find_path $package*src.tar.gz`
228         if [ "$found" = "" ]; then
229                 found=`find_path $package.tar.gz`
230         fi
231         if [ "$found" = "" ]; then
232                 found=`find_path $name*tar.gz`
233         fi
234         if [ "$found" = "" ]; then
235                 echo "$package: no such tarball"
236                 exit 1
237         fi
238         
239         untar $found $package
240         patch=`expand $name _patch`
241         count=0
242         while [ "x$patch" != "x" ]; do
243                 (
244                 cd $package
245                 found=`find_path $patch`
246                 if [ "$found" = "" ]; then
247                         echo "$patch: no such file"
248                         exit 1
249                 fi
250                 patch -p1 -E < $found
251                 )
252                 count=`expr $count + 1`
253                 patch=`expand $name _patch$count`
254         done
255         set -x
256         mkdir $type-$package
257         cd $type-$package
258
259         rm -f config.cache
260         CFLAGS="$name_cflags" LDFLAGS="$name_ldflags" ../$package/configure $type_configure $name_configure || exit 1
261         make $name_make || exit 1
262         make install $name_install || exit 1
263 )
264 }
265
266 ## urg, let's hope Cygnus uses rpm for packaging its next release
267 pack ()
268 {(
269         set -
270         package=$1
271
272         zip=$WWW/$package.zip
273         if [ -e $zip ]; then
274                 echo "$zip: package exists"
275                 echo "$zip: skipping"
276                 exit 0
277         fi
278
279         name=`echo $package | sed 's/-.*//'`
280         name_pack_install=`expand $name _pack_install`
281         install_root=/tmp/$package-install
282         install_prefix=$install_root/$NATIVE_PREFIX/$package
283
284         set -x
285         rm -rf $install_root
286         mkdir -p $install_prefix
287
288         cd $PREFIX/src/$type-$package || exit 1
289         make install prefix=$install_prefix $name_pack_install
290
291         ## duh, rename executables,
292         ## for people that use a dumb shell instead of bash
293         cd $install_prefix/bin &&
294         for i in `/bin/ls -d1 *`; do
295                 fix_extension $i .exe '.*Windows.*\(executable\).*'
296                 fix_extension $i .py '.*\(python\).*'
297         done
298
299         rm -f $zip
300         cd $install_root && zip -r $zip .$NATIVE_PREFIX
301 )
302 }
303 ##################
304 # end of functions
305 ##################
306
307 #
308 # setup
309 #
310
311 set -x
312 mkdir -p $ROOT
313 if [ ! -d $PREFIX ]; then
314         cd $ROOT
315         found=`find_path $cygwin_binary`
316         if [ "$found" = "" ]; then
317                 echo "$cygwin_binary: no such tarball"
318                 exit 1
319         fi
320         tar xzf $found
321         # urg, bug in gcc's cross-make configuration
322         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
323
324         cd $PREFIX
325
326         # urg, bug in gcc's cross-make configuration
327         rm -f include
328         ln -s $PREFIX/$TARGET_ARCH/include .
329 else
330         echo "$PREFIX: already exists"
331         echo "$cygwin_binary: skipping"
332 fi
333
334 # mingw
335 if [ ! -d $PREFIX/$TARGET_ARCH ]; then
336         cd $PREFIX
337         found=`find_path $mingw_binary`
338         if [ "$found" = "" ]; then
339                 echo "$mingw_binary: no such tarball"
340                 exit 1
341         fi
342         tar xzf $found
343
344         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
345         rm -f include
346         mkdir -p $PREFIX/i386-mingw32/include
347         ln -s $PREFIX/i386-mingw32 $TARGET_ARCH
348         ln -s $PREFIX/$TARGET_ARCH/include .
349 fi
350
351 if [ ! -e $NATIVE_PREFIX ]; then
352         ln -s $ROOT /Cygnus || exit 1
353 fi
354
355 mkdir -p $PREFIX/src
356 cd $PREFIX/src
357 PATH=$PATH:$PREFIX/bin
358
359 type=cross
360 for i in $cross_packages; do
361         if build $i; then
362                 true
363         else
364                 echo "$i: build failed"
365                 exit 1
366         fi
367 done
368
369 # urg, bug in gcc's cross-make install
370 mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
371 mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
372 ln -f $PREFIX/bin/$TARGET_ARCH-gcc $PREFIX/$TARGET_ARCH/bin/cc 
373 ln -f $PREFIX/bin/$TARGET_ARCH-c++ $PREFIX/$TARGET_ARCH/bin/c++
374 ln -f $PREFIX/bin/$TARGET_ARCH-g++ $PREFIX/$TARGET_ARCH/bin/g++
375
376 PATH=$PREFIX/$TARGET_ARCH/bin:$PREFIX/bin:$PATH 
377
378 mkdir -p $PREFIX/src
379 cd $PREFIX/src
380
381 set -x
382 type=native
383 for i in $native_packages; do
384         if build $i; then
385                 pack $i
386                 continue
387         fi
388         exit 1
389 done
390
391 rm -f $WWW/$CYGWIN_DLL.zip
392 cd $PREFIX/bin && zip $WWW/$CYGWIN_DLL.zip $CYGWIN_DLL