This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
embed.fnc: Mark unlnk as Core only
[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 '..'
a3815e44 34 -s suffix suffix to append 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
d2540b73 39 -c cleanup perform a cleanup before building: clean git repo and target directory/tarballs
5f244db9
DM
40EOF
41
42my %opts;
d2540b73 43getopts('xncr:s:', \%opts) or usage;
5f244db9
DM
44@ARGV && usage;
45
46$relroot = defined $opts{r} ? $opts{r} : "..";
08aa1457 47
48die "Must be in root of the perl source tree.\n"
49 unless -f "./MANIFEST" and -f "patchlevel.h";
50
1ae6ead9 51open PATCHLEVEL, '<', 'patchlevel.h' or die;
3ffabb8c
GS
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
d2540b73
N
78cleanup($relroot, $reldir) if $opts{c};
79
08aa1457 80print "Cross-checking the MANIFEST...\n";
81($missfile, $missentry) = fullcheck();
37d29c6f 82@$missentry
41fd77f8 83 = grep {$_ !~ m!^\.(?:git|github|mailmap)! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
9b05e874
JV
84if (@$missfile ) {
85 warn "Can't make a release with MANIFEST files missing:\n";
86 warn "\t".$_."\n" for (@$missfile);
87}
88if (@$missentry ) {
89 warn "Can't make a release with files not listed in MANIFEST\n";
90 warn "\t".$_."\n" for (@$missentry);
91
92}
90248788
TB
93if ("@$missentry" =~ m/\.orig\b/) {
94 # Handy listing of find command and .orig files from patching work.
95 # I tend to run 'xargs rm' and copy and paste the file list.
96 my $cmd = "find . -name '*.orig' -print";
97 print "$cmd\n";
98 system($cmd);
99}
3e3baf6d 100die "Aborted.\n" if @$missentry or @$missfile;
08aa1457 101print "\n";
102
b59922b7 103# VMS no longer has hardcoded version numbers descrip.mms
48e117bb
GS
104
105print "Creating $relroot/$reldir release directory...\n";
d2540b73
N
106die "$relroot/$reldir release directory already exists [consider using -c]\n" if -e "$relroot/$reldir";
107die "$relroot/$reldir.tar.gz release file already exists [consider using -c]\n" if -e "$relroot/$reldir.tar.gz";
108die "$relroot/$reldir.tar.xz release file already exists [consider using -c]\n" if $opts{x} && -e "$relroot/$reldir.tar.xz";
48e117bb
GS
109mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
110print "\n";
111
112
113print "Copying files to release directory...\n";
114# ExtUtils::Manifest maniread does not preserve the order
115$cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir";
86cd7d77
JH
116system($cmd) == 0
117 or die "$cmd failed";
48e117bb
GS
118print "\n";
119
6e24577b 120chdir "$relroot/$reldir" or die $!;
48e117bb 121
d38b68fe 122
08aa1457 123print "Setting file permissions...\n";
bf955a65
GS
124system("find . -type f -print | xargs chmod 0444");
125system("find . -type d -print | xargs chmod 0755");
5326e4da 126my @exe = map { my ($f) = split; glob($f) }
ff906f87
DG
127 grep { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ }
128 map { split "\n" }
129 do { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> };
130
86cd7d77
JH
131system("chmod +x @exe") == 0
132 or die "system: $!";
6e24577b 133
f7f713ed 134my @writables = qw(
f3513db0
JH
135 NetWare/config_H.wc
136 NetWare/Makefile
f2c01b15 137 feature.h
11b27549 138 lib/feature.pm
ac634a9a 139 keywords.h
26ea9e12 140 keywords.c
ac634a9a
JH
141 opcode.h
142 opnames.h
143 pp_proto.h
ac634a9a 144 proto.h
f7f713ed
GS
145 embed.h
146 embedvar.h
fa9ec1c9 147 overload.inc
e9e0c7d0 148 overload.h
8b09643d 149 mg_vtable.h
7baf245a
KW
150 dist/Devel-PPPort/module2.c
151 dist/Devel-PPPort/module3.c
e120c24f 152 cpan/autodie/t/touch_me
e9e0c7d0
NC
153 reentr.c
154 reentr.h
155 regcharclass.h
f7f713ed 156 regnodes.h
0ebdc6d5 157 warnings.h
ac634a9a 158 lib/warnings.pm
e120c24f 159 win32/GNUmakefile
ac634a9a
JH
160 win32/Makefile
161 win32/makefile.mk
f29c64d6 162 win32/config_H.gc
f7f713ed 163 win32/config_H.vc
18b94d96 164 uconfig.h
f7f713ed 165);
c9e35064
MH
166
167my $out = `chmod u+w @writables 2>&1`;
168if ($? != 0) {
169 warn $out;
170 if ($out =~ /no such file/i) {
171 warn "Check that the files above still exist in the Perl core.\n";
172 warn "If not, remove them from \@writables in Porting/makerel\n";
173 }
174 exit 1;
c9e35064 175}
f7f713ed 176
976a2e28
MH
177warn $out if $out;
178
6e24577b
GS
179chdir ".." or die $!;
180
1baeb402
DG
181exit if $opts{n};
182
f27ffc4a 183my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
85bdf03b 184
0dcf3caa
LB
185print "Checking if you have 7z...\n";
186my $output_7z = `7z 2>&1`;
187my $have_7z = defined $output_7z && $output_7z =~ /7-Zip/;
08aa1457 188
0dcf3caa
LB
189print "Checking if you have advdef...\n";
190my $output_advdef = `advdef --version 2>&1`;
191my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/;
192
193if ($have_7z) {
194 print "Creating and compressing the tar.gz file with 7z...\n";
195 $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz";
85bdf03b 196 system($cmd) == 0 or die "$cmd failed";
0dcf3caa
LB
197} else {
198 print "Creating and compressing the tar.gz file...\n";
199 $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
200 system($cmd) == 0 or die "$cmd failed";
201 if ($have_advdef) {
202 print "Recompressing the tar.gz file with advdef...\n";
203 $cmd = "advdef -z -4 $reldir.tar.gz";
204 system($cmd) == 0 or die "$cmd failed";
205 }
206}
207
f276fdad 208if ($opts{x}) {
b38ca28d 209 print "Creating and compressing the tar.xz file with xz...\n";
f276fdad
CBW
210 $cmd = "tar cf - $reldir | xz -z -c > $reldir.tar.xz";
211 system($cmd) == 0 or die "$cmd failed";
212}
213
85bdf03b 214print "\n";
9b05e874 215
ecc9c9d9
DM
216system("ls -ld $perl*");
217print "\n";
218
e8c01f92 219my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
ecc9c9d9 220for my $sha (qw(sha1 shasum sha1sum)) {
e8c01f92 221 if (`which $sha 2>$null`) {
ecc9c9d9
DM
222 system("$sha $perl*.tar.*");
223 last;
224 }
9b05e874 225}
d2540b73
N
226
227sub cleanup {
228 my ( $relroot, $reldir ) = @_;
229
230 require File::Path;
231
232 my @cmds = (
233 [ qw{make distclean} ],
234 [ qw{git clean -dxf} ],
235 );
236
237 foreach my $cmd (@cmds) {
238 print join( ' ', "Running:", @$cmd, "\n" );
239 system @$cmd;
240 die "fail to run ".(join(' ', @$cmd) ) unless $? == 0;
241 }
242
243 if ( -d "$relroot/$reldir" ) {
244 print "Removing directory $relroot/$reldir\n";
245 File::Path::rmtree("$relroot/$reldir");
246 }
247
248 # always clean both
249 my @files = ( "$relroot/$reldir.tar.gz", "$relroot/$reldir.tar.xz" );
250
251 foreach my $f ( @files ) {
252 next unless -f $f;
253 print "Removing file '$f'\n";
254 unlink($f);
255 }
256
257 return;
258
259}
260
2611;