Massage remote a bit
[llpp.git] / configure.sh
blob702922d3b62f73a98fa8f7b814d6baee295c3ab6
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="openssl"
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)"
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 srcdir=$(cd >/dev/null $(dirname $0) && pwd -P)
67 cat <<EOF
68 cflags=$cflags -O $(pkg-config --cflags $pkgs)
69 lflags=$libs
70 srcdir=$srcdir
71 buildtype=$buildtype
72 builddir=$builddir
73 lablglcflags=$lablglcflags
74 EOF
75 test -e $srcdir/mupdf/build/$buildtype/libmujs.a && echo 'mujs=-lmujs'
76 test $native && {
77 echo "cmo=.cmx"
78 echo "cma=.cmxa"
79 command 2>&1 >/dev/null -v ocamlopt.opt && optsuf=".opt" || optsuf=""
80 echo "ocamlc=ocamlopt$optsuf"
81 echo "linksocclib=-cclib"
82 echo "customflag="
83 } || {
84 echo "cmo=.cmo"
85 echo "cma=.cma"
86 command 2>&1 >/dev/null -v ocamlc.opt && optsuf=".opt" || optsuf=""
87 echo "ocamlc=ocamlc$optsuf"
88 echo "linksocclib="
89 echo "customflag=-custom"
91 ) >.config || true
93 cat <<EOF
94 Configuration results are saved in $(pwd -P)/.config
95 To build - type: ninja$helpcmdl
96 EOF