1 # Copyright (C) 2001-2007, The Perl Foundation.
6 config/gen/platform.pm - Platform Files
10 Moves the various platform-specific files into place.
14 package gen
::platform
;
20 use base
qw(Parrot::Configure::Step);
22 use Parrot
::Configure
::Utils
':gen';
27 $data{description
} = q{Moving platform files into place};
33 my ( $self, $conf ) = @_;
35 my $verbose = $conf->options->get('verbose');
36 my $platform = lc ( $conf->data->get_p5('OSNAME') );
38 $platform = "ansi" if defined( $conf->options->get('miniparrot') );
39 $platform = "win32" if $platform =~ /^msys/;
40 $platform = "win32" if $platform =~ /^mingw/;
43 if ( ( split m/-/, $conf->data->get_p5('archname'), 2 )[0] eq 'ia64' ) {
47 $platform = 'generic' unless -d
"config/gen/platform/$platform";
49 print " platform='$platform' " if $verbose;
51 my $generated = $conf->data->get('TEMP_generated');
52 $generated = '' unless defined $generated;
53 print " ($generated) " if $verbose;
54 print("\n") if defined $verbose && $verbose == 2;
59 * c-file-style: "parrot"
62 * vim: expandtab shiftwidth=4:
66 # headers are merged into platform.h
78 my $plat_h = q{include/parrot/platform.h};
79 $conf->append_configure_log($plat_h);
80 open my $PLATFORM_H, ">", $plat_h
81 or die "Can't open $plat_h: $!";
83 print {$PLATFORM_H} <<"END_HERE";
85 ** !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
87 ** This file is generated automatically by config/gen/platform.pm
89 #ifndef PARROT_PLATFORM_H_GUARD
90 #define PARROT_PLATFORM_H_GUARD
93 ** platform.h [$platform version]
95 ** DO NOT EDIT THIS FILE
97 ** Generated by config/gen/platform.pm
103 my $header_file = "config/gen/platform/generic/$_";
104 if ( -e "config/gen/platform/$platform/$_" ) {
105 $header_file = "config/gen/platform/$platform/$_";
108 if ( -e $header_file ) {
110 print("\t$header_file\n") if defined $verbose && $verbose == 2;
111 open my $IN_H, "<", "$header_file"
112 or die "Can't open $header_file: $!";
114 # slurp in the header file
117 # remove the (in this case) superfluous coda
118 $in_h =~ s{\Q$coda\E\n*\z}{}xgs;
120 print {$PLATFORM_H} <<"END_HERE
";
124 #line 1 "$header_file"
126 print {$PLATFORM_H} $in_h, "\n\n";
130 # just fall through if file is missing; means neither this platform nor
131 # generic has anything to contribute for this feature. this might not
132 # be desirable if porters don't see the appropriate file in generic/ and
133 # shoehorn their function into the wrong file rather than creating the
134 # correct one from the above list in their $platform/ dir (e.g. misc.c).
137 # finally append generated
138 @headers = grep { /\.h$/ } split( m/,/, $generated );
142 print("\t$_\n") if defined $verbose && $verbose == 2;
143 open my $IN_H, "<", "$_" or die "Can
't open $_: $!";
144 print {$PLATFORM_H} <<"END_HERE";
150 print {$PLATFORM_H} <$IN_H>, "\n\n";
154 warn("Header file '$_' listed in TEMP_generated but not found\n");
159 print $PLATFORM_H <<"END_HERE";
160 #endif /* PARROT_PLATFORM_H_GUARD */
167 # implementation files are merged into platform.c
182 my $plat_c = q{src/platform.c};
183 $conf->append_configure_log($plat_c);
184 open my $PLATFORM_C, ">", $plat_c
185 or die "Can't open $plat_c: $!";
187 print {$PLATFORM_C} <<"END_HERE";
189 ** platform.c [$platform version]
191 ** DO NOT EDIT THIS FILE
193 ** Generated by config/gen/platform.pm
196 /* HEADERIZER HFILE: none */
197 /* HEADERIZER STOP */
200 # We need to put things from begin.c before the parrot.h include.
201 if ( -e "config/gen/platform/$platform/begin.c" ) {
203 open my $IN_C, "<", "config/gen/platform/$platform/begin.c" or die "Can't open begin.c: $!";
205 # slurp in the C file
208 # remove the (in this case) superfluous coda
209 $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
211 print {$PLATFORM_C} <<"END_HERE
";
215 #line 1 "config
/gen/platfor
m/$platform/begin
.c
"
217 print {$PLATFORM_C} $in_c, "\n\n";
222 print {$PLATFORM_C} <<'END_HERE';
223 #include "parrot
/parrot
.h
"
228 my $impl_file = "config
/gen/platfor
m/generic/$_";
229 if ( -e "config
/gen/platfor
m/$platform/$_" ) {
230 $impl_file = "config
/gen/platfor
m/$platform/$_";
233 if ( -e $impl_file ) {
235 print("\t$impl_file\n") if defined $verbose && $verbose == 2;
236 open my $IN_C, "<", "$impl_file" or die "Can
't open $impl_file: $!";
238 # slurp in the C file
241 # remove the (in this case) superfluous coda
242 $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
244 print {$PLATFORM_C} <<"END_HERE";
250 print {$PLATFORM_C} $in_c, "\n\n";
255 # append generated c files
256 @impls = grep { /\.c$/ } split( m/,/, $generated );
260 print("\t$_\n") if defined $verbose && $verbose == 2;
261 open my $IN_C, "<", "$_" or die "Can't
open $_: $!";
262 print {$PLATFORM_C} <<"END_HERE";
268 print {$PLATFORM_C} <$IN_C>, "\n\n";
273 # append the C code coda to the generated file
274 print {$PLATFORM_C} <<"END_HERE";
281 if ( $conf->data->get('platform_asm') ) {
282 my $asm_file = "config/gen/platform/$platform/asm.s";
283 if ( -e $asm_file ) {
284 copy_if_diff( $asm_file, "src/platform_asm.s" );
288 # interface is the same for all platforms
289 copy_if_diff( "config/gen/platform/platform_interface.h",
290 "include/parrot/platform_interface.h" );
299 # cperl-indent-level: 4
302 # vim: expandtab shiftwidth=4: