Patch for issue 845 and 828
[luatex.git] / build-luatex.sh
blobb2e4e25d19ea3c5e6beec679074a1d9df31d4dab
1 #!/usr/bin/env bash
2 # $Id: build.sh 4634 2013-04-21 14:45:45Z hhenkel $
4 # Copyright (c) 2005-2011 Martin Schröder <martin@luatex.org>
5 # Copyright (c) 2009-2011 Taco Hoekwater <taco@luatex.org>
6 # Copyright (c) 2013-2013 Luigi Scarso and Hans Hagen (mingw stuff)
8 # Permission to use, copy, modify, and distribute this software for any
9 # purpose with or without fee is hereby granted, provided that the above
10 # copyright notice and this permission notice appear in all copies.
12 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 # new script to build luatex binaries
21 # ----------
22 # Options:
23 # --make : only make, no make distclean; configure
24 # --parallel : make -j 2 -l 3.0
25 # --nostrip : do not strip binary
26 # --warnings= : enable compiler warnings
27 # --mingw : crosscompile for mingw32 from i-386linux
28 # --mingw32 : crosscompile 32 binary on unix
29 # --mingw64 : crosscompile 64 binary on unix
30 # --msys : crosscompile 32 binary on windows
31 # --msys32 : crosscompile 32 binary on windows
32 # --msys64 : crosscompile 64 binary on windows
33 # --host= : target system for mingw32 cross-compilation
34 # --build= : build system for mingw32 cross-compilation
35 # --arch= : crosscompile for ARCH on OS X
36 # --debug : CFLAGS="-g -O0" --warnings=max --nostrip
38 # L/H: we assume a 64 bit build system .. it took us two days of experimenting with all
39 # kind of permutations to figure it out .. partly due to tangle/tie dependencies and
40 # we're not there yes as there are messages with respect to popen and so
42 # todo:
44 # - generate ctangle and tie
45 # - get rid of otangle and tangle dependencies
46 # - don't generate bins we don't need
47 # - maybe make cario in mplib optional
49 # Patch suggested by Fabrice Popineau in texk/web2c/lib/lib.h: #define eof weof
51 $DEBUG
53 # try to find bash, in case the standard shell is not capable of
54 # handling the generated configure's += variable assignments
55 if which bash >/dev/null
56 then
57 CONFIG_SHELL=`which bash`
58 export CONFIG_SHELL
61 # try to find gnu make; we may need it
62 MAKE=make;
63 if make -v 2>&1| grep "GNU Make" >/dev/null
64 then
65 echo "Your make is a GNU-make; I will use that"
66 elif gmake -v >/dev/null 2>&1
67 then
68 MAKE=gmake;
69 export MAKE;
70 echo "You have a GNU-make installed as gmake; I will use that"
71 else
72 echo "I can't find a GNU-make; I'll try to use make and hope that works."
73 echo "If it doesn't, please install GNU-make."
76 ONLY_MAKE=FALSE
77 STRIP_LUATEX=TRUE
78 WARNINGS=yes
79 MINGWCROSS=FALSE
80 MINGWCROSS64=FALSE
81 MINGWMSYS=FALSE
82 MINGWMSYS64=FALSE
83 CONFHOST=
84 CONFBUILD=
85 MACCROSS=FALSE
86 JOBS_IF_PARALLEL=${JOBS_IF_PARALLEL:-3}
87 MAX_LOAD_IF_PARALLEL=${MAX_LOAD_IF_PARALLEL:-2}
89 CFLAGS="$CFLAGS"
91 until [ -z "$1" ]; do
92 case "$1" in
93 --make ) ONLY_MAKE=TRUE ;;
94 --nostrip ) STRIP_LUATEX=FALSE ;;
95 --debug ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-g -O0 $CFLAGS" ;;
96 --warnings=*) WARNINGS=`echo $1 | sed 's/--warnings=\(.*\)/\1/' ` ;;
97 --mingw ) MINGWCROSS=TRUE ;;
98 --mingw32 ) MINGWCROSS=TRUE ;;
99 --mingw64 ) MINGWCROSS64=TRUE ;;
100 --msys ) MINGWMSYS=TRUE ;;
101 --msys32 ) MINGWMSYS=TRUE ;;
102 --msys64 ) MINGWMSYS64=TRUE ;;
103 --host=* ) CONFHOST="$1" ;;
104 --build=* ) CONFBUILD="$1" ;;
105 --parallel ) MAKE="$MAKE -j $JOBS_IF_PARALLEL -l $MAX_LOAD_IF_PARALLEL" ;;
106 --arch=* ) MACCROSS=TRUE; ARCH=`echo $1 | sed 's/--arch=\(.*\)/\1/' ` ;;
107 * ) echo "ERROR: invalid build.sh parameter: $1"; exit 1 ;;
108 esac
109 shift
110 done
113 STRIP=strip
114 LUATEXEXE=luatex
116 case `uname` in
117 MINGW64* ) LUATEXEXE=luatex.exe ;;
118 MINGW32* ) LUATEXEXE=luatex.exe ;;
119 CYGWIN* ) LUATEXEXE=luatex.exe ;;
120 esac
122 WARNINGFLAGS=--enable-compiler-warnings=$WARNINGS
124 B=build
126 OLDPATH=$PATH
128 if [ "$MINGWCROSS" = "TRUE" ]
129 then
130 B=build-windows
131 PATH=`pwd`/extrabin/mingw:$PATH
132 LUATEXEXE=luatex.exe
133 CFLAGS="-mtune=nocona -g -O3 $CFLAGS"
134 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
135 CONFHOST="--host=i586-mingw32msvc"
136 CONFBUILD="--build=x86_64-unknown-linux-gnu"
137 STRIP="${CONFHOST#--host=}-strip"
138 LDFLAGS="-Wl,--large-address-aware $CFLAGS"
139 export CFLAGS CXXFLAGS LDFLAGS
142 if [ "$MINGWCROSS64" = "TRUE" ]
143 then
144 B=build-windows64
145 PATH=`pwd`/extrabin/mingw:$PATH
146 LUATEXEXE=luatex.exe
147 CFLAGS="-mtune=nocona -g -O3 -static-libgcc -static-libstdc++ $CFLAGS"
148 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
149 CONFHOST="--host=x86_64-w64-mingw32"
150 CONFBUILD="--build=x86_64-unknown-linux-gnu"
151 STRIP="${CONFHOST#--host=}-strip"
152 LDFLAGS="$CFLAGS"
153 export CFLAGS CXXFLAGS LDFLAGS
156 if [ "$MINGWMSYS" = "TRUE" ]
157 then
158 B=build-win32
159 PATH=`pwd`/extrabin/msys:$PATH
160 LUATEXEXE=luatex.exe
161 STRIP=strip.exe
162 CFLAGS="-mtune=nocona -m32 -g -O3 $CFLAGS"
163 CXXFLAGS="-mtune=nocona -m32 -g -O3 $CXXFLAGS"
164 CONFHOST="--host=i586-mingw32"
165 CONFBUILD="--build=x86_64-w64-mingw32"
166 LDFLAGS="-m32"
167 CPPFLAGS="-m32"
168 export CFLAGS CXXFLAGS LDFLAGS CPPFLAGS
171 if [ "$MINGWMSYS64" = "TRUE" ]
172 then
173 B=build-win64
174 PATH=`pwd`/extrabin/mingw:$PATH
175 LUATEXEXE=luatex.exe
176 STRIP=strip.exe
177 CFLAGS="-mtune=nocona -g -O3 $CFLAGS"
178 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
179 CONFHOST="--host=x86_64-w64-mingw32"
180 CONFBUILD="--build=x86_64-w64-mingw32"
181 LDFLAGS=""
182 CPPFLAGS=""
183 export CFLAGS CXXFLAGS LDFLAGS CPPFLAGS
186 if [ "$MACCROSS" = "TRUE" ]
187 then
188 # make sure that architecture parameter is valid
189 case $ARCH in
190 i386 | x86_64 | ppc | ppc64 ) ;;
191 * ) echo "ERROR: architecture $ARCH is not supported"; exit 1;;
192 esac
193 B=build-$ARCH
194 CFLAGS="-arch $ARCH -g -O2 $CFLAGS"
195 CXXFLAGS="-arch $ARCH -g -O2 $CXXFLAGS"
196 LDFLAGS="-arch $ARCH $LDFLAGS"
197 export CFLAGS CXXFLAGS LDFLAGS
200 if [ "$STRIP_LUATEX" = "FALSE" ]
201 then
202 export CFLAGS
205 # ----------
206 # clean up, if needed
207 if [ -r "$B"/Makefile -a $ONLY_MAKE = "FALSE" ]
208 then
209 rm -rf "$B"
210 elif [ ! -r "$B"/Makefile ]
211 then
212 ONLY_MAKE=FALSE
214 if [ ! -r "$B" ]
215 then
216 mkdir "$B"
219 # get a new svn version header
220 ( cd source ; ./texk/web2c/luatexdir/getluatexsvnversion.sh )
222 cd "$B"
224 if [ "$ONLY_MAKE" = "FALSE" ]
225 then
226 TL_MAKE=$MAKE ../source/configure $CONFHOST $CONFBUILD $WARNINGFLAGS\
227 --enable-cxx-runtime-hack \
228 --enable-silent-rules \
229 --disable-all-pkgs \
230 --disable-shared \
231 --disable-largefile \
232 --disable-ptex \
233 --disable-ipc \
234 --enable-dump-share \
235 --enable-mp \
236 --enable-luatex \
237 --without-system-harfbuzz \
238 --without-system-ptexenc \
239 --without-system-kpathsea \
240 --without-system-poppler \
241 --without-system-xpdf \
242 --without-system-freetype \
243 --without-system-freetype2 \
244 --without-system-gd \
245 --without-system-libpng \
246 --without-system-teckit \
247 --without-system-zlib \
248 --without-system-t1lib \
249 --without-system-icu \
250 --without-system-graphite \
251 --without-system-zziplib \
252 --without-mf-x-toolkit --without-x \
253 || exit 1
256 $MAKE
258 # the fact that these makes inside libs/ have to be done manually for the cross
259 # compiler hints that something is wrong in the --enable/--disable switches above,
260 # but I am too lazy to look up what is wrong exactly.
261 # (perhaps more files needed to be copied from TL?)
263 (cd libs/zziplib; $MAKE all )
264 (cd libs/zlib; $MAKE all )
265 (cd libs/libpng; $MAKE all )
266 (cd libs/poppler; $MAKE all )
268 (cd texk/kpathsea; $MAKE )
269 (cd texk/web2c; $MAKE $LUATEXEXE )
271 # go back
272 cd ..
274 if [ "$STRIP_LUATEX" = "TRUE" ] ;
275 then
276 $STRIP "$B"/texk/web2c/$LUATEXEXE
277 else
278 echo "luatex binary not stripped"
281 PATH=$OLDPATH
283 # show the results
284 ls -l "$B"/texk/web2c/$LUATEXEXE