Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] handle variables in make targets



Here's a patch that adds simple variable handling to the useperl side of
the _make completer.  For instance, I have some targets that look like
this:

rsync$(EXEEXT): $(OBJS)

With the current script, this puts the literal string "rsync$(EXEEXT)"
into the edit buffer, which is not good because EXEEXT isn't defined in
the environment (just in the Makefile).  This patch tries to handle both
delayed expansion (=) and immediate expansion (:=) syntax, but does not
deal with variable references that don't use () or {}.

Comments?

..wayne..
--- _make	18 Aug 2004 20:30:27 -0000	1.7
+++ _make	18 Aug 2004 22:43:50 -0000
@@ -34,12 +34,19 @@ else
        tmp=( $(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null | $cmdargs) )
     elif [[ -n $useperl ]]; then
       tmp=(
-      $(perl -ne '@matches = /^(?:([a-zA-Z0-9]+[^\/\t=\s]+)\s*)+:(?:[^=]|$)/  and
-	print join(" ", @matches), "\n";
-if (/^\.include\s+\<bsd\.port\.(subdir\.|pre\.)?mk>/ ||
+      $(perl -ne '
+if (($var, $colon, $val) = /^([a-zA-Z0-9]+[^\/\t:=\s]+)\s*(:)?=\s*(.*?)\s*$/) {
+    1 while ($colon && $val =~ s/\$[({]([^})]+)[})]/$ENV{$1}/);
+    $ENV{$var} = $val;
+} elsif (@matches = /^(?:([a-zA-Z0-9]+[^\/\t=\s]+)\s*)+:(?:[^=]|$)/) {
+    foreach (@matches) {
+        1 while (s/\$[({]([^})]+)[})]/$ENV{$1}/);
+        print $_, "\n";
+    }
+} elsif (/^\.include\s+\<bsd\.port\.(subdir\.|pre\.)?mk>/ ||
     /^\.include\s+\".*mk\/bsd\.pkg\.(subdir\.)?mk\"/) {
     print "fetch fetch-list extract patch configure build install reinstall deinstall package describe checkpatch checksum makesum\n";
-    }
+}
 ' $file)
 	)
     else


Messages sorted by: Reverse Date, Date, Thread, Author