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)) {
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_dir}, $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 adjust_version_extension {
114 return if ($context->{release} eq $context->{trelease});
116 my $variant = substr( $context->{release}, length($context->{trelease}) );
117 if ( $context->{release} ne $context->{trelease} . $variant ) {
118 die "Broken version numbering, I'm buggy";
121 my $srcdir = File::Spec->catdir( $context->{release_tree}, 'src', 'src' );
122 my $version_h = File::Spec->catfile( $srcdir, 'version.h' );
124 my $fh = new IO::File $version_h, 'r';
125 die "Cannot read version.h: $!\n" unless ( defined $fh );
127 $fh->close() or die "Failed to close-read($version_h): $!\n";
131 for ( $i = 0 ; $i < @lines ; ++$i ) {
132 if ( $lines[$i] =~ /EXIM_VARIANT_VERSION/ ) {
137 die "Cannot find version.h EXIM_VARIANT_VERSION\n" unless $found;
138 unless ( $lines[$i] =~ m/^\s* \# \s* define \s+ EXIM_VARIANT_VERSION \s+ "(.*)" \s* $/x ) {
139 die "Broken version.h EXIM_VARIANT_VERSION line\n";
142 print( "WARNING: version.h has a variant tag already defined: $1\n" );
143 print( " not changing that tag\n" );
147 $lines[$i] = qq{#define EXIM_VARIANT_VERSION\t\t"$variant"\n};
148 # deliberately not verbose constrained:
149 print( "Adjusting version.h for $variant release.\n" );
151 $fh = new IO::File $version_h, "w";
152 die "Cannot write version.h: $!\n" unless ( defined $fh );
153 $fh->print( @lines );
154 $fh->close() or die "Failed to close-write($version_h): $!\n";
157 # ------------------------------------------------------------------
159 sub build_html_documentation {
162 my $genpath = $context->{webgen_base} . '/script/gen.pl';
163 my $templates = $context->{webgen_base} . '/templates';
164 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
165 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
166 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
171 ( $genpath, '--spec', $spec, '--filter', $filter, '--latest', $context->{trelease}, '--tmpl', $templates, '--docroot', $dir );
173 print "Executing ", join( ' ', @cmd ), "\n";
176 # move directory into right place
177 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
180 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
181 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
185 # ------------------------------------------------------------------
187 sub copy_docbook_files {
190 # where the generated docbook files can be found
191 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
193 # where the website docbook source dir is - push files to here
194 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
195 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
197 foreach my $file ( 'spec.xml', 'filter.xml' ) {
198 my $from = File::Spec->catfile( $docdir, $file );
199 my $to = File::Spec->catfile( $context->{docbook}, $file );
200 my $webto = File::Spec->catfile( $webdir, $file );
202 copy( $from, $webto );
206 # ------------------------------------------------------------------
208 sub build_documentation {
211 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
212 system("cd '$docdir' && ./OS-Fixups && make everything") == 0
213 || croak "Doc build failed";
215 copy_docbook_files($context);
216 build_html_documentation($context);
219 # ------------------------------------------------------------------
221 sub move_text_docs_into_pkg {
224 my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
225 my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
226 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
227 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
229 # move generated documents from docbook stuff
230 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
231 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
234 # move text documents across
235 foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
237 # skip a few we dont want
238 my $fn = ( File::Spec->splitpath($file) )[2];
240 if ( ( $fn eq 'ABOUT' )
241 || ( $fn eq 'ChangeLog.0' )
242 || ( $fn eq 'test-harness.txt' ) );
243 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
247 # ------------------------------------------------------------------
249 sub build_pspdfinfo_directory {
252 ##foreach my $format (qw/pdf postscript texinfo info/) {
253 foreach my $format (qw/pdf postscript/) {
254 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
255 mkpath( $target, { verbose => ( $verbose || $debug ) } );
257 # move documents across
261 $context->{release_tree},
265 ( $format eq 'postscript' )
273 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
278 # ------------------------------------------------------------------
280 sub build_main_package_directory {
283 # build the exim package directory path
284 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
286 # initially we move the exim-src directory to the new directory name
287 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
288 || croak "Rename of src dir failed - $!";
290 # add Local subdirectory
291 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
293 # now add the text docs
294 move_text_docs_into_pkg($context);
297 # ------------------------------------------------------------------
299 sub build_package_directories {
302 build_main_package_directory($context);
303 build_pspdfinfo_directory($context);
306 # ------------------------------------------------------------------
311 print "Cleaning up\n" if ($verbose);
312 rmtree( $context->{release_tree}, { verbose => $debug } );
313 rmtree( $context->{docbook}, { verbose => $debug } );
314 rmtree( $context->{pkgdirs}, { verbose => $debug } );
317 # ------------------------------------------------------------------
319 sub create_tar_files {
322 my $pkgs = $context->{pkgs};
323 my $pkgdirs = $context->{pkgdirs};
324 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
325 my $dirname = ( File::Spec->splitdir($dir) )[-1];
326 system("tar cfz ${pkgs}/${dirname}.tar.gz -C ${pkgdirs} ${dirname}");
327 system("tar cfj ${pkgs}/${dirname}.tar.bz2 -C ${pkgdirs} ${dirname}");
331 # ------------------------------------------------------------------
337 orig_dir => File::Spec->curdir(),
338 tmp_dir => File::Temp->newdir(),
339 webgen_base => "$FindBin::Bin/../../../exim-website",
343 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
347 'directory=s' => \$context->{directory},
348 'webgen_base=s' => \$context->{webgen_base},
349 'verbose!' => \$verbose,
353 'delete!' => \$delete,
354 'cleanup!' => \$cleanup,
358 pod2usage( -exitval => 1, -verbose => 0 );
360 pod2usage(0) if $help;
361 pod2usage( -verbose => 2 ) if $man;
363 get_and_check_version( shift, $context );
364 $context->{tag} = build_tag($context);
365 deal_with_working_directory( $context, $delete );
366 export_git_tree($context);
367 chdir( $context->{directory} ) || die;
368 unpack_tree($context);
369 adjust_version_extension($context);
370 build_documentation($context);
371 build_package_directories($context);
372 create_tar_files($context);
373 do_cleanup($context) if ($cleanup);
382 mk_exim_release.pl - Build an exim release
386 mk_exim_release.pl [options] version
389 --debug force debug mode (SQL Trace)
390 --verbose force verbose mode
391 --help display this help and exits
392 --man displays man page
393 --directory=dir dir to package
394 --delete Delete packaging directory at start
402 Forces debug mode cause all SQL statements generated by L<DBIx::Class>
407 Force verbose mode - currently this has no effect
411 Display help and exits
421 Builds an exim release.
423 Starting in a populated git repo that has already been tagged for
424 release, build docs, build packages etc.
426 Parameter is the version number to build as - ie 4.72 4.72RC1 etc
430 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
434 Copyright 2010 Exim Maintainers. All rights reserved.