2 # Copyright (c) The Exim Maintainers 2016
19 # ------------------------------------------------------------------
21 sub get_and_check_version {
25 # make sure this looks like a real release version
26 # which should (currently) be 4.xx[.y] or 4.xx[.y]_RCx
27 unless ( $release =~ /^(?<release>(?<major>4\.\d\d)(?:\.(?<minor>\d+))?(?<rc>_RC\d+)?)$/ ) {
28 croak "The given version number does not look right - $release";
30 $context->{release} = $+{release};
31 $context->{major} = $+{major};
32 $context->{minor} = $+{minor};
33 $context->{candidatev} = $+{rc};
35 ($context->{trelease} = $+{release}) =~ s/_RC\d+//;
38 # ------------------------------------------------------------------
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;
48 return sprintf( 'exim-%s', $modversion );
51 # ------------------------------------------------------------------
53 sub deal_with_working_directory {
57 # Set default directory
58 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
59 my $directory = $context->{directory};
61 # ensure the working directory is not in place
62 if ( -d $directory ) {
64 print "Deleting existing $directory\n" if ($verbose);
65 rmtree( $directory, { verbose => $debug } );
67 if ( -d $directory ) {
68 croak "Working directory $directory exists";
72 # create base directory
73 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
75 # set and create subdirectories
76 foreach (qw(release_tree pkgs pkgdirs docbook tmp)) {
77 $context->{$_} = File::Spec->catdir( $context->{directory}, $_ );
78 mkpath( $context->{$_}, { verbose => ( $verbose || $debug ) } );
82 # ------------------------------------------------------------------
88 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp}, $context->{pkgname}, $context->{release} );
89 $context->{tmp_archive_file} = $archive_file;
90 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 # Currently (25. Feb. 2016) the mk_exim_release.pl up to now can't
128 # deal with security releases.!? So we need a current
129 # mk_exim_release.pl. But if we use a current (master), the
130 # reversion script returns wrong version info (it's running inside
131 # the Git tree and uses git --describe, which always returns the
132 # current version of master.) I do not want to change the old
133 # reversion scripts (in 4.86.1, 4.85.1).
135 # Thus we've to provide the version.sh, based on the info we have
136 # about the release. If reversion finds this, it doesn't try to find
137 # it's own way to get a valid version number from the git.
139 # 4.89 series: the logic here did not handle _RC<N> thus breaking RC
140 # status in versions. nb: candidatev in context should be same as $variant
142 my $stamp = $context->{minor} ? '_'.$context->{minor} : '';
143 $stamp .= $context->{candidatev} if $context->{candidatev};
145 open(my $v, '>', 'version.sh') or die "Can't open '>version.sh' $!\n";
147 # initial version automatically generated from $0
148 EXIM_RELEASE_VERSION=$context->{major}
149 EXIM_VARIANT_VERSION=$stamp
150 EXIM_COMPILE_NUMBER=0
156 # Later, if we get the reversion script fixed, we can call it again.
157 # For now (25. Feb. 2016) we'll leave it unused.
158 my @cmd = ("../scripts/reversion", "release", $context->{tag});
159 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
160 system(@cmd) == 0 || croak "reversion failed";
164 -f "version.sh" or die "failed to create version.sh";
167 # ------------------------------------------------------------------
169 sub build_html_documentation {
172 my $genpath = $context->{webgen_base} . '/script/gen.pl';
173 my $templates = $context->{webgen_base} . '/templates';
174 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
175 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
176 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
181 $genpath, '--spec', $spec, '--filter',
182 $filter, '--latest', $context->{trelease}, '--tmpl',
183 $templates, '--docroot', $dir, '--localstatic'
185 push @cmd, '--verbose' if $verbose or $debug;
187 print "Executing ", join( ' ', @cmd ), "\n";
190 # move directory into right place
191 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
194 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
195 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
199 # ------------------------------------------------------------------
201 sub copy_docbook_files {
204 # where the generated docbook files can be found
205 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
207 # where the website docbook source dir is - push files to here
208 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
209 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
211 foreach my $file ( 'spec.xml', 'filter.xml' ) {
212 my $from = File::Spec->catfile( $docdir, $file );
213 my $to = File::Spec->catfile( $context->{docbook}, $file );
214 my $webto = File::Spec->catfile( $webdir, $file );
216 copy( $from, $webto );
220 # ------------------------------------------------------------------
222 sub build_documentation {
225 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
226 # documentation building gets the truncated release, without RC
227 system("cd '$docdir' && ./OS-Fixups && $context->{make_cmd} EXIM_VER=$context->{trelease} everything") == 0
228 || croak "Doc build failed";
230 copy_docbook_files($context);
231 build_html_documentation($context) if $context->{web};
234 # ------------------------------------------------------------------
236 sub move_text_docs_into_pkg {
239 my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
240 my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
241 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
242 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
244 # move generated documents from docbook stuff
245 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
246 die "Empty file \"$file\"\n" if -z File::Spec->catfile( $old_docdir, $file );
247 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
250 # move text documents across
251 foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
253 # skip a few we dont want
254 my $fn = ( File::Spec->splitpath($file) )[2];
256 if ( ( $fn eq 'ABOUT' )
257 || ( $fn eq 'ChangeLog.0' )
258 || ( $fn eq 'test-harness.txt' )
259 # Debian issue re licensing of RFCs
260 || ( $fn =~ /^draft-ietf-.*/ )
261 || ( $fn =~ /^rfc.*/ )
263 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
267 # ------------------------------------------------------------------
269 sub build_pspdfinfo_directory {
272 ##foreach my $format (qw/pdf postscript texinfo info/) {
273 foreach my $format (qw/pdf postscript/) {
274 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
275 mkpath( $target, { verbose => ( $verbose || $debug ) } );
277 # move documents across
281 $context->{release_tree},
285 ( $format eq 'postscript' )
293 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
298 # ------------------------------------------------------------------
300 sub build_main_package_directory {
303 # build the exim package directory path
304 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
306 # initially we move the exim-src directory to the new directory name
307 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
308 || croak "Rename of src dir failed - $!";
310 # add Local subdirectory
311 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
313 # now add the text docs
314 move_text_docs_into_pkg($context);
317 # ------------------------------------------------------------------
319 sub build_package_directories {
322 build_main_package_directory($context);
323 build_pspdfinfo_directory($context) if $context->{build_docs};
326 # ------------------------------------------------------------------
331 print "Cleaning up\n" if ($verbose);
332 chdir( $context->{directory} ) || die;
333 rmtree( $context->{release_tree}, { verbose => $debug } );
334 rmtree( $context->{docbook}, { verbose => $debug } );
335 rmtree( $context->{pkgdirs}, { verbose => $debug } );
338 # ------------------------------------------------------------------
340 # We prefer gtar to tar if gtar exists in $PATH
344 my $tar = $context->{tar_cmd};
346 return unless $tar eq 'tar';
348 foreach my $d (File::Spec->path()) {
349 my $p = File::Spec->catfile($d, 'gtar');
351 $context->{tar_cmd} = $p;
352 print "Switched tar command to: $p\n" if ($verbose);
358 # ------------------------------------------------------------------
360 sub create_tar_files {
363 my $pkgs = $context->{pkgs};
364 my $pkgdirs = $context->{pkgdirs};
365 my $tar = $context->{tar_cmd};
367 foreach my $c (keys %{ $context->{compressors} }) {
368 print "Compression: $c\t$context->{compressors}{$c}\n";
372 # We ideally do not want local system user information in release tarballs;
373 # those are artifacts of use of tar for backups and have no place in
374 # software release packaging; if someone extracts as root, then they should
375 # get sane file ownerships.
377 if (`tar --help 2>&1` =~ /^\s*--owner=/m) {
378 $ownership .= " --owner=$context->{tar_perms}{user} --group=$context->{tar_perms}{group}";
379 # on this GNU tar, --numeric-owner works during creation too
380 $ownership .= " --numeric-owner";
383 # See also environment variables set in main, tuning compression levels
385 # compressors-dict-key, file-extension, flags-as-string
386 [ "gzip", "gz", "--gzip" ],
387 [ "bzip2", "bz2", "--bzip2" ],
388 [ "lzip", "lz", "--lzip" ],
389 [ "xz", "xz", "--xz" ],
392 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
393 my $dirname = ( File::Spec->splitdir($dir) )[-1];
394 foreach my $comp (@COMPRESSIONS) {
395 my ($compkey, $extension, $flags) = @{$comp};
396 next unless $context->{compressors}{$compkey};
397 print "Creating: ${pkgs}/${dirname}.tar.${extension}\n" if ($verbose || $debug);
398 system("$tar cf ${pkgs}/${dirname}.tar.${extension} ${flags} ${ownership} -C ${pkgdirs} ${dirname}");
404 # ------------------------------------------------------------------
407 $0 =~ m|^(?:\./)?release-process/scripts/|
408 or die "$0: please call this script from the root of the Exim project sources\n";
412 orig_dir => File::Spec->curdir(),
413 tmp_dir => File::Temp->newdir(),
414 webgen_base => "$FindBin::Bin/../../../exim-website",
432 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
433 # We are creating files for mass distribution, so work harder to make smaller files.
435 $ENV{'BZIP2'} = '-9';
436 # xz documents minimum file sizes for levels higher than -6 to be useful and each
437 # requires more RAM on the decompressing system. Exim tarball currently 24MiB so
439 $ENV{'XZ_DEFAULTS'} = '-8';
442 'directory=s' => \$context->{directory},
443 'webgen_base=s' => \$context->{webgen_base},
444 'tar=s' => \$context->{tar_cmd},
445 'make=s' => \$context->{make_cmd},
446 'lzip!' => \$context->{compressors}{lzip},
447 'verbose!' => \$verbose,
449 'help|?' => sub { pod2usage(-verbose => 1, -exit => 0) },
450 'man!' => sub { pod2usage(-verbose => 2, -exit => 0, -noperldoc => system('perldoc -V >/dev/null 2>&1')) },
451 'delete!' => \$delete,
452 'cleanup!' => \$cleanup,
453 'build-docs!' => \$context->{build_docs},
454 'web!' => \$context->{web},
455 ) and @ARGV == 1 or pod2usage;
458 get_and_check_version( shift, $context );
459 fix_paths_tar($context);
460 $context->{tag} = build_tag($context);
461 deal_with_working_directory( $context, $delete );
462 export_git_tree($context);
463 chdir( $context->{directory} ) || die;
464 unpack_tree($context);
465 make_version_script($context);
466 build_documentation($context) if $context->{build_docs};
467 build_package_directories($context);
468 create_tar_files($context);
469 do_cleanup($context) if ($cleanup);
478 mk_exim_release - Build an exim release
482 mk_exim_release [options] version
486 B<mk_exim_release> builds an exim release.
488 Starting in a populated git repo that has already been tagged for
489 release it builds docs, packages etc. Parameter is the version number
490 to build as - ie 4.72 4.72RC1, 4.86.1, etc
492 After creating the release files, they should be signed. There is another
493 helper for creating the signatures:
494 F<release-process/scripts/sign_exim_packages>.
496 Call B<mk_exim_release> about like this:
498 release-process/scripts/mk_exim_release 4.99
507 Forces debug mode. (default: no debug info)
509 =item B<--[no]delete>
511 Delete a pre-existing package directory at start. (default: don't delete)
513 =item B<--directory> I<dir>
515 Change the name of the package directory (default: F<< exim-packaging-<version> >>)
519 Display short help and exit cleanly. (default: don't do that)
523 Control the creation of B<lzip> tarballs. (default: do not use lzip)
525 =item B<--make> I<cmd>
527 Force the use of a specific C<make> command. This may be necessary if C<make> is not
528 C<gmake> (default: C<make>)
532 Display man page and exit cleanly. (default: don't do that)
534 =item B<--tar> I<cmd>
536 Use to override the path to the C<tar> command. Need GNU tar in case
537 I<lzip> is selected. (default: C<gtar>, if not found, use C<tar>)
541 Control the creation of the website. For creation of the website, the F<../exim-website>
542 directory must exist. (default: create the website)
546 Force verbose mode. (default: no verbosity)
552 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>,
553 some changes by Heiko Schlittermann <hs@schlittermann.de>
557 Copyright 2010-2016 Exim Maintainers. All rights reserved.