#!/usr/bin/env perl

use FindBin;
use lib $FindBin::Bin;
use Run qw(ret run);
use strict;

my $home = $ENV{'CHPL_HOME'};
if ( ! -d $home ) {
  $home = $FindBin::Bin . "/../../";
}

my $llvm;
my $preset_llvm = $ENV{'CHPL_LLVM'};

if ($preset_llvm eq "") {
  my $hostplatform = run("platform", "--host");
  my $hostcompiler = run("compiler", "--host");
  my $targplatform = run("platform", "--target");
  my $subdir = $home . "/third-party/llvm/install/" .
               $hostplatform . "-" . $hostcompiler;
  if ( -d $subdir && -f "$subdir/include/llvm/PassSupport.h" ) {
    $llvm = 'llvm';
  } else {
    $llvm = 'none';
  }
} else {
  $llvm = $preset_llvm;
}

ret($llvm);
print "$llvm\n" unless caller;
