]> git.donarmstrong.com Git - debhelper.git/commitdiff
Smart debian/rules parser for dh.
authorModestas Vainius <modestas@vainius.eu>
Mon, 16 Feb 2009 22:56:04 +0000 (00:56 +0200)
committerJoey Hess <joey@gnu.kitenet.net>
Fri, 27 Feb 2009 20:11:43 +0000 (15:11 -0500)
This parser is based on the output which make -p emits. It's a bit
more slower due to the need to run make itself but it is not dumb.

Signed-off-by: Modestas Vainius <modestas@vainius.eu>
(cherry picked from commit 3d774a91dd355f8236c63bd81fc4dfe5fa88219d)

dh

diff --git a/dh b/dh
index d0165c9969394d4e2e65d9d9204eb1c00f009fd9..e3a5943e959c36802e279789b7bcc52c8e986c24 100755 (executable)
--- a/dh
+++ b/dh
@@ -494,17 +494,33 @@ my $rules_parsed;
 sub rules_explicit_target {
        # Checks if a specified target exists as an explicit target
        # in debian/rules. 
-       # Currently this is accomplished via a stupid makefile parser.
        my $target=shift;
+       my $processing_targets = 0;
+       my $not_a_target = 0;
        
        if (! $rules_parsed) {  
-               open(IN, "<debian/rules") || warning("dh cannot read debian/rules: $!");
-               while (<IN>) {
-                       if (/^([a-zA-Z_]+):/) {
-                               $targets{$1}=1;
+               open(MAKE, "make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null |");
+               while (<MAKE>) {
+                       if ($processing_targets) {
+                               if (/^# Not a target:/) {
+                                       $not_a_target = 1;
+                               } else {
+                                       if (!$not_a_target && /^([^#:]+)::?/ && !exists $targets{$1}) {
+                                               # Target is defined.
+                                               # NOTE: if it is a depenency of .PHONY it will be
+                                               # defined too but that's ok.
+                                               $targets{$1} = 1;
+                                       }
+                                       # "Not a target:" is always followed by a target name,
+                                       # so resetting this one here is safe.
+                                       $not_a_target = 0;
+                               }
+                       } elsif (/^# Files$/) {
+                               $processing_targets = 1;
                        }
                }
-               close IN;
+               close MAKE;
+               $rules_parsed = 1;
        }
 
        return exists $targets{$target};