-
Notifications
You must be signed in to change notification settings - Fork 47
/
make.pl
executable file
·128 lines (119 loc) · 3.41 KB
/
make.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
# recompiles Perlito using itself saving result in lib*-new
use strict;
use warnings;
my $target_switch = shift || '-Cperl5';
my $backend;
my $target_dir;
my $target_suffix;
if ( $target_switch eq '-Cperl5' ) {
$backend = 'perl5';
$target_dir = 'lib5';
$target_suffix = '.pm';
}
elsif ( $target_switch eq '-Clisp' ) {
$backend = 'lisp';
$target_dir = 'liblisp';
$target_suffix = '.lisp';
}
elsif ( $target_switch eq '-Cjs' ) {
$backend = 'javascript';
$target_dir = 'libjs';
$target_suffix = '.js';
}
elsif ( $target_switch eq '-Cparrot' ) {
$backend = 'parrot';
$target_dir = 'libparrot';
$target_suffix = '.pir';
}
elsif ( $target_switch eq '-Cpython' ) {
$backend = 'python';
$target_dir = 'libpy';
$target_suffix = '.py';
}
elsif ( $target_switch eq '-Cruby' ) {
$backend = 'ruby';
$target_dir = 'librb';
$target_suffix = '.rb';
}
elsif ( $target_switch eq '-Cast-perl5' ) {
$backend = 'ast-perl5';
$target_dir = 'libast-perl5';
$target_suffix = '.p5ast';
}
elsif ( $target_switch eq '-Cast-json' ) {
$backend = 'ast-json';
$target_dir = 'libast-json';
$target_suffix = '.json';
}
else {
die "invalid option: $target_switch\n";
}
system( "rm -r '${target_dir}-new'" );
make( 'lib', $target_dir, "${target_dir}-new" );
if ( test( "${target_dir}-new" ) ) {
backup( $target_dir );
rename( $target_dir, "${target_dir}-new" );
}
#---
sub test {
warn "\n";
warn "automatic testing is not implemented yet.\n";
return 0;
}
sub backup {
}
sub compile {
my ($in,$out) = @_;
print("perl perlito.pl $target_switch $in > $out\n");
system("perl perlito.pl $target_switch $in > $out");
}
sub make {
my ($source,$old,$new) = @_;
mkdir($new);
my %seen;
for my $dir (`find $source -type d`) {
chomp($dir);
$dir =~ s/^\Q$source\/\E//;
next if $dir eq 'lib';
print("mkdir $new/$dir\n");
mkdir("$new/$dir");
}
for my $file (`find $source -name '*.pm'`) {
chomp($file);
$file =~ s/^\Q$source\/\E//;
next if $file eq "Perlito/Perl5/Runtime.pm"; # skip - this is a perl5 file
my $new_file = $file;
$new_file =~ s/\.pm$/$target_suffix/;
my $ast_file = $file;
$ast_file =~ s/\.pm$/.p5ast/;
$ast_file = "libast-perl5/$ast_file";
my $date_ast = -M $ast_file;
my $date_src = -M "$source/$file";
# warn " src $date_src ast $ast_file $date_ast ", ( $date_ast && $date_ast < $date_src && -s $ast_file ? "ok" : "not ok" ), "\n";
if ( $date_ast && $date_ast < $date_src && -s $ast_file ) {
# warn "ast looks ok\n";
if ( $backend eq 'ast-perl5' ) {
# skip
print("cp '$ast_file' '$new/$new_file'\n");
system("cp '$ast_file' '$new/$new_file'");
}
else {
compile( $ast_file, "$new/$new_file" );
}
}
else {
# warn "ast is outdated\n";
compile("$source/$file","$new/$new_file");
}
$seen{$file} = 1;
}
for my $file (`find $source -name '*.*'`) {
chomp($file);
$file =~ s/^\Q$source\/\E//;
if ( !$seen{$file} ) {
print("cp '$source/$file' '$new/$file'\n");
system("cp '$source/$file' '$new/$file'");
}
}
}