-# calculate build number
-$build += $main::version;
-$build = "$build.$branch" if $branch;
+# try to load the database
+if (DXSql::init($dsn)) {
+ $dbh = DXSql->new($dsn);
+ $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh;
+}
+
+# try to load Encode and Git
+{
+ local $^W = 0;
+ my $w = $SIG{__DIE__};
+ $SIG{__DIE__} = 'IGNORE';
+ eval { require Encode; };
+ unless ($@) {
+ import Encode;
+ $can_encode = 1;
+ }
+ eval { require Git; };
+ unless ($@) {
+ import Git;
+
+ # determine the real version number
+ $gitbranch = 'none';
+ $gitversion = 'none';
+ my $repo = Git->repository(Directory => "$root/.git");
+ if ($repo) {
+ my $desc = $repo->command_oneline(['describe'], STDERR => 0);
+ if ($desc) {
+ my ($v, $s, $b, $g) = $desc =~ /^([\d.]+)(?:\.(\d+))?-(\d+)-g([0-9a-f]+)/;
+ $version = $v;
+ $subversion = $s || 0;
+ $build = $b || 0;
+ $gitversion = "$g\[r]";
+ }
+ }
+ my @branch = $repo->command([qw{branch}], STDERR=>0);
+ for (@branch) {
+ my ($star, $b) = split /\s+/;
+ if ($star eq '*') {
+ $gitbranch = $b;
+ last;
+ }
+ }
+
+ }
+ $SIG{__DIE__} = $w;
+}