This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update epigraph for 5.35.8
[perl5.git] / Porting / makerel
CommitLineData
23b3bd7f 1#!/usr/bin/perl -w
08aa1457 2
ddc12dcf
KW
3use strict;
4use warnings;
5
63d690b1 6# A tool to build a perl release tarball
08aa1457 7# Very basic but functional - if you're on a unix system.
08aa1457 8#
e8c01f92
SH
9# If you're on Win32 then it should still work, but various Unix command-line
10# tools will need to be available somewhere. An obvious choice is to install
11# Cygwin and ensure its 'bin' folder is on the PATH in the shell where you run
12# this script. The Cygwin 'bin' folder needs to precede the Windows 'system32'
13# folder so that Cygwin's 'find' command is found in preference to the Windows
fbfa7c02
SH
14# 'find' command. In addition to the commands installed by default, your Cygwin
15# installation will need to contain at least the 'cpio' and '7z' commands.
16# Finally, ensure that the 'awk', 'shasum' (if you have it) and '7z' commands
17# are copies of 'gawk.exe', 'sha1sum.exe' and 'lib\p7zip\7z.exe' respectively,
18# rather than the links to them that only work in a Cygwin bash shell which
19# they are by default.
e8c01f92 20#
08aa1457 21# No matter how automated this gets, you'll always need to read
63d690b1
JV
22# and re-read pumpkin.pod and release_managers_guide.pod to
23# check for things to be done at various stages of the process.
08aa1457 24#
25# Tim Bunce, June 1997
26
27use ExtUtils::Manifest qw(fullcheck);
5f244db9
DM
28$ExtUtils::Manifest::Quiet = 1;
29use Getopt::Std;
08aa1457 30
31$|=1;
5f244db9
DM
32
33sub usage { die <<EOF; }
c6bee77e 34usage: $0 [ -r rootdir ] [-s suffix ] [ -x ] [ -n ]
5f244db9
DM
35 -r rootdir directory under which to create the build dir and tarball
36 defaults to '..'
a3815e44 37 -s suffix suffix to append to the perl-x.y.z dir and tarball name
47e01c32 38 defaults to the concatenation of the local_patches entry
5f244db9 39 in patchlevel.h (or blank, if none)
bb56637e 40 -x make a .xz file in addition to a .gz file
1baeb402 41 -n do not make any tarballs, just the directory
b38ce61e
KW
42 -c cleanup perform a cleanup before building: clean git repo and target
43 directory/tarballs
44 -e Make the outputs be translated into EBCDIC. (They can then
45 be downloaded directly to an EBCDIC platform without needing
46 any further translation.)
5f244db9
DM
47EOF
48
49my %opts;
b38ce61e
KW
50getopts('exncr:s:', \%opts) or usage;
51
5f244db9
DM
52@ARGV && usage;
53
ddc12dcf 54my $relroot = defined $opts{r} ? $opts{r} : "..";
08aa1457 55
56die "Must be in root of the perl source tree.\n"
57 unless -f "./MANIFEST" and -f "patchlevel.h";
58
1ae6ead9 59open PATCHLEVEL, '<', 'patchlevel.h' or die;
3ffabb8c
GS
60my @patchlevel_h = <PATCHLEVEL>;
61close PATCHLEVEL;
d4257220 62my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h;
08aa1457 63print $patchlevel_h;
ddc12dcf
KW
64my $revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/;
65my $patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/;
66my $subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/;
55d729e4 67die "Unable to parse patchlevel.h" unless $subversion >= 0;
ddc12dcf 68my $vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion);
08aa1457 69
3ffabb8c
GS
70# fetch list of local patches
71my (@local_patches, @lpatch_tags, $lpatch_tags);
699a100d
RS
72@local_patches = grep { !/^\s*,?NULL/ && ! /,"uncommitted-changes"/ }
73 grep { /^static.*local_patches/../^};/ }
74 @patchlevel_h;
3ffabb8c
GS
75@lpatch_tags = map { /^\s*,"(\w+)/ } @local_patches;
76$lpatch_tags = join "-", @lpatch_tags;
77
ddc12dcf
KW
78my $perl = "perl-$vers";
79my $reldir = "$perl";
5f244db9
DM
80
81$lpatch_tags = $opts{s} if defined $opts{s};
3ffabb8c 82$reldir .= "-$lpatch_tags" if $lpatch_tags;
08aa1457 83
f27ffc4a 84print "\nMaking a release for $perl in $relroot/$reldir\n\n";
08aa1457 85
d2540b73
N
86cleanup($relroot, $reldir) if $opts{c};
87
08aa1457 88print "Cross-checking the MANIFEST...\n";
ddc12dcf 89my ($missfile, $missentry) = fullcheck();
37d29c6f 90@$missentry
41fd77f8 91 = grep {$_ !~ m!^\.(?:git|github|mailmap)! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
9b05e874
JV
92if (@$missfile ) {
93 warn "Can't make a release with MANIFEST files missing:\n";
94 warn "\t".$_."\n" for (@$missfile);
95}
96if (@$missentry ) {
97 warn "Can't make a release with files not listed in MANIFEST\n";
98 warn "\t".$_."\n" for (@$missentry);
99
100}
90248788
TB
101if ("@$missentry" =~ m/\.orig\b/) {
102 # Handy listing of find command and .orig files from patching work.
103 # I tend to run 'xargs rm' and copy and paste the file list.
104 my $cmd = "find . -name '*.orig' -print";
105 print "$cmd\n";
106 system($cmd);
107}
3e3baf6d 108die "Aborted.\n" if @$missentry or @$missfile;
08aa1457 109print "\n";
110
b59922b7 111# VMS no longer has hardcoded version numbers descrip.mms
48e117bb
GS
112
113print "Creating $relroot/$reldir release directory...\n";
d2540b73
N
114die "$relroot/$reldir release directory already exists [consider using -c]\n" if -e "$relroot/$reldir";
115die "$relroot/$reldir.tar.gz release file already exists [consider using -c]\n" if -e "$relroot/$reldir.tar.gz";
116die "$relroot/$reldir.tar.xz release file already exists [consider using -c]\n" if $opts{x} && -e "$relroot/$reldir.tar.xz";
48e117bb
GS
117mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
118print "\n";
119
120
121print "Copying files to release directory...\n";
122# ExtUtils::Manifest maniread does not preserve the order
ddc12dcf 123my $cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir";
86cd7d77
JH
124system($cmd) == 0
125 or die "$cmd failed";
48e117bb
GS
126print "\n";
127
6e24577b 128chdir "$relroot/$reldir" or die $!;
48e117bb 129
5326e4da 130my @exe = map { my ($f) = split; glob($f) }
ff906f87
DG
131 grep { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ }
132 map { split "\n" }
133 do { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> };
134
bf65ee6f
KW
135if ($opts{e}) {
136 require './regen/charset_translations.pl';
acc1f7a1 137
bf65ee6f
KW
138 # Translation tables, so far only to 1047
139 my @charset = grep { /1047/ } get_supported_code_pages();
140
141 my $charset = $charset[0];
142 my $a2e = get_a2n($charset);
acc1f7a1 143
b38ce61e
KW
144 die "$0 must be run on an ASCII platform" if ord("A") != 65;
145
146 print "Translating to EBCDIC...\n";
147
148 open my $mani_fh, "<", "MANIFEST" or die "Can't read copied MANIFEST: $!";
149 my @manifest = <$mani_fh>; # Slurp in whole thing before the file gets trashed
150 close $mani_fh or die "Couldn't close MANIFEST: $!";
151 while (defined ($_ = shift @manifest)) {
152 chomp;
153 my $file = $_ =~ s/\s.*//r; # Rmv description to get just the file
154 # name
b38ce61e
KW
155
156 local $/; # slurp mode
157 open my $fh, "+<:raw", $file or die "Can't read copied $file: $!";
158 my $text = <$fh>;
159 my $xlated = "";
27a374b3
KW
160 my $utf16_high = 0;
161 my $utf16_low = 0;
162
163 my $potential_BOM = substr($text, 0, 2);
164 if ($potential_BOM eq "\xFE\xFF") {
165 $utf16_high = 0;
166 $utf16_low = 1;
167 print STDERR "$file is UTF-16BE\n";
168 }
169 elsif ($potential_BOM eq "\xFF\xFE") {
170 $utf16_high = 1;
171 $utf16_low = 0;
172 print STDERR "$file is UTF-16LE\n";
173 }
174
175 if ($utf16_high || $utf16_low) {
176 my $len = length $text;
177 die "Odd length in UTF-16 files: $file" if $len % 2;
178
179 # Look 2 bytes at a time
180 for (my $i = 0; $i < $len; $i+=2) {
181 my $cur = substr($text, $i, 2);
182
183 # If the code point's high byte is 0, it means the code point
184 # itself is 00-FF, so want native value of it.
185 if (substr($cur, $utf16_high, 1) eq "\0") {
186
187 # Just substitute the translated native value
188 my $low_byte = substr($cur, $utf16_low, 1);
bf65ee6f 189 $low_byte = chr $a2e->[ord $low_byte];
27a374b3
KW
190 substr($cur, $utf16_low, 1) = $low_byte;
191 }
192
193 $xlated .= $cur;
194 }
195 }
196 elsif (-B $file) { # Binary files aren't translated
197 print STDERR "$file is binary\n";
198 close $fh or die "Couldn't close $file: $!";
199 next;
200 }
201 else {
f60fa022
KW
202 if ( ! utf8::decode($text)
203 || $text =~ / ^ [[:ascii:][:cntrl:]]* $ /x)
e4b57ba3 204 {
e4b57ba3
KW
205 # Here, either $text isn't legal UTF-8; or it is, but it
206 # consists entirely of one of the 160 ASCII and control
207 # characters whose EBCDIC representation is the same whether
208 # UTF-EBCDIC or not. This means we just translate
209 # byte-by-byte from Latin1 to EBCDIC.
bf65ee6f 210 $xlated = ($text =~ s/(.)/chr $a2e->[ord $1]/rsge);
e4b57ba3
KW
211 }
212 else {
213
214 # Here, $text is legal UTF-8, and the representation of some
215 # character(s) in it it matters if is encoded in UTF-EBCDIC or
216 # not. Also, the decode caused $text to now be viewed as
217 # UTF-8 characters instead of the input bytes. We convert to
218 # UTF-EBCDIC.
bf65ee6f 219 $xlated = ($text =~ s/(.)/cp_2_utfbytes(ord $1, $charset)/rsge);
b38ce61e 220 }
27a374b3 221 }
b38ce61e 222
e4b57ba3 223 # Overwrite the file with the translation
b38ce61e
KW
224 truncate $fh, 0;
225 seek $fh, 0, 0;
226 print $fh $xlated;
227
228 close $fh or die "Couldn't close $file: $!";
229 }
230}
231
232print "Setting file permissions...\n";
ecef3a65 233system("find . -type f -print | xargs chmod 0644");
b38ce61e
KW
234system("find . -type d -print | xargs chmod 0755");
235
86cd7d77
JH
236system("chmod +x @exe") == 0
237 or die "system: $!";
6e24577b 238
b38ce61e 239# MANIFEST may be resorted, so needs to be writable
f7f713ed 240my @writables = qw(
f2c01b15 241 feature.h
11b27549 242 lib/feature.pm
ac634a9a 243 keywords.h
26ea9e12 244 keywords.c
b38ce61e 245 MANIFEST
ac634a9a
JH
246 opcode.h
247 opnames.h
248 pp_proto.h
ac634a9a 249 proto.h
f7f713ed
GS
250 embed.h
251 embedvar.h
fa9ec1c9 252 overload.inc
e9e0c7d0 253 overload.h
8b09643d 254 mg_vtable.h
7baf245a
KW
255 dist/Devel-PPPort/module2.c
256 dist/Devel-PPPort/module3.c
e120c24f 257 cpan/autodie/t/touch_me
e9e0c7d0
NC
258 reentr.c
259 reentr.h
260 regcharclass.h
f7f713ed 261 regnodes.h
0ebdc6d5 262 warnings.h
ac634a9a 263 lib/warnings.pm
e120c24f 264 win32/GNUmakefile
ac634a9a 265 win32/Makefile
f29c64d6 266 win32/config_H.gc
f7f713ed 267 win32/config_H.vc
18b94d96 268 uconfig.h
f7f713ed 269);
c9e35064
MH
270
271my $out = `chmod u+w @writables 2>&1`;
272if ($? != 0) {
273 warn $out;
274 if ($out =~ /no such file/i) {
275 warn "Check that the files above still exist in the Perl core.\n";
276 warn "If not, remove them from \@writables in Porting/makerel\n";
277 }
278 exit 1;
c9e35064 279}
f7f713ed 280
976a2e28
MH
281warn $out if $out;
282
6e24577b
GS
283chdir ".." or die $!;
284
1baeb402
DG
285exit if $opts{n};
286
f27ffc4a 287my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
85bdf03b 288
b38ce61e
KW
289my $output_7z;
290my $have_7z;
291if (! $opts{e}) {
292 print "Checking if you have 7z...\n";
293 $output_7z = `7z 2>&1`;
294 $have_7z = defined $output_7z && $output_7z =~ /7-Zip/;
295}
08aa1457 296
0dcf3caa
LB
297print "Checking if you have advdef...\n";
298my $output_advdef = `advdef --version 2>&1`;
299my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/;
300
b38ce61e 301if (! $opts{e} && $have_7z) {
0dcf3caa
LB
302 print "Creating and compressing the tar.gz file with 7z...\n";
303 $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz";
85bdf03b 304 system($cmd) == 0 or die "$cmd failed";
0dcf3caa
LB
305} else {
306 print "Creating and compressing the tar.gz file...\n";
b38ce61e
KW
307 my $extra_opts = "";
308 if ($opts{e}) {
309 print "(Using ustar format since is for an EBCDIC box)\n";
310 $extra_opts = ' --format=ustar';
311 }
312 $cmd = "tar cf - $extra_opts $reldir | gzip --best > $reldir.tar.gz";
0dcf3caa
LB
313 system($cmd) == 0 or die "$cmd failed";
314 if ($have_advdef) {
315 print "Recompressing the tar.gz file with advdef...\n";
316 $cmd = "advdef -z -4 $reldir.tar.gz";
317 system($cmd) == 0 or die "$cmd failed";
318 }
319}
320
f276fdad 321if ($opts{x}) {
b38ca28d 322 print "Creating and compressing the tar.xz file with xz...\n";
f276fdad
CBW
323 $cmd = "tar cf - $reldir | xz -z -c > $reldir.tar.xz";
324 system($cmd) == 0 or die "$cmd failed";
325}
326
85bdf03b 327print "\n";
9b05e874 328
ecc9c9d9
DM
329system("ls -ld $perl*");
330print "\n";
331
e8c01f92 332my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
ecc9c9d9 333for my $sha (qw(sha1 shasum sha1sum)) {
e8c01f92 334 if (`which $sha 2>$null`) {
ecc9c9d9
DM
335 system("$sha $perl*.tar.*");
336 last;
337 }
9b05e874 338}
d2540b73
N
339
340sub cleanup {
341 my ( $relroot, $reldir ) = @_;
342
343 require File::Path;
344
345 my @cmds = (
346 [ qw{make distclean} ],
347 [ qw{git clean -dxf} ],
348 );
349
350 foreach my $cmd (@cmds) {
351 print join( ' ', "Running:", @$cmd, "\n" );
352 system @$cmd;
353 die "fail to run ".(join(' ', @$cmd) ) unless $? == 0;
354 }
355
356 if ( -d "$relroot/$reldir" ) {
357 print "Removing directory $relroot/$reldir\n";
358 File::Path::rmtree("$relroot/$reldir");
359 }
360
361 # always clean both
362 my @files = ( "$relroot/$reldir.tar.gz", "$relroot/$reldir.tar.xz" );
363
364 foreach my $f ( @files ) {
365 next unless -f $f;
366 print "Removing file '$f'\n";
367 unlink($f);
368 }
369
370 return;
371
372}
373
3741;