Safety
[llpp.git] / configure.sh
blobfa57c606b7c7a141a7f9d8e09b4e1977ff274508
1 #!/bin/sh
2 set -e
4 unset cflags
5 test $(uname -m) = "x86_64" && buildtype=native || buildtype=release
7 usage () {
8 echo "$1"
9 cat 1>&2 <<EOF
10 usage: $0 [-F] [-b build-type] [-O] [-n]
11 options:
12 -F: use fontconfig
13 -b: MuPDF's build type [default native]
14 -O: use ocamlfind for lablGL discovery
15 -n: use native OCaml compiler (bytecode otherwise)
17 build-type = debug|release|native
18 EOF
19 exit $2
22 while getopts nFb:O opt; do
23 case $opt in
24 F) fontconfig=true; cflags="$cflags -DUSE_FONTCONFIG";;
25 b) buildtype="$OPTARG";;
26 O) ocamlfind=true;;
27 n) native=true;;
28 ?) usage "" 0;;
29 esac
30 done
32 pkgs="freetype2 zlib openssl" # j(peg|big2dec)?
33 test $fontconfig && pkgs="$pkgs fontconfig" || true
34 pwd=$(pwd -P)
36 expr >/dev/null "$0" : "/.*" && {
37 path="$0"
38 builddir="$pwd"
39 helpcmdl=" -f $(dirname $path)/build.ninja"
40 } || {
41 path="$pwd/$0"
42 builddir="build"
43 helcmdl=""
44 mkdir -p $builddir
46 builddir=$(cd $builddir >/dev/null $builddir && pwd -P)
48 libs="$(pkg-config --libs $pkgs) -ljpeg -ljbig2dec -lopenjpeg"
50 test $ocamlfind && {
51 lablgldir="$(ocamlfind query lablgl)" || exit 1
52 lablglcflags="-I $lablgldir"
53 } || {
54 lablglcflags="-I +lablGL"
58 if test $(uname -m) = "x86_64"; then
59 cflags="$cflags -fPIC"
60 else
61 if test $buildtype = "native"; then
62 echo "native build type does not work for non x86_64 targets"
63 exit 1
65 fi;
66 cat <<EOF
67 cflags=$cflags -O $(pkg-config --cflags $pkgs)
68 lflags=$libs
69 srcdir=$(cd >/dev/null $(dirname $0) && pwd -P)
70 buildtype=$buildtype
71 builddir=$builddir
72 lablglcflags=$lablglcflags
73 EOF
74 test -e mupdf/build/$buildtype/libmujs.a && echo 'mujs=-lmujs'
75 test $native && {
76 echo "cmo=.cmx"
77 echo "cma=.cmxa"
78 command 2>&1 >/dev/null -v ocamlopt.opt && optsuf=".opt" || optsuf=""
79 echo "ocamlc=ocamlopt$optsuf"
80 echo "linksocclib=-cclib"
81 echo "customflag="
82 } || {
83 echo "cmo=.cmo"
84 echo "cma=.cma"
85 command 2>&1 >/dev/null -v ocamlc.opt && optsuf=".opt" || optsuf=""
86 echo "ocamlc=ocamlc$optsuf"
87 echo "linksocclib="
88 echo "customflag=-custom"
90 ) >.config || true
92 cat <<EOF
93 Configuration results are saved in $(pwd -P)/.config
94 To build - type: ninja$helpcmdl
95 EOF