This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
makemeta no longer relies on the currently executing perl for version
[perl5.git] / Porting / makemeta
CommitLineData
3e9ed10a
FD
1#!./perl -w
2# this script must be run by the current perl to get perl's version right
0c429c78 3#
bfc0a3e7 4# Create META.yml and META.json files in the current directory. Must be run from the
0c429c78 5# root directory of a perl source tree.
0cf51544
JH
6
7use strict;
8use warnings;
0cf51544 9
bfc0a3e7
CBW
10my $opts = {
11 'META.yml' => { version => '1.4' },
12 'META.json' => { version => '2' },
13};
14
15my $file = shift;
16die "Must specify META.yml or META.json" unless $file and defined $opts->{$file};
3e9ed10a 17
b39f0a19 18my ($vers, $stat ) = _determine_status();
bfc0a3e7
CBW
19
20my $distmeta = {
b39f0a19 21 'version' => $vers,
bfc0a3e7
CBW
22 'name' => 'perl',
23 'author' => [
24 'perl5-porters@perl.org'
25 ],
26 'license' => [
27 'perl_5'
28 ],
29 'abstract' => 'The Perl 5 language interpreter',
b39f0a19 30 'release_status' => $stat,
bfc0a3e7
CBW
31 'dynamic_config' => 1,
32 'resources' => {
33 'repository' => {
34 'url' => 'http://perl5.git.perl.org/'
35 },
36 'homepage' => 'http://www.perl.org/',
37 'bugtracker' => {
38 'web' => 'http://rt.perl.org/perlbug/'
39 },
40 'license' => [
41 'http://dev.perl.org/licenses/'
42 ],
43 },
44};
45
46use lib "Porting";
47use File::Basename qw( dirname );
48use CPAN::Meta;
df1ad5b3
JV
49
50BEGIN {
51 # Get function prototypes
2bd4012d 52 require 'regen/regen_lib.pl';
df1ad5b3
JV
53}
54
0cf51544
JH
55use Maintainers qw(%Modules get_module_files get_module_pat);
56
57my @CPAN = grep { $Modules{$_}{CPAN} } keys %Modules;
1ce0c05c 58my @files = ('autodoc.pl', 'lib/unicore/mktables', 'TestInit.pm',
bfc0a3e7
CBW
59 'Porting/Maintainers.pm', 'Porting/perldelta_template.pod',
60 map { get_module_files($_) } @CPAN);
a3265265 61my @dirs = ('cpan', 'win32', 'mad', grep { -d $_ && $_ !~ /^cpan/ } map { get_module_pat($_) } @CPAN);
0cf51544 62
3e9ed10a
FD
63my %dirs;
64@dirs{@dirs} = ();
65
bfc0a3e7 66@files =
3e9ed10a
FD
67 grep {
68 my $d = $_;
2ccec147 69 my $previous_d = '';
3e9ed10a 70 while(($d = dirname($d)) ne "."){
2ccec147 71 last if $d eq $previous_d; # safety valve
3e9ed10a 72 last if exists $dirs{$d};
2ccec147 73 $previous_d = $d;
3e9ed10a
FD
74 }
75
76 # if $d is "." it means we tried every parent dir of the file and none
77 # of them were in the private list
bfc0a3e7 78
2ccec147 79 $d eq "." || $d eq $previous_d;
3e9ed10a
FD
80 }
81 sort { lc $a cmp lc $b } @files;
82
bfc0a3e7 83@dirs = sort { lc $a cmp lc $b } @dirs;
0cf51544 84
bfc0a3e7
CBW
85$distmeta->{no_index}->{file} = \@files;
86$distmeta->{no_index}->{directory} = \@dirs;
0cf51544 87
bfc0a3e7
CBW
88my $meta = CPAN::Meta->create( $distmeta );
89my $fh = open_new($file);
90print $fh $meta->as_string( $opts->{$file} );
284e4287 91close_and_rename($fh);
bfc0a3e7
CBW
92exit 0;
93
94sub _determine_status {
95 my $patchlevel_h = 'patchlevel.h';
96 return unless -e $patchlevel_h;
97 my $status = '';
b39f0a19 98 my $version = '';
bfc0a3e7
CBW
99 {
100 my %defines;
101 open my $fh, '<', $patchlevel_h;
102 my @vers;
103 while (<$fh>) {
104 chomp;
105 next unless m!^#define! or m!!;
106 if ( m!^#define! ) {
107 my ($foo,$bar) = ( split /\s+/ )[1,2];
108 $defines{$foo} = $bar;
109 }
110 elsif ( m!\"RC\d+\"! ) {
111 $status = 'testing';
112 last;
113 }
114 }
115 unless ( $status ) {
116 $status = $defines{PERL_VERSION} % 2 ? 'unstable' : 'stable';
117 }
b39f0a19
CBW
118 if ( my @wotsits = grep { defined $defines{$_} } qw(PERL_REVISION PERL_VERSION PERL_SUBVERSION) ) {
119 $version = sprintf '%d.%03d%03d', map { $defines{$_} } @wotsits;
120 }
121 else {
122 # Well, you never know
123 $version = sprintf '5.%03d_%02d', map { $defines{$_} } qw(PATCHLEVEL SUBVERSION);
124 }
bfc0a3e7 125 }
b39f0a19 126 return ( $version, $status );
bfc0a3e7 127}