This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #126133] autodie touches its touch_me, make it writable
[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
PP
21#
22# Tim Bunce, June 1997
23
24use ExtUtils::Manifest qw(fullcheck);
5f244db9
DM
25$ExtUtils::Manifest::Quiet = 1;
26use Getopt::Std;
08aa1457
PP
27
28$|=1;
5f244db9
DM
29
30sub usage { die <<EOF; }
1baeb402 31usage: $0 [ -r rootdir ] [-s suffix ] [ -b ] [ -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)
85bdf03b 37 -b make a .bz2 file in addtion to a .gz file
f276fdad 38 -x make a .xz file in addtion to a .gz file
1baeb402 39 -n do not make any tarballs, just the directory
5f244db9
DM
40EOF
41
42my %opts;
f276fdad 43getopts('bxnr:s:', \%opts) or usage;
5f244db9
DM
44@ARGV && usage;
45
46$relroot = defined $opts{r} ? $opts{r} : "..";
08aa1457
PP
47
48die "Must be in root of the perl source tree.\n"
49 unless -f "./MANIFEST" and -f "patchlevel.h";
50
3ffabb8c
GS
51open PATCHLEVEL,"<patchlevel.h" or die;
52my @patchlevel_h = <PATCHLEVEL>;
53close PATCHLEVEL;
d4257220 54my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h;
08aa1457 55print $patchlevel_h;
93136620 56$revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/;
d4257220
GS
57$patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/;
58$subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/;
55d729e4 59die "Unable to parse patchlevel.h" unless $subversion >= 0;
93136620 60$vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion);
08aa1457 61
3ffabb8c
GS
62# fetch list of local patches
63my (@local_patches, @lpatch_tags, $lpatch_tags);
699a100d
RS
64@local_patches = grep { !/^\s*,?NULL/ && ! /,"uncommitted-changes"/ }
65 grep { /^static.*local_patches/../^};/ }
66 @patchlevel_h;
3ffabb8c
GS
67@lpatch_tags = map { /^\s*,"(\w+)/ } @local_patches;
68$lpatch_tags = join "-", @lpatch_tags;
69
2a7df08c 70$perl = "perl-$vers";
f27ffc4a 71$reldir = "$perl";
5f244db9
DM
72
73$lpatch_tags = $opts{s} if defined $opts{s};
3ffabb8c 74$reldir .= "-$lpatch_tags" if $lpatch_tags;
08aa1457 75
f27ffc4a 76print "\nMaking a release for $perl in $relroot/$reldir\n\n";
08aa1457 77
08aa1457
PP
78print "Cross-checking the MANIFEST...\n";
79($missfile, $missentry) = fullcheck();
37d29c6f
NC
80@$missentry
81 = grep {$_ !~ m!^\.git/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
9b05e874
JV
82if (@$missfile ) {
83 warn "Can't make a release with MANIFEST files missing:\n";
84 warn "\t".$_."\n" for (@$missfile);
85}
86if (@$missentry ) {
87 warn "Can't make a release with files not listed in MANIFEST\n";
88 warn "\t".$_."\n" for (@$missentry);
89
90}
90248788
TB
91if ("@$missentry" =~ m/\.orig\b/) {
92 # Handy listing of find command and .orig files from patching work.
93 # I tend to run 'xargs rm' and copy and paste the file list.
94 my $cmd = "find . -name '*.orig' -print";
95 print "$cmd\n";
96 system($cmd);
97}
3e3baf6d 98die "Aborted.\n" if @$missentry or @$missfile;
08aa1457
PP
99print "\n";
100
b59922b7 101# VMS no longer has hardcoded version numbers descrip.mms
48e117bb
GS
102
103print "Creating $relroot/$reldir release directory...\n";
104die "$relroot/$reldir release directory already exists\n" if -e "$relroot/$reldir";
105die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz";
106mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
107print "\n";
108
109
110print "Copying files to release directory...\n";
111# ExtUtils::Manifest maniread does not preserve the order
112$cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir";
86cd7d77
JH
113system($cmd) == 0
114 or die "$cmd failed";
48e117bb
GS
115print "\n";
116
6e24577b 117chdir "$relroot/$reldir" or die $!;
48e117bb 118
d38b68fe 119
08aa1457 120print "Setting file permissions...\n";
bf955a65
GS
121system("find . -type f -print | xargs chmod 0444");
122system("find . -type d -print | xargs chmod 0755");
5326e4da 123my @exe = map { my ($f) = split; glob($f) }
ff906f87
DG
124 grep { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ }
125 map { split "\n" }
126 do { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> };
127
86cd7d77
JH
128system("chmod +x @exe") == 0
129 or die "system: $!";
6e24577b 130
f7f713ed 131my @writables = qw(
f3513db0
JH
132 NetWare/config_H.wc
133 NetWare/Makefile
f2c01b15 134 feature.h
11b27549 135 lib/feature.pm
ac634a9a 136 keywords.h
26ea9e12 137 keywords.c
ac634a9a
JH
138 opcode.h
139 opnames.h
140 pp_proto.h
ac634a9a 141 proto.h
f7f713ed
GS
142 embed.h
143 embedvar.h
fa9ec1c9 144 overload.inc
e9e0c7d0 145 overload.h
8b09643d 146 mg_vtable.h
ac634a9a
JH
147 perlapi.h
148 perlapi.c
b2861970
NC
149 cpan/Devel-PPPort/module2.c
150 cpan/Devel-PPPort/module3.c
e120c24f 151 cpan/autodie/t/touch_me
e9e0c7d0
NC
152 reentr.c
153 reentr.h
154 regcharclass.h
f7f713ed 155 regnodes.h
0ebdc6d5 156 warnings.h
ac634a9a 157 lib/warnings.pm
e120c24f 158 win32/GNUmakefile
ac634a9a 159 win32/Makefile
f78a30ba 160 win32/Makefile.ce
ac634a9a 161 win32/makefile.mk
2b3f5c13 162 win32/config_H.ce
f29c64d6 163 win32/config_H.gc
f7f713ed 164 win32/config_H.vc
18b94d96 165 uconfig.h
f7f713ed 166);
c9e35064
MH
167
168my $out = `chmod u+w @writables 2>&1`;
169if ($? != 0) {
170 warn $out;
171 if ($out =~ /no such file/i) {
172 warn "Check that the files above still exist in the Perl core.\n";
173 warn "If not, remove them from \@writables in Porting/makerel\n";
174 }
175 exit 1;
c9e35064 176}
f7f713ed 177
976a2e28
MH
178warn $out if $out;
179
6e24577b
GS
180chdir ".." or die $!;
181
1baeb402
DG
182exit if $opts{n};
183
f27ffc4a 184my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
85bdf03b 185
0dcf3caa
LB
186print "Checking if you have 7z...\n";
187my $output_7z = `7z 2>&1`;
188my $have_7z = defined $output_7z && $output_7z =~ /7-Zip/;
08aa1457 189
0dcf3caa
LB
190print "Checking if you have advdef...\n";
191my $output_advdef = `advdef --version 2>&1`;
192my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/;
193
194if ($have_7z) {
195 print "Creating and compressing the tar.gz file with 7z...\n";
196 $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz";
85bdf03b 197 system($cmd) == 0 or die "$cmd failed";
0dcf3caa
LB
198} else {
199 print "Creating and compressing the tar.gz file...\n";
200 $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
201 system($cmd) == 0 or die "$cmd failed";
202 if ($have_advdef) {
203 print "Recompressing the tar.gz file with advdef...\n";
204 $cmd = "advdef -z -4 $reldir.tar.gz";
205 system($cmd) == 0 or die "$cmd failed";
206 }
207}
208
209if ($opts{b}) {
210 if ($have_7z) {
211 print "Creating and compressing the tar.bz2 file with 7z...\n";
212 $cmd = "tar cf - $reldir | 7z a -tbzip2 -mx9 -bd -si $reldir.tar.bz2";
213 system($cmd) == 0 or die "$cmd failed";
214 } else {
215 print "Creating and compressing the tar.bz2 file...\n";
216 $cmd = "tar cf - $reldir | bzip2 > $reldir.tar.bz2";
217 system($cmd) == 0 or die "$cmd failed";
218 }
85bdf03b
DM
219}
220
f276fdad
CBW
221if ($opts{x}) {
222 print "Creating and compressing the tar.gz file with 7z...\n";
223 $cmd = "tar cf - $reldir | xz -z -c > $reldir.tar.xz";
224 system($cmd) == 0 or die "$cmd failed";
225}
226
85bdf03b 227print "\n";
9b05e874 228
ecc9c9d9
DM
229system("ls -ld $perl*");
230print "\n";
231
e8c01f92 232my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
ecc9c9d9 233for my $sha (qw(sha1 shasum sha1sum)) {
e8c01f92 234 if (`which $sha 2>$null`) {
ecc9c9d9
DM
235 system("$sha $perl*.tar.*");
236 last;
237 }
9b05e874 238}