Cosmetics
[llpp.git] / buildall.sh
blob9d53335e97fea437a56a381c25ee0eed3fa1e124
1 # builds "hard" prerequisites and llpp
2 set -e
4 filt='^$'
5 while getopts j:f: opt; do
6 case "$opt" in
7 j) jobs="-j $OPTARG";;
8 f) filt="$OPTARG";;
9 ?)
10 printf "usage: $0 [-j N] [opt]\n";
11 exit 1;;
12 esac
13 done
14 shift $(($OPTIND - 1))
16 mkdir -p 3rdp
17 cd 3rdp
18 root=$(pwd)
20 lablgl=http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/dist/lablgl-1.05.tar.gz
21 baseurl="http://git.ghostscript.com/"
23 mupdfrev=67ebe59a41f8b2deaf78dc916c5cd203d3fcc3a3
24 mudir=mupdf-$(printf "%.7s" $mupdfrev)
25 mutgz=mupdf-$mupdfrev.tgz
26 muurl="${baseurl}?p=mupdf.git;a=snapshot;h=$mupdfrev;sf=tgz"
28 test -d lablgl-1.05 || (wget -nc $lablgl && tar -xzf lablgl-1.05.tar.gz)
29 test -e $mutgz || wget -nc $muurl -O $mutgz
30 test -d $mudir || tar -xzf $mutgz
32 fetch() {
33 while read r m; do
34 d=$m-$(printf "%.7s" $r)
35 t=$m-$r.tgz
36 test $m = jbig2dec && p=$m || p=thirdparty/$m
37 u="${baseurl}?p=$p.git;a=snapshot;h=$r;sf=tgz"
38 test -e $t || wget -nc $u -O $t
39 test -e $mudir/thirdparty/$m/README ||
40 (rm -fr $mudir/thirdparty/$m &&
41 tar -xzf $t &&
42 mv $d $mudir/thirdparty/$m)
43 done
46 grep -v -E "$filt" <<-EOF | fetch
47 2ef0a19842ae1172bec153225328aaaeaf130a18 freetype
48 d02b3649334e59e862b37c70d7d0fa9e086a524c jbig2dec
49 219d59dcfd0e6ce8a3d8c5510e29237f0b5078ed jpeg
50 0970aed6e3990f8df7ef1b70cc22d024439b46d2 openjpeg
51 c16b1b18ddaaf090caf321af831bccac6381a381 zlib
52 EOF
54 executable_p() {
55 command -v $1 >/dev/null 2>&1
58 executable_p gmake && make=gmake || make=make
60 (cd lablgl-1.05 \
61 && sed 17d Makefile.config.linux.mdk > Makefile.config \
62 && $make lib $(test "$1" = opt && echo libopt) \
63 && $make install \
64 BINDIR=$root/bin \
65 LIBDIR=$root/lib/ocaml \
66 DLLDIR=$root/lib/ocaml/stublibs \
67 INSTALLDIR=$root/lib/ocaml/lablGL)
69 (cd $mudir && $make $jobs build=release)
71 cd ..
73 srcpath=$(dirname $0)
75 tp=$root/$mudir/thirdparty
77 ccopt="-O"
78 ccopt="$ccopt -I $tp/jbig2dec"
79 ccopt="$ccopt -I $tp/jpeg"
80 ccopt="$ccopt -I $tp/freetype/include"
81 ccopt="$ccopt -I $tp/openjpeg/libopenjpeg"
82 ccopt="$ccopt -I $tp/zlib"
83 ccopt="$ccopt -I $root/$mudir/include"
85 ccopt="$ccopt -D_GNU_SOURCE"
87 cclib="$cclib -L$root/$mudir/build/release"
88 cclib="$cclib -lmupdf -lmupdf-js-none"
89 cclib="$cclib -lz -ljpeg -lopenjpeg -ljbig2dec -lpthread -lcrypto"
90 cclib="$cclib -lX11"
92 expr "$filt" : '.*freetype.*' && {
93 ccopt="$ccopt $(freetype-config --cflags) -include ft2build.h"
94 cclib="$cclib $(freetype-config --libs)"
95 } || {
96 ccopt="$ccopt -include $tp/freetype/include/ft2build.h"
97 cclib="$cclib -lfreetype"
100 echo Building llpp...
102 sh $srcpath/mkhelp.sh $srcpath/keystoml.ml $srcpath/KEYS > help.ml
104 if test "$1" = "opt"; then
105 executable_p ocamlopt.opt && comp=ocamlopt.opt || comp=ocamlopt
106 cmsuf=cmx
107 dolink() {
108 $comp -o llpp \
109 -I $root/lib/ocaml/lablGL \
110 str.cmxa unix.cmxa lablgl.cmxa \
111 link.o \
112 -cclib "$cclib" \
113 help.cmx \
114 utils.cmx \
115 parser.cmx \
116 wsi.cmx \
117 main.cmx
119 else
120 executable_p ocamlc.opt && comp=ocamlc.opt || comp=ocamlc
121 cmsuf=cmo
122 dolink() {
123 $comp -custom -o llpp \
124 -I $root/lib/ocaml/lablGL \
125 str.cma unix.cma lablgl.cma \
126 link.o \
127 -cclib "$cclib" \
128 help.cmo \
129 utils.cmo \
130 parser.cmo \
131 wsi.cmo \
132 main.cmo
136 $comp -c -o link.o -ccopt "$ccopt" $srcpath/link.c
137 $comp -c -o help.$cmsuf help.ml
138 $comp -c -o utils.$cmsuf $srcpath/utils.ml
139 $comp -c -o wsi.cmi $srcpath/wsi.mli
140 $comp -c -o wsi.$cmsuf $srcpath/wsi.ml
141 $comp -c -o parser.$cmsuf $srcpath/parser.ml
142 $comp -c -o main.$cmsuf -I $root/lib/ocaml/lablGL $srcpath/main.ml
143 dolink
145 echo All done