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