a few more chapters of the manual (HH)
[luatex.git] / build.sh
blob33f39de312c35f73dbd472192a877195e31630cc
1 #!/usr/bin/env bash
3 # Copyright (c) 2005-2011 Martin Schröder <martin@luatex.org>
4 # Copyright (c) 2009-2014 Taco Hoekwater <taco@luatex.org>
5 # Copyright (c) 2012-2014 Luigi Scarso <luigi@luatex.org>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 # new script to build luatex binaries
20 # ----------
21 # Options:
22 # --jit : also build luajittex
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 x86_64linux
28 # --mingw32 : crosscompile for mingw32 from x86_64linux
29 # --mingw64 : crosscompile for mingw64 from x86_64linux
30 # --host= : target system for mingw32 cross-compilation
31 # --build= : build system for mingw32 cross-compilation
32 # --arch= : crosscompile for ARCH on OS X
33 # --clang : use clang & clang++
34 # --debug : CFLAGS="-g -O0" --warnings=max --nostrip
35 # --debugopt : CFLAGS="-g -O3" --warnings=max --nostrip
36 $DEBUG
37 #export CFLAGS="-D_FORTIFY_SOURCE=2 -O3"
38 #export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
40 # try to find bash, in case the standard shell is not capable of
41 # handling the generated configure's += variable assignments
42 if which bash >/dev/null
43 then
44 CONFIG_SHELL=`which bash`
45 export CONFIG_SHELL
48 # try to find gnu make; we may need it
49 MAKE=make
50 if make -v 2>&1| grep "GNU Make" >/dev/null
51 then
52 echo "Your make is a GNU-make; I will use that"
53 elif gmake -v >/dev/null 2>&1
54 then
55 MAKE=gmake;
56 export MAKE;
57 echo "You have a GNU-make installed as gmake; I will use that"
58 else
59 echo "I can't find a GNU-make; I'll try to use make and hope that works."
60 echo "If it doesn't, please install GNU-make."
63 BUILDJIT=FALSE
64 ONLY_MAKE=FALSE
65 STRIP_LUATEX=TRUE
66 WARNINGS=yes
67 MINGWCROSS=FALSE
68 MINGWCROSS64=FALSE
69 MACCROSS=FALSE
70 CLANG=FALSE
71 CONFHOST=
72 CONFBUILD=
73 JOBS_IF_PARALLEL=${JOBS_IF_PARALLEL:-8}
74 MAX_LOAD_IF_PARALLEL=${MAX_LOAD_IF_PARALLEL:-8}
75 TARGET_CC=gcc
76 TARGET_TCFLAGS=
78 CFLAGS="$CFLAGS"
79 CXXFLAGS="$CXXFLAGS"
81 until [ -z "$1" ]; do
82 case "$1" in
83 --jit ) BUILDJIT=TRUE ;;
84 --nojit ) BUILDJIT=FALSE ;;
85 --make ) ONLY_MAKE=TRUE ;;
86 --nostrip ) STRIP_LUATEX=FALSE ;;
87 --debugopt ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-O3 -g -g3 $CFLAGS" ; CXXFLAGS="-O3 -g -g3 $CXXFLAGS" ;;
88 --debug ) STRIP_LUATEX=FALSE; WARNINGS=max ; CFLAGS="-O0 -g -g3 $CFLAGS" ; CXXFLAGS="-O0 -g -g3 $CXXFLAGS" ;;
89 --clang ) export CC=clang; export CXX=clang++ ; TARGET_CC=$CC ; CLANG=TRUE ;;
90 --warnings=*) WARNINGS=`echo $1 | sed 's/--warnings=\(.*\)/\1/' ` ;;
91 --mingw ) MINGWCROSS=TRUE ;;
92 --mingw32 ) MINGWCROSS=TRUE ;;
93 --mingw64 ) MINGWCROSS64=TRUE ;;
94 --host=* ) CONFHOST="$1" ;;
95 --build=* ) CONFBUILD="$1" ;;
96 --parallel ) MAKE="$MAKE -j $JOBS_IF_PARALLEL -l $MAX_LOAD_IF_PARALLEL" ;;
97 --arch=* ) MACCROSS=TRUE; ARCH=`echo $1 | sed 's/--arch=\(.*\)/\1/' ` ;;
98 * ) echo "ERROR: invalid build.sh parameter: $1"; exit 1 ;;
99 esac
100 shift
101 done
104 STRIP=strip
105 LUATEXEXEJIT=luajittex
106 LUATEXEXE=luatex
108 case `uname` in
109 MINGW32* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
110 CYGWIN* ) LUATEXEXEJIT=luajittex.exe ; LUATEXEXE=luatex.exe ;;
111 Darwin ) STRIP="strip -u -r" ;;
112 esac
114 WARNINGFLAGS=--enable-compiler-warnings=$WARNINGS
116 B=build
118 ## Useful for cross-compilation for ARM
119 if [ "x$CONFHOST" != "x" ]
120 then
121 B="build-$CONFHOST"
122 B=`printf "$B"| sed 's/--host=//'`
125 if [ "$CLANG" = "TRUE" ]
126 then
127 B=build-clang
130 if [ "$MINGWCROSS64" = "TRUE" ]
131 then
132 B=build-windows64
133 LUATEXEXEJIT=luajittex.exe
134 LUATEXEXE=luatex.exe
135 OLDPATH=$PATH
136 PATH=/usr/mingw32/bin:$PATH
137 PATH=`pwd`/extrabin/mingw:$PATH
138 CFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CFLAGS"
139 CXXFLAGS="-mtune=nocona -g -O3 -fno-lto -fno-use-linker-plugin $CXXFLAGS"
140 : ${CONFHOST:=--host=x86_64-w64-mingw32}
141 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
142 RANLIB="${CONFHOST#--host=}-ranlib"
143 STRIP="${CONFHOST#--host=}-strip"
144 LDFLAGS="${LDFLAGS} -fno-lto -fno-use-linker-plugin -static-libgcc -static-libstdc++"
145 export CFLAGS CXXFLAGS LDFLAGS
148 if [ "$MINGWCROSS" = "TRUE" ]
149 then
150 B=build-windows
151 LUATEXEXEJIT=luajittex.exe
152 LUATEXEXE=luatex.exe
153 OLDPATH=$PATH
154 PATH=/usr/mingw32/bin:$PATH
155 PATH=`pwd`/extrabin/mingw:$PATH
156 CFLAGS="-mtune=nocona -g -O3 $CFLAGS"
157 CXXFLAGS="-mtune=nocona -g -O3 $CXXFLAGS"
158 : ${CONFHOST:=--host=i586-mingw32msvc}
159 : ${CONFBUILD:=--build=x86_64-unknown-linux-gnu}
160 RANLIB="${CONFHOST#--host=}-ranlib"
161 STRIP="${CONFHOST#--host=}-strip"
162 LDFLAGS="-Wl,--large-address-aware -Wl,--stack,2621440 $CFLAGS"
163 export CFLAGS CXXFLAGS LDFLAGS BUILDCXX BUILDCC
167 if [ "$MACCROSS" = "TRUE" ]
168 then
169 # make sure that architecture parameter is valid
170 case $ARCH in
171 i386 | x86_64 | ppc | ppc64 ) ;;
172 * ) echo "ERROR: architecture $ARCH is not supported"; exit 1;;
173 esac
174 B=build-$ARCH
175 CFLAGS="-arch $ARCH -g -O2 $CFLAGS"
176 CXXFLAGS="-arch $ARCH -g -O2 $CXXFLAGS"
177 LDFLAGS="-arch $ARCH $LDFLAGS"
178 export CFLAGS CXXFLAGS LDFLAGS
182 ### Dirty trick to check Darwin X86_64
183 # 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)
184 # HOST_SYS=$(uname -s)
185 # echo HOST_SYS=$HOST_SYS
186 # echo TARGET_TESTARCH=$TARGET_TESTARCH
187 # if [ $HOST_SYS == "Darwin" ]
188 # then
189 # if [ $TARGET_TESTARCH == "x64" ]
190 # then
191 # export LDFLAGS="-pagezero_size 10000 -image_base 100000000 $LDFLAGS"
192 # echo Setting LDFLAGS=$LDFLAGS
193 # fi
194 # fi
197 if [ "$STRIP_LUATEX" = "FALSE" ]
198 then
199 export CFLAGS
200 export CXXFLAGS
203 # ----------
204 # clean up, if needed
205 if [ -r "$B"/Makefile -a $ONLY_MAKE = "FALSE" ]
206 then
207 rm -rf "$B"
208 elif [ ! -r "$B"/Makefile ]
209 then
210 ONLY_MAKE=FALSE
212 if [ ! -r "$B" ]
213 then
214 mkdir "$B"
217 # get a new svn version header
218 if [ "$WARNINGS" = "max" ]
219 then
220 rm -f source/texk/web2c/luatexdir/luatex_svnversion.h
222 ( cd source ; ./texk/web2c/luatexdir/getluatexsvnversion.sh )
224 cd "$B"
226 JITENABLE=
227 if [ "$BUILDJIT" = "TRUE" ]
228 then
229 JITENABLE="--enable-luajittex --without-system-luajit "
235 if [ "$ONLY_MAKE" = "FALSE" ]
236 then
237 TL_MAKE=$MAKE ../source/configure $CONFHOST $CONFBUILD $WARNINGFLAGS\
238 --enable-cxx-runtime-hack \
239 --enable-silent-rules \
240 --disable-all-pkgs \
241 --disable-shared \
242 --disable-ptex \
243 --disable-largefile \
244 --disable-ipc \
245 --enable-dump-share \
246 --enable-mp \
247 --enable-luatex $JITENABLE \
248 --without-system-ptexenc \
249 --without-system-kpathsea \
250 --without-system-poppler \
251 --without-system-xpdf \
252 --without-system-freetype \
253 --without-system-freetype2 \
254 --without-system-gd \
255 --without-system-libpng \
256 --without-system-teckit \
257 --without-system-zlib \
258 --without-system-t1lib \
259 --without-system-icu \
260 --without-system-graphite \
261 --without-system-zziplib \
262 --without-mf-x-toolkit --without-x \
263 || exit 1
266 $MAKE
268 # the fact that these makes inside libs/ have to be done manually for the cross
269 # compiler hints that something is wrong in the --enable/--disable switches above,
270 # but I am too lazy to look up what is wrong exactly.
271 # (perhaps more files needed to be copied from TL?)
273 (cd libs; $MAKE all )
274 (cd libs/zzip; $MAKE all )
275 (cd libs/zlib; $MAKE all )
276 (cd libs/libpng; $MAKE all )
277 (cd libs/poppler; $MAKE all )
278 (cd texk; $MAKE web2c/Makefile)
279 (cd texk/kpathsea; $MAKE )
280 if [ "$BUILDJIT" = "TRUE" ]
281 then
282 (cd libs/luajit; $MAKE all )
283 (cd texk/web2c; $MAKE $LUATEXEXEJIT)
285 (cd texk/web2c; $MAKE $LUATEXEXE )
288 # go back
289 cd ..
291 if [ "$STRIP_LUATEX" = "TRUE" ] ;
292 then
293 if [ "$BUILDJIT" = "TRUE" ]
294 then
295 $STRIP "$B"/texk/web2c/$LUATEXEXEJIT
297 $STRIP "$B"/texk/web2c/$LUATEXEXE
298 else
299 echo "lua(jit)tex binary not stripped"
302 if [ "$MINGWCROSS" = "TRUE" ]
303 then
304 PATH=$OLDPATH
307 # show the result
308 if [ "$BUILDJIT" = "TRUE" ]
309 then
310 ls -l "$B"/texk/web2c/$LUATEXEXEJIT
312 ls -l "$B"/texk/web2c/$LUATEXEXE