-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile.PL
More file actions
302 lines (245 loc) · 8.78 KB
/
Makefile.PL
File metadata and controls
302 lines (245 loc) · 8.78 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
use 5.020;
use ExtUtils::MakeMaker;
use strict;
use warnings;
use Config;
use Getopt::Long;
use FindBin;
use lib "$FindBin::Bin/lib";
use Getopt::Long 'GetOptions';
use File::Find 'find';
use File::Temp;
use SPVM::Builder::Util;
use SPVM::Builder::Util::API;
use SPVM::Builder::Config;
# If you edit yacc/spvm_yacc.y, spvm_yacc.c must be re-generated by the following command before "perl Makefile.PL"
# yacc/bison.sh
# Check supported environment
my $make;
{
# SPVM requires a 64-bit address space (pointer size must be 8 bytes)
# This ensures support for large memory maps required by coroutines.
my $ptrsize = $Config{ptrsize};
if ($ptrsize < 8) {
warn "SPVM doesn't support 32-bit address spaces (the pointer size is $ptrsize bytes). A 64-bit environment is required.\n";
die "OS unsupported\n";
}
# Don't support C++ compilers that does not support -std=c++11 option.
{
my $config = SPVM::Builder::Config->new_cpp;
my $cc = $config->cc;
my $tmp_dir = File::Temp->newdir;
my $cmd = "$cc -o $tmp_dir/cpp11.o -std=c++11 t/test_files/os_support/cpp11.cpp";
unless (system($cmd) == 0) {
warn "SPVM doesn't support C++ compilers that does not support -std=c++11 option.\n";
die "OS unsupported\n";
}
}
# SPVM requires GNU Make for the order-only dependency syntax '|' and the 'override' syntax.
# On FreeBSD, the default "make" is BSD Make, so we need to use "gmake" (GNU Make) instead.
if ($^O eq 'freebsd') {
my $success = system('gmake', '--version') == 0;
if ($success) {
$make = 'gmake';
}
else {
warn "SPVM needs GNU Make.\n";
die "OS unsupported\n";
}
}
# Don't support nmake
my $make = $Config{make};
if ($make eq 'nmake') {
warn "SPVM doesn't support nmake. The current \"make\" is \"$make\".\n";
die "OS unsupported\n";
}
}
my @defines;
my $optimize;
GetOptions(
"define=s" => \@defines,
"optimize=s" => \$optimize,
"ccflags=s" => \my @ccflags,
"lddlflags=s" => \my @lddlflags,
'meta' => \my $meta,
'no-build-spvm-modules' => \my $no_build_spvm_modules,
'no-precompile-tests' => \my $no_precompile_tests,
'devel' => \my $devel,
);
if ($meta) {
$no_build_spvm_modules = 1;
$no_precompile_tests = 1;
}
my $default_config = SPVM::Builder::Util::API::create_default_config;
my $std = $default_config->std;
# Macro
@defines = map { "-D$_" } @defines;
# optimize
unless ($optimize) {
if ($devel) {
$optimize = "-O0 -g";
}
unless ($optimize) {
$optimize = $default_config->optimize;
}
}
# ccflags
my $ccflags = $Config{ccflags};
$ccflags .= " -std=$std";
$ccflags .= " " . join(' ', @{$default_config->thread_ccflags}, @ccflags);
# lddlflags
my $lddlflags = $Config{lddlflags};
$lddlflags .= " " . join(' ', @{$default_config->thread_ldflags}, @lddlflags);
# I want to print warnings, but if gcc version is different, can't suppress no needed warning message.
# so I dicide not to print warning in release version
if ($ENV{SPVM_TEST_ENABLE_WARNINGS}) {
$ccflags .= ' -Wall -Wextra -Wno-unused-label -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wno-missing-field-initializers';
}
# INC
my $inc = '-Ilib/SPVM/Builder/include';
SPVM::Builder::Util::build_precompile_header_content_c_source();
# Source files
my $spvm_core_source_file_names = SPVM::Builder::Util::get_spvm_core_source_file_names();
my @spvm_csource_files = map { "lib/SPVM/Builder/src/$_" } @$spvm_core_source_file_names;
my @csource_files = ('SPVM.c', @spvm_csource_files);
# Header files(This is only used to resolve dependencies)
my @spvm_header_files = glob 'lib/SPVM/Builder/include/*.h';
my @header_files = ('ppport.h', @spvm_header_files);
my $cpus = SPVM::Builder::Util::API::get_cpu_count();
my $jobs = $cpus + 2;
# Limit the maximum number of parallel jobs to 16 to prevent Windows from exhausting OS resources, such as process handles and kernel memory, ensuring stable performance during JIT builds.
if ($jobs > 16) {
$jobs = 16;
}
WriteMakefile(
NAME => 'SPVM',
VERSION_FROM => 'lib/SPVM.pm',
LICENSE => 'mit',
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/SPVM.pm', # retrieve abstract from module
AUTHOR => 'Yuki Kimoto<kimoto.yuki@gmail.com>') : ()),
CCFLAGS => $ccflags,
OPTIMIZE => $optimize,
LDDLFLAGS => $lddlflags,
C => [@csource_files],
H => [@header_files],
OBJECT => '$(O_FILES)', # link all the C files too
INC => $inc,
test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t t/*/*/*/*.t'},
clean => {FILES => "SPVM.o lib/SPVM/Builder/src/*.o .spvm_build t/.spvm_build t/*/.spvm_build t/03_precompile t/test_files_tmp t/*/test_files_tmp t/exe/.spvm_build"},
DEFINE => "@defines -o \$@",
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'https://github.com/yuki-kimoto/SPVM.git',
web => 'https://github.com/yuki-kimoto/SPVM',
},
bugtracker => {
web => "https://github.com/yuki-kimoto/SPVM/issues",
},
},
},
EXE_FILES => ['script/spvm', 'script/spvmcc', 'script/spvmdist', 'script/spvmdeps'],
PREREQ_PM => {
'ExtUtils::CBuilder' => '0.280236',
'Time::Piece' => '1.12',
'JSON::PP' => '2.27105',
},
TEST_REQUIRES => {
'Test::More' => '0.92',
},
NORECURS => 1,
macro => {
MAKEFLAGS => "-j$jobs",
# Inject eval "\$ENV{HARNESS_OPTIONS}='j$jobs'" at the beginning of the command line for parallel tests overriding TEST_VERBOSE
# Constraints for Windows shell compatibility (pwsh/cmd.exe):
# 1. The entire command is wrapped in double quotes.
# 2. No backslashes (\) to avoid escape hell.
# 3. No dollar signs ($) to prevent pwsh variable expansion.
# 4. No nested parentheses to avoid pwsh tokenization errors.
# 5. Only '();. are used for maximum safety.
# 6. Minimal symbols to avoid edge cases in shell parsing.
'override TEST_VERBOSE' => "scalar (eval chr(36) . q(ENV{HARNESS_OPTIONS}='j$jobs'), 0)",
},
$make ? (MAKE => $make) : (),
);
package MY {
use File::Find 'find';
# Add Build shared library make rule
sub MY::postamble {
# The content of Makefile
my $make_rule = '';
unless ($no_build_spvm_modules) {
require SPVM::Builder::Util::API;
# For loading resources
local @INC = @INC;
unshift @INC, 'lib';
my $options = {};
if (defined $optimize) {
$options->{optimize} = $optimize;
}
$options->{dependent_files} = ['SPVM.xs'];
$options->{order_only_dependent_files} = ['$(INST_DYNAMIC)', 'pm_to_blib'];
# Test create_make_rule for backward compatibility and practical testing
$make_rule .= SPVM::Builder::Util::API::create_make_rule_native('Fn', $options);
$make_rule .= SPVM::Builder::Util::API::create_make_rule_precompile('Fn', $options);
# Native classes (excluding Fn)
$options->{native_classes} = [
'Format',
'Sync::Mutex',
'Native',
'Native::Compiler',
'Native::ClassFile',
'Native::Runtime',
'Native::Env',
'Native::Stack',
'Native::BasicType',
'Native::ClassVar',
'Native::Field',
'Native::Method',
'Native::Arg',
'Native::MethodCall',
'Native::API',
'Native::Constant',
];
# Precompile classes (excluding Fn)
$options->{precompile_classes} = [
'Format',
'Sort',
'Packer',
];
# Specify text files containing additional classes for practical tests
# These files contain newline-separated class names like 'Array'
$options->{native_classes_file} = 'native_classes.txt';
$options->{precompile_classes_file} = 'precompile_classes.txt';
# Generate a single parallel make rule for the rest
$make_rule .= SPVM::Builder::Util::API::create_make_rule_parallel($options);
}
unless ($no_precompile_tests) {
# Create precompile tests
my @test_files;
find(
sub {
if (-f $File::Find::name) {
my $rel_path = $File::Find::name;
$rel_path =~ s|^\Q$FindBin::Bin/||;
# Slip hidden files
return if $rel_path =~ /[\/\\]\./;
push @test_files, $rel_path;
}
},
"$FindBin::Bin/t/02_vm"
);
my $test_files_str = join(' ', @test_files);
my $time_stamp_file = "$FindBin::Bin/t/03_precompile/time_stamp.txt";
$make_rule .= "dynamic :: $time_stamp_file\n";
$make_rule .= "\t\$(NOECHO) \$(NOOP)\n\n";
$make_rule .= "$time_stamp_file :: t/utils/copy_vm_to_precompile.pl $test_files_str\n";
$make_rule .= "\tperl t/utils/copy_vm_to_precompile.pl\n";
}
return $make_rule;
}
}
1;