1 # Copyright (C) 2001-2010, Parrot Foundation.
6 config/gen/config_pm.pm - Record configuration data
10 Writes the C<Parrot::Config::Generated> Perl module, the
11 F<runtime/parrot/library/config.fpmc> generator program, and the F<myconfig>
16 package gen
::config_pm
;
21 use base
qw(Parrot::Configure::Step);
22 use Parrot
::Configure
::Utils
':gen';
25 use File
::Spec
::Functions
qw(catdir);
30 $data{description
} = q{Record configuration data for later retrieval};
33 myconfig
=> 'config/gen/config_pm/myconfig.in',
34 config_pir
=> 'config/gen/config_pm/config_pir.in',
35 Config_pm
=> 'config/gen/config_pm/Config_pm.in',
36 config_lib
=> 'config/gen/config_pm/config_lib_pir.in',
42 my ( $self, $conf ) = @_;
46 my $template = $self->{templates
}->{myconfig
};
47 $conf->genfile($template, 'myconfig' );
49 $template = $self->{templates
}->{config_pir
};
50 my $gen_pir = q{runtime/parrot/library/config.pir};
51 $conf->append_configure_log($gen_pir);
52 $conf->genfile($template, $gen_pir );
54 $template = $self->{templates
}->{Config_pm
};
55 open( my $IN, "<", $template )
56 or die "Can't open $template: $!";
58 my $configdir = catdir
(qw
/lib Parrot Config/);
59 unless ( -d
$configdir ) {
61 or die "Can't create dir $configdir: $!";
63 my $gen_pm = q{lib/Parrot/Config/Generated.pm};
64 $conf->append_configure_log($gen_pm);
65 open( my $OUT, ">", $gen_pm )
66 or die "Can't open $gen_pm: $!";
68 # escape spaces in current directory
72 # Build directory can have non ascii characters
73 # Maybe not the better fix, but allows keep working on the issue.
76 if ($cwd =~ /[^[:ascii:]]/) {
77 $cwdcharset = 'binary:';
80 my $pkg = __PACKAGE__
;
83 # DO NOT EDIT THIS FILE
84 # Generated by $pkg from $template
89 s/\@PCONFIG\@/$conf->data->dump(q{c}, q{*PConfig})/e;
90 s/\@PCONFIGTEMP\@/$conf->data->dump(q{c_temp}, q{*PConfig_Temp})/e;
94 close $IN or die "Can't close $template: $!";
95 close $OUT or die "Can't close $gen_pm: $!";
97 $template = $self->{templates
}->{config_lib
};
98 open( $IN, "<", $template ) or die "Can't open '$template': $!";
99 my $c_l_pir = q{config_lib.pir};
100 $conf->append_configure_log($c_l_pir);
101 open( $OUT, ">", $c_l_pir ) or die "Can't open $c_l_pir: $!";
103 print {$OUT} <<"END";
105 # DO NOT EDIT THIS FILE
106 # Generated by $pkg from $template and \%PConfig
107 # This file should be the last thing run during
108 # the make process, after Parrot is built.
112 my %p5_keys = map { $_ => 1 } $conf->data->keys_p5();
113 # A few of these keys are still useful.
114 my @p5_keys_whitelist = qw(archname ccflags longsize optimize);
115 foreach my $key (@p5_keys_whitelist) {
116 delete($p5_keys{$key});
121 for my $k ( sort { lc $a cmp lc $b || $a cmp $b } $conf->data->keys ) {
122 next if exists $p5_keys{$k};
123 next if $k =~ /_provisional$/;
125 my $v = $conf->data->get($k);
129 die "type of '$k' is not supported : $type\n";
134 # escape unescaped double quotes
135 $v =~ s/(?<!\\)"/\\"/g;
138 if ($v =~ /[^[:ascii:]]/) {
139 $charset = 'binary:';
141 print {$OUT} qq( set \
$P0["$k"], $charset"$v"\n);
145 print {$OUT} qq( set \
$P0["$k"], \
$S2\n);
149 elsif (s/\"\@PWD\@\"/$cwdcharset\"$cwd\"/) {
157 close $IN or die "Can't close $template: $!";
158 close $OUT or die "Can't close $c_l_pir: $!";
167 # cperl-indent-level: 4
170 # vim: expandtab shiftwidth=4: