]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Lib.pm
Adjust code to add deprecation warning for compatability level 4. (Man page already...
[debhelper.git] / Debian / Debhelper / Dh_Lib.pm
index 2d1934be4dc04b850496f029b85d0a47a20a59f2..960f2721e6444a2fc619bb402a524de2d536ca35 100644 (file)
@@ -16,7 +16,8 @@ use vars qw(@ISA @EXPORT %dh);
            &compat &addsubstvar &delsubstvar &excludefile &package_arch
            &is_udeb &udeb_filename &debhelper_script_subst &escape_shell
            &inhibit_log &load_log &write_log &dpkg_architecture_value
-           &sourcepackage);
+           &sourcepackage
+           &is_make_jobserver_unavailable &clean_jobserver_makeflags);
 
 my $max_compat=7;
 
@@ -312,7 +313,7 @@ sub dirname {
                        }
                }
 
-               if ($c < 4 && ! $warned_compat) {
+               if ($c <= 4 && ! $warned_compat) {
                        warning("Compatibility levels before 5 are deprecated.");
                        $warned_compat=1;
                }
@@ -794,4 +795,32 @@ sub debhelper_script_subst {
        }
 }
 
+# Checks if make's jobserver is enabled via MAKEFLAGS, but
+# the FD used to communicate with it is actually not available.
+sub is_make_jobserver_unavailable {
+       if (exists $ENV{MAKEFLAGS} && 
+           $ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+               if (!open(my $in, "<&$1")) {
+                       return 1; # unavailable
+               }
+               else {
+                       close $in;
+                       return 0; # available
+               }
+       }
+
+       return; # no jobserver specified
+}
+
+# Cleans out jobserver options from MAKEFLAGS.
+sub clean_jobserver_makeflags {
+       if (exists $ENV{MAKEFLAGS}) {
+               if ($ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+                       $ENV{MAKEFLAGS} =~ s/(?:^|\s)--jobserver-fds=\S+//g;
+                       $ENV{MAKEFLAGS} =~ s/(?:^|\s)-j\b//g;
+               }
+               delete $ENV{MAKEFLAGS} if $ENV{MAKEFLAGS} =~ /^\s*$/;
+       }
+}
+
 1