Robustness
[llpp.git] / configure.sh
blobdad63a7ea6dd03613035afcc5d1a8c3c86c58cf6
1 #!/bin/sh
2 set -e
4 unset cflags
5 buildtype=native
7 usage () {
8 echo "$1"
9 cat 1>&2 <<EOF
10 usage: $0 [-F] [-b build-type] [-O] [mudir]
11 options:
12 -F: use fontconfig
13 -b: MuPDF's build type [default native]
14 -O: use ocamlfind for lablGL discovery
16 build-type = debug|release|native
17 mudir = path to MuPDF's git checkout
18 EOF
19 exit $2
22 while getopts eFb:O opt; do
23 case $opt in
24 F) fontconfig=true; cflags="$cflags -DUSE_FONTCONFIG";;
25 b) buildtype="$OPTARG";;
26 O) ocamlfind=true;;
27 ?) usage "" 0;;
28 esac
29 done
30 shift $((OPTIND - 1))
32 mupdf="$1"
33 test -e "$mupdf" || usage "Don't know where to find MuPDF's git checkout" 1
35 pkgs="freetype2 zlib openssl" # j(peg|big2dec)?
36 test $fontconfig && pkgs="$pkgs fontconfig" || true
37 pwd=$(pwd -P)
39 expr >/dev/null "$0" : "/.*" && {
40 path="$0"
41 builddir="$pwd"
42 helpcmdl=" -f $(dirname $path)/build.ninja"
43 } || {
44 path="$pwd/$0"
45 builddir="build"
46 helcmdl=""
47 mkdir -p $builddir
49 builddir=$(cd $builddir >/dev/null $builddir && pwd -P)
51 libs="$(pkg-config --libs $pkgs) -ljpeg -ljbig2dec -lopenjpeg"
53 test $ocamlfind && {
54 lablgldir="$(ocamlfind query lablgl)" || exit 1
55 lablglcflags="-I $lablgldir"
56 } || {
57 lablglcflags="-I +lablGL"
60 (cat <<EOF
61 cflags=$cflags $(pkg-config --cflags $pkgs)
62 lflags=$libs
63 srcdir=$(cd >/dev/null $(dirname $0) && pwd -P)
64 buildtype=$buildtype
65 mupdf=$mupdf
66 builddir=$builddir
67 lablglcflags=$lablglcflags
68 EOF
69 test $(uname -m) = "x86_64" && {
70 echo 'cflags=$cflags -fPIC'
71 echo "mujs=-lmujs"
72 }) >.config || true
74 cat <<EOF
75 Configuration results are saved in $(pwd -P)/.config
76 To build - type: ninja$helpcmdl
77 EOF