This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Added -x option to makerel to produce .xz tarballs
[perl5.git] / Porting / makerel
1 #!/usr/bin/perl -w
2
3 # A tool to build a perl release tarball
4 # Very basic but functional - if you're on a unix system.
5 #
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
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.
17 #
18 # No matter how automated this gets, you'll always need to read
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.
21 #
22 # Tim Bunce, June 1997
23
24 use ExtUtils::Manifest qw(fullcheck);
25 $ExtUtils::Manifest::Quiet = 1;
26 use Getopt::Std;
27
28 $|=1;
29
30 sub usage { die <<EOF; }
31 usage: $0 [ -r rootdir ] [-s suffix ] [ -b ] [ -n ]
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
35                  defaults to the concatenation of the local_patches entry
36                  in patchlevel.h (or blank, if none)
37     -b           make a .bz2 file in addtion to a .gz file
38     -x           make a .xz file in addtion to a .gz file
39     -n           do not make any tarballs, just the directory
40 EOF
41
42 my %opts;
43 getopts('bxnr:s:', \%opts) or usage;
44 @ARGV && usage;
45
46 $relroot = defined $opts{r} ? $opts{r} : "..";
47
48 die "Must be in root of the perl source tree.\n"
49         unless -f "./MANIFEST" and -f "patchlevel.h";
50
51 open PATCHLEVEL,"<patchlevel.h" or die;
52 my @patchlevel_h = <PATCHLEVEL>;
53 close PATCHLEVEL;
54 my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h;
55 print $patchlevel_h;
56 $revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/;
57 $patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/;
58 $subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/;
59 die "Unable to parse patchlevel.h" unless $subversion >= 0;
60 $vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion);
61
62 # fetch list of local patches
63 my (@local_patches, @lpatch_tags, $lpatch_tags);
64 @local_patches = grep { !/^\s*,?NULL/ && ! /,"uncommitted-changes"/ }
65                  grep { /^static.*local_patches/../^};/ }
66                  @patchlevel_h;
67 @lpatch_tags   = map  {  /^\s*,"(\w+)/ } @local_patches;
68 $lpatch_tags   = join "-", @lpatch_tags;
69
70 $perl = "perl-$vers";
71 $reldir = "$perl";
72
73 $lpatch_tags = $opts{s} if defined $opts{s};
74 $reldir .= "-$lpatch_tags" if $lpatch_tags;
75
76 print "\nMaking a release for $perl in $relroot/$reldir\n\n";
77
78 print "Cross-checking the MANIFEST...\n";
79 ($missfile, $missentry) = fullcheck();
80 @$missentry
81     = grep {$_ !~ m!^\.git/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
82 if (@$missfile ) {
83     warn "Can't make a release with MANIFEST files missing:\n";
84     warn "\t".$_."\n" for (@$missfile);
85 }
86 if (@$missentry ) {
87     warn "Can't make a release with files not listed in MANIFEST\n";
88     warn "\t".$_."\n" for (@$missentry);
89
90 }
91 if ("@$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 }
98 die "Aborted.\n" if @$missentry or @$missfile;
99 print "\n";
100
101 # VMS no longer has hardcoded version numbers descrip.mms
102
103 print "Creating $relroot/$reldir release directory...\n";
104 die "$relroot/$reldir release directory already exists\n"   if -e "$relroot/$reldir";
105 die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz";
106 mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
107 print "\n";
108
109
110 print "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";
113 system($cmd) == 0
114     or die "$cmd failed";
115 print "\n";
116
117 chdir "$relroot/$reldir" or die $!;
118
119
120 print "Setting file permissions...\n";
121 system("find . -type f -print     | xargs chmod 0444");
122 system("find . -type d -print     | xargs chmod 0755");
123 my @exe = map   { my ($f) = split; glob($f) }
124           grep  { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ }
125           map   { split "\n" }
126           do    { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> };
127
128 system("chmod +x @exe") == 0
129     or die "system: $!";
130
131 my @writables = qw(
132     NetWare/config_H.wc
133     NetWare/Makefile
134     feature.h
135     lib/feature.pm
136     keywords.h
137     keywords.c
138     opcode.h
139     opnames.h
140     pp_proto.h
141     proto.h
142     embed.h
143     embedvar.h
144     overload.c
145     overload.h
146     mg_vtable.h
147     perlapi.h
148     perlapi.c
149     cpan/Devel-PPPort/module2.c
150     cpan/Devel-PPPort/module3.c
151     reentr.c
152     reentr.h
153     regcharclass.h
154     regnodes.h
155     warnings.h
156     lib/warnings.pm
157     win32/Makefile
158     win32/Makefile.ce
159     win32/makefile.mk
160     win32/config_H.ce
161     win32/config_H.gc
162     win32/config_H.vc
163     uconfig.h
164 );
165
166 my $out = `chmod u+w @writables 2>&1`;
167 if ($? != 0) {
168     warn $out;
169     if ($out =~ /no such file/i) {
170         warn "Check that the files above still exist in the Perl core.\n";
171         warn "If not, remove them from \@writables in Porting/makerel\n";
172     }
173     exit 1;
174 }
175
176 warn $out if $out;
177
178 chdir ".." or die $!;
179
180 exit if $opts{n};
181
182 my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
183
184 print "Checking if you have 7z...\n";
185 my $output_7z = `7z 2>&1`;
186 my $have_7z = defined $output_7z && $output_7z =~ /7-Zip/;
187
188 print "Checking if you have advdef...\n";
189 my $output_advdef = `advdef --version 2>&1`;
190 my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/;
191
192 if ($have_7z) {
193     print "Creating and compressing the tar.gz file with 7z...\n";
194     $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz";
195     system($cmd) == 0 or die "$cmd failed";
196 } else {
197     print "Creating and compressing the tar.gz file...\n";
198     $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
199     system($cmd) == 0 or die "$cmd failed";
200     if ($have_advdef) {
201         print "Recompressing the tar.gz file with advdef...\n";
202         $cmd = "advdef -z -4 $reldir.tar.gz";
203         system($cmd) == 0 or die "$cmd failed";
204     }
205 }
206
207 if ($opts{b}) {
208     if ($have_7z) {
209         print "Creating and compressing the tar.bz2 file with 7z...\n";
210         $cmd = "tar cf - $reldir | 7z a -tbzip2 -mx9 -bd -si $reldir.tar.bz2";
211         system($cmd) == 0 or die "$cmd failed";
212     } else {
213         print "Creating and compressing the tar.bz2 file...\n";
214         $cmd = "tar cf - $reldir | bzip2 > $reldir.tar.bz2";
215         system($cmd) == 0 or die "$cmd failed";
216     }
217 }
218
219 if ($opts{x}) {
220     print "Creating and compressing the tar.gz file with 7z...\n";
221     $cmd = "tar cf - $reldir | xz -z -c > $reldir.tar.xz";
222     system($cmd) == 0 or die "$cmd failed";
223 }
224
225 print "\n";
226
227 system("ls -ld $perl*");
228 print "\n";
229
230 my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
231 for my $sha (qw(sha1 shasum sha1sum)) {
232     if (`which $sha 2>$null`) {
233         system("$sha $perl*.tar.*");
234         last;
235     }
236 }