black-hole-solitaire / black-hole-solitaire / all-in-a-row-c-solver / Tatzer

#!/usr/bin/env perl

# This is a script to configure the distribution. Its primary audience
# are the core developers and halo developers, and not end-users. Please
# see the INSTALL file for proper building instructions using cmake.
#
# "Tatzer" (Taf-Tzadik-Reish) is the Hebrew word for "configure!".

use strict;
use warnings;

use Getopt::Long;

my $build_type = "debug";
my $state_storage;
my $prefix = "/usr";
my $build_static_lib = 0;
my $test_suite = 1;
my $cpu_arch;
my $omit_frame;
my $state_storage_libavl2_tree;
my $stack_storage_libavl2_tree;
my $with_context_var = 1;
my $max_bench_threads_num = 4;
my $pack_size;
my $link_to_static = 0;

sub set_both
{
    my $val = shift;
    $state_storage = $val;

    return;
}

sub set_hash
{
    return set_both("INTERNAL_HASH");
}

set_hash();

my %themes =
(
    tt => [qw(-r --notest-suite --static)],
    bench => [qw(-l tt --omit-frame)],
    fc_bench => [qw(-l bench)],
);

foreach my $rec (
    {id => "p4", a => "pentium4"},
    {id => "x64", a => "barcelona"},
    {id => "c2", a => "core2",},
    {id => "ci7", a => "corei7-avx",}
)
{
    my $id = $rec->{id};
    my $arch = $rec->{a};

    $themes{$id} = ["--arch=$arch"];
    # Benchmark for freecell only
    $themes{$id.'b'} = [qw(-l fc_bench -l), $id];
    # Generalised benchmark - not freecell-only - should pass the tests.
    $themes{$id.'bb'} = [qw(-l bench -l), $id];
    # Memory conserving theme - for freecell only
    $themes{$id.'m'} = [qw(-l fc_reduce_mem -l), $id];
    # Generalised Memory conserving theme - not only for freecell
    $themes{$id.'mm'} = [qw(-l reduce_mem -l), $id];
    # Testing theme - aims to run the tests quickly
    $themes{$id.'t'} = ['-l', $id.'bb', '--rwd', '--dbm=kaztree', '--test-suite',];

    # For use by PySolFC
    $themes{$id . "_pysol"} = ['-l', $id.'bb', '--num-stacks=14', "--prefix=$ENV{HOME}/apps/fcs-for-pysol",];
}

my @new_argv = @ARGV;

CALC_NEW_ARGV:
for (my $idx = 0; $idx < @new_argv ; $idx++)
{
    if ($new_argv[$idx] =~ m{\A-l(.*)\z}ms)
    {
        my $start_idx = $idx;

        my $param = $1 || $new_argv[++$idx];

        if (! (my $cmd = $themes{$param}) )
        {
            die "Unknown -l argument $param!";
        }
        else
        {
            splice (@new_argv, $start_idx, $idx-$start_idx+1, @$cmd);
        }

        $idx = $start_idx;
        redo CALC_NEW_ARGV;
    }
}

@ARGV = @new_argv;

GetOptions(
    'd|debug' => sub {
        my ($opt, $val) = @_;
        if ($val)
        {
            $build_type = "debug";
        }
        return;
    },
    'r|release' => sub {
        my ($opt, $val) = @_;
        if ($val)
        {
            $build_type = "release";
        }
        elsif ($build_type eq "release")
        {
            $build_type = "debug";
        }
        return;
    },
    'p|pos=s' => \$state_storage,
    'libavl2-p=s' => \$state_storage_libavl2_tree,
    'libavl2-c=s' => \$stack_storage_libavl2_tree,
    'prefix=s' => \$prefix,
    'test-suite!' => \$test_suite,
    'tokyo' => sub { return set_both("TOKYO_CAB_HASH"); },
    'hash' => \&set_hash,
    'static' => \$build_static_lib,
    'profile' => sub {
        my ($opt, $val) = @_;
        if ($val)
        {
            $build_type = "profile";
        }
        elsif ($build_type eq "profile")
        {
            $build_type = "debug";
        }
        return;
    },
    'minsize' => sub {
        $build_type = "MinSizeRel";
        return;
    },
    'arch=s' => \$cpu_arch,
    'omit-frame!' => \$omit_frame,
    'with-ctx-var!' => \$with_context_var,
    'max-bench-threads-num=i' => \$max_bench_threads_num,
    'pack-size=i' => \$pack_size,
    'static!' => \$link_to_static,
) or
    die "Wrong options";

my $dir = shift(@ARGV) || '.';

if ($state_storage_libavl2_tree)
{
    $state_storage = "LIBAVL2_TREE";
}

# This cache is sometimes causing problems.
unlink("CMakeCache.txt");

my @cmd= ("cmake",
    "-DCMAKE_BUILD_TYPE=$build_type",
    "-DBHS_STATE_STORAGE=BHS_STATE_STORAGE_$state_storage",
    "-DCMAKE_INSTALL_PREFIX=$prefix",
    "-DDATADIR=$prefix/share",
    ((!$build_static_lib) ? ("-DBUILD_STATIC_LIBRARY=") : ()),
    (defined($pack_size) ? ("-DFCS_IA_PACK_SIZE=$pack_size") : ()),
    ($test_suite ? ("-DFCS_WITH_TEST_SUITE=1") : ()),
    (defined($cpu_arch) ? ("-DCPU_ARCH=$cpu_arch") : ()),
    ($omit_frame ? "-DOPTIMIZATION_OMIT_FRAME_POINTER=1" : ()),
    ($state_storage_libavl2_tree
        ? "-DFCS_STATE_STORAGE_LIBAVL2_TREE_TYPE=$state_storage_libavl2_tree"
        : ()
    ),
    ($stack_storage_libavl2_tree
        ? "-DFCS_STACK_STORAGE_LIBAVL2_TREE_TYPE=$stack_storage_libavl2_tree"
        : ()
    ),
    (exists($ENV{"LIBAVL2_SOURCE_DIR"})
        ? ("-DLIBAVL2_SOURCE_DIR=$ENV{LIBAVL2_SOURCE_DIR}")
        : ()
    ),
    $dir
);

print(join(" ", @cmd), "\n");
exec(@cmd);

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2009 Shlomi Fish

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

=cut
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.