forked from Leont/libperl--
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild
executable file
·140 lines (117 loc) · 3.45 KB
/
Build
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
128
129
130
131
132
133
134
135
136
137
138
139
140
#! /usr/bin/perl
#This should eventually become the product of a Build.PL
use 5.008;
use strict;
use warnings;
use lib 'inc';
use Library::Build;
use Config;
use ExtUtils::Embed qw/ldopts/;
my @debug = qw/-ggdb3 -DDEBUG/;
my @warnings = qw/-Wall -Wshadow -Wnon-virtual-dtor -Wsign-promo -Wextra/;
my @testcleanfiles = (<t/*.o>, <t/*.t>);
my @cleanfiles = (qw{/examples/combined source/ppport.h source/evaluate.C headers/config.h blib}, @testcleanfiles);
my @cc_flags = (@debug, @warnings);
my %libraries = (
'perl++' => {
input => [ qw/array.C call.C evaluate.C exporter.C glob.C hash.C handle.C helpers.C interpreter.C primitives.C reference.C regex.C regex_foreign.C scalar.C/ ],
input_dir => 'source',
linker_flags => ldopts . ' -lstdc++',
include_dirs => [qw/headers source/],
cc_flags => \@cc_flags,
'c++' => 1,
},
'tap++' => {
input => 'tap++.C',
input_dir => 'source',
include_dirs => [ qw/headers/ ],
cc_flags => \@cc_flags,
linker_flags => '-lstdc++',
'c++' => 1,
},
);
my %options = (
silent => 0,
);
sub build {
create_dir(\%options, 'blib');
create_by_system {
(my $oldname = $_ ) =~ s{ headers / (\w+) \.h }{source/$1.pre}x;
"$Config{cpp} $Config{ccflags} -I$Config{archlibexp}/CORE $oldname > $_";
} \%options, qw{headers/config.h headers/extend.h};
create_by_system { "$^X $_.PL > $_" } \%options, 'source/evaluate.C';
for my $library_name (keys %libraries) {
build_library($library_name => $libraries{$library_name});
}
}
my %tests = map { (my $foo = $_) =~ s/\.C$/.t/; $_ => $foo } glob 't/*.C';
my %examples = (
executables => [ qw/combined game/ ],
libraries => [ qw/Extend/ ]
);
sub build_examples {
for my $example_name (@{$examples{executables}}) {
build_executable("examples/$example_name.C", "blib/example_name",
include_dirs => [ 'headers' ],
extra_compiler_flags => \@cc_flags,
extra_linker_flags => [ qw/-lstdc++ -Lblib -lperl++/ ],
);
}
for my $example_name (@{$examples{libraries}}) {
build_library($example_name, {
input => [ "$example_name.C" ],
input_dir => 'examples',
include_dirs => [ 'headers' ],
cc_flags => \@cc_flags,
linker_flags => [ qw/-lstdc++ -Lblib -lperl++/ ],
libfile => "blib/$example_name.$Config{dlext}",
});
}
}
sub build_tests {
for my $test_source (sort keys %tests) {
build_executable($test_source, $tests{$test_source},
include_dirs => [ 'headers' ],
extra_compiler_flags => \@cc_flags,
extra_linker_flags => [ qw/-lstdc++ -Lblib -lperl++ -ltap++/ ],
);
}
}
#my %examples = map { (my $foo = $_) =~ s{ ^ examples/ (.*) \.C $ } {blib/$1}x; $_ => $foo } glob 'examples/*.C';
for my $argument (@ARGV) {
if ($argument =~ / ^ (\w+) = (.*) $ /xms) {
$options{$1} = $2;
}
else {
$options{$argument} = 1;
}
}
make_silent($options{silent}) if $options{silent};
my @test_goals = $options{test_files} ? split / /, $options{test_files} : sort values %tests;
my %action_map = (
build => \&build,
test => sub {
build;
build_tests;
run_tests(\%options, @test_goals)
},
testbuild => sub {
build;
build_tests;
},
examples => sub {
build;
build_examples;
},
clean => sub {
remove_tree(\%options, @cleanfiles);
},
testclean => sub {
remove_tree(\%options, @testcleanfiles);
},
help => sub {
print "No help available yet\n";
},
);
my $action = $action_map{shift || 'build'} or die "No such action defined\n";
$action->();