Refactor
[llpp.git] / build.sh
blob29f6c36ec8caf46bf6b13b11cef930e04e436d53
1 #!/bin/sh
2 set -e
3 if test x"$1" = x; then
4 printf "No build directory specified\n" 1>&2
5 exit 1
6 else
7 builddir="$1"
8 fi
9 test $( (ocamlc 2>/dev/null --version || echo 0.0) \
10 | awk -F. '{print $1 $2}') -lt 404 && {
11 echo "OCaml version 4.04.0 or higher required"
12 exit 1
13 } || true
15 case $(uname -s) in
16 Darwin)
17 wsi=wsi/osx
18 macos=true
21 wsi=wsi/x11
22 macos=false
24 esac
26 test x"$2" = "x" || cty="$2" && cty=""
28 ccopt="$CFLAGS -Wno-pointer-sign -O2"
29 mlopt='-warn-error +a -w +a -g -safe-string'
30 if test -z "$native"; then
31 comp=ocamlc$cty
32 osu=.cmo
33 asu=.cma
34 lfl=-custom
35 else
36 comp=ocamlopt$cty
37 osu=.cmx
38 asu=.cmxa
39 lfl=
41 ccomp=$(ocamlc -config | grep bytecomp_c_co | cut -d: -f2)
42 mkdir -p "$builddir/lablGL" "$builddir/$wsi"
43 srcdir=$(dirname $0)
44 version=$(cd $srcdir && git describe --tags 2>/dev/null) || version=unknown
45 shortversion=$(echo $version | sed -n 's/v\([0-9]*\).*/\1/p')
46 mloptgl="-I $srcdir/lablGL -I $builddir/lablGL"
47 $comp -ccopt "$ccopt -o $builddir/lablGL/ml_raw.o" -c $srcdir/lablGL/ml_raw.c
48 $comp -ccopt "$ccopt -o $builddir/lablGL/ml_gl.o" -c $srcdir/lablGL/ml_gl.c
49 $comp -ccopt "$ccopt -o $builddir/lablGL/ml_glarray.o" -c $srcdir/lablGL/ml_glarray.c
50 if $macos; then
51 $comp -ccopt "-D__COCOA__ -I $srcdir/mupdf/include -I $srcdir/mupdf/thirdparty/freetype/include -Wextra -Wall -Werror -D_GNU_SOURCE -O -g -std=c99 -pedantic-errors -Wunused-parameter -Wsign-compare -Wshadow -o $builddir/link.o" -c $srcdir/link.c
52 $ccomp -c -I $(ocamlc -where) -o $builddir/main_osx.o $srcdir/main_osx.m
53 else
54 $comp -ccopt "-I $srcdir/mupdf/include -I $srcdir/mupdf/thirdparty/freetype/include -Wextra -Wall -Werror -D_GNU_SOURCE -O -g -std=c99 -pedantic-errors -Wunused-parameter -Wsign-compare -Wshadow -o $builddir/link.o" -c $srcdir/link.c
56 /bin/sh $srcdir/mkhelp.sh $srcdir/KEYS "$version" >$builddir/help.ml
57 $comp -c $mloptgl -o $builddir/keys$osu $srcdir/keys.ml
58 $comp -c $mloptgl -o $builddir/lablGL/gl$osu $srcdir/lablGL/gl.ml
59 $comp -c $mloptgl -o $builddir/lablGL/raw$osu $srcdir/lablGL/raw.ml
60 $comp -c $mloptgl -o $builddir/lablGL/glPix$osu $srcdir/lablGL/glPix.ml
61 $comp -c $mloptgl -o $builddir/lablGL/glDraw$osu $srcdir/lablGL/glDraw.ml
62 $comp -c $mloptgl -o $builddir/lablGL/glTex.cmi $srcdir/lablGL/glTex.mli
63 $comp -c $mloptgl -o $builddir/lablGL/glMisc.cmi $srcdir/lablGL/glMisc.mli
64 $comp -c $mloptgl -o $builddir/lablGL/glMat$osu $srcdir/lablGL/glMat.ml
65 $comp -c $mloptgl -o $builddir/lablGL/glMisc$osu $srcdir/lablGL/glMisc.ml
66 $comp -c $mloptgl -o $builddir/lablGL/glFunc$osu $srcdir/lablGL/glFunc.ml
67 $comp -c $mloptgl -o $builddir/lablGL/glTex$osu $srcdir/lablGL/glTex.ml
68 $comp -c $mloptgl -o $builddir/lablGL/glArray$osu $srcdir/lablGL/glArray.ml
69 $comp -c $mloptgl -o $builddir/lablGL/glClear$osu $srcdir/lablGL/glClear.ml
70 $comp -c -o $builddir/help$osu $builddir/help.ml
71 $comp -c $mlopt -o $builddir/utils$osu $srcdir/utils.ml
72 $comp -c $mlopt -I $builddir -o $builddir/parser$osu $srcdir/parser.ml
73 $comp -c $mlopt -I $builddir -o $builddir/$wsi/wsi.cmi $srcdir/$wsi/wsi.mli
74 $comp -c $mloptgl -I $builddir -I $builddir/$wsi -o $builddir/config$osu $srcdir/config.ml
75 $comp -c $mloptgl -I $builddir -I $builddir/$wsi -o $builddir/main$osu $srcdir/main.ml
76 $comp -c $mlopt -I $builddir -I $builddir/$wsi -o $builddir/wsi$osu $srcdir/$wsi/wsi.ml
78 if $macos; then
79 $comp -g $lfl -I lablGL -o $builddir/llpp unix$asu str$asu $builddir/help$osu $builddir/lablGL/raw$osu $builddir/utils$osu $builddir/parser$osu $builddir/lablGL/glMisc$osu $builddir/wsi$osu $builddir/lablGL/gl$osu $builddir/lablGL/glMat$osu $builddir/lablGL/glFunc$osu $builddir/lablGL/glClear$osu $builddir/lablGL/glPix$osu $builddir/lablGL/glTex$osu $builddir/lablGL/glDraw$osu $builddir/config$osu $builddir/lablGL/glArray$osu $builddir/main$osu $builddir/link.o $builddir/main_osx.o -cclib "-framework Cocoa -framework OpenGL -lmupdf -lmupdfthird -lpthread -L$srcdir/mupdf/build/native $builddir/lablGL/ml_gl.o $builddir/lablGL/ml_glarray.o $builddir/lablGL/ml_raw.o"
80 mkdir -p $builddir/llpp.app/Contents/MacOS
81 cat $srcdir/misc/Info.plist | sed s/@VERSION@/$shortversion/ | sed s/@BUNDLE_VERSION@/$version/ > $builddir/llpp.app/Contents/Info.plist
82 cp $builddir/llpp $builddir/llpp.app/Contents/MacOS/
83 else
84 $comp -g $lfl -I lablGL -o $builddir/llpp unix$asu str$asu $builddir/help$osu $builddir/lablGL/raw$osu $builddir/utils$osu $builddir/parser$osu $builddir/lablGL/glMisc$osu $builddir/wsi$osu $builddir/lablGL/gl$osu $builddir/lablGL/glMat$osu $builddir/lablGL/glFunc$osu $builddir/lablGL/glClear$osu $builddir/lablGL/glPix$osu $builddir/lablGL/glTex$osu $builddir/lablGL/glDraw$osu $builddir/config$osu $builddir/lablGL/glArray$osu $builddir/main$osu $builddir/link.o -cclib "-lX11 -lGL -lmupdf -lmupdfthird -lpthread -L$srcdir/mupdf/build/native $builddir/lablGL/ml_gl.o $builddir/lablGL/ml_glarray.o $builddir/lablGL/ml_raw.o"