3 # This is a script to configure the distribution. Its primary audience
4 # are the core developers and halo developers, and not end-users. Please
5 # see the INSTALL file for proper building instructions using cmake.
7 # "Tatzer" (Taf-Tzadik-Reish) is the Hebrew word for "configure!".
12 use Getopt::Long qw/ GetOptions /;
13 use Path::Tiny qw/path/;
15 my %BOOL_OPTS_WITH_FALSE_DEFAULTS =
16 ( 'omit-frame' => 'OPTIMIZATION_OMIT_FRAME_POINTER', );
18 my %TRUE_BOOL_OPTS = ( 'test-suite' => 'FCS_WITH_TEST_SUITE', );
20 my %INT_OPTS = ( 'pack-size' => 'FCS_IA_PACK_SIZE', );
23 'arch' => { param => 'CPU_ARCH', },
24 'prefix' => { param => 'CMAKE_INSTALL_PREFIX', },
27 my ( $key, $param ) = @$_;
28 ( $key => +{ prefix => "${param}_", param => $param } )
29 } ( [ 'p|pos' => 'BHS_STATE_STORAGE' ], )
33 my @BOOL_OPTS_WITH_FALSE_DEFAULTS__KEYS = keys %BOOL_OPTS_WITH_FALSE_DEFAULTS;
35 my %bool_opts_with_false_defaults__values =
36 ( map { $_ => 0 } @BOOL_OPTS_WITH_FALSE_DEFAULTS__KEYS );
38 my @TRUE_BOOL_KEYS = keys %TRUE_BOOL_OPTS;
39 my %true_bool_opts__values = map { $_ => 1 } @TRUE_BOOL_KEYS;
41 my @INT_OPS__KEYS = keys %INT_OPTS;
43 my %int_opts__values = ( map { $_ => undef() } @INT_OPS__KEYS );
45 my @STR_OPTS__KEYS = keys %STR_OPTS;
46 for my $k (@STR_OPTS__KEYS)
48 $STR_OPTS{$k}{'value'} = undef();
49 $STR_OPTS{$k}{'prefix'} //= '';
52 $STR_OPTS{'prefix'}{value} = '/usr';
54 my $build_type = "debug";
56 my $build_static_lib = 0;
57 my $with_context_var = 1;
58 my $max_bench_threads_num = 4;
59 my $link_to_static = 0;
64 foreach my $k ('p|pos')
66 $STR_OPTS{$k}{'value'} = $val;
73 return set_both("INTERNAL_HASH");
79 tt => [qw(-r --notest-suite --static)],
80 bench => [qw(-l tt --omit-frame)],
81 fc_bench => [qw(-l bench)],
82 testing => [qw(--rwd --test-suite)],
86 my $SEED_KEY = 'FCS_THEME_RAND';
87 my $SEED = $ENV{$SEED_KEY};
90 if ( $SEED =~ /[^0-9]/ )
92 die "Invalid value for seed!";
95 foreach my $flags ( values %themes )
97 for ( my $idx = 0 ; $idx < @$flags ; ++$idx )
99 my $flag = $flags->[$idx];
110 my @k = sort { $a cmp $b } keys %k;
112 require Math::Random::MT;
113 my $gen = Math::Random::MT->new($SEED);
117 if ( $gen->rand() < 0.5 )
122 my $FN = "run-t-$SEED.bash";
123 path($FN)->spew_utf8( join( ' ', $^X, $0, @subset ) . "\n" );
124 delete $ENV{$SEED_KEY};
128 my $HOME = $ENV{HOME};
131 { id => "c2", a => "core2", },
132 { id => "ci7", a => "corei7-avx", },
133 { id => "n2", a => "native", },
134 { id => "p4", a => "pentium4" },
135 { id => "x64", a => "barcelona" },
139 my $arch = $rec->{a};
141 $themes{$id} = [ "--arch=$arch", "--prefix=$HOME/apps/fcs", ];
144 my ( $suffix, $theme ) = @_;
145 $themes{ $id . $suffix } = [@$theme];
149 my ( $suffix, $theme ) = @_;
150 return $def->( $suffix, [ '-l', $theme, '-l', $id ] );
153 my ( $suffix, $theme ) = @_;
154 return $def->( $suffix, [ '-l', $id . 'bb', @$theme ] );
157 # Benchmark for freecell only
158 $id_def->( b => 'fc_bench' );
160 # Generalised benchmark - not freecell-only - should pass the tests.
161 $id_def->( bb => 'bench' );
163 # Memory conserving theme - for freecell only
164 $id_def->( m => 'fc_reduce_mem' );
166 # Generalised Memory conserving theme - not only for freecell
167 $id_def->( mm => 'reduce_mem' );
169 # Testing theme - aims to run the tests quickly
170 $bb_def->( t => [qw(-l testing)] );
174 _pysol => [ '-l', 'pysol_defs', "--prefix=$HOME/apps/fcs-for-pysol", ]
178 my @new_argv = @ARGV;
181 for ( my $idx = 0 ; $idx < @new_argv ; ++$idx )
183 if ( my ($arg_val) = $new_argv[$idx] =~ m{\A-l(.*)\z}ms )
185 my $start_idx = $idx;
187 my $param = $arg_val || $new_argv[ ++$idx ];
189 if ( !( my $cmd = $themes{$param} ) )
191 die "Unknown -l argument $param!";
195 splice( @new_argv, $start_idx, $idx - $start_idx + 1, @$cmd );
212 my ( $opt, $val ) = @_;
215 $build_type = "debug";
220 my ( $opt, $val ) = @_;
223 $build_type = "release";
225 elsif ( $build_type eq "release" )
227 $build_type = "debug";
231 'hash' => \&set_hash,
233 my ( $opt, $val ) = @_;
236 $build_type = "profile";
238 elsif ( $build_type eq "profile" )
240 $build_type = "debug";
245 $build_type = "MinSizeRel";
248 'gen=s' => \$generate_what,
250 my ( $opt, $val ) = @_;
252 $build_type = "RelWithDebInfo";
256 'tokyo' => sub { return set_both("TOKYO_CAB_HASH"); },
257 'static' => \$build_static_lib,
258 'with-ctx-var!' => \$with_context_var,
259 'max-bench-threads-num=i' => \$max_bench_threads_num,
260 'static!' => \$link_to_static,
262 map { ; "$_!" => \( $bool_opts_with_false_defaults__values{$_} ) }
263 @BOOL_OPTS_WITH_FALSE_DEFAULTS__KEYS
265 ( map { ; "$_!" => \( $true_bool_opts__values{$_} ) } @TRUE_BOOL_KEYS ),
266 ( map { ; "$_=i" => \( $int_opts__values{$_} ) } @INT_OPS__KEYS ),
267 ( map { ; "$_=s" => \( $STR_OPTS{$_}{value} ) } @STR_OPTS__KEYS ),
268 ) or die "Wrong options";
270 my $path_to_source_dir;
274 $path_to_source_dir = shift(@ARGV);
278 die "Junk at the end of ARGV - <@ARGV>";
283 $path_to_source_dir = path($0)->parent(2)->child("fortune-mod");
286 # This cache is sometimes causing problems.
287 unlink("CMakeCache.txt");
288 path($_)->remove_tree foreach ( '_Inline', 't/_Inline' );
289 unlink( glob("*.so") );
294 defined( $ENV{CMAKE_MAKE_PROGRAM} )
295 ? "-DCMAKE_MAKE_PROGRAM=$ENV{CMAKE_MAKE_PROGRAM}"
298 ( defined($generate_what) ? ( "-G", $generate_what ) : () ),
299 "-DCMAKE_BUILD_TYPE=$build_type",
300 "-DDATADIR=$STR_OPTS{prefix}{value}/share",
301 ( ( !$build_static_lib ) ? ("-DBUILD_STATIC_LIBRARY=") : () ),
304 $bool_opts_with_false_defaults__values{$_}
305 ? ( "-D" . $BOOL_OPTS_WITH_FALSE_DEFAULTS{$_} . "=1" )
307 } @BOOL_OPTS_WITH_FALSE_DEFAULTS__KEYS
312 . $TRUE_BOOL_OPTS{$_} . '='
313 . ( $true_bool_opts__values{$_} ? '1' : '' )
318 defined( $int_opts__values{$_} )
319 ? ( "-D" . $INT_OPTS{$_} . "=" . $int_opts__values{$_} )
326 my $r = $STR_OPTS{$k};
328 defined($v) ? ("-D$r->{param}=$r->{prefix}$v") : ()
333 push @cmd, $path_to_source_dir;
335 print( join( " ", @cmd ), "\n" );
336 my $exit_code = system(@cmd);
337 exit( $exit_code ? 1 : 0 );
341 =head1 COPYRIGHT AND LICENSE
343 This file is part of Black Hole Solitaire Solver. It is subject to the license
344 terms in the COPYING file found in the top-level directory of this distribution
345 and at https://github.com/shlomif/black-hole-solitaire/blob/master/LICENSE .
346 No part of Black Hole Solitaire Solver, including this file, may be copied,
347 modified, propagated, or distributed except according to the terms contained
350 Copyright (c) 2009 Shlomi Fish