Fix doc/ directory assembly in build-script.
[exim.git] / release-process / scripts / mk_exim_release.pl
index 0697124cac4b3acd8a5b84939d5a33315cbaa680..566f2619d8748d5531982ef001ba8150be32f565 100755 (executable)
@@ -11,6 +11,7 @@ use File::Path;
 use File::Temp;
 use FindBin;
 use Getopt::Long;
+use IO::File;
 use Pod::Usage;
 
 my $debug   = 0;
@@ -109,6 +110,54 @@ sub unpack_tree {
 
 # ------------------------------------------------------------------
 
+sub adjust_version_extension {
+    my $context = shift;
+
+    return if ($context->{release} eq $context->{trelease});
+
+    my $variant = substr( $context->{release}, length($context->{trelease}) );
+    if ( $context->{release} ne $context->{trelease} . $variant ) {
+        die "Broken version numbering, I'm buggy";
+    }
+    my $srcdir    = File::Spec->catdir( $context->{release_tree}, 'src', 'src' );
+    my $version_h = File::Spec->catfile( $srcdir, 'version.h' );
+
+    my $fh        = new IO::File $version_h, 'r';
+    die "Cannot read version.h: $!\n" unless ( defined $fh );
+    my @lines = <$fh>;
+    $fh->close() or die "Failed to close-read($version_h): $!\n";
+
+    my $found = 0;
+    my $i;
+    for ( $i = 0 ; $i < @lines ; ++$i ) {
+        if ( $lines[$i] =~ /EXIM_VARIANT_VERSION/ ) {
+            $found = 1;
+           last;
+        }
+    }
+    die "Cannot find version.h EXIM_VARIANT_VERSION\n" unless $found;
+    unless ( $lines[$i] =~ m/^\s* \# \s* define \s+ EXIM_VARIANT_VERSION \s+ "(.*)" \s* $/x ) {
+        die "Broken version.h EXIM_VARIANT_VERSION line\n";
+    }
+    if ( length $1 ) {
+        print( "WARNING: version.h has a variant tag already defined: $1\n" );
+        print( "         not changing that tag\n" );
+        return;
+    }
+
+    $lines[$i] = qq{#define EXIM_VARIANT_VERSION\t\t"$variant"\n};
+    # deliberately not verbose constrained:
+    print( "Adjusting version.h for $variant release.\n" );
+
+    $fh = new IO::File $version_h, "w";
+    die "Cannot write version.h: $!\n" unless ( defined $fh );
+    $fh->print( @lines );
+    $fh->close() or die "Failed to close-write($version_h): $!\n";
+}
+
+# ------------------------------------------------------------------
+
 sub build_html_documentation {
     my $context = shift;
 
@@ -174,7 +223,8 @@ sub build_documentation {
 sub move_text_docs_into_pkg {
     my $context = shift;
 
-    my $old_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc', 'doc-docbook' );
+    my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
+    my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
     my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
     mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
 
@@ -184,7 +234,7 @@ sub move_text_docs_into_pkg {
     }
 
     # move text documents across
-    foreach my $file ( glob( File::Spec->catfile( 'doc/doc-txt', '*' ) ) ) {
+    foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
 
         # skip a few we dont want
         my $fn = ( File::Spec->splitpath($file) )[2];
@@ -318,6 +368,7 @@ sub create_tar_files {
     export_git_tree($context);
     chdir( $context->{directory} ) || die;
     unpack_tree($context);
+    adjust_version_extension($context);
     build_documentation($context);
     build_package_directories($context);
     create_tar_files($context);