Avoid name clashes
[llpp.git] / configure.sh
blobccd435ad334516c41fd61e3ac774000cd69a9230
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] [-n] [mudir]
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 mudir = path to MuPDF's git checkout
19 EOF
20 exit $2
23 while getopts nFb:O opt; do
24 case $opt in
25 F) fontconfig=true; cflags="$cflags -DUSE_FONTCONFIG";;
26 b) buildtype="$OPTARG";;
27 O) ocamlfind=true;;
28 n) native=true;;
29 ?) usage "" 0;;
30 esac
31 done
32 shift $((OPTIND - 1))
34 mupdf="$1"
35 test -e "$mupdf" || usage "Don't know where to find MuPDF's git checkout" 1
37 pkgs="freetype2 zlib openssl" # j(peg|big2dec)?
38 test $fontconfig && pkgs="$pkgs fontconfig" || true
39 pwd=$(pwd -P)
41 expr >/dev/null "$0" : "/.*" && {
42 path="$0"
43 builddir="$pwd"
44 helpcmdl=" -f $(dirname $path)/build.ninja"
45 } || {
46 path="$pwd/$0"
47 builddir="build"
48 helcmdl=""
49 mkdir -p $builddir
51 builddir=$(cd $builddir >/dev/null $builddir && pwd -P)
53 libs="$(pkg-config --libs $pkgs) -ljpeg -ljbig2dec -lopenjpeg"
55 test $ocamlfind && {
56 lablgldir="$(ocamlfind query lablgl)" || exit 1
57 lablglcflags="-I $lablgldir"
58 } || {
59 lablglcflags="-I +lablGL"
62 (cat <<EOF
63 cflags=$cflags -O $(pkg-config --cflags $pkgs)
64 lflags=$libs
65 srcdir=$(cd >/dev/null $(dirname $0) && pwd -P)
66 buildtype=$buildtype
67 mupdf=$mupdf
68 builddir=$builddir
69 lablglcflags=$lablglcflags
70 EOF
71 test $(uname -m) = "x86_64" && echo 'cflags=$cflags -fPIC'
72 test -e $mupdf/build/$buildtype/libmujs.a && echo 'mujs=-lmujs'
73 test $native && {
74 echo "cmo=.cmx"
75 echo "cma=.cmxa"
76 echo "ocamlc=ocamlopt.opt"
77 echo "linksocclib=-cclib"
78 echo "customflag="
79 } || {
80 echo "cmo=.cmo"
81 echo "cma=.cma"
82 echo "ocamlc=ocamlc.opt"
83 echo "linksocclib="
84 echo "customflag=-custom"
86 ) >.config || true
88 cat <<EOF
89 Configuration results are saved in $(pwd -P)/.config
90 To build - type: ninja$helpcmdl
91 EOF