]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/make-cygwin-cross.sh
patch::: 1.3.38.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 #  * 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 #  * guile-1.3.4.tar.gz
27 #
28 #  * lilypond-1.3.38.jcn1.tar.gz
29 #
30 #  * lots of disk space, ca 353MB
31 #
32
33 ################
34 # config section
35 ################
36
37 ROOT=/usr/src/cygwin-net-485
38 PREFIX=$ROOT/usr
39 NATIVE_PREFIX=/Cygnus/usr
40
41 # urg
42 DEVEL=/home/fred
43 WWW=$DEVEL/WWW/lilypond/gnu-windows
44 #WWW=/tmp
45
46 CYGWIN_SOURCE=$DEVEL/sourceware.cygnus.com/pub/cygwin/private/cygwin-net-485
47 SOURCE_PATH=$DEVEL/usr/src/releases:$DEVEL/usr/src/patches:$DEVEL/usr/src/lilypond/Documentation/ntweb
48
49 HOST=`uname -m`-gnu-`uname -s | tr '[A-Z]' '[a-z]'`
50
51 cygwin_binary=cygwin-20000301.tar.gz
52 TARGET_ARCH=i686-pc-cygwin
53 CYGWIN_DLL=cygwin1-net-485.dll
54
55 cross_packages="
56 binutils-19990818
57 gcc-2.95.2
58 flex
59 bison
60 "
61
62 not_yet_needed=cygwin-2000301
63
64 cross_configure='--prefix=$PREFIX --target=$TARGET_ARCH'
65 ##native_configure='--prefix=$NATIVE_PREFIX --target=$TARGET_ARCH'
66 gcc_make='LANGUAGES="c++"'
67 cygwin_make='-k || true'
68
69 native_configure='--target=$TARGET_ARCH --build=$TARGET_ARCH --host=$HOST --oldincludedir=$PREFIX/include --prefix=$NATIVE_PREFIX'
70
71 guile_patch='guile-1.3.4-gnu-windows.patch'
72 guile_configure='--enable-sizeof-int=4 --enable-sizeof-long=4 --enable-restartable-syscalls=yes'
73 guile_make='oldincludedir=$PREFIX/include'
74
75 lilypond_version=@TOPLEVEL_VERSION@
76 #lilypond_prefix="$NATIVE_PREFIX/lilypond-$lilypond_version"
77 lilypond_ldflags='-L$PREFIX/lib -lguile $PREFIX/bin/$CYGWIN_DLL'
78 #lilypond_configure='--prefix=$lilypond_prefix'
79 ## URG, help2man: doesn't know about cross-compilation.
80 #lilypond_make='-k || make -k || true'
81 lilypond_patch=lilypond-manpages.patch
82 lilypond_install='--just-print'
83
84 native_packages="
85 guile-1.3.4
86 lilypond-$lilypond_version
87 "
88
89
90 #######################
91 # end of config section
92 #######################
93
94 cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
95 cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs`
96 source_path=`echo $SOURCE_PATH:$cygwin_source_path | sed 's/:/ /g'`
97
98 # mingw doesn't work yet. 
99 #TARGET_ARCH=i686-pc-mingw32
100 #
101 # building cross-compiler i686-pc-mingw32-gcc exists on:
102 #
103 #  /usr/src/cygwin-mingw/usr/src/cross-gcc-2.95.2/gcc/xgcc -B/usr/src/cygwin-mingw/usr/src/cross-gcc-2.95.2/gcc/ -B/usr/src/cygwin-mingw/usr/i686-pc-mingw32/bin/ -I/usr/src/cygwin-mingw/usr/i686-pc-mingw32/include -O2 -I../../gcc-2.95.2/gcc/../winsup/include -DCROSS_COMPILE -DIN_GCC     -g -O2 -I./include   -g1  -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED   -I. -I../../gcc-2.95.2/gcc -I../../gcc-2.95.2/gcc/config -I../../gcc-2.95.2/gcc/../include -c
104 #
105 # with:
106 #
107 #  ../../gcc-2.95.2/gcc/libgcc2.c:2582: conflicting types for `getpagesize'
108 #/usr/src/cygwin-mingw/usr/i686-pc-mingw32/include/sys/unistd.h:43: previous declaration of `getpagesize'
109 # it seems that __CYGWIN__ is not defined in mingw compiler/or compiler isn't
110 # fully ported to mingw
111
112 ###########
113 # functions
114 ###########
115
116 untar ()
117 {(
118         set -x
119         tarball=$1
120         dest_dir=$2
121
122         first_dir=`tar tzf $tarball | head -1`
123         src_dir=`dirname $first_dir`
124
125         if [ "$src_dir" = "src" -o "$src_dir" = "./src" \
126           -o "$src_dir" = "." ]; then
127                 src_dir=$first_dir
128         fi
129
130         tar xzf $tarball
131
132         if [ "$src_dir" != "$dest_dir" -a "$src_dir" != "$dest_dir/" ]; then
133                 mv $src_dir $dest_dir
134                 rm -rf ./$first_dir
135         fi
136 )
137 }
138
139 expand ()
140 {(
141
142         set -
143         string=`eval echo $\`eval echo ${1}${2}\``
144         eval echo $string
145 )
146 }
147
148 build ()
149 {(
150         package=$1
151         set -
152         if [ -d $package ]; then
153                 echo "$package: directory exists"
154                 echo "$package: skipping"
155                 exit 0
156         fi
157
158         name=`echo $package | sed 's/-.*//'`
159         name_patch=`expand $name _patch`
160         name_ldflags=`expand $name _ldflags`
161         name_configure=`expand $name _configure`
162         type_configure=`expand $type _configure`
163         name_make=`expand $name _make`
164         name_install=`expand $name _install`
165
166         found=`find_path $package*src.tar.gz`
167         if [ "$found" = "" ]; then
168                 found=`find_path $package.tar.gz`
169         fi
170         if [ "$found" = "" ]; then
171                 found=`find_path $name*tar.gz`
172         fi
173         if [ "$found" = "" ]; then
174                 echo "$package: no such tarball"
175                 exit 1
176         fi
177         
178         untar $found $package
179         if [ "x$name_patch" != "x" ]; then
180                 (
181                 cd $package
182                 found=`find_path $name_patch`
183                 if [ "$found" = "" ]; then
184                         echo "$name_patch: no such file"
185                         exit 1
186                 fi
187                 patch -p1 -E < $found
188                 )
189         fi
190         set -x
191         mkdir $type-$package
192         cd $type-$package
193
194         rm -f config.cache
195         LDFLAGS="$name_ldflags" ../$package/configure $type_configure $name_configure || exit 1
196         make $name_make || exit 1
197         make install $name_install || exit 1
198 )
199 }
200
201 ## urg, let's hope Cygnus uses rpm for packaging its next release
202 pack ()
203 {(
204         set -
205         package=$1
206         name=`echo $package | sed 's/-.*//'`
207         name_pack_install=`expand $name _pack_install`
208         install_root=/tmp/$package-install
209         install_prefix=$install_root/$NATIVE_PREFIX
210
211         set -x
212         rm -rf $install_root
213         mkdir -p $install_prefix
214
215         cd $PREFIX/src/$type-$package || exit 1
216         make install prefix=$install_prefix $name_pack_install
217
218         ## duh, rename executables,
219         ## for people that use a dumb shell instead of bash
220         cd $install_prefix/bin &&
221         for i in `/bin/ls -d1 *`; do
222                 base=`basename $i .exe`
223                 if [ $base.exe != $i ]; then
224                         type="`file $i`"
225                         if expr "$type" : '.*Windows.*\(executable\).*'; then
226                                 mv -f $i $base.exe
227                         fi
228                 fi
229         done
230         rm -f $WWW/$package.zip
231         cd $install_root && zip -r $WWW/$package.zip .$NATIVE_PREFIX
232 )
233 }
234
235 find_path ()
236 {(
237         set -
238         expr=$1
239         found=
240         for i in $source_path; do
241                 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
242                 if [ -e "$found" ]; then
243                         break
244                 fi
245         done
246         echo $found
247 )
248 }
249 ##################
250 # end of functions
251 ##################
252
253 #
254 # setup
255 #
256
257 set -x
258 mkdir -p $ROOT
259 if [ ! -d $PREFIX ]; then
260         cd $ROOT
261         found=`find_path $cygwin_binary`
262         if [ "$found" = "" ]; then
263                 echo "$cygwin_binary: no such tarball"
264                 exit 1
265         fi
266         tar xzf $found
267         # urg, bug in gcc's cross-make configuration
268         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
269
270         cd $PREFIX
271         # urg, bug in gcc's cross-make configuration
272         if [ ! -e include ]; then
273                 #mv include huh-include
274                 # not target-arch, but [i686-]pc-cygwin!
275                 ln -s $PREFIX/i686-pc-cygwin/include .
276                 # these necessary only for mingw32
277                 ln -s $PREFIX/i686-pc-cygwin/include $TARGET_ARCH
278                 ln -s $PREFIX/include $PREFIX/$TARGET_ARCH/include
279         fi
280 else
281         echo "$PREFIX: already exists"
282         echo "$cygwin_binary: skipping"
283 fi
284
285 if [ ! -e $NATIVE_PREFIX ]; then
286         ln -s $ROOT /Cygnus || exit 1
287 fi
288
289 mkdir -p $PREFIX/src
290 cd $PREFIX/src
291 PATH=$PATH:$PREFIX/bin
292
293 type=cross
294 for i in $cross_packages; do
295         if build $i; then
296                 true
297         else
298                 echo "$i: build failed"
299                 exit 1
300         fi
301 done
302
303 # urg, bug in gcc's cross-make install
304 mv -f $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
305 ln -f $PREFIX/bin/$TARGET_ARCH-gcc $PREFIX/$TARGET_ARCH/bin/cc 
306 ln -f $PREFIX/bin/$TARGET_ARCH-c++ $PREFIX/$TARGET_ARCH/bin/c++
307 ln -f $PREFIX/bin/$TARGET_ARCH-g++ $PREFIX/$TARGET_ARCH/bin/g++
308
309 PATH=$PREFIX/$TARGET_ARCH/bin:$PREFIX/bin:$PATH 
310
311 mkdir -p $PREFIX/src
312 cd $PREFIX/src
313
314 set -x
315 type=native
316 for i in $native_packages; do
317         if build $i; then
318                 pack $i
319                 continue
320         fi
321         exit 1
322 done
323
324 rm -f $WWW/$CYGWIN_DLL.zip
325 cd $PREFIX/bin && zip $WWW/$CYGWIN_DLL.zip $CYGWIN_DLL