better condition for *bsd* for ffi (trunk & tags)
[luatex.git] / build.sh
blob018f6773089b3a7453ba94fc3fac1c2035815bee
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 8 -l 8.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 if [ "x$CONFHOST" != "x" ]
176 then
177 B="build-$CONFHOST"
178 B=`printf "$B"| sed 's/--host=//'`
180 CFLAGS="-arch $ARCH -g -O2 $CFLAGS"
181 CXXFLAGS="-arch $ARCH -g -O2 $CXXFLAGS"
182 LDFLAGS="-arch $ARCH $LDFLAGS"
183 STRIP="${CONFHOST#--host=}-strip -u -r -A -n"
184 export CFLAGS CXXFLAGS LDFLAGS
188 ### Dirty trick to check Darwin X86_64
189 # 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)
190 # HOST_SYS=$(uname -s)
191 # echo HOST_SYS=$HOST_SYS
192 # echo TARGET_TESTARCH=$TARGET_TESTARCH
193 # if [ $HOST_SYS == "Darwin" ]
194 # then
195 # if [ $TARGET_TESTARCH == "x64" ]
196 # then
197 # export LDFLAGS="-pagezero_size 10000 -image_base 100000000 $LDFLAGS"
198 # echo Setting LDFLAGS=$LDFLAGS
199 # fi
200 # fi
203 if [ "$STRIP_LUATEX" = "FALSE" ]
204 then
205 export CFLAGS
206 export CXXFLAGS
209 # ----------
210 # clean up, if needed
211 if [ -r "$B"/Makefile -a $ONLY_MAKE = "FALSE" ]
212 then
213 rm -rf "$B"
214 elif [ ! -r "$B"/Makefile ]
215 then
216 ONLY_MAKE=FALSE
218 if [ ! -r "$B" ]
219 then
220 mkdir "$B"
223 # get a new svn version header
224 if [ "$WARNINGS" = "max" ]
225 then
226 rm -f source/texk/web2c/luatexdir/luatex_svnversion.h
228 ( cd source ; ./texk/web2c/luatexdir/getluatexsvnversion.sh )
230 cd "$B"
232 JITENABLE=
233 if [ "$BUILDJIT" = "TRUE" ]
234 then
235 JITENABLE="--enable-luajittex --without-system-luajit "
241 if [ "$ONLY_MAKE" = "FALSE" ]
242 then
243 TL_MAKE=$MAKE ../source/configure $CONFHOST $CONFBUILD $WARNINGFLAGS\
244 --enable-cxx-runtime-hack \
245 --enable-silent-rules \
246 --disable-all-pkgs \
247 --disable-shared \
248 --disable-ptex \
249 --disable-largefile \
250 --disable-ipc \
251 --enable-dump-share \
252 --enable-mp \
253 --enable-luatex $JITENABLE \
254 --without-system-ptexenc \
255 --without-system-kpathsea \
256 --without-system-poppler \
257 --without-system-xpdf \
258 --without-system-freetype \
259 --without-system-freetype2 \
260 --without-system-gd \
261 --without-system-libpng \
262 --without-system-teckit \
263 --without-system-zlib \
264 --without-system-t1lib \
265 --without-system-icu \
266 --without-system-graphite \
267 --without-system-zziplib \
268 --without-mf-x-toolkit --without-x \
269 || exit 1
272 $MAKE
274 # the fact that these makes inside libs/ have to be done manually for the cross
275 # compiler hints that something is wrong in the --enable/--disable switches above,
276 # but I am too lazy to look up what is wrong exactly.
277 # (perhaps more files needed to be copied from TL?)
279 (cd libs; $MAKE all )
280 (cd libs/zziplib; $MAKE all )
281 (cd libs/zlib; $MAKE all )
282 (cd libs/libpng; $MAKE all )
283 (cd libs/poppler; $MAKE all )
284 (cd texk; $MAKE web2c/Makefile)
285 (cd texk/kpathsea; $MAKE )
286 if [ "$BUILDJIT" = "TRUE" ]
287 then
288 (cd libs/luajit; $MAKE all )
289 (cd texk/web2c; $MAKE $LUATEXEXEJIT)
291 (cd texk/web2c; $MAKE $LUATEXEXE )
294 # go back
295 cd ..
297 if [ "$STRIP_LUATEX" = "TRUE" ] ;
298 then
299 if [ "$BUILDJIT" = "TRUE" ]
300 then
301 $STRIP "$B"/texk/web2c/$LUATEXEXEJIT
303 $STRIP "$B"/texk/web2c/$LUATEXEXE
304 else
305 echo "lua(jit)tex binary not stripped"
308 if [ "$MINGWCROSS" = "TRUE" ]
309 then
310 PATH=$OLDPATH
313 # show the result
314 if [ "$BUILDJIT" = "TRUE" ]
315 then
316 ls -l "$B"/texk/web2c/$LUATEXEXEJIT
318 ls -l "$B"/texk/web2c/$LUATEXEXE