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