tagged release 0.6.4
[parrot.git] / config / gen / platform.pm
blob64f7500dbccbfcf9742e56d9e136eb0835b76fb3
1 # Copyright (C) 2001-2007, The Perl Foundation.
2 # $Id$
4 =head1 NAME
6 config/gen/platform.pm - Platform Files
8 =head1 DESCRIPTION
10 Moves the various platform-specific files into place.
12 =cut
14 package gen::platform;
16 use strict;
17 use warnings;
20 use base qw(Parrot::Configure::Step);
22 use Parrot::Configure::Utils ':gen';
24 sub _init {
25 my $self = shift;
26 my %data;
27 $data{description} = q{Moving platform files into place};
28 $data{result} = q{};
29 return \%data;
32 sub runstep {
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/;
41 $platform =~ s/^ms//;
43 if ( ( split m/-/, $conf->data->get_p5('archname'), 2 )[0] eq 'ia64' ) {
44 $platform = '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;
56 my $coda = <<'CODA';
58 * Local variables:
59 * c-file-style: "parrot"
60 * buffer-read-only: t
61 * End:
62 * vim: expandtab shiftwidth=4:
64 CODA
66 # headers are merged into platform.h
67 my @headers = qw/
68 io.h
69 math.h
70 misc.h
71 dl.h
72 signal.h
73 stat.h
74 threads.h
75 string.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";
84 /* ex: set ro:
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
100 END_HERE
102 foreach (@headers) {
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 ) {
109 local $/ = undef;
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
115 my $in_h = <$IN_H>;
117 # remove the (in this case) superfluous coda
118 $in_h =~ s{\Q$coda\E\n*\z}{}xgs;
120 print {$PLATFORM_H} <<"END_HERE";
122 ** $header_file:
124 #line 1 "$header_file"
125 END_HERE
126 print {$PLATFORM_H} $in_h, "\n\n";
127 close $IN_H;
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 );
139 for (@headers) {
140 if ( -e $_ ) {
141 local $/ = undef;
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";
146 ** $_
148 #line 1 "$_"
149 END_HERE
150 print {$PLATFORM_H} <$IN_H>, "\n\n";
151 close $IN_H;
153 else {
154 warn("Header file '$_' listed in TEMP_generated but not found\n");
158 # Add the C-coda
159 print $PLATFORM_H <<"END_HERE";
160 #endif /* PARROT_PLATFORM_H_GUARD */
162 $coda
163 END_HERE
165 close $PLATFORM_H;
167 # implementation files are merged into platform.c
168 my @impls = qw/
169 time.c
170 env.c
171 dl.c
172 stat.c
173 math.c
174 memalign.c
175 signal.c
176 itimer.c
177 memexec.c
178 exec.c
179 misc.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 */
198 END_HERE
200 # We need to put things from begin.c before the parrot.h include.
201 if ( -e "config/gen/platform/$platform/begin.c" ) {
202 local $/ = undef;
203 open my $IN_C, "<", "config/gen/platform/$platform/begin.c" or die "Can't open begin.c: $!";
205 # slurp in the C file
206 my $in_c = <$IN_C>;
208 # remove the (in this case) superfluous coda
209 $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
211 print {$PLATFORM_C} <<"END_HERE";
213 ** begin.c
215 #line 1 "config/gen/platform/$platform/begin.c"
216 END_HERE
217 print {$PLATFORM_C} $in_c, "\n\n";
218 close $IN_C;
221 # Copy the rest.
222 print {$PLATFORM_C} <<'END_HERE';
223 #include "parrot/parrot.h"
225 END_HERE
227 for (@impls) {
228 my $impl_file = "config/gen/platform/generic/$_";
229 if ( -e "config/gen/platform/$platform/$_" ) {
230 $impl_file = "config/gen/platform/$platform/$_";
233 if ( -e $impl_file ) {
234 local $/ = undef;
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
239 my $in_c = <$IN_C>;
241 # remove the (in this case) superfluous coda
242 $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
244 print {$PLATFORM_C} <<"END_HERE";
246 ** $impl_file:
248 #line 1 "$impl_file"
249 END_HERE
250 print {$PLATFORM_C} $in_c, "\n\n";
251 close $IN_C;
255 # append generated c files
256 @impls = grep { /\.c$/ } split( m/,/, $generated );
257 for (@impls) {
258 if ( -e $_ ) {
259 local $/ = undef;
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";
264 ** $_:
266 #line 1 "$_"
267 END_HERE
268 print {$PLATFORM_C} <$IN_C>, "\n\n";
269 close $IN_C;
273 # append the C code coda to the generated file
274 print {$PLATFORM_C} <<"END_HERE";
276 $coda
277 END_HERE
279 close $PLATFORM_C;
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" );
292 return 1;
297 # Local Variables:
298 # mode: cperl
299 # cperl-indent-level: 4
300 # fill-column: 100
301 # End:
302 # vim: expandtab shiftwidth=4: