Add captype and tfshark binaries to .gitignore
[metze/wireshark/wip.git] / make-version.pl
index 95eea07c5d407b5630f1533f582f12003427931c..9c0cd25769c7477bdb53a5a17bb026b908b3eb5e 100755 (executable)
@@ -37,7 +37,7 @@
 #   pkg_format - Like "format", but used for the local package version.
 #
 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
-# configure.in and the VERSION macro in config.nmake will have the
+# configure.ac and the VERSION macro in config.nmake will have the
 # pkg_format template appended to the version number. svnversion.h will
 # _not_ be generated if either argument is present.
 #
@@ -55,6 +55,7 @@
 use strict;
 
 use Time::Local;
+use File::Basename;
 use POSIX qw(strftime);
 use Getopt::Long;
 use Pod::Usage;
@@ -68,17 +69,19 @@ my $tortoise_file = "tortoise_template";
 my $last_change = 0;
 my $revision = 0;
 my $repo_path = "unknown";
+my $git_description = undef;
 my $get_svn = 0;
 my $set_svn = 0;
 my $set_version = 0;
 my $set_release = 0;
 my %version_pref = (
        "version_major" => 1,
-       "version_minor" => 9,
-       "version_micro" => 0,
+       "version_minor" => 11,
+       "version_micro" => 3,
        "version_build" => 0,
 
        "enable"        => 1,
+       "git_client"    => 0,
        "svn_client"    => 1,
        "tortoise_svn"  => 0,
        "format"        => "SVN %Y%m%d%H%M%S",
@@ -93,15 +96,16 @@ my %version_pref = (
        #"pkg_format" => "",
        );
 my $srcdir = ".";
-my $svn_info_cmd = "";
+my $info_cmd = "";
 
 # Ensure we run with correct locale
 $ENV{LANG} = "C";
 $ENV{LC_ALL} = "C";
+$ENV{GIT_PAGER} = "";
 
 # Run "svn info".  Parse out the most recent modification time and the
 # revision number.
-sub read_svn_info {
+sub read_repo_info {
        my $line;
        my $version_format = $version_pref{"format"};
        my $package_format = "";
@@ -117,19 +121,90 @@ sub read_svn_info {
                $package_format = $version_pref{"pkg_format"};
        }
 
-       if (-d "$srcdir/.svn") {
+       if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
+               $info_source = "Command line (git)";
+               $version_pref{"git_client"} = 1;
+       } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
                $info_source = "Command line (svn info)";
-               $svn_info_cmd = "svn info $srcdir";
+               $info_cmd = "svn info $srcdir";
        } elsif (-d "$srcdir/.git/svn") {
                $info_source = "Command line (git-svn)";
-               $svn_info_cmd = "(cd $srcdir; git svn info)";
+               $info_cmd = "(cd $srcdir; git svn info)";
        }
 
-       if ($version_pref{"svn_client"}) {
+       #Git can give us:
+       #
+       # A big ugly hash: git rev-parse HEAD
+       # 1ddc83849075addb0cac69a6fe3782f4325337b9
+       #
+       # A small ugly hash: git rev-parse --short HEAD
+       # 1ddc838
+       #
+       # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
+       # origin/master-1.8
+       #
+       # A version description: git describe --tags --dirty
+       # wireshark-1.8.12-15-g1ddc838
+       #
+       # Number of commits in this branch: git rev-list --count HEAD
+       # 48879
+       #
+       # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
+       # 320
+       #
+       # Refs: git ls-remote code.wireshark.org:wireshark
+       # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
+
+       if ($version_pref{"git_client"}) {
+               eval {
+                       use warnings "all";
+                       no warnings "all";
+
+                       chomp($line = qx{git log -1 --pretty=format:%at});
+                       if (defined($line)) {
+                               $last_change = $line;
+                       }
+
+                       # Commits in current (master-1.8) branch. We may want to use
+                       # a different number.
+                       chomp($line = qx{git rev-list --count ea19c7f952ce9fc53fe4c223f1d9d6797346258b..HEAD});
+                       if (defined($line)) {
+                               $revision = $line;
+                       }
+
+                       chomp($line = qx{git ls-remote --get-url origin});
+                       if (defined($line)) {
+                               $repo_url = $line;
+                       }
+
+                       # Probably not quite what we're looking for
+                       chomp($line = qx{git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
+                       if (defined($line)) {
+                               $repo_path = basename($line);
+                       }
+
+
+                       # XXX After the SVN->git migration we'll create tags for 1.11.x.
+                       # Until then we'll fake it.
+                       #chomp($line = qx{git describe --tags --dirty});
+                       chomp($line = qx{git rev-parse --short HEAD});
+                       if (defined($line)) {
+                               #$git_description = $line;
+                               $git_description = "wireshark-1.11." . $version_pref{"version_minor"} .
+                                       "-$revision-g$line";
+                       }
+
+                       1;
+               };
+
+               if ($last_change && $revision && $repo_url && $repo_path) {
+                       $do_hack = 0;
+               }
+       } elsif ($version_pref{"svn_client"}) {
                eval {
                        use warnings "all";
                        no warnings "all";
-                       $line = qx{$svn_info_cmd};
+                       $line = qx{$info_cmd};
                        if (defined($line)) {
                                if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
                                        $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
@@ -158,8 +233,8 @@ sub read_svn_info {
                close(TORTOISE);
 
                $info_source = "Command line (SubWCRev)";
-               $svn_info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
-               my $tortoise = system($svn_info_cmd);
+               $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
+               my $tortoise = system($info_cmd);
                if ($tortoise == 0) {
                        $do_hack = 0;
                }
@@ -182,6 +257,60 @@ sub read_svn_info {
                }
                close (CFGNMAKE);
        }
+       if ($revision == 0 and -d "$srcdir/.git") {
+
+               # Try git...
+               eval {
+                       use warnings "all";
+                       no warnings "all";
+                       # If someone had properly tagged 1.9.0 we could also use
+                       # "git describe --abbrev=1 --tags HEAD"
+                       
+                       $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
+                       $line = qx{$info_cmd};
+                       if (defined($line)) {
+                               if ($line =~ /svn path=.*; revision=(\d+)/) {
+                                       $revision = $1;
+                               }
+                       }
+                       $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
+                       $line = qx{$info_cmd};
+                       if (defined($line)) {
+                               if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
+                                       $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
+                               }
+                       }
+                       $info_cmd = "(cd $srcdir; git branch)";
+                       $line = qx{$info_cmd};
+                       if (defined($line)) {
+                               if ($line =~ /\* (\S+)/) {
+                                       $repo_path = $1;
+                               }
+                       }
+                       1;
+                       };
+       }
+       if ($revision == 0 and -d "$srcdir/.bzr") {
+
+               # Try bzr...
+               eval {
+                       use warnings "all";
+                       no warnings "all";
+                       $info_cmd = "(cd $srcdir; bzr log -l 1)";
+                       $line = qx{$info_cmd};
+                       if (defined($line)) {
+                               if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
+                                       $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
+                               }
+                               if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
+                                       $revision = $1;
+                                       $repo_path = $2;
+                               }
+                       }
+                       1;
+                       };
+       }
+
 
        # 'svn info' failed or the user really wants us to dig around in .svn/entries
        if ($do_hack) {
@@ -251,27 +380,27 @@ Fin
 }
 
 
-# Read configure.in, then write it back out with an updated
+# Read configure.ac, then write it back out with an updated
 # "AC_INIT" line.
-sub update_configure_in
+sub update_configure_ac
 {
        my $line;
        my $contents = "";
        my $version = "";
-       my $filepath = "$srcdir/configure.in";
+       my $filepath = "$srcdir/configure.ac";
 
        return if (!$set_version && $package_string eq "");
 
        open(CFGIN, "< $filepath") || die "Can't read $filepath!";
        while ($line = <CFGIN>) {
-               if ($line =~ /^AC_INIT\(wireshark, (\d+)\.(\d+).(\d+).*([\r\n]+)$/) {
-                       $line = sprintf("AC_INIT\(wireshark, %d.%d.%d%s)$4",
-                                       $set_version ? $version_pref{"version_major"} : $1,
-                                       $set_version ? $version_pref{"version_minor"} : $2,
-                                       $set_version ? $version_pref{"version_micro"} : $3,
-                                       $package_string
-                                      );
-
+               if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
+                       $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
+               } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
+                       $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
+               } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
+                       $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
+               } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
+                       $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
                }
                $contents .= $line
        }
@@ -313,23 +442,23 @@ sub update_config_nmake
        print "$filepath has been updated.\n";
 }
 
-# Read docbook/release_notes.xml, then write it back out with an updated
-# "WiresharkCurrentVersion" line.
+# Read docbook/asciidoc.conf, then write it back out with an updated
+# wireshark-version replacement line.
 sub update_release_notes
 {
        my $line;
        my $contents = "";
        my $version = "";
-       my $filepath = "$srcdir/docbook/release-notes.xml";
+       my $filepath = "$srcdir/docbook/asciidoc.conf";
 
        return if (!$set_version);
 
-       open(RELNOTES, "< $filepath") || die "Can't read $filepath!";
-       while ($line = <RELNOTES>) {
-               #   <!ENTITY WiresharkCurrentVersion "1.7.1">
+       open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
+       while ($line = <ADOC_CONF>) {
+               # wireshark-version:\[\]=1.9.1
 
-               if ($line =~ /<\!ENTITY\s+WiresharkCurrentVersion\s+.*([\r\n]+)$/) {
-                       $line = sprintf("<!ENTITY WiresharkCurrentVersion \"%d.%d.%d\">$1",
+               if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
+                       $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
                                        $version_pref{"version_major"},
                                        $version_pref{"version_minor"},
                                        $version_pref{"version_micro"},
@@ -338,9 +467,9 @@ sub update_release_notes
                $contents .= $line
        }
 
-       open(RELNOTES, "> $filepath") || die "Can't write $filepath!";
-       print(RELNOTES $contents);
-       close(RELNOTES);
+       open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
+       print(ADOC_CONF $contents);
+       close(ADOC_CONF);
        print "$filepath has been updated.\n";
 }
 
@@ -388,7 +517,7 @@ sub update_debian_wcf
        while ($line = <DWCF>) {
                # /usr/lib/wireshark/libwireshark.so.1.1.0
 
-               if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap).so\.\d+\.\d+\.)\d+$}) {
+               if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap|filetap).so\.\d+\.\d+\.)\d+$}) {
                        $line = sprintf("$1%d\n", $version_pref{"version_micro"});
                }
                $contents .= $line
