This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Regression test for 34394ecd - SVs that were only on the tmps stack leaked.
[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. Your Cygwin installation will need to contain at least the
12 # 'cpio' command, in addition to the commands installed by default, and it will
13 # also be useful to have 'curl' and 'diffstat' installed too for later stages
14 # of the release process (namely, Porting\corelist.pl and generating the commit
15 # statistics for the perlXYZdelta.pod file respectively). Finally, ensure that
16 # the 'awk' and 'shasum' commands are copies of gawk.exe and sha1sum.exe
17 # respectively, rather the links to them that only work in a Cygwin bash shell
18 # which they are by default.
19 #
20 # No matter how automated this gets, you'll always need to read
21 # and re-read pumpkin.pod and release_managers_guide.pod to
22 # check for things to be done at various stages of the process.
23 #
24 # Tim Bunce, June 1997
25
26 use ExtUtils::Manifest qw(fullcheck);
27 $ExtUtils::Manifest::Quiet = 1;
28 use Getopt::Std;
29
30 $|=1;
31
32 sub usage { die <<EOF; }
33 usage: $0 [ -r rootdir ] [-s suffix ] [ -b ]
34     -r rootdir   directory under which to create the build dir and tarball
35                  defaults to '..'
36     -s suffix    suffix to append to to the perl-x.y.z dir and tarball name
37                  defaults to the concatenaion of the local_patches entry
38                  in patchlevel.h (or blank, if none)
39     -b           make a .bz2 file in addtion to a .gz file
40 EOF
41
42 my %opts;
43 getopts('br: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 { /^static.*local_patches/../^};/ } @patchlevel_h;
65 @local_patches = grep { !/^\s*,?NULL/  } @local_patches;
66 @lpatch_tags   = map  {  /^\s*,"(\w+)/ } @local_patches;
67 $lpatch_tags   = join "-", @lpatch_tags;
68
69 $perl = "perl-$vers";
70 $reldir = "$perl";
71
72 $lpatch_tags = $opts{s} if defined $opts{s};
73 $reldir .= "-$lpatch_tags" if $lpatch_tags;
74
75 print "\nMaking a release for $perl in $relroot/$reldir\n\n";
76
77 print "Cross-checking the MANIFEST...\n";
78 ($missfile, $missentry) = fullcheck();
79 @$missentry
80     = grep {$_ !~ m!^\.git/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
81 if (@$missfile ) {
82     warn "Can't make a release with MANIFEST files missing:\n";
83     warn "\t".$_."\n" for (@$missfile);
84 }
85 if (@$missentry ) {
86     warn "Can't make a release with files not listed in MANIFEST\n";
87     warn "\t".$_."\n" for (@$missentry);
88
89 }
90 if ("@$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 }
97 die "Aborted.\n" if @$missentry or @$missfile;
98 print "\n";
99
100 # VMS no longer has hardcoded version numbers descrip.mms
101
102 print "Creating $relroot/$reldir release directory...\n";
103 die "$relroot/$reldir release directory already exists\n"   if -e "$relroot/$reldir";
104 die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz";
105 mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
106 print "\n";
107
108
109 print "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";
112 system($cmd) == 0
113     or die "$cmd failed";
114 print "\n";
115
116 chdir "$relroot/$reldir" or die $!;
117
118
119 my $SEARCH_ROOTS = 't ext lib dist cpan';
120
121 print "Setting file permissions...\n";
122 system("find . -type f -print     | xargs chmod 0444");
123 system("find . -type d -print     | xargs chmod 0755");
124 system("find $SEARCH_ROOTS -name '*.t'     -print | xargs chmod +x");
125 system("find $SEARCH_ROOTS -name 'test.pl' -print | xargs chmod +x");
126 my @exe = qw(
127     Configure
128     configpm
129     configure.gnu
130     embed.pl
131     installperl
132     installman
133     keywords.pl
134     opcode.pl
135     t/TEST
136     *.SH
137     vms/ext/filespec.t
138     x2p/*.SH
139     Porting/findrfuncs
140     Porting/genlog
141     Porting/makerel
142     Porting/*.pl
143     mpeix/nm
144     mpeix/relink
145     Cross/generate_config_sh
146     Cross/warp
147 );
148 system("chmod +x @exe") == 0
149     or die "system: $!";
150
151 my @writables = qw(
152     NetWare/config_H.wc
153     NetWare/Makefile
154     keywords.h
155     opcode.h
156     opnames.h
157     pp_proto.h
158     pp.sym
159     proto.h
160     embed.h
161     embedvar.h
162     global.sym
163     overload.c
164     overload.h
165     perlapi.h
166     perlapi.c
167     cpan/Devel-PPPort/module2.c
168     cpan/Devel-PPPort/module3.c
169     reentr.c
170     reentr.h
171     regcharclass.h
172     regnodes.h
173     warnings.h
174     lib/warnings.pm
175     win32/Makefile
176     win32/Makefile.ce
177     win32/makefile.mk
178     win32/config_H.bc
179     win32/config_H.gc
180     win32/config_H.vc
181     utils/Makefile
182     uconfig.h
183 );
184 system("chmod +w @writables") == 0
185     or die "system: $!";
186
187 chdir ".." or die $!;
188
189 my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
190
191 print "Creating and compressing the tar.gz file...\n";
192 $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
193 system($cmd) == 0 or die "$cmd failed";
194
195 if ($opts{b}) {
196     print "Creating and compressing the tar.bz2 file...\n";
197     $cmd = "tar cf - $reldir | bzip2 > $reldir.tar.bz2";
198     system($cmd) == 0 or die "$cmd failed";
199 }
200
201 print "\n";
202
203 system("ls -ld $perl*");
204 print "\n";
205
206 my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null';
207 for my $sha (qw(sha1 shasum sha1sum)) {
208     if (`which $sha 2>$null`) {
209         system("$sha $perl*.tar.*");
210         last;
211     }
212 }