Fix small issues.
[llpp.git] / configure.sh
blob178ec9a341bf9abbf97505dd428a833aa19cbe7e
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] [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"
63 if test $(uname -m) = "x86_64"; then
64 cflags="$cflags -fPIC"
65 else
66 if test $buildtype = "native"; then
67 echo "native build type does not work for non x86_64 targets"
68 exit 1
70 fi;
71 cat <<EOF
72 cflags=$cflags -O $(pkg-config --cflags $pkgs)
73 lflags=$libs
74 srcdir=$(cd >/dev/null $(dirname $0) && pwd -P)
75 buildtype=$buildtype
76 mupdf=$mupdf
77 builddir=$builddir
78 lablglcflags=$lablglcflags
79 EOF
80 test -e $mupdf/build/$buildtype/libmujs.a && echo 'mujs=-lmujs'
81 test $native && {
82 echo "cmo=.cmx"
83 echo "cma=.cmxa"
84 echo "ocamlc=ocamlopt.opt"
85 echo "linksocclib=-cclib"
86 echo "customflag="
87 } || {
88 echo "cmo=.cmo"
89 echo "cma=.cma"
90 echo "ocamlc=ocamlc.opt"
91 echo "linksocclib="
92 echo "customflag=-custom"
94 ) >.config || true
96 cat <<EOF
97 Configuration results are saved in $(pwd -P)/.config
98 To build - type: ninja$helpcmdl
99 EOF