]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - make/common.pm
Bump the API revision for the previous commit.
[user/henk/code/inspircd.git] / make / common.pm
index d5a2f06c73c0cb8537fb03a910875d840efe0f7c..ba6b03f87d4472d19640e98021c0f3114578cd38 100644 (file)
@@ -31,11 +31,13 @@ use Exporter              qw(import);
 use File::Path            qw(mkpath);
 use File::Spec::Functions qw(rel2abs);
 
+use make::console;
+
 our @EXPORT = qw(create_directory
                  get_cpu_count
                  get_version
                  read_config_file
-                 module_installed);
+                 write_config_file);
 
 sub create_directory($$) {
        my ($location, $permissions) = @_;
@@ -57,7 +59,7 @@ sub get_version {
 
        # Attempt to retrieve missing version information from Git
        chomp(my $gr = `git describe --tags 2>/dev/null`);
-       if ($gr =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\d+-g(\w+))?$/) {
+       if ($gr =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:[a-z]+\d+)?(?:-\d+-g(\w+))?$/) {
                $version{MAJOR} //= $1;
                $version{MINOR} //= $2;
                $version{PATCH} //= $3;
@@ -87,12 +89,6 @@ sub get_version {
        return %version;
 }
 
-sub module_installed($) {
-       my $module = shift;
-       eval("use $module;");
-       return !$@;
-}
-
 sub get_cpu_count {
        my $count = 1;
        if ($^O =~ /bsd/) {
@@ -121,4 +117,15 @@ sub read_config_file($) {
        return %config;
 }
 
+sub write_config_file($%) {
+       my $path = shift;
+       my %config = @_;
+       open(my $fh, '>', $path) or print_error "unable to write to $path: $!";
+       while (my ($key, $value) = each %config) {
+               $value //= '';
+               say $fh "$key $value";
+       }
+       close $fh;
+}
+
 1;