beta-0.89.2
[luatex.git] / build.sh
blob53ce60875c34becfc597628ac75b6c05a8141f65
1 #!/usr/bin/env bash
2 # $Id: build.sh 5534 2015-11-17 18:12:17Z luigi $
4 # Copyright (c) 2005-2011 Martin Schröder <martin@luatex.org>
5 # Copyright (c) 2009-2014 Taco Hoekwater <taco@luatex.org>
6 # Copyright (c) 2012-2014 Luigi Scarso <luigi@luatex.org>
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 # --jit : also build luajittex
24 # --make : only make, no make distclean; configure
25 # --parallel : make -j 2 -l 3.0
26 # --nostrip : do not strip binary
27 # --warnings= : enable compiler warnings
28 # --mingw : crosscompile for mingw32 from x86_64linux
29 # --mingw32 : crosscompile for mingw32 from x86_64linux
30 # --mingw64 : crosscompile for mingw64 from x86_64linux
31 # --host= : target system for mingw32 cross-compilation
32 # --build= : build system for mingw32 cross-compilation
33 # --arch= : crosscompile for ARCH on OS X
34 # --clang : use clang & clang++
35 # --debug : CFLAGS="-g -O0" --warnings=max --nostrip
36 $DEBUG
38 # try to find bash, in case the standard shell is not capable of
39 # handling the generated configure's += variable assignments
40 if which bash >/dev/null
41 then
42 CONFIG_SHELL=`which bash`
43 export CONFIG_SHELL
46 # try to find gnu make; we may need it
47 MAKE=make;
48 if make -v 2>&1| grep "GNU Make" >/dev/null
49 then
50 echo "Your make is a GNU-make; I will use that"
51 elif gmake -v >/dev/null 2>&1
52 then
53 MAKE=gmake;
54 export MAKE;
55 echo "You have a GNU-make installed as gmake; I will use that"
56 else
57 echo "I can't find a GNU-make; I'll try to use make and hope that works."
58 echo "If it doesn't, please install GNU-make."
61 BUILDJIT=FALSE
62 ONLY_MAKE=FALSE
63 STRIP_LUATEX=TRUE
64 WARNINGS=yes
65 MINGWCROSS=FALSE
66 MINGWCROSS64=FALSE
67 MACCROSS=FALSE
68 CLANG=FALSE
69 CONFHOST=
70 CONFBUILD=
71 JOBS_IF_PARALLEL=${JOBS_IF_PARALLEL:-3}
72 MAX_LOAD_IF_PARALLEL=${MAX_LOAD_IF_PARALLEL:-2}
73 TARGET_CC=gcc
74 TARGET_TCFLAGS=
76 CFLAGS="$CFLAGS"
77 CXXFLAGS="$CXXFLAGS"
79 until [ -z "$1" ]; do
80 case "$1" in
81 --jit ) BUILDJIT=TRUE ;;
82 --nojit ) BUILDJIT=FALSE ;;
83 --make ) ONLY_MAKE=TRUE ;;
84 --nostrip ) STRIP_LUATEX=FALSE ;;
85 --debug ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-O0 -g -g3 $CFLAGS" ; CXXFLAGS="-O0 -g -g3 $CXXFLAGS" ;;
86 --clang ) export CC=clang; export CXX=clang++ ; TARGET_CC=$CC ; CLANG=TRUE ;;
87 --warnings=*) WARNINGS=`echo $1 | sed 's/--warnings=\(.*\)/\1/' ` ;;
88 --mingw ) MINGWCROSS=TRUE ;;
89 --mingw32 ) MINGWCROSS=TRUE ;;
90 --mingw64 ) MINGWCROSS64=TRUE ;;
91 --host=* ) CONFHOST="$1" ;;
92 --build=* ) CONFBUILD="$1" ;;
93 --parallel ) MAKE="$MAKE -j $JOBS_IF_PARALLEL -l $MAX_LOAD_IF_PARALLEL" ;;
94 --arch=* ) MACCROSS=TRUE; ARCH=`echo $1 | sed 's/--arch=\(.*\)/\1/' ` ;;
95 * ) echo "ERROR: invalid build.sh parameter: $1"; exit 1 ;;
96 esac
97 shift
98 done
101 STRIP=strip
102 LUATEXEXEJIT=luajittex
103 LUATEXEXE=luatex
105 case `uname` in
106 MINGW32* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
107 CYGWIN* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
108 Darwin ) STRIP="strip -u -r" ;;
109 esac
111 WARNINGFLAGS=--enable-compiler-warnings=$WARNINGS
113 B=build
115 if [ "$CLANG" = "TRUE" ]
116 then
117 B=build-clang
120 if [ "$MINGWCROSS64" = "TRUE" ]
121 then
122 B=build-windows64
123 LUATEXEXEJIT=luajittex.exe
124 LUATEXEXE=luatex.exe
125 OLDPATH=$PATH
126 PATH=/usr/mingw32/bin:$PATH
127 PATH=`pwd`/extrabin/mingw:$PATH
128 CFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CFLAGS"
129 CXXFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CXXFLAGS"
130 : ${CONFHOST:=--host=x86_64-w64-mingw32}
131 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
132 RANLIB="${CONFHOST#--host=}-ranlib"
133 STRIP="${CONFHOST#--host=}-strip"
134 LDFLAGS="${LDFLAGS} -fno-lto -fno-use-linker-plugin -static-libgcc -static-libstdc++"
135 export CFLAGS CXXFLAGS LDFLAGS
138 if [ "$MINGWCROSS" = "TRUE" ]
139 then
140 B=build-windows
141 LUATEXEXEJIT=luajittex.exe
142 LUATEXEXE=luatex.exe
143 OLDPATH=$PATH
144 PATH=/usr/mingw32/bin:$PATH
145 PATH=`pwd`/extrabin/mingw:$PATH
146 CFLAGS="-mtune=nocona -g -O3 $CFLAGS"
147 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
148 : ${CONFHOST:=--host=i586-mingw32msvc}
149 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
150 RANLIB="${CONFHOST#--host=}-ranlib"
151 STRIP="${CONFHOST#--host=}-strip"
152 LDFLAGS="-Wl,--large-address-aware -Wl,--stack,2621440 $CFLAGS"
153 export CFLAGS CXXFLAGS LDFLAGS BUILDCXX BUILDCC
157 if [ "$MACCROSS" = "TRUE" ]
158 then
159 # make sure that architecture parameter is valid
160 case $ARCH in
161 i386 | x86_64 | ppc | ppc64 ) ;;
162 * ) echo "ERROR: architecture $ARCH is not supported"; exit 1;;
163 esac
164 B=build-$ARCH
165 CFLAGS="-arch $ARCH -g -O2 $CFLAGS"
166 CXXFLAGS="-arch $ARCH -g -O2 $CXXFLAGS"
167 LDFLAGS="-arch $ARCH $LDFLAGS"
168 export CFLAGS CXXFLAGS LDFLAGS
172 ### Dirty trick to check Darwin X86_64
173 # TARGET_TESTARCH=$( ($TARGET_CC $TARGET_TCFLAGS -E source/libs/luajit/luajit-2.0.2/src/lj_arch.h -dM|grep -q LJ_TARGET_X64 && echo x64) || echo NO)
174 # HOST_SYS=$(uname -s)
175 # echo HOST_SYS=$HOST_SYS
176 # echo TARGET_TESTARCH=$TARGET_TESTARCH
177 # if [ $HOST_SYS == "Darwin" ]
178 # then
179 # if [ $TARGET_TESTARCH == "x64" ]
180 # then
181 # export LDFLAGS="-pagezero_size 10000 -image_base 100000000 $LDFLAGS"
182 # echo Setting LDFLAGS=$LDFLAGS
183 # fi
184 # fi
187 if [ "$STRIP_LUATEX" = "FALSE" ]
188 then
189 export CFLAGS
190 export CXXFLAGS
193 # ----------
194 # clean up, if needed
195 if [ -r "$B"/Makefile -a $ONLY_MAKE = "FALSE" ]
196 then
197 rm -rf "$B"
198 elif [ ! -r "$B"/Makefile ]
199 then
200 ONLY_MAKE=FALSE
202 if [ ! -r "$B" ]
203 then
204 mkdir "$B"
207 # get a new svn version header
208 if [ "$WARNINGS" = "max" ]
209 then
210 rm -f source/texk/web2c/luatexdir/luatex_svnversion.h
212 ( cd source ; ./texk/web2c/luatexdir/getluatexsvnversion.sh )
214 cd "$B"
216 JITENABLE=
217 if [ "$BUILDJIT" = "TRUE" ]
218 then
219 JITENABLE="--enable-luajittex --without-system-luajit "
223 if [ "$ONLY_MAKE" = "FALSE" ]
224 then
225 TL_MAKE=$MAKE ../source/configure $CONFHOST $CONFBUILD $WARNINGFLAGS\
226 --enable-cxx-runtime-hack \
227 --enable-silent-rules \
228 --disable-all-pkgs \
229 --disable-shared \
230 --disable-largefile \
231 --disable-ptex \
232 --disable-ipc \
233 --enable-dump-share \
234 --enable-mp \
235 --enable-luatex $JITENABLE \
236 --without-system-ptexenc \
237 --without-system-kpathsea \
238 --without-system-poppler \
239 --without-system-xpdf \
240 --without-system-freetype \
241 --without-system-freetype2 \
242 --without-system-gd \
243 --without-system-libpng \
244 --without-system-teckit \
245 --without-system-zlib \
246 --without-system-t1lib \
247 --without-system-icu \
248 --without-system-graphite \
249 --without-system-zziplib \
250 --without-mf-x-toolkit --without-x \
251 || exit 1
254 $MAKE
256 # the fact that these makes inside libs/ have to be done manually for the cross
257 # compiler hints that something is wrong in the --enable/--disable switches above,
258 # but I am too lazy to look up what is wrong exactly.
259 # (perhaps more files needed to be copied from TL?)
261 (cd libs; $MAKE all )
262 (cd libs/zzip; $MAKE all )
263 (cd libs/zlib; $MAKE all )
264 (cd libs/libpng; $MAKE all )
265 (cd libs/poppler; $MAKE all )
266 (cd texk; $MAKE web2c/Makefile)
267 (cd texk/kpathsea; $MAKE )
268 if [ "$BUILDJIT" = "TRUE" ]
269 then
270 (cd libs/luajit; $MAKE all )
271 (cd texk/web2c; $MAKE $LUATEXEXEJIT)
273 (cd texk/web2c; $MAKE $LUATEXEXE )
276 # go back
277 cd ..
279 if [ "$STRIP_LUATEX" = "TRUE" ] ;
280 then
281 if [ "$BUILDJIT" = "TRUE" ]
282 then
283 $STRIP "$B"/texk/web2c/$LUATEXEXEJIT
285 $STRIP "$B"/texk/web2c/$LUATEXEXE
286 else
287 echo "lua(jit)tex binary not stripped"
290 if [ "$MINGWCROSS" = "TRUE" ]
291 then
292 PATH=$OLDPATH
295 # show the result
296 if [ "$BUILDJIT" = "TRUE" ]
297 then
298 ls -l "$B"/texk/web2c/$LUATEXEXEJIT
300 ls -l "$B"/texk/web2c/$LUATEXEXE