<commit_before># Configure.pm 

say "\nConfigure.pm is preparing to make your Makefile.\n";

# Determine how this Configure.p6 was invoked, to write the same paths
# and executables into the Makefile variables. The variables are:
# PERL6       how to execute a Perl 6 script
# PERL6LIB    initial value of @*INC, where use <module> searches
# PERL6BIN    directory where executables such as prove reside
# RAKUDO_DIR  (deprecated) currently the location of Rakudo's Test.pm

my $parrot_dir = %*VM<config><build_dir>;
my $rakudo_dir;
my $perl6;
# There are now just two possible relationships between the parrot and
# rakudo directories: rakudo/parrot or parrot/languages/rakudo
if $parrot_dir ~~ / <parrot_in_rakudo> / {
    # first case, rakudo/parrot for example if installed using new
    # 'git clone ...rakudo.git' then 'perl Configure.pl --gen-parrot'
    $rakudo_dir = $parrot_dir.subst( / '/parrot' $ /, ''); #'
}
elsif "$parrot_dir/languages/rakudo" ~~ :d {
    # second case, parrot/languages/rakudo if installed the old way
    $rakudo_dir = "$parrot_dir/languages/rakudo";
}
else {
    say "PARROT_DIR unexpected $parrot_dir";
    exit(1);
}
if "$rakudo_dir/perl6" ~~ :f or "$rakudo_dir/perl6.exe" ~~ :f {
    $perl6 = "$rakudo_dir/perl6";  # the fake executable from pbc_to_exe
}
else {
    $perl6 = "$parrot_dir/parrot $rakudo_dir/perl6.pbc";
}

say "PERL6       $perl6";
# The perl6-examples/lib/SVG directory is one level below lib/, so trim
# off the last / and directory name off PWD to make PERL6LIB.
my $perl6lib = %*ENV<PWD>.subst( / \/ <-[/]>+ $ /, '' ); # trim slash then non slash at end
say "PERL6LIB    $perl6lib";
# The perl6-examples/bin directory is a sibling of PERL6LIB
my $perl6bin = $perl6lib.subst( '/lib', '/bin' );
say "PERL6BIN    $perl6bin";
say "RAKUDO_DIR  $rakudo_dir";

# Read Makefile.in, edit, write Makefile
my $maketext = slurp( 'Makefile.in' );
$maketext .= subst( 'Makefile.in', 'Makefile' );
$maketext .= subst( 'To be read', 'Written' );
$maketext .= subst( 'replaces <TOKENS>', 'defined these' );
$maketext .= subst( '<PERL6>',      $perl6 );
$maketext .= subst( '<PERL6LIB>',   $perl6lib );
$maketext .= subst( '<PERL6BIN>',   $perl6bin );
$maketext .= subst( '<RAKUDO_DIR>', $rakudo_dir );
squirt( 'Makefile', $maketext );

# Job done.
say "\nMakefile is ready, running 'make' on it.";
run "make";
say "Configure and 'make' are complete. Use 'make help' to view other options.";
say "";


# The opposite of slurp
sub squirt( Str $filename, Str $text ) {
    my $handle = open( $filename, :w );    # should check for success
    $handle.print: $text;<commit_msg>added error checking to open call<commit_after># Configure.pm 

say "\nConfigure.pm is preparing to make your Makefile.\n";

# Determine how this Configure.p6 was invoked, to write the same paths
# and executables into the Makefile variables. The variables are:
# PERL6       how to execute a Perl 6 script
# PERL6LIB    initial value of @*INC, where use <module> searches
# PERL6BIN    directory where executables such as prove reside
# RAKUDO_DIR  (deprecated) currently the location of Rakudo's Test.pm

my $parrot_dir = %*VM<config><build_dir>;
my $rakudo_dir;
my $perl6;
# There are now just two possible relationships between the parrot and
# rakudo directories: rakudo/parrot or parrot/languages/rakudo
if $parrot_dir ~~ / <parrot_in_rakudo> / {
    # first case, rakudo/parrot for example if installed using new
    # 'git clone ...rakudo.git' then 'perl Configure.pl --gen-parrot'
    $rakudo_dir = $parrot_dir.subst( / '/parrot' $ /, ''); #'
}
elsif "$parrot_dir/languages/rakudo" ~~ :d {
    # second case, parrot/languages/rakudo if installed the old way
    $rakudo_dir = "$parrot_dir/languages/rakudo";
}
else {
    say "PARROT_DIR unexpected $parrot_dir";
    exit(1);
}
if "$rakudo_dir/perl6" ~~ :f or "$rakudo_dir/perl6.exe" ~~ :f {
    $perl6 = "$rakudo_dir/perl6";  # the fake executable from pbc_to_exe
}
else {
    $perl6 = "$parrot_dir/parrot $rakudo_dir/perl6.pbc";
}

say "PERL6       $perl6";
# The perl6-examples/lib/SVG directory is one level below lib/, so trim
# off the last / and directory name off PWD to make PERL6LIB.
my $perl6lib = %*ENV<PWD>.subst( / \/ <-[/]>+ $ /, '' ); # trim slash then non slash at end
say "PERL6LIB    $perl6lib";
# The perl6-examples/bin directory is a sibling of PERL6LIB
my $perl6bin = $perl6lib.subst( '/lib', '/bin' );
say "PERL6BIN    $perl6bin";
say "RAKUDO_DIR  $rakudo_dir";

# Read Makefile.in, edit, write Makefile
my $maketext = slurp( 'Makefile.in' );
$maketext .= subst( 'Makefile.in', 'Makefile' );
$maketext .= subst( 'To be read', 'Written' );
$maketext .= subst( 'replaces <TOKENS>', 'defined these' );
$maketext .= subst( '<PERL6>',      $perl6 );
$maketext .= subst( '<PERL6LIB>',   $perl6lib );
$maketext .= subst( '<PERL6BIN>',   $perl6bin );
$maketext .= subst( '<RAKUDO_DIR>', $rakudo_dir );
squirt( 'Makefile', $maketext );

# Job done.
say "\nMakefile is ready, running 'make' on it.";
run "make";
say "Configure and 'make' are complete. Use 'make help' to view other options.";
say "";


# The opposite of slurp
sub squirt( Str $filename, Str $text ) {
    my $handle = open( $filename, :w )
        or die $!;
    $handle.print: $text;
{'fraction_non_alphanumeric': 0.14457601222307104, 'fraction_numerical': 0.012223071046600458, 'mean_word_length': 3.8625812441968432, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3550782', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1913, 'n_words': 584}