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