Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 457 lines (405 sloc) 11.9 KB
#!/bin/bash
# Copyright (c) 2011, Julien Verlaguet
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of Julien Verlaguet nor the names of
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cpp=""
cc=""
ar=""
ocamlc=""
ocamlopt=""
ocamldep=""
ocamllex=""
ocamlyacc=""
llc=""
llbindings=""
opt=""
llvm_cma=""
llvm_analysis_cma=""
llvm_bitwriter_cma=""
llvm_scalar_opts_cma=""
llvm_target_cma=""
stdlibdir=""
bindir=""
libdir=""
stack_align=""
trampoline_size=""
max_reg_ret=""
echo "**************************"
echo "* Configuring linearML *"
echo "**************************"
echo ""
while [ $# -gt 0 ]
do
case "$1" in
"") break;;
--cpp)
cpp=$2 ; shift ;;
--cc)
cc=$2 ; shift ;;
--ar)
ar=$2 ; shift ;;
--ocamlc)
ocamlc=$2 ; shift ;;
--ocamlopt)
ocamlopt=$2 ; shift ;;
--ocamldep)
ocamldep=$2 ; shift ;;
--ocamllex)
ocamllex=$2 ; shift ;;
--ocamlyacc)
ocamlyacc=$2 ; shift ;;
--bindir)
bindir=$ ; shift ;;
--libdir)
libdir=$2 ; shift ;;
--llc)
llc=$2 ; shift ;;
--llbindings)
llbindings=$2 ; shift ;;
--opt)
opt=$2 ; shift ;;
*) echo "Unkown option: \"$1\"" 2>&1 ; exit 2 ;;
esac;
shift
done
os=`uname`
make=`which make`
if test -z "$make"; then
echo "Couldn't file make"
fi
if test -z "$cc"; then
cc=`which gcc`;
if test -z "$cc"; then
echo "Couldn't find a C compiler please use --cc";
exit 2
fi
echo -e "Found cc\t: $cc"
fi
if test -z "$ar"; then
ar=`which ar`;
if test -z "$ar"; then
echo "Couldn't find ar please use --ar";
exit 2
fi
echo -e "Found ar\t: $ar"
fi
if test -z "$cpp"; then
cpp=`which g++`;
if test -z "$cpp"; then
echo "Couldn't find a C++ compiler please use --cpp";
exit 2
fi
echo -e "Found cpp\t: $cpp"
fi
if test -z "$ocamlc"; then
ocamlc=`which ocamlc.opt`;
if test -z "$ocamlc"; then
ocamlc=`which ocamlc`;
if test -z "$ocamlc"; then
echo "Couldn't find ocamlc compiler please use --ocamlc";
exit 2
fi
fi
echo -e "Found ocamlc\t: $ocamlc"
fi
if test -z "$ocamlopt"; then
ocamlopt=`which ocamlopt.opt`;
if test -z "$ocamlopt"; then
ocamlopt=`which ocamlopt`;
if test -z "$ocamlopt"; then
echo "Couldn't find ocamlopt please use --ocamlopt";
exit 2
fi
fi
echo -e "Found ocamlopt\t: $ocamlopt"
fi
if test -z "$ocamldep"; then
ocamldep=`which ocamldep`;
if test -z "$ocamldep"; then
echo "Couldn't find ocamldep please use --ocamldep" ; exit 2
fi
echo -e "Found ocamldep\t: $ocamldep"
fi
if test -z "$ocamllex"; then
ocamllex=`which ocamllex`;
if test -z "$ocamllex"; then
echo "Couldn't find ocamllex please use --ocamllex" ; exit 2
fi
echo -e "Found ocamllex\t: $ocamllex"
fi
if test -z "$ocamlyacc"; then
ocamlyacc=`which ocamlyacc`;
if test -z "$ocamlyacc"; then
echo "Couldn't find ocamlyacc please use --ocamlyacc" ; exit 2
fi
echo -e "Found ocamlyacc\t: $ocamlyacc"
fi
if test -z "$llc"; then
llc=`which llc-2.8`;
if test -z "$llc"; then
llc=`which llc`;
if test -z "$llc"; then
echo "Couldn't find a llc (llvm compiler) please use --llc";
exit 2
fi
fi
echo -e "Found llc\t: $llc"
fi
if test -z "$opt"; then
opt=`which opt-2.8`;
if test -z "$opt"; then
opt=`which opt`;
if test -z "$opt"; then
echo "Couldn't find a opt (llvm compiler) please use --opt";
exit 2
fi
fi
echo -e "Found opt\t: $opt"
fi
if [ $os = "Darwin" ]; then
llvm_cma="`ocamlc -where`/llvm.cma"
llbindings=`dirname $llvm_cma`
llvm_analysis_cma="$llbindings/llvm_analysis.cma"
llvm_analysis_cma_base="analysis"
llvm_bitwriter_cma="$llbindings/llvm_bitwriter.cma"
llvm_bitwriter_cma_base="bitwriter"
llvm_scalar_opts_cma="$llbindings/llvm_scalar_opts.cma"
llvm_scalar_opts_cma_base="sopts"
llvm_target_cma="$llbindings/llvm_target.cma"
llvm_target_cma_base="target"
fi
if test "$llbindings"; then
llvm_cma="$llbindings/llvm.cma";
llvm_analysis_cma="$llbindings/llvm_analysis.cma"
llvm_bitwriter_cma="$llbindings/llvm_bitwriter.cma"
llvm_scalar_opts_cma="$llbindings/llvm_scalar_opts.cma"
llvm_target_cma="$llbindings/llvm_target.cma"
if ! test -e "$llbindings/llvm.cma"; then
echo "Couldn't find: $llvm_cma"; exit 2;
fi
if ! test -e $llvm_analysis_cma; then
echo "Couldn't find: $llvm_analysis_cma"; exit 2;
fi
if ! test -e $llvm_bitwriter_cma; then
echo "Couldn't find: $llvm_bitwriter_cma"; exit 2;
fi
if ! test -e $llvm_scalar_opts_cma; then
echo "Couldn't find: $llvm_scalar_opts_cma"; exit 2;
fi
if ! test -e $llvm_target_cma; then
echo "Couldn't find: $llvm_target_cma"; exit 2;
fi
else $llbindings=$(ocamlc -where)
fi
if test -z "$llbindings"; then
if test -z "$llvm_cma"; then
llvm_cma="/usr/lib/ocaml/llvm-2.8/llvm.cma"
fi
if ! test -e "$llvm_cma"; then
llvm_cma="/usr/lib/ocaml/llvm-2.8/llvm.cma"
if ! test -e "$llvm_cma"; then
llvm_cma="/usr/local/lib/ocaml/llvm-2.8/llvm.cma"
if ! test -e "$llvm_cma"; then
llvm_cma="/usr/local/lib/ocaml/llvm.cma"
if ! test -e "$llvm_cma"; then
echo "Could not find ocaml bindings for llvm!" ; exit 2
fi
fi
fi
fi
llbindings=`dirname $llvm_cma`
if test -z "$llbindings"; then
llbindings="/usr/lib/ocaml/llvm-2.8"
fi
if test -z "$llbindings"; then
llbindings="/usr/lib/ocaml/llvm"
fi
if test -z "$llbindings"; then
llbindings="/usr/local/lib/ocaml/llvm"
fi
if test -z "$llbindings"; then
llbindings="/usr/share/lib/ocaml/llvm"
fi
if test -z "$llbindings"; then
echo "Could not find ocaml bindings for llvm" ;
exit 2
fi
echo -e "Found bindings\t: $llbindings"
llvm_cma="$llbindings/llvm.cma"
llvm_cma_base="llvm"
if test -z "$llvm_cma"; then
echo "Cound not find llvm.cma" ;
exit 2
else echo -e "Found $llvm_cma_base\t: $llvm_cma"
fi
llvm_analysis_cma="$llbindings/llvm_analysis.cma"
llvm_analysis_cma_base="analysis"
if test -z "$llvm_analysis_cma"; then
echo "Cound not find llvm_analysis.cma" ;
exit 2
else echo -e "Found $llvm_analysis_cma_base\t: $llvm_analysis_cma"
fi
llvm_bitwriter_cma="$llbindings/llvm_bitwriter.cma"
llvm_bitwriter_cma_base="bitwriter"
if test -z "$llvm_bitwriter_cma"; then
echo "Cound not find llvm°bitwriter.cma" ;
exit 2
else echo -e "Found $llvm_bitwriter_cma_base\t: $llvm_bitwriter_cma"
fi
llvm_scalar_opts_cma="$llbindings/llvm_scalar_opts.cma"
llvm_scalar_opts_cma_base="sopts"
if test -z "$llvm_scalar_opts_cma"; then
echo "Cound not find llvm_scalar_opts.cma" ;
exit 2
else echo -e "Found $llvm_scalar_opts_cma_base\t: $llvm_scalar_opts_cma"
fi
llvm_target_cma="$llbindings/llvm_target.cma"
llvm_target_cma_base="target"
if test -z "$llvm_target_cma"; then
echo "Cound not find llvm_target.cma" ;
exit 2
else echo -e "Found $llvm_target_cma_base\t: $llvm_target_cma"
fi
fi
echo ""
llc_version=`$llc -version | grep version` ;
if [[ "$llc_version" =~ .*version.2.[8|9].* ]]; then
echo -e "Checking llc \t: OK$llc_version"
else
echo "Bad version of llc (expected version 2.8): $version" 2>&1;
exit 2
fi
opt_version=`$opt -version | grep version` ;
if [[ "$opt_version" =~ .*version.2.[8|9].* ]]; then
echo -e "Checking opt \t: OK$opt_version"
else
echo "Bad version of opt (expected version 2.8): $version" 2>&1;
exit 2
fi
ocamlc_version=`$ocamlc -version` ;
if [[ "$ocamlc_version" =~ 3.1[^0].* ]]; then
echo -e "Checking ocamlc \t: OK $ocamlc_version"
else
echo "Bad version of ocamlc (< 3.11): $version" 2>&1;
exit 2
fi
ocamlopt_version=`$ocamlopt -version` ;
if [[ "$ocamlopt_version" =~ 3.1[^0].* ]]; then
echo -e "Checking ocamlopt\t: OK $ocamlopt_version"
else
echo "Bad version of ocamlopt (< 3.11): $version" 2>&1;
exit 2
fi
ocamllex_version=`$ocamllex -version` ;
if [[ "$ocamllex_version" =~ 3.1[^0].* ]]; then
echo -e "Checking ocamllex\t: OK $ocamllex_version"
else
echo "Bad version of ocamllex (< 3.11): $version" 2>&1;
exit 2
fi
ocamlyacc_version=`$ocamlyacc -version` ;
if [[ "$ocamlyacc_version" =~ 3.1[^0].* ]]; then
echo -e "Checking ocamlyacc\t: OK $ocamlyacc_version"
else
echo "Bad version of ocamlyacc (< 3.11): $version" 2>&1;
exit 2
fi
ocamldep_version=`$ocamldep -version` ;
if [[ "$ocamldep_version" =~ 3.1[^0].* ]]; then
echo -e "Checking ocamldep\t: OK $ocamldep_version"
else
echo "Bad version of ocamldep (< 3.11): $version" 2>&1;
exit 2
fi
echo ""
gcc conf/size.c -o conf/get_size
march=`conf/get_size`
rm conf/get_size
if [[ "$march" == "ARCH_32" ]]; then
echo -e "Architecture\t: 32 bits"
else if [[ "$march" == "ARCH_64" ]]; then
echo -e "Architecture\t: 64 bits"
else echo "Unknown architecture!" ; exit 2
fi
fi
if test -z "$libdir"; then
libdir="$PWD/stdlib"
# will do for now
fi
config="Makefile.config"
rm -f "$config"
touch "$config"
echo "OCAMLLIB = $llbindings" >> "$config"
echo "OCAMLC = $ocamlc" >> "$config"
echo "OCAMLOPT = $ocamlopt" >> "$config"
echo "OCAMLDEP = $ocamldep" >> "$config"
echo "OCAMLLEX = $ocamllex" >> "$config"
echo "OCAMLYACC = $ocamlyacc" >> "$config"
echo "CC = $cc" >> "$config"
echo "AR = $ar" >> "$config"
echo "CPP = $cpp" >> "$config"
echo "LLVM_LIBS = $llvm_cma $llvm_analysis_cma $llvm_bitwriter_cma $llvm_scalar_opts_cma $llvm_target_cma" >> "$config"
config_ml="compiler/genGlobals.ml"
config_h="stdlib/config.h"
rm -f "$config_ml"
rm -f "$config_h"
touch "$config_ml"
if [[ $march == "ARCH_32" ]]; then
stack_align="4"
trampoline_size="10"
max_reg_ret="4"
data_layout="s0:32:32"
echo "#define ARCH_32" > "$config_h"
fi
if [[ $march == "ARCH_64" ]]; then
stack_align="8"
trampoline_size="16"
max_reg_ret="4"
data_layout="s0:64:64"
echo "#define ARCH_64" > "$config_h"
fi
echo -e "Stack alignment\t: $stack_align"
echo -e "Trampoline size\t: $trampoline_size"
echo -e "Return in registers\t: $max_reg_ret"
echo "let arch_type = \"$march\"" >> "$config_ml"
echo "let tramp_size = $trampoline_size" >> "$config_ml"
echo "let tramp_align = $stack_align" >> "$config_ml"
echo "let max_reg_return = $max_reg_ret" >> "$config_ml"
echo "let data_layout = \"$data_layout\"" >> "$config_ml"
echo "let llc = \"$llc\"" >> "$config_ml"
echo "let opt = \"$opt\"" >> "$config_ml"
echo "let stdlibdir = \"$libdir\"" >> "$config_ml"
echo "let cc = \"$cc\"" >> "$config_ml"
echo "let ar = \"$ar\"" >> "$config_ml"
echo ""
echo -e "Generated\t: $config"
echo -e "Generated\t: $config_ml"
echo -e "Generated\t: $config_h"
echo ""
echo "You can now start compiling LinearML"