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