18 # ------------------------------------------------------------------
20 sub get_and_check_version
{
24 # make sure this looks like a real release version
25 # which should (currently) be 4.xx or 4.xx_RCx
26 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
27 croak
"The given version number does not look right - $release";
29 my $full_release = $1; # untainted here...
30 my $trunc_release = $full_release;
31 $trunc_release =~ s/^(4\.\d\d)(?:_RC\d+)?$/$1/;
33 $context->{release
} = $full_release;
34 $context->{trelease
} = $trunc_release;
37 # ------------------------------------------------------------------
42 # The CVS tag consists of exim-$version where $version
43 # is the version number with . replaced with _
44 my $modversion = $context->{release
};
45 $modversion =~ tr/0-9RC/_/cs;
47 return sprintf( 'exim-%s', $modversion );
50 # ------------------------------------------------------------------
52 sub deal_with_working_directory
{
56 # Set default directory
57 $context->{directory
} ||= File
::Spec
->rel2abs( sprintf( 'exim-packaging-%s', $context->{release
} ) );
58 my $directory = $context->{directory
};
60 # ensure the working directory is not in place
61 if ( -d
$directory ) {
63 print "Deleting existing $directory\n" if ($verbose);
64 rmtree
( $directory, { verbose
=> $debug } );
66 if ( -d
$directory ) {
67 croak
"Working directory $directory exists";
71 # create base directory
72 mkpath
( $context->{directory
}, { verbose
=> ( $verbose || $debug ) } );
74 # set and create subdirectories
75 foreach (qw(release_tree pkgs pkgdirs docbook tmp)) {
76 $context->{$_} = File
::Spec
->catdir( $context->{directory
}, $_ );
77 mkpath
( $context->{$_}, { verbose
=> ( $verbose || $debug ) } );
81 # ------------------------------------------------------------------
87 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp
}, $context->{pkgname
}, $context->{release
} );
88 $context->{tmp_archive_file
} = $archive_file;
89 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag
} );
92 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
93 system(@cmd) == 0 || croak
"Export failed";
96 # ------------------------------------------------------------------
101 die "Cannot see archive file\n" unless ( -f
$context->{tmp_archive_file
} );
102 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file
}, '-C', $context->{release_tree
} );
105 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
106 system(@cmd) == 0 || croak
"Unpack failed";
109 # ------------------------------------------------------------------
111 sub make_version_script
{
114 my $variant = substr( $context->{release
}, length($context->{trelease
}) );
115 if ( $context->{release
} ne $context->{trelease
} . $variant ) {
116 die "Broken version numbering, I'm buggy";
119 my $srcdir = File
::Spec
->catdir( $context->{release_tree
}, 'src', 'src' );
120 chdir $srcdir or die "chdir $srcdir: $\n";
122 if ( -f
"version.sh" ) {
123 print( "WARNING: version.sh already exists - leaving it in place\n" );
127 my @cmd = ("../scripts/reversion", "release");
128 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
129 system(@cmd) == 0 || croak
"reversion failed";
133 -f
"version.sh" or die "failed to create version.h";
136 # ------------------------------------------------------------------
138 sub build_html_documentation
{
141 my $genpath = $context->{webgen_base
} . '/script/gen.pl';
142 my $templates = $context->{webgen_base
} . '/templates';
143 my $dir = File
::Spec
->catdir( $context->{release_tree
}, 'html' );
144 my $spec = File
::Spec
->catfile( $context->{docbook
}, 'spec.xml' );
145 my $filter = File
::Spec
->catfile( $context->{docbook
}, 'filter.xml' );
150 $genpath, '--spec', $spec, '--filter',
151 $filter, '--latest', $context->{trelease
}, '--tmpl',
152 $templates, '--docroot', $dir, '--localstatic',
153 (($verbose||$debug) ?
'--verbose' : '')
156 print "Executing ", join( ' ', @cmd ), "\n";
159 # move directory into right place
160 my $sourcedir = File
::Spec
->catdir( $context->{docbook
}, 'filter.xml' );
163 File
::Spec
->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease
} ) ),
164 File
::Spec
->catdir( $context->{pkgdirs
}, sprintf( 'exim-html-%s', $context->{release
} ) )
168 # ------------------------------------------------------------------
170 sub copy_docbook_files
{
173 # where the generated docbook files can be found
174 my $docdir = File
::Spec
->catdir( $context->{release_tree
}, 'doc', 'doc-docbook' );
176 # where the website docbook source dir is - push files to here
177 my $webdir = File
::Spec
->catdir( $context->{webgen_base
}, 'docbook', $context->{trelease
} );
178 mkpath
( $webdir, { verbose
=> ( $verbose || $debug ) } );
180 foreach my $file ( 'spec.xml', 'filter.xml' ) {
181 my $from = File
::Spec
->catfile( $docdir, $file );
182 my $to = File
::Spec
->catfile( $context->{docbook
}, $file );
183 my $webto = File
::Spec
->catfile( $webdir, $file );
185 copy
( $from, $webto );
189 # ------------------------------------------------------------------
191 sub build_documentation
{
194 my $docdir = File
::Spec
->catdir( $context->{release_tree
}, 'doc', 'doc-docbook' );
195 # documentation building gets the truncated release, without RC
196 system("cd '$docdir' && ./OS-Fixups && $context->{make_cmd} EXIM_VER=$context->{trelease} everything") == 0
197 || croak
"Doc build failed";
199 copy_docbook_files
($context);
200 build_html_documentation
($context);
203 # ------------------------------------------------------------------
205 sub move_text_docs_into_pkg
{
208 my $old_docdir = File
::Spec
->catdir( $context->{release_tree
}, 'doc', 'doc-docbook' );
209 my $old_txtdir = File
::Spec
->catdir( $context->{release_tree
}, 'doc', 'doc-txt' );
210 my $new_docdir = File
::Spec
->catdir( $context->{eximpkgdir
}, 'doc' );
211 mkpath
( $new_docdir, { verbose
=> ( $verbose || $debug ) } );
213 # move generated documents from docbook stuff
214 foreach my $file (qw
/exim.8 spec.txt filter.txt/) {
215 move
( File
::Spec
->catfile( $old_docdir, $file ), File
::Spec
->catfile( $new_docdir, $file ) );
218 # move text documents across
219 foreach my $file ( glob( File
::Spec
->catfile( $old_txtdir, '*' ) ) ) {
221 # skip a few we dont want
222 my $fn = ( File
::Spec
->splitpath($file) )[2];
224 if ( ( $fn eq 'ABOUT' )
225 || ( $fn eq 'ChangeLog.0' )
226 || ( $fn eq 'test-harness.txt' )
227 # Debian issue re licensing of RFCs
228 || ( $fn =~ /^draft-ietf-.*/ )
229 || ( $fn =~ /^rfc.*/ )
231 move
( $file, File
::Spec
->catfile( $new_docdir, $fn ) );
235 # ------------------------------------------------------------------
237 sub build_pspdfinfo_directory
{
240 ##foreach my $format (qw/pdf postscript texinfo info/) {
241 foreach my $format (qw
/pdf postscript/) {
242 my $target = File
::Spec
->catdir( $context->{pkgdirs
}, sprintf( 'exim-%s-%s', $format, $context->{release
} ), 'doc' );
243 mkpath
( $target, { verbose
=> ( $verbose || $debug ) } );
245 # move documents across
249 $context->{release_tree
},
253 ( $format eq 'postscript' )
261 move
( $file, File
::Spec
->catfile( $target, ( File
::Spec
->splitpath($file) )[2] ) );
266 # ------------------------------------------------------------------
268 sub build_main_package_directory
{
271 # build the exim package directory path
272 $context->{eximpkgdir
} = File
::Spec
->catdir( $context->{pkgdirs
}, sprintf( 'exim-%s', $context->{release
} ) );
274 # initially we move the exim-src directory to the new directory name
275 rename( File
::Spec
->catdir( $context->{release_tree
}, 'src' ), $context->{eximpkgdir
} )
276 || croak
"Rename of src dir failed - $!";
278 # add Local subdirectory
279 mkpath
( File
::Spec
->catdir( $context->{eximpkgdir
}, 'Local' ), { verbose
=> ( $verbose || $debug ) } );
281 # now add the text docs
282 move_text_docs_into_pkg
($context);
285 # ------------------------------------------------------------------
287 sub build_package_directories
{
290 build_main_package_directory
($context);
291 build_pspdfinfo_directory
($context);
294 # ------------------------------------------------------------------
299 print "Cleaning up\n" if ($verbose);
300 rmtree
( $context->{release_tree
}, { verbose
=> $debug } );
301 rmtree
( $context->{docbook
}, { verbose
=> $debug } );
302 rmtree
( $context->{pkgdirs
}, { verbose
=> $debug } );
305 # ------------------------------------------------------------------
307 # We prefer gtar to tar if gtar exists in $PATH
311 my $tar = $context->{tar_cmd
};
313 return unless $tar eq 'tar';
315 foreach my $d (File
::Spec
->path()) {
316 my $p = File
::Spec
->catfile($d, 'gtar');
318 $context->{tar_cmd
} = $p;
319 print "Switched tar command to: $p\n" if ($verbose);
325 # ------------------------------------------------------------------
327 sub create_tar_files
{
330 my $pkgs = $context->{pkgs
};
331 my $pkgdirs = $context->{pkgdirs
};
332 my $tar = $context->{tar_cmd
};
334 foreach my $c (keys %{ $context->{compressors
} }) {
335 print "Compression: $c\t$context->{compressors}{$c}\n";
339 foreach my $dir ( glob( File
::Spec
->catdir( $pkgdirs, ( 'exim*-' . $context->{release
} ) ) ) ) {
340 my $dirname = ( File
::Spec
->splitdir($dir) )[-1];
341 if ($context->{compressors
}{gzip
}) {
342 print "Creating: ${pkgs}/${dirname}.tar.gz\n" if ($verbose || $debug);
343 system("$tar cf ${pkgs}/${dirname}.tar.gz --gzip -C ${pkgdirs} ${dirname}")
345 if ($context->{compressors
}{bzip2
}) {
346 print "Creating: ${pkgs}/${dirname}.tar.bz2\n" if ($verbose || $debug);
347 system("$tar cf ${pkgs}/${dirname}.tar.bz2 --bzip2 -C ${pkgdirs} ${dirname}")
349 if ($context->{compressors
}{lzip
}) {
350 print "Creating: ${pkgs}/${dirname}.tar.lz\n" if ($verbose || $debug);
351 system("$tar cf ${pkgs}/${dirname}.tar.lz --lzip -C ${pkgdirs} ${dirname}")
356 # ------------------------------------------------------------------
362 orig_dir
=> File
::Spec
->curdir(),
363 tmp_dir
=> File
::Temp
->newdir(),
364 webgen_base
=> "$FindBin::Bin/../../../exim-website",
375 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
379 'directory=s' => \
$context->{directory
},
380 'webgen_base=s' => \
$context->{webgen_base
},
381 'tar=s' => \
$context->{tar_cmd
},
382 'make=s' => \
$context->{make_cmd
},
383 'lzip!' => \
$context->{compressors
}{lzip
},
384 'verbose!' => \
$verbose,
388 'delete!' => \
$delete,
389 'cleanup!' => \
$cleanup,
393 pod2usage
( -exitval
=> 1, -verbose
=> 0 );
395 pod2usage
(0) if $help;
396 pod2usage
( -verbose
=> 2 ) if $man;
398 get_and_check_version
( shift, $context );
399 fix_paths_tar
($context);
400 $context->{tag
} = build_tag
($context);
401 deal_with_working_directory
( $context, $delete );
402 export_git_tree
($context);
403 chdir( $context->{directory
} ) || die;
404 unpack_tree
($context);
405 make_version_script
($context);
406 build_documentation
($context);
407 build_package_directories
($context);
408 create_tar_files
($context);
409 do_cleanup
($context) if ($cleanup);
418 mk_exim_release.pl - Build an exim release
422 mk_exim_release.pl [options] version
425 --debug force debug mode (SQL Trace)
426 --verbose force verbose mode
427 --help display this help and exits
428 --man displays man page
429 --tar=cmd command to use for tar
430 --make=cmd command to use for make
431 --directory=dir dir to package
432 --no-lzip do not create .tar.lz files
433 --delete Delete packaging directory at start
441 Forces debug mode cause all SQL statements generated by L<DBIx::Class>
446 Use to override the path to the tar command; without this, will search for
447 gtar, and if not found use tar. Need GNU tar for lzip, unless --no-lzip is
452 Use to override the path/name of the make command.
453 Useful sometimes to force gmake.
457 Build the lzip tarballs.
465 Display help and exits
475 Builds an exim release.
477 Starting in a populated git repo that has already been tagged for
478 release, build docs, build packages etc.
480 Parameter is the version number to build as - ie 4.72 4.72RC1 etc
484 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
488 Copyright 2010 Exim Maintainers. All rights reserved.