use the _new macro instead of _old also in trunk (HH)
[luatex.git] / build.sh
blob9d47859f5432361fe8e59c16eed63715d360082c
1 #!/usr/bin/env bash
2 # $Id$
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 # --debugopt : CFLAGS="-g -O3" --warnings=max --nostrip
37 $DEBUG
38 #export CFLAGS="-D_FORTIFY_SOURCE=2 -O3"
39 #export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
41 # try to find bash, in case the standard shell is not capable of
42 # handling the generated configure's += variable assignments
43 if which bash >/dev/null
44 then
45 CONFIG_SHELL=`which bash`
46 export CONFIG_SHELL
49 # try to find gnu make; we may need it
50 MAKE=make
51 if make -v 2>&1| grep "GNU Make" >/dev/null
52 then
53 echo "Your make is a GNU-make; I will use that"
54 elif gmake -v >/dev/null 2>&1
55 then
56 MAKE=gmake;
57 export MAKE;
58 echo "You have a GNU-make installed as gmake; I will use that"
59 else
60 echo "I can't find a GNU-make; I'll try to use make and hope that works."
61 echo "If it doesn't, please install GNU-make."
64 BUILDJIT=FALSE
65 ONLY_MAKE=FALSE
66 STRIP_LUATEX=TRUE
67 WARNINGS=yes
68 MINGWCROSS=FALSE
69 MINGWCROSS64=FALSE
70 MACCROSS=FALSE
71 CLANG=FALSE
72 CONFHOST=
73 CONFBUILD=
74 JOBS_IF_PARALLEL=${JOBS_IF_PARALLEL:-8}
75 MAX_LOAD_IF_PARALLEL=${MAX_LOAD_IF_PARALLEL:-8}
76 TARGET_CC=gcc
77 TARGET_TCFLAGS=
79 CFLAGS="$CFLAGS"
80 CXXFLAGS="$CXXFLAGS"
82 until [ -z "$1" ]; do
83 case "$1" in
84 --jit ) BUILDJIT=TRUE ;;
85 --nojit ) BUILDJIT=FALSE ;;
86 --make ) ONLY_MAKE=TRUE ;;
87 --nostrip ) STRIP_LUATEX=FALSE ;;
88 --debugopt ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-O3 -g -g3 $CFLAGS" ; CXXFLAGS="-O3 -g -g3 $CXXFLAGS" ;;
89 --debug ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-O0 -g -g3 $CFLAGS" ; CXXFLAGS="-O0 -g -g3 $CXXFLAGS" ;;
90 --clang ) export CC=clang; export CXX=clang++ ; TARGET_CC=$CC ; CLANG=TRUE ;;
91 --warnings=*) WARNINGS=`echo $1 | sed 's/--warnings=\(.*\)/\1/' ` ;;
92 --mingw ) MINGWCROSS=TRUE ;;
93 --mingw32 ) MINGWCROSS=TRUE ;;
94 --mingw64 ) MINGWCROSS64=TRUE ;;
95 --host=* ) CONFHOST="$1" ;;
96 --build=* ) CONFBUILD="$1" ;;
97 --parallel ) MAKE="$MAKE -j $JOBS_IF_PARALLEL -l $MAX_LOAD_IF_PARALLEL" ;;
98 --arch=* ) MACCROSS=TRUE; ARCH=`echo $1 | sed 's/--arch=\(.*\)/\1/' ` ;;
99 * ) echo "ERROR: invalid build.sh parameter: $1"; exit 1 ;;
100 esac
101 shift
102 done
105 STRIP=strip
106 LUATEXEXEJIT=luajittex
107 LUATEXEXE=luatex
109 case `uname` in
110 MINGW32* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
111 CYGWIN* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
112 Darwin ) STRIP="strip -u -r" ;;
113 esac
115 WARNINGFLAGS=--enable-compiler-warnings=$WARNINGS
117 B=build
119 ## Useful for cross-compilation for ARM
120 if [ "x$CONFHOST" != "x" ]
121 then
122 B="build-$CONFHOST"
123 B=`printf "$B"| sed 's/--host=//'`
126 if [ "$CLANG" = "TRUE" ]
127 then
128 B=build-clang
131 if [ "$MINGWCROSS64" = "TRUE" ]
132 then
133 B=build-windows64
134 LUATEXEXEJIT=luajittex.exe
135 LUATEXEXE=luatex.exe
136 OLDPATH=$PATH
137 PATH=/usr/mingw32/bin:$PATH
138 PATH=`pwd`/extrabin/mingw:$PATH
139 CFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CFLAGS"
140 CXXFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CXXFLAGS"
141 : ${CONFHOST:=--host=x86_64-w64-mingw32}
142 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
143 RANLIB="${CONFHOST#--host=}-ranlib"
144 STRIP="${CONFHOST#--host=}-strip"
145 LDFLAGS="${LDFLAGS} -fno-lto -fno-use-linker-plugin -static-libgcc -static-libstdc++"
146 export CFLAGS CXXFLAGS LDFLAGS
149 if [ "$MINGWCROSS" = "TRUE" ]
150 then
151 B=build-windows
152 LUATEXEXEJIT=luajittex.exe
153 LUATEXEXE=luatex.exe
154 OLDPATH=$PATH
155 PATH=/usr/mingw32/bin:$PATH
156 PATH=`pwd`/extrabin/mingw:$PATH
157 CFLAGS="-mtune=nocona -g -O3 $CFLAGS"
158 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
159 : ${CONFHOST:=--host=i586-mingw32msvc}
160 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
161 RANLIB="${CONFHOST#--host=}-ranlib"
162 STRIP="${CONFHOST#--host=}-strip"
163 LDFLAGS="-Wl,--large-address-aware -Wl,--stack,2621440 $CFLAGS"
164 export CFLAGS CXXFLAGS LDFLAGS BUILDCXX BUILDCC
168 if [ "$MACCROSS" = "TRUE" ]
169 then
170 # make sure that architecture parameter is valid
171 case $ARCH in
172 i386 | x86_64 | ppc | ppc64 ) ;;
173 * ) echo "ERROR: architecture $ARCH is not supported"; exit 1;;
174 esac
175 B=build-$ARCH
176 CFLAGS="-arch $ARCH -g -O2 $CFLAGS"
177 CXXFLAGS="-arch $ARCH -g -O2 $CXXFLAGS"
178 LDFLAGS="-arch $ARCH $LDFLAGS"
179 export CFLAGS CXXFLAGS LDFLAGS
183 ### Dirty trick to check Darwin X86_64
184 # 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)
185 # HOST_SYS=$(uname -s)
186 # echo HOST_SYS=$HOST_SYS
187 # echo TARGET_TESTARCH=$TARGET_TESTARCH
188 # if [ $HOST_SYS == "Darwin" ]
189 # then
190 # if [ $TARGET_TESTARCH == "x64" ]
191 # then
192 # export LDFLAGS="-pagezero_size 10000 -image_base 100000000 $LDFLAGS"
193 # echo Setting LDFLAGS=$LDFLAGS
194 # fi
195 # fi
198 if [ "$STRIP_LUATEX" = "FALSE" ]
199 then
200 export CFLAGS
201 export CXXFLAGS
204 # ----------
205 # clean up, if needed
206 if [ -r "$B"/Makefile -a $ONLY_MAKE = "FALSE" ]
207 then
208 rm -rf "$B"
209 elif [ ! -r "$B"/Makefile ]
210 then
211 ONLY_MAKE=FALSE
213 if [ ! -r "$B" ]
214 then
215 mkdir "$B"
218 # get a new svn version header
219 if [ "$WARNINGS" = "max" ]
220 then
221 rm -f source/texk/web2c/luatexdir/luatex_svnversion.h
223 ( cd source ; ./texk/web2c/luatexdir/getluatexsvnversion.sh )
225 cd "$B"
227 JITENABLE=
228 if [ "$BUILDJIT" = "TRUE" ]
229 then
230 JITENABLE="--enable-luajittex --without-system-luajit "
236 if [ "$ONLY_MAKE" = "FALSE" ]
237 then
238 TL_MAKE=$MAKE ../source/configure $CONFHOST $CONFBUILD $WARNINGFLAGS\
239 --enable-cxx-runtime-hack \
240 --enable-silent-rules \
241 --disable-all-pkgs \
242 --disable-shared \
243 --disable-ptex \
244 --disable-largefile \
245 --disable-ipc \
246 --enable-dump-share \
247 --enable-mp \
248 --enable-luatex $JITENABLE \
249 --without-system-ptexenc \
250 --without-system-kpathsea \
251 --without-system-poppler \
252 --without-system-xpdf \
253 --without-system-freetype \
254 --without-system-freetype2 \
255 --without-system-gd \
256 --without-system-libpng \
257 --without-system-teckit \
258 --without-system-zlib \
259 --without-system-t1lib \
260 --without-system-icu \
261 --without-system-graphite \
262 --without-system-zziplib \
263 --without-mf-x-toolkit --without-x \
264 || exit 1
267 $MAKE
269 # the fact that these makes inside libs/ have to be done manually for the cross
270 # compiler hints that something is wrong in the --enable/--disable switches above,
271 # but I am too lazy to look up what is wrong exactly.
272 # (perhaps more files needed to be copied from TL?)
274 (cd libs; $MAKE all )
275 (cd libs/zzip; $MAKE all )
276 (cd libs/zlib; $MAKE all )
277 (cd libs/libpng; $MAKE all )
278 (cd libs/poppler; $MAKE all )
279 (cd texk; $MAKE web2c/Makefile)
280 (cd texk/kpathsea; $MAKE )
281 if [ "$BUILDJIT" = "TRUE" ]
282 then
283 (cd libs/luajit; $MAKE all )
284 (cd texk/web2c; $MAKE $LUATEXEXEJIT)
286 (cd texk/web2c; $MAKE $LUATEXEXE )
289 # go back
290 cd ..
292 if [ "$STRIP_LUATEX" = "TRUE" ] ;
293 then
294 if [ "$BUILDJIT" = "TRUE" ]
295 then
296 $STRIP "$B"/texk/web2c/$LUATEXEXEJIT
298 $STRIP "$B"/texk/web2c/$LUATEXEXE
299 else
300 echo "lua(jit)tex binary not stripped"
303 if [ "$MINGWCROSS" = "TRUE" ]
304 then
305 PATH=$OLDPATH
308 # show the result
309 if [ "$BUILDJIT" = "TRUE" ]
310 then
311 ls -l "$B"/texk/web2c/$LUATEXEXEJIT
313 ls -l "$B"/texk/web2c/$LUATEXEXE