8c9e9c1a5663379dc18e414da8e9bb70740c6558
[p5sagit/p5-mst-13.2.git] / Porting / makerel
1 #!/usr/bin/perl -w
2
3 # A first attempt at some automated support for making a perl release.
4 # Very basic but functional - if you're on a unix system.
5 #
6 # No matter how automated this gets, you'll always need to read
7 # and re-read pumpkin.pod checking for things to be done at various
8 # stages of the process.
9 #
10 # Tim Bunce, June 1997
11
12 use ExtUtils::Manifest qw(fullcheck);
13 $ExtUtils::Manifest::Quiet = 1;
14 use Getopt::Std;
15
16 $|=1;
17
18 sub usage { die <<EOF; }
19 usage: $0 [ -r rootdir ] [-s suffix ] [ -b ]
20     -r rootdir   directory under which to create the build dir and tarball
21                  defaults to '..'
22     -s suffix    suffix to append to to the perl-x.y.z dir and tarball name
23                  defaults to the concatenaion of the local_patches entry
24                  in patchlevel.h (or blank, if none)
25     -b           make a .bz2 file in addtion to a .gz file
26 EOF
27
28 my %opts;
29 getopts('br:s:', \%opts) or usage;
30 @ARGV && usage;
31
32 $relroot = defined $opts{r} ? $opts{r} : "..";
33
34 die "Must be in root of the perl source tree.\n"
35         unless -f "./MANIFEST" and -f "patchlevel.h";
36
37 open PATCHLEVEL,"<patchlevel.h" or die;
38 my @patchlevel_h = <PATCHLEVEL>;
39 close PATCHLEVEL;
40 my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h;
41 print $patchlevel_h;
42 $revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/;
43 $patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/;
44 $subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/;
45 die "Unable to parse patchlevel.h" unless $subversion >= 0;
46 $vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion);
47
48 # fetch list of local patches
49 my (@local_patches, @lpatch_tags, $lpatch_tags);
50 @local_patches = grep { /^static.*local_patches/../^};/ } @patchlevel_h;
51 @local_patches = grep { !/^\s*,?NULL/  } @local_patches;
52 @lpatch_tags   = map  {  /^\s*,"(\w+)/ } @local_patches;
53 $lpatch_tags   = join "-", @lpatch_tags;
54
55 $perl = "perl-$vers";
56 $reldir = "$perl";
57
58 $lpatch_tags = $opts{s} if defined $opts{s};
59 $reldir .= "-$lpatch_tags" if $lpatch_tags;
60
61 print "\nMaking a release for $perl in $relroot/$reldir\n\n";
62
63 print "Cross-checking the MANIFEST...\n";
64 ($missfile, $missentry) = fullcheck();
65 @$missentry
66     = grep {$_ !~ m!^\.git/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry;
67 warn "Can't make a release with MANIFEST files missing.\n" if @$missfile;
68 warn "Can't make a release with files not listed in MANIFEST.\n" if @$missentry;
69 if ("@$missentry" =~ m/\.orig\b/) {
70     # Handy listing of find command and .orig files from patching work.
71     # I tend to run 'xargs rm' and copy and paste the file list.
72     my $cmd = "find . -name '*.orig' -print";
73     print "$cmd\n";
74     system($cmd);
75 }
76 die "Aborted.\n" if @$missentry or @$missfile;
77 print "\n";
78
79 # VMS no longer has hardcoded version numbers descrip.mms
80
81 print "Creating $relroot/$reldir release directory...\n";
82 die "$relroot/$reldir release directory already exists\n"   if -e "$relroot/$reldir";
83 die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz";
84 mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n";
85 print "\n";
86
87
88 print "Copying files to release directory...\n";
89 # ExtUtils::Manifest maniread does not preserve the order
90 $cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir";
91 system($cmd) == 0
92     or die "$cmd failed";
93 print "\n";
94
95 chdir "$relroot/$reldir" or die $!;
96
97 print "Setting file permissions...\n";
98 system("find . -type f -print     | xargs chmod 0444");
99 system("find . -type d -print     | xargs chmod 0755");
100 system("find t ext lib -name '*.t'     -print | xargs chmod +x");
101 system("find t ext lib -name 'test.pl' -print | xargs chmod +x");
102 my @exe = qw(
103     Configure
104     configpm
105     configure.gnu
106     embed.pl
107     installperl
108     installman
109     keywords.pl
110     opcode.pl
111     t/TEST
112     *.SH
113     vms/ext/Stdio/test.pl
114     vms/ext/filespec.t
115     x2p/*.SH
116     Porting/findrfuncs
117     Porting/genlog
118     Porting/makerel
119     Porting/*.pl
120     mpeix/nm
121     mpeix/relink
122     Cross/generate_config_sh
123     Cross/warp
124 );
125 system("chmod +x @exe") == 0
126     or die "system: $!";
127
128 my @writables = qw(
129     NetWare/config_H.wc
130     NetWare/Makefile
131     keywords.h
132     opcode.h
133     opnames.h
134     pp_proto.h
135     pp.sym
136     proto.h
137     embed.h
138     embedvar.h
139     global.sym
140     overload.c
141     overload.h
142     perlapi.h
143     perlapi.c
144     ext/Devel-PPPort/module2.c
145     ext/Devel-PPPort/module3.c
146     reentr.c
147     reentr.h
148     regcharclass.h
149     regnodes.h
150     warnings.h
151     lib/warnings.pm
152     win32/Makefile
153     win32/Makefile.ce
154     win32/makefile.mk
155     win32/config_H.bc
156     win32/config_H.gc
157     win32/config_H.vc
158     utils/Makefile
159     uconfig.h
160 );
161 system("chmod +w @writables") == 0
162     or die "system: $!";
163
164 print "Adding CRs to DOSish files...\n";
165 # This list is also in curliff.pl.
166 my @crlf = qw(
167     djgpp/configure.bat
168     README.ce
169     README.dos
170     README.symbian
171     README.win32
172     symbian/config.pl
173     symbian/makesis.pl
174     symbian/README
175     symbian/xsbuild.pl
176     win32/Makefile
177     win32/Makefile.ce
178     win32/ce-helpers/compile-all.bat
179     win32/ce-helpers/compile.bat
180     win32/ce-helpers/registry.bat
181     win32/distclean.bat
182     win32/makefile.mk
183 );
184 system("perl -pi -e 's/\\015*\\012/\\015\\012/' @crlf") == 0
185     or die "system: $!";
186 print "\n";
187
188 chdir ".." or die $!;
189
190 my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch
191
192 print "Creating and compressing the tar.gz file...\n";
193 $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz";
194 system($cmd) == 0 or die "$cmd failed";
195
196 if ($opts{b}) {
197     print "Creating and compressing the tar.bz2 file...\n";
198     $cmd = "tar cf - $reldir | bzip2 > $reldir.tar.bz2";
199     system($cmd) == 0 or die "$cmd failed";
200 }
201
202 print "\n";
203 system("ls -ld $perl*");