This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Faster feature checks
[perl5.git] / Porting / makerel
CommitLineData
23b3bd7f 1#!/usr/bin/perl -w
08aa1457 2
63d690b1 3# A tool to build a perl release tarball
08aa1457 4# Very basic but functional - if you're on a unix system.
08aa1457 5#
e8c01f92
SH
6# If you're on Win32 then it should still work, but various Unix command-line
7# tools will need to be available somewhere. An obvious choice is to install
8# Cygwin and ensure its 'bin' folder is on the PATH in the shell where you run
9# this script. The Cygwin 'bin' folder needs to precede the Windows 'system32'
10# folder so that Cygwin's 'find' command is found in preference to the Windows
fbfa7c02
SH
11# 'find' command. In addition to the commands installed by default, your Cygwin
12# installation will need to contain at least the 'cpio' and '7z' commands.
13# Finally, ensure that the 'awk', 'shasum' (if you have it) and '7z' commands
14# are copies of 'gawk.exe', 'sha1sum.exe' and 'lib\p7zip\7z.exe' respectively,
15# rather than the links to them that only work in a Cygwin bash shell which
16# they are by default.
e8c01f92 17#
08aa1457 18# No matter how automated this gets, you'll always need to read
63d690b1
JV
19# and re-read pumpkin.pod and release_managers_guide.pod to
20# check for things to be done at various stages of the process.
08aa1457 21#
22# Tim Bunce, June 1997
23
24use ExtUtils::Manifest qw(fullcheck);
5f244db9
DM
25$ExtUtils::Manifest::Quiet = 1;
26use Getopt::Std;
08aa1457 27
28$|=1;
5f244db9
DM
29
30sub usage { die <<EOF; }
c6bee77e 31usage: $0 [ -r rootdir ] [-s suffix ] [ -x ] [ -n ]
5f244db9
DM
32 -r rootdir directory under which to create the build dir and tarball
33 defaults to '..'
34 -s suffix suffix to append to to the perl-x.y.z dir and tarball name
47e01c32 35 defaults to the concatenation of the local_patches entry
5f244db9 36 in patchlevel.h (or blank, if none)
bb56637e 37 -x make a .xz file in addition to a .gz file
1baeb402 38 -n do not make any tarballs, just the directory
5f244db9
DM
39EOF
40
41my %opts;
326c4aeb 42getopts('xnr:s:', \%opts) or usage;
5f244db9
DM
43@ARGV && usage;
44
45$relroot = defined $opts{r} ? $opts{r} : "..";
08aa1457 46
47die "Must be in root of the perl source tree.\n"
48 unless -f "./MANIFEST" and -f "patchlevel.h";
49
1ae6ead9 50open PATCHLEVEL, '<', 'patchlevel.h' or die;
3ffabb8c
GS
51my @patchlevel_h = <PATCHLEVEL>;
52close PATCHLEVEL;
d4257220 53my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h;
08aa1457 54print $patchlevel_h;
93136620 55$revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/;
d4257220
GS
56$patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/;
57$subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/;
55d729e4 58die "Unable to parse patchlevel.h" unless $subversion >= 0;
93136620 59$vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion);
08aa1457 60
3ffabb8c
GS
61# fetch list of local patches
62my (@local_patches, @lpatch_tags, $lpatch_tags);
699a100d
RS
63@local_patches = grep { !/^\s*,?NULL/ && ! /,"uncommitted-changes"/ }
64 grep { /^static.*local_patches/../^};/ }
65 @patchlevel_h;
3ffabb8c
GS
66@lpatch_tags = map { /^\s*,"(\w+)/ } @local_patches;
67$lpatch_tags = join "-", @lpatch_tags;
68
2a7df08c 69$perl = "perl-$vers";
f27ffc4a 70$reldir = "$perl";
5f244db9
DM
71
72$lpatch_tags = $opts{s} if defined $opts{s};
3ffabb8c 73$reldir .= "-$lpatch_tags" if $lpatch_tags;
08aa1457 74
f27ffc4a 75print "\nMaking a release for $perl in $relroot/$reldir\n\n";
08aa1457 76
08aa1457 77print "Cross-checking the MANIFEST...\n";
78($missfile, $missentry) = fullcheck();
37d29c6f 79@$missentry
79ff1055 80 = grep {$_ !~ m!^\.(?:git|github)/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
9b05e874
JV
81if (@$missfile ) {
82 warn "Can't make a release with MANIFEST files missing:\n";
83 warn "\t".$_."\n" for (@$missfile);
84}
85if (@$missentry ) {
86 warn "Can't make a release with files not listed in MANIFEST\n";
87 warn "\t".$_."\n" for (@$missentry);
88
89}
90248788
TB
90if ("@$missentry" =~ m/\.orig\b/) {
91 # Handy listing of find command and .orig files from patching work.
92 # I tend to run 'xargs rm' and copy and paste the file list.
93 my $cmd = "find . -name '*.orig' -print";
94 print "$cmd\n";
95 system($cmd);
96}
3e3baf6d 97die "Aborted.\n" if @$missentry or @$missfile;
08aa1457 98print "\n";
99
b59922b7 100# VMS no longer has hardcoded version numbers descrip.mms
48e117bb
GS
101
102print "Creating $relroot/$reldir release directory...\n";
103die "$relroot/$reldir release directory already exists\n" if -e "$relroot/$reldir";
104die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz";
105mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
106print "\n";
107
108
109print "Copying files to release directory...\n";
110# ExtUtils::Manifest maniread does not preserve the order
111$cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir";
86cd7d77
JH
112system($cmd) == 0
113 or die "$cmd failed";
48e117bb
GS
114print "\n";
115
6e24577b 116chdir "$relroot/$reldir" or die $!;
48e117bb 117
d38b68fe 118
08aa1457 119print "Setting file permissions...\n";
bf955a65
GS
120system("find . -type f -print | xargs chmod 0444");
121system("find . -type d -print | xargs chmod 0755");
5326e4da 122my @exe = map { my ($f) = split; glob($f) }
ff906f87
DG
123 grep { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ }
124 map { split "\n" }
125 do { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> };
126
86cd7d77
JH
127system("chmod +x @exe") == 0
128 or die "system: $!";
6e24577b 129
f7f713ed 130my @writables = qw(
f3513db0
JH
131 NetWare/config_H.wc
132 NetWare/Makefile
f2c01b15 133 feature.h
11b27549 134 lib/feature.pm
ac634a9a 135 keywords.h
26ea9e12 136 keywords.c
ac634a9a
JH
137 opcode.h
138 opnames.h
139 pp_proto.h
ac634a9a 140 proto.h
f7f713ed
GS
141 embed.h
142 embedvar.h
fa9ec1c9 143 overload.inc
e9e0c7d0 144 overload.h
8b09643d 145 mg_vtable.h
ac634a9a
JH
146 perlapi.h
147 perlapi.c
7baf245a
KW
148 dist/Devel-PPPort/module2.c
149 dist/Devel-PPPort/module3.c
e120c24f 150 cpan/autodie/t/touch_me
e9e0c7d0
NC
151 reentr.c
152 reentr.h
153 regcharclass.h
f7f713ed 154 regnodes.h
0ebdc6d5 155 warnings.h
ac634a9a 156 lib/warnings.pm
e120c24f 157 win32/GNUmakefile
ac634a9a
JH
158 win32/Makefile
159 win32/makefile.mk
f29c64d6 160 win32/config_H.gc
f7f713ed 161 win32/config_H.vc
18b94d96 162 uconfig.h
f7f713ed 163);
c9e35064
MH
164
165my $out = `chmod u+w @writables 2>&1`;
166if ($? != 0) {
167 warn $out;
168 if ($out =~ /no such file/i) {
169 warn "Check that the files above still exist in the Perl core.\n";
170 warn "If not, remove them from \@writables in Porting/makerel\n";
171 }
172 exit 1;
c9e35064 173}
f7f713ed 174
976a2e28
MH
175warn $out if $out;
176
6e24577b
GS
177chdir ".." or die $!;
178
1baeb402
DG
179exit if $opts{n};
180
f27ffc4a 181my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
85bdf03b 182
0dcf3caa
LB
183print "Checking if you have 7z...\n";
184my $output_7z = `7z 2>&1`;
185my $have_7z = defined $output_7z && $output_7z =~ /7-Zip/;
08aa1457 186
0dcf3caa
LB
187print "Checking if you have advdef...\n";
188my $output_advdef = `advdef --version 2>&1`;
189my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/;
190
191if ($have_7z) {
192 print "Creating and compressing the tar.gz file with 7z...\n";
193 $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz";
85bdf03b 194 system($cmd) == 0 or die "$cmd failed";
0dcf3caa
LB
195} else {
196 print "Creating and compressing the tar.gz file...\n";
197 $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
198 system($cmd) == 0 or die "$cmd failed";
199 if ($have_advdef) {
200 print "Recompressing the tar.gz file with advdef...\n";
201 $cmd = "advdef -z -4 $reldir.tar.gz";
202 system($cmd) == 0 or die "$cmd failed";
203 }
204}
205
f276fdad 206if ($opts{x}) {
b38ca28d 207 print "Creating and compressing the tar.xz file with xz...\n";
f276fdad
CBW
208 $cmd = "tar cf - $reldir | xz -z -c > $reldir.tar.xz";
209 system($cmd) == 0 or die "$cmd failed";
210}
211
85bdf03b 212print "\n";
9b05e874 213
ecc9c9d9
DM
214system("ls -ld $perl*");
215print "\n";
216
e8c01f92 217my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
ecc9c9d9 218for my $sha (qw(sha1 shasum sha1sum)) {
e8c01f92 219 if (`which $sha 2>$null`) {
ecc9c9d9
DM
220 system("$sha $perl*.tar.*");
221 last;
222 }
9b05e874 223}