Skip to content
This repository
tree: c6bab4c40d
Fetching contributors…

Cannot retrieve contributors at this time

executable file 456 lines (405 sloc) 12.178 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
#!/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.3.[0|1].* ]]; 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.3.[0|1].* ]]; then
    echo -e "Checking opt \t: OK$opt_version"
else
    echo "Bad version of opt (expected version 3.0): $version" 2>&1;
    exit 2
fi

ocamlc_version=`$ocamlc -version` ;
if [[ "$ocamlc_version" =~ 4.00.* ]]; 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" =~ 4.00.* ]]; 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" =~ 4.00.* ]]; then
    echo -e "Checking ocamllex\t: OK $ocamllex_version"
else
    echo "Bad version of ocamllex (< 4.00): $version" 2>&1;
    exit 2
fi

ocamlyacc_version=`$ocamlyacc -version` ;
if [[ "$ocamlyacc_version" =~ 4.00.* ]]; 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" =~ 4.00.* ]]; 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"
Something went wrong with that request. Please try again.