@@ -415,10 +544,10 @@ sub update_lib_releases
        #   "If the library source code has changed at all since the last
        #    update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
        # epan changes with each minor release, almost by definition. wiretap
-       # changes with *most* releases.
+       # and filetap changes with *most* releases.
        #
        # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
-       for $filedir ("epan", "wiretap") {      # "wsutil"
+       for $filedir ("epan", "wiretap", "filetap") {   # "wsutil"
                $contents = "";
                $filepath = $filedir . "/Makefile.am";
                open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
@@ -441,7 +570,7 @@ sub update_lib_releases
 # Update distributed files that contain any version information
 sub update_versioned_files
 {
-       &update_configure_in;
+       &update_configure_ac;
        &update_config_nmake;
        &update_release_notes;
        &update_debian_changelog;
@@ -456,7 +585,11 @@ sub print_svn_revision
        my $svn_revision;
        my $needs_update = 1;
 
-       if ($last_change && $revision) {
+       if ($git_description) {
+               $svn_revision = "#define SVNVERSION \"" .
+                       $git_description . "\"\n" .
+                       "#define SVNPATH \"" . $repo_path . "\"\n";
+       } elsif ($last_change && $revision) {
                $svn_revision = "#define SVNVERSION \"SVN Rev " .
                        $revision . "\"\n" .
                        "#define SVNPATH \"" . $repo_path . "\"\n";
@@ -532,7 +665,7 @@ sub get_config {
 
 &get_config();
 
-&read_svn_info();
+&read_repo_info();
 
 &print_svn_revision;
 
@@ -573,13 +706,27 @@ make-version.pl [options] [source directory]
     --get-svn, -g              Print the SVN revision and source.
     --set-svn, -s              Set the information in svnversion.h
     --set-version, -v          Set the major, minor, and micro versions in
-                               configure.in, config.nmake, debian/changelog,
-                              and docbook/release_notes.xml.
+                               configure.ac, config.nmake, debian/changelog,
+                              and docbook/asciidoc.conf.
                                Resets the release information when used by
                               itself.
-    --set-release, -r          Set the release information in configure.in
+    --set-release, -r          Set the release information in configure.ac
                                and config.nmake
     --package-version, -p      Deprecated. Same as --set-release.
 
 Options can be used in any combination. If none are specified B<--set-svn>
 is assumed.
+
+#
+# Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+#
+# Local variables:
+# c-basic-offset: 8
+# tab-width: 8
+# indent-tabs-mode: t
+# End:
+#
+# vi: set shiftwidth=8 tabstop=8 noexpandtab:
+# :indentSize=8:tabSize=8:noTabs=false:
+#
+#