Merge branch 'master' of git://git.exim.org/exim
[exim.git] / release-process / scripts / mk_exim_release.pl
CommitLineData
8a483da6
NM
1#!/usr/bin/perl
2#
3# $Cambridge: exim/release-process/scripts/mk_exim_release.pl,v 1.1 2010/06/03 12:00:38 nm4 Exp $
4#
5use strict;
6use warnings;
7use Carp;
8use File::Copy;
9use File::Spec;
10use File::Path;
8f29c950 11use File::Temp;
be914e6c 12use FindBin;
8a483da6
NM
13use Getopt::Long;
14use Pod::Usage;
15
16my $debug = 0;
17my $verbose = 0;
18
19# ------------------------------------------------------------------
20
21sub get_and_check_version {
22 my $release = shift;
be914e6c 23 my $context = shift;
8a483da6
NM
24
25 # make sure this looks like a real release version
8f29c950 26 # which should (currently) be 4.xx or 4.xx_RCx
8a483da6
NM
27 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
28 croak "The given version number does not look right - $release";
29 }
be914e6c
NM
30 my $full_release = $1; # untainted here...
31 my $trunc_release = $full_release;
32 $trunc_release =~ s/^(4\.\d\d)(?:_RC\d+)?$/$1/;
33
34 $context->{release} = $full_release;
35 $context->{trelease} = $trunc_release;
8a483da6
NM
36}
37
38# ------------------------------------------------------------------
39
8f29c950 40sub build_tag {
8a483da6
NM
41 my $context = shift;
42
43 # The CVS tag consists of exim-$version where $version
44 # is the version number with . replaced with _
45 my $modversion = $context->{release};
46 $modversion =~ tr/0-9RC/_/cs;
47
48 return sprintf( 'exim-%s', $modversion );
49}
50
51# ------------------------------------------------------------------
52
53sub deal_with_working_directory {
54 my $context = shift;
55 my $delete = shift;
56
57 # Set default directory
58 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
59 my $directory = $context->{directory};
60
61 # ensure the working directory is not in place
62 if ( -d $directory ) {
63 if ($delete) {
64 print "Deleting existing $directory\n" if ($verbose);
65 rmtree( $directory, { verbose => $debug } );
66 }
67 if ( -d $directory ) {
68 croak "Working directory $directory exists";
69 }
70 }
71
72 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
73}
74
75# ------------------------------------------------------------------
76
8f29c950 77sub export_git_tree {
8a483da6
NM
78 my $context = shift;
79
8f29c950
NM
80 # build git command
81 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp_dir}, $context->{pkgname}, $context->{release} );
82 $context->{tmp_archive_file} = $archive_file;
83 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
8a483da6 84
8f29c950 85 # run git command
8a483da6
NM
86 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
87 system(@cmd) == 0 || croak "Export failed";
88}
89
90# ------------------------------------------------------------------
91
8f29c950
NM
92sub unpack_tree {
93 my $context = shift;
94
95 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
96 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file} );
97
98 # run command
99 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
100 system(@cmd) == 0 || croak "Unpack failed";
101}
102
103# ------------------------------------------------------------------
104
be914e6c
NM
105sub build_html_documentation {
106 my $context = shift;
107
108 my $genpath = $context->{webgen_base} . '/script/gen.pl';
109 my $templates = $context->{webgen_base} . '/templates';
110 my $dir = 'html';
111 mkdir($dir);
112
113 my @cmd = (
114 $genpath, '--spec', 'doc/doc-docbook/spec.xml', '--filter',
115 'doc/doc-docbook/filter.xml', '--latest', $context->{trelease}, '--tmpl',
116 $templates, '--docroot', $dir
117 );
118
119 print "Executing ", join( ' ', @cmd ), "\n";
120 system(@cmd);
121
122 # move directory into right place
123 rename( sprintf( 'html/exim-html-%s', $context->{trelease} ), sprintf( 'exim-html-%s', $context->{release} ) );
124}
125
126# ------------------------------------------------------------------
127
8a483da6 128sub build_documentation {
be914e6c
NM
129 my $context = shift;
130
8f29c950 131 system("cd doc/doc-docbook && ./OS-Fixups && make everything") == 0
8a483da6 132 || croak "Doc build failed";
be914e6c
NM
133
134 build_html_documentation($context);
8a483da6
NM
135}
136
137# ------------------------------------------------------------------
138
139sub move_text_docs_into_pkg {
140 my $context = shift;
141
8f29c950 142 my $old_docdir = 'doc/doc-docbook';
8a483da6
NM
143 my $new_docdir = File::Spec->catdir( $context->{pkgdir}, 'doc' );
144 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
145
146 # move generated documents from docbook stuff
147 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
148 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
149 }
150
151 # move text documents across
8f29c950 152 foreach my $file ( glob( File::Spec->catfile( 'doc/doc-txt', '*' ) ) ) {
8a483da6
NM
153
154 # skip a few we dont want
155 my $fn = ( File::Spec->splitpath($file) )[2];
156 next
157 if ( ( $fn eq 'ABOUT' )
158 || ( $fn eq 'ChangeLog.0' )
159 || ( $fn eq 'test-harness.txt' ) );
160 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
161 }
162}
163
164# ------------------------------------------------------------------
165
166sub build_pspdfinfo_directory {
167 my $context = shift;
168
169 ##foreach my $format (qw/pdf postscript texinfo info/) {
170 foreach my $format (qw/pdf postscript/) {
171 my $dir = sprintf( 'exim-%s-%s', $format, $context->{release} );
172 my $target = File::Spec->catdir( $dir, 'doc' );
173 mkpath( $target, { verbose => ( $verbose || $debug ) } );
174
175 # move documents across
176 foreach my $file (
177 glob(
178 File::Spec->catfile(
8f29c950 179 'doc/doc-docbook',
8a483da6
NM
180 (
181 ( $format eq 'postscript' )
182 ? '*.ps'
183 : ( '*.' . $format )
184 )
185 )
186 )
187 )
188 {
189 my $fn = ( File::Spec->splitpath($file) )[2];
190 move( $file, File::Spec->catfile( $target, $fn ) );
191 }
192 }
193}
194
195# ------------------------------------------------------------------
196
8a483da6
NM
197sub build_main_package_directory {
198 my $context = shift;
199
200 # initially we move the exim-src directory to the new directory name
201 my $pkgdir = sprintf( 'exim-%s', $context->{release} );
202 $context->{pkgdir} = $pkgdir;
8f29c950 203 rename( 'src', $pkgdir ) || croak "Rename of src dir failed - $!";
8a483da6
NM
204
205 # add Local subdirectory
206 my $target = File::Spec->catdir( $pkgdir, 'Local' );
207 mkpath( $target, { verbose => ( $verbose || $debug ) } );
208
209 # now add the text docs
210 move_text_docs_into_pkg($context);
211}
212
213# ------------------------------------------------------------------
214
215sub build_package_directories {
216 my $context = shift;
217
218 build_main_package_directory($context);
219 build_pspdfinfo_directory($context);
8a483da6
NM
220}
221
222# ------------------------------------------------------------------
223
224sub create_tar_files {
225 my $context = shift;
226
227 foreach my $dir ( glob( 'exim*-' . $context->{release} ) ) {
228 system("tar cfz ${dir}.tar.gz ${dir}");
229 system("tar cfj ${dir}.tar.bz2 ${dir}");
230 }
231}
232
233# ------------------------------------------------------------------
234{
235 my $man;
236 my $help;
237 my $context = {
be914e6c
NM
238 pkgname => 'exim',
239 orig_dir => File::Spec->curdir(),
240 tmp_dir => File::Temp->newdir(),
241 webgen_base => "$FindBin::Bin/../../../exim-website",
8a483da6
NM
242 };
243 my $delete;
8f29c950 244 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
8a483da6
NM
245
246 unless (
247 GetOptions(
be914e6c
NM
248 'directory=s' => \$context->{directory},
249 'webgen_base=s' => \$context->{webgen_base},
250 'verbose!' => \$verbose,
251 'debug!' => \$debug,
252 'help|?' => \$help,
253 'man!' => \$man,
254 'delete!' => \$delete,
8a483da6
NM
255 )
256 )
257 {
258 pod2usage( -exitval => 1, -verbose => 0 );
259 }
260 pod2usage(0) if $help;
261 pod2usage( -verbose => 2 ) if $man;
262
be914e6c
NM
263 get_and_check_version( shift, $context );
264 $context->{tag} = build_tag($context);
8a483da6 265 deal_with_working_directory( $context, $delete );
8f29c950 266 export_git_tree($context);
8a483da6 267 chdir( $context->{directory} ) || die;
8f29c950 268 unpack_tree($context);
8a483da6
NM
269 build_documentation($context);
270 build_package_directories($context);
271 create_tar_files($context);
272}
273
2741;
275
276__END__
277
278=head1 NAME
279
280mk_exim_release.pl - Build an exim release
281
282=head1 SYNOPSIS
283
284mk_exim_release.pl [options] version
285
286 Options:
287 --debug force debug mode (SQL Trace)
288 --verbose force verbose mode
289 --help display this help and exits
290 --man displays man page
291 --directory=dir dir to package
8a483da6
NM
292 --delete Delete packaging directory at start
293
294=head1 OPTIONS
295
296=over 4
297
298=item B<--debug>
299
300Forces debug mode cause all SQL statements generated by L<DBIx::Class>
301to be output.
302
303=item B<--verbose>
304
305Force verbose mode - currently this has no effect
306
307=item B<--help>
308
309Display help and exits
310
311=item B<--man>
312
313Display man page
314
315=back
316
317=head1 DESCRIPTION
318
319Builds an exim release.
320
8f29c950
NM
321Starting in a populated git repo that has already been tagged for
322release, build docs, build packages etc.
8a483da6
NM
323
324Parameter is the version number to build as - ie 4.72 4.72RC1 etc
325
326=head1 AUTHOR
327
328Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
329
330=head1 COPYRIGHT
331
8f29c950 332Copyright 2010 Exim Maintainers. All rights reserved.
8a483da6
NM
333
334=cut