#! /bin/sh # configuration script # This file is part of the Zarith library # http://forge.ocamlcore.org/projects/zarith . # It is distributed under LGPL 2 licensing, with static linking exception. # See the LICENSE file included in the distribution. # # Copyright (c) 2010-2011 Antoine Miné, Abstraction project. # Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS), # a joint laboratory by: # CNRS (Centre national de la recherche scientifique, France), # ENS (École normale supérieure, Paris, France), # INRIA Rocquencourt (Institut national de recherche en informatique, France). # options installdir='auto' ocamllibdir='auto' gmp='auto' perf='no' ocaml='ocaml' ocamlc='ocamlc' ocamlopt='ocamlopt' ocamlmklib='ocamlmklib' ocamldep='ocamldep' ocamldoc='ocamldoc' ccinc="$CPPFLAGS" ldflags="$LDFLAGS" cclib='' ccdef='' mlflags="$OCAMLFLAGS" mloptflags="$OCAMLOPTFLAGS" mlinc="$OCAMLINC" objsuffix="o" ocamlfind="auto" # sanitize LC_ALL=C export LC_ALL unset IFS # help help() { cat <" > tmp.c echo "int main() { return 1; }" >> tmp.c r=1 $CC $ccopt $ccinc -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0 if test ! -f tmp.o; then r=0; fi rm -f tmp.c tmp.o if test $r -eq 0; then echo "not found"; else echo "found"; fi return $r } checklib() { echo_n "library $1: " rm -f tmp.c tmp.out echo "int main() { return 1; }" > tmp.c r=1 $CC $ccopt $ldflags $cclib tmp.c -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi rm -f tmp.c tmp.o tmp.out if test $r -eq 0; then echo "not found"; else echo "found"; fi return $r } checkcc() { echo_n "checking compilation with $cc $ccopt: " rm -f tmp.c tmp.out echo "int main() { return 1; }" >> tmp.c r=1 $CC $ccopt tmp.c -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi rm -f tmp.c tmp.o tmp.out if test $r -eq 0; then echo "not working"; else echo "working"; fi return $r } checkcmxalib() { echo_n "library $1: " $ocamlopt $mloptflags $1 -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi rm -f tmp.out if test $r -eq 0; then echo "not found"; else echo "found"; fi return $r } # check required programs searchbinreq $ocaml searchbinreq $ocamlc searchbinreq $ocamldep searchbinreq $ocamlmklib if searchbin $ocamldoc; then ocamldoc='' fi if test -n "$CC"; then searchbinreq "$CC" ccopt="$CFLAGS" else ccopt="-O3 -Wall -Wextra $CFLAGS" fi # optional native-code generation hasocamlopt='no' searchbin $ocamlopt if test $? -eq 1; then hasocamlopt='yes'; fi # check C compiler checkcc if test $? -eq 0; then # try again with (almost) no options ccopt='-O' checkcc if test $? -eq 0; then echo "cannot compile and link program"; exit 2; fi fi # directories if test "$ocamllibdir" = "auto" then ocamllibdir=`ocamlc -where | sed 's/\r$//'` fi if test ! -f "$ocamllibdir/caml/mlvalues.h" then echo "cannot find OCaml libraries in $ocamllibdir"; exit 2; fi ccinc="-I$ocamllibdir $ccinc" checkinc "caml/mlvalues.h" if test $? -eq 0; then echo "cannot include caml/mlvalues.h"; exit 2; fi # optional dynamic linking hasdynlink='no' if test $hasocamlopt = yes then checkcmxalib dynlink.cmxa if test $? -eq 1; then hasdynlink='yes'; fi fi # installation method searchbin ocamlfind if test $? -eq 1 && test $ocamlfind != "no"; then instmeth='findlib' if test "$installdir" = "auto" then installdir=`ocamlfind printconf destdir`; fi else searchbin install if test $? -eq 1; then instmeth='install' else echo "no installation method found"; exit 2; fi if test "$installdir" = "auto"; then installdir="$ocamllibdir"; fi fi # detect OCaml's word-size echo "print_int (Sys.word_size);;" > tmp.ml wordsize=`ocaml tmp.ml` echo "OCaml's word size is $wordsize" rm -f tmp.ml # check GMP, MPIR if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then if pkg-config gmp 2>/dev/null; then echo 'package gmp: found' gmp='OK' cclib="$cclib $(pkg-config --libs gmp)" ccinc="$ccinc $(pkg-config --cflags gmp)" ccdef="-DHAS_GMP $ccdef" else checkinc gmp.h if test $? -eq 1; then checklib gmp if test $? -eq 1; then gmp='OK' cclib="$cclib -lgmp" ccdef="-DHAS_GMP $ccdef" fi fi fi fi if test "$gmp" = 'mpir' || test "$gmp" = 'auto'; then checkinc mpir.h if test $? -eq 1; then checklib mpir if test $? -eq 1; then gmp='OK' cclib="$cclib -lmpir" ccdef="-DHAS_MPIR $ccdef" fi fi fi if test "$gmp" != 'OK'; then echo "cannot find GMP nor MPIR"; exit 2; fi # OCaml version ocamlver=`ocamlc -version` # OCaml version 4.04 or later is required case "$ocamlver" in [123].* | 4.0[0123].*) echo "OCaml version $ocamlver is no longer supported." echo "OCaml version 4.04.0 or later is required." exit 2 ;; esac # -bin-annot available since 4.00.0 echo "OCaml supports -bin-annot to produce documentation" hasbinannot='yes' # Changes to C API (the custom_operation struct) since 4.08.0 case "$ocamlver" in [123].* | 4.0[01234567].* ) echo "Using OCaml legacy C API custom operations" ccdef="-DZ_OCAML_LEGACY_CUSTOM_OPERATIONS $ccdef" ;; *) ;; esac # dump Makefile cat > Makefile <