18 # ------------------------------------------------------------------
20 sub get_and_check_version {
24 # make sure this looks like a real release version
25 # which should (currently) be 4.xx[.y] or 4.xx[.y]_RCx
26 unless ( $release =~ /^(?<release>(?<major>4\.\d\d)(?:\.(?<minor>\d+))?(?:_RC\d+)?)$/ ) {
27 croak "The given version number does not look right - $release";
29 $context->{release} = $+{release};
30 $context->{major} = $+{major};
31 $context->{minor} = $+{minor};
33 ($context->{trelease} = $+{release}) =~ s/_RC\d+//;
36 # ------------------------------------------------------------------
41 # The CVS tag consists of exim-$version where $version
42 # is the version number with . replaced with _
43 my $modversion = $context->{release};
44 $modversion =~ tr/0-9RC/_/cs;
46 return sprintf( 'exim-%s', $modversion );
49 # ------------------------------------------------------------------
51 sub deal_with_working_directory {
55 # Set default directory
56 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
57 my $directory = $context->{directory};
59 # ensure the working directory is not in place
60 if ( -d $directory ) {
62 print "Deleting existing $directory\n" if ($verbose);
63 rmtree( $directory, { verbose => $debug } );
65 if ( -d $directory ) {
66 croak "Working directory $directory exists";
70 # create base directory
71 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
73 # set and create subdirectories
74 foreach (qw(release_tree pkgs pkgdirs docbook tmp)) {
75 $context->{$_} = File::Spec->catdir( $context->{directory}, $_ );
76 mkpath( $context->{$_}, { verbose => ( $verbose || $debug ) } );
80 # ------------------------------------------------------------------
86 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp}, $context->{pkgname}, $context->{release} );
87 $context->{tmp_archive_file} = $archive_file;
88 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
90 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
91 system(@cmd) == 0 || croak "Export failed";
94 # ------------------------------------------------------------------
99 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
100 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file}, '-C', $context->{release_tree} );
103 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
104 system(@cmd) == 0 || croak "Unpack failed";
107 # ------------------------------------------------------------------
109 sub make_version_script {
112 my $variant = substr( $context->{release}, length($context->{trelease}) );
113 if ( $context->{release} ne $context->{trelease} . $variant ) {
114 die "Broken version numbering, I'm buggy";
117 my $srcdir = File::Spec->catdir( $context->{release_tree}, 'src', 'src' );
118 chdir $srcdir or die "chdir $srcdir: $!\n";
120 if ( -f "version.sh" ) {
121 print( "WARNING: version.sh already exists - leaving it in place\n" );
125 # Currently (25. Feb. 2016) the mk_exim_release.pl up to now can't
126 # deal with security releases.!? So we need a current
127 # mk_exim_release.pl. But if we use a current (master), the
128 # reversion script returns wrong version info (it's running inside
129 # the Git tree and uses git --describe, which always returns the
130 # current version of master.) I do not want to change the old
131 # reversion scripts (in 4.86.1, 4.85.1).
133 # Thus we've to provide the version.sh, based on the info we have
134 # about the release. If reversion finds this, it doesn't try to find
135 # it's own way to get a valid version number from the git.
136 open(my $v, '>', 'version.sh') or die "Can't open '>version.sh' $!\n";
138 # initial version automatically generated from $0
139 EXIM_RELEASE_VERSION=$context->{major}
140 EXIM_VARIANT_VERSION=@{[$context->{minor}?'_'.$context->{minor}:'']}
141 EXIM_COMPILE_NUMBER=0
147 # Later, if we get the reversion script fixed, we can call it again.
148 # For now (25. Feb. 2016) we'll leave it unused.
149 my @cmd = ("../scripts/reversion", "release", $context->{tag});
150 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
151 system(@cmd) == 0 || croak "reversion failed";
155 -f "version.sh" or die "failed to create version.sh";
158 # ------------------------------------------------------------------
160 sub build_html_documentation {
163 my $genpath = $context->{webgen_base} . '/script/gen.pl';
164 my $templates = $context->{webgen_base} . '/templates';
165 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
166 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
167 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
172 $genpath, '--spec', $spec, '--filter',
173 $filter, '--latest', $context->{trelease}, '--tmpl',
174 $templates, '--docroot', $dir, '--localstatic'
176 push @cmd, '--verbose' if $verbose or $debug;
178 print "Executing ", join( ' ', @cmd ), "\n";
181 # move directory into right place
182 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
185 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
186 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
190 # ------------------------------------------------------------------
192 sub copy_docbook_files {
195 # where the generated docbook files can be found
196 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
198 # where the website docbook source dir is - push files to here
199 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
200 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
202 foreach my $file ( 'spec.xml', 'filter.xml' ) {
203 my $from = File::Spec->catfile( $docdir, $file );
204 my $to = File::Spec->catfile( $context->{docbook}, $file );
205 my $webto = File::Spec->catfile( $webdir, $file );
207 copy( $from, $webto );
211 # ------------------------------------------------------------------
213 sub build_documentation {
216 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
217 # documentation building gets the truncated release, without RC
218 system("cd '$docdir' && ./OS-Fixups && $context->{make_cmd} EXIM_VER=$context->{trelease} everything") == 0
219 || croak "Doc build failed";
221 copy_docbook_files($context);
222 build_html_documentation($context);
225 # ------------------------------------------------------------------
227 sub move_text_docs_into_pkg {
230 my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
231 my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
232 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
233 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
235 # move generated documents from docbook stuff
236 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
237 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
240 # move text documents across
241 foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
243 # skip a few we dont want
244 my $fn = ( File::Spec->splitpath($file) )[2];
246 if ( ( $fn eq 'ABOUT' )
247 || ( $fn eq 'ChangeLog.0' )
248 || ( $fn eq 'test-harness.txt' )
249 # Debian issue re licensing of RFCs
250 || ( $fn =~ /^draft-ietf-.*/ )
251 || ( $fn =~ /^rfc.*/ )
253 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
257 # ------------------------------------------------------------------
259 sub build_pspdfinfo_directory {
262 ##foreach my $format (qw/pdf postscript texinfo info/) {
263 foreach my $format (qw/pdf postscript/) {
264 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
265 mkpath( $target, { verbose => ( $verbose || $debug ) } );
267 # move documents across
271 $context->{release_tree},
275 ( $format eq 'postscript' )
283 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
288 # ------------------------------------------------------------------
290 sub build_main_package_directory {
293 # build the exim package directory path
294 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
296 # initially we move the exim-src directory to the new directory name
297 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
298 || croak "Rename of src dir failed - $!";
300 # add Local subdirectory
301 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
303 # now add the text docs
304 move_text_docs_into_pkg($context);
307 # ------------------------------------------------------------------
309 sub build_package_directories {
312 build_main_package_directory($context);
313 build_pspdfinfo_directory($context) if $context->{build_docs};
316 # ------------------------------------------------------------------
321 print "Cleaning up\n" if ($verbose);
322 chdir( $context->{directory} ) || die;
323 rmtree( $context->{release_tree}, { verbose => $debug } );
324 rmtree( $context->{docbook}, { verbose => $debug } );
325 rmtree( $context->{pkgdirs}, { verbose => $debug } );
328 # ------------------------------------------------------------------
330 # We prefer gtar to tar if gtar exists in $PATH
334 my $tar = $context->{tar_cmd};
336 return unless $tar eq 'tar';
338 foreach my $d (File::Spec->path()) {
339 my $p = File::Spec->catfile($d, 'gtar');
341 $context->{tar_cmd} = $p;
342 print "Switched tar command to: $p\n" if ($verbose);
348 # ------------------------------------------------------------------
350 sub create_tar_files {
353 my $pkgs = $context->{pkgs};
354 my $pkgdirs = $context->{pkgdirs};
355 my $tar = $context->{tar_cmd};
357 foreach my $c (keys %{ $context->{compressors} }) {
358 print "Compression: $c\t$context->{compressors}{$c}\n";
362 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
363 my $dirname = ( File::Spec->splitdir($dir) )[-1];
364 if ($context->{compressors}{gzip}) {
365 print "Creating: ${pkgs}/${dirname}.tar.gz\n" if ($verbose || $debug);
366 system("$tar cf ${pkgs}/${dirname}.tar.gz --gzip -C ${pkgdirs} ${dirname}")
368 if ($context->{compressors}{bzip2}) {
369 print "Creating: ${pkgs}/${dirname}.tar.bz2\n" if ($verbose || $debug);
370 system("$tar cf ${pkgs}/${dirname}.tar.bz2 --bzip2 -C ${pkgdirs} ${dirname}")
372 if ($context->{compressors}{lzip}) {
373 print "Creating: ${pkgs}/${dirname}.tar.lz\n" if ($verbose || $debug);
374 system("$tar cf ${pkgs}/${dirname}.tar.lz --lzip -C ${pkgdirs} ${dirname}")
379 # ------------------------------------------------------------------
385 orig_dir => File::Spec->curdir(),
386 tmp_dir => File::Temp->newdir(),
387 webgen_base => "$FindBin::Bin/../../../exim-website",
399 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
403 'directory=s' => \$context->{directory},
404 'webgen_base=s' => \$context->{webgen_base},
405 'tar=s' => \$context->{tar_cmd},
406 'make=s' => \$context->{make_cmd},
407 'lzip!' => \$context->{compressors}{lzip},
408 'verbose!' => \$verbose,
412 'delete!' => \$delete,
413 'cleanup!' => \$cleanup,
414 'build-docs!' => \$context->{build_docs},
418 pod2usage( -exitval => 1, -verbose => 0 );
420 pod2usage(0) if $help;
421 pod2usage( -verbose => 2 ) if $man;
423 get_and_check_version( shift, $context );
424 fix_paths_tar($context);
425 $context->{tag} = build_tag($context);
426 deal_with_working_directory( $context, $delete );
427 export_git_tree($context);
428 chdir( $context->{directory} ) || die;
429 unpack_tree($context);
430 make_version_script($context);
431 build_documentation($context) if $context->{build_docs};
432 build_package_directories($context);
433 create_tar_files($context);
434 do_cleanup($context) if ($cleanup);
443 mk_exim_release.pl - Build an exim release
447 mk_exim_release.pl [options] version
450 --debug force debug mode
451 --verbose force verbose mode
452 --help display this help and exits
453 --man displays man page
454 --tar=cmd command to use for tar
455 --make=cmd command to use for make
456 --directory=dir dir to package
457 --no-lzip do not create .tar.lz files
458 --delete Delete packaging directory at start
459 --noweb skip the website generation
471 Use to override the path to the tar command; without this, will search for
472 gtar, and if not found use tar. Need GNU tar for lzip, unless --no-lzip is
477 Use to override the path/name of the make command.
478 Useful sometimes to force gmake.
482 Build the lzip tarballs.
490 Display help and exits
500 Builds an exim release.
502 Starting in a populated git repo that has already been tagged for
503 release, build docs, build packages etc.
505 Parameter is the version number to build as - ie 4.72 4.72RC1, 4.86.1, etc
509 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
513 Copyright 2010 Exim Maintainers. All rights reserved.