]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/make-cygwin-cross.sh
patch::: 1.3.38.jcn3
[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'
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_configure='--enable-sizeof-int=4 --enable-sizeof-long=4 --enable-restartable-syscalls=yes'
110 guile_make='oldincludedir=$PREFIX/include'
111
112 # We need to get guile properly installed for cross-development, ie
113 # at our prefix: $PREFIX.  When packaging, the prefix we configured
114 # for, will be used.
115 #
116 guile_install='prefix=$PREFIX'
117
118 lilypond_version=@TOPLEVEL_VERSION@
119 if [ $target = mingw ]; then
120         lilypond_cflags='-I $PREFIX/$TARGET_ARCH/include -I $PREFIX/i686-pc-cygwin/include'
121 fi
122 lilypond_ldflags='-L$PREFIX/lib -lguile $PREFIX/bin/$CYGWIN_DLL'
123 #lilypond_configure='--prefix=$lilypond_prefix'
124 ## URG, help2man: doesn't know about cross-compilation.
125 #lilypond_make='-k || make -k || true'
126 lilypond_patch=lilypond-manpages.patch
127 # Don't install lilypond
128 lilypond_install='--just-print'
129
130 native_packages="
131 guile-1.3.4
132 lilypond-$lilypond_version
133 "
134
135 #######################
136 # end of config section
137 #######################
138
139 cygwin_dirs=`/bin/ls -d1 $CYGWIN_SOURCE/*`
140 cygwin_source_path=`echo $CYGWIN_SOURCE $cygwin_dirs`
141 source_path=`echo $SOURCE_PATH:$cygwin_source_path | sed 's/:/ /g'`
142
143 ###########
144 # functions
145 ###########
146
147 untar ()
148 {(
149         set -x
150         tarball=$1
151         dest_dir=$2
152
153         first_dir=`tar tzf $tarball | head -1`
154         src_dir=`dirname $first_dir`
155
156         if [ "$src_dir" = "src" -o "$src_dir" = "./src" \
157           -o "$src_dir" = "." ]; then
158                 src_dir=$first_dir
159         fi
160
161         tar xzf $tarball
162
163         if [ "$src_dir" != "$dest_dir" -a "$src_dir" != "$dest_dir/" ]; then
164                 mv $src_dir $dest_dir
165                 rm -rf ./$first_dir
166         fi
167 )
168 }
169
170 expand ()
171 {(
172
173         set -
174         string=`eval echo $\`eval echo ${1}${2}\``
175         eval echo $string
176 )
177 }
178
179 find_path ()
180 {(
181         set -
182         expr=$1
183         found=
184         for i in $source_path; do
185                 found=`/bin/ls -d1 $i/$expr 2>/dev/null | head -1`
186                 if [ -e "$found" ]; then
187                         break
188                 fi
189         done
190         echo $found
191 )
192 }
193
194 fix_extension ()
195 {
196         file=$1
197         ext=$2
198         expr="$3"
199         base=`basename $file $ext`
200         if [ $base$ext != $i ]; then
201                 type="`file $file`"
202                 if expr "$type" : "$expr"; then
203                         mv -f $file $base$ext
204                 fi
205         fi
206 }
207
208 build ()
209 {(
210         package=$1
211         set -
212         if [ -d $package ]; then
213                 echo "$package: directory exists"
214                 echo "$package: skipping"
215                 exit 0
216         fi
217
218         name=`echo $package | sed 's/-.*//'`
219         name_cflags=`expand $name _cflags`
220         name_ldflags=`expand $name _ldflags`
221         name_configure=`expand $name _configure`
222         type_configure=`expand $type _configure`
223         name_make=`expand $name _make`
224         name_install=`expand $name _install`
225
226         found=`find_path $package*src.tar.gz`
227         if [ "$found" = "" ]; then
228                 found=`find_path $package.tar.gz`
229         fi
230         if [ "$found" = "" ]; then
231                 found=`find_path $name*tar.gz`
232         fi
233         if [ "$found" = "" ]; then
234                 echo "$package: no such tarball"
235                 exit 1
236         fi
237         
238         untar $found $package
239         patch=`expand $name _patch`
240         count=0
241         while [ "x$patch" != "x" ]; do
242                 (
243                 cd $package
244                 found=`find_path $patch`
245                 if [ "$found" = "" ]; then
246                         echo "$patch: no such file"
247                         exit 1
248                 fi
249                 patch -p1 -E < $found
250                 )
251                 count=`expr $count + 1`
252                 patch=`expand $name _patch$count`
253         done
254         set -x
255         mkdir $type-$package
256         cd $type-$package
257
258         rm -f config.cache
259         CFLAGS="$name_cflags" LDFLAGS="$name_ldflags" ../$package/configure $type_configure $name_configure || exit 1
260         make $name_make || exit 1
261         make install $name_install || exit 1
262 )
263 }
264
265 ## urg, let's hope Cygnus uses rpm for packaging its next release
266 pack ()
267 {(
268         set -
269         package=$1
270         name=`echo $package | sed 's/-.*//'`
271         name_pack_install=`expand $name _pack_install`
272         install_root=/tmp/$package-install
273         install_prefix=$install_root/$NATIVE_PREFIX/$package
274
275         set -x
276         rm -rf $install_root
277         mkdir -p $install_prefix
278
279         cd $PREFIX/src/$type-$package || exit 1
280         make install prefix=$install_prefix $name_pack_install
281
282         ## duh, rename executables,
283         ## for people that use a dumb shell instead of bash
284         cd $install_prefix/bin &&
285         for i in `/bin/ls -d1 *`; do
286                 fix_extension $i .exe '.*Windows.*\(executable\).*'
287                 fix_extension $i .py '.*\(python\).*'
288         done
289
290         rm -f $WWW/$package.zip
291         cd $install_root && zip -r $WWW/$package.zip .$NATIVE_PREFIX
292 )
293 }
294 ##################
295 # end of functions
296 ##################
297
298 #
299 # setup
300 #
301
302 set -x
303 mkdir -p $ROOT
304 if [ ! -d $PREFIX ]; then
305         cd $ROOT
306         found=`find_path $cygwin_binary`
307         if [ "$found" = "" ]; then
308                 echo "$cygwin_binary: no such tarball"
309                 exit 1
310         fi
311         tar xzf $found
312         # urg, bug in gcc's cross-make configuration
313         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
314
315         cd $PREFIX
316
317         # urg, bug in gcc's cross-make configuration
318         rm -f include
319         ln -s $PREFIX/$TARGET_ARCH/include .
320 else
321         echo "$PREFIX: already exists"
322         echo "$cygwin_binary: skipping"
323 fi
324
325 # mingw
326 if [ ! -d $PREFIX/$TARGET_ARCH ]; then
327         cd $PREFIX
328         found=`find_path $mingw_binary`
329         if [ "$found" = "" ]; then
330                 echo "$mingw_binary: no such tarball"
331                 exit 1
332         fi
333         tar xzf $found
334
335         mkdir -p $PREFIX/lib/gcc-lib/$TARGET_ARCH/2.95.2
336         rm -f include
337         mkdir -p $PREFIX/i386-mingw32/include
338         ln -s $PREFIX/i386-mingw32 $TARGET_ARCH
339         ln -s $PREFIX/$TARGET_ARCH/include .
340 fi
341
342 if [ ! -e $NATIVE_PREFIX ]; then
343         ln -s $ROOT /Cygnus || exit 1
344 fi
345
346 mkdir -p $PREFIX/src
347 cd $PREFIX/src
348 PATH=$PATH:$PREFIX/bin
349
350 type=cross
351 for i in $cross_packages; do
352         if build $i; then
353                 true
354         else
355                 echo "$i: build failed"
356                 exit 1
357         fi
358 done
359
360 # urg, bug in gcc's cross-make install
361 mv $PREFIX/bin/cygwin1.dll $PREFIX/bin/$CYGWIN_DLL
362 mv $PREFIX/bin/mingwc10.dll $PREFIX/bin/$MINGW_DLL
363 ln -f $PREFIX/bin/$TARGET_ARCH-gcc $PREFIX/$TARGET_ARCH/bin/cc 
364 ln -f $PREFIX/bin/$TARGET_ARCH-c++ $PREFIX/$TARGET_ARCH/bin/c++
365 ln -f $PREFIX/bin/$TARGET_ARCH-g++ $PREFIX/$TARGET_ARCH/bin/g++
366
367 PATH=$PREFIX/$TARGET_ARCH/bin:$PREFIX/bin:$PATH 
368
369 mkdir -p $PREFIX/src
370 cd $PREFIX/src
371
372 set -x
373 type=native
374 for i in $native_packages; do
375         if build $i; then
376                 pack $i
377                 continue
378         fi
379         exit 1
380 done
381
382 rm -f $WWW/$CYGWIN_DLL.zip
383 cd $PREFIX/bin && zip $WWW/$CYGWIN_DLL.zip $CYGWIN_DLL