chiark / gitweb /
Syntax: Line joining with &\
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 18 Dec 2019 21:44:15 +0000 (21:44 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 29 Dec 2019 16:04:44 +0000 (16:04 +0000)
make has a weird rule for line joining in recipes, where the \ is
retained.  This is very annoying espcially when writing little scripts
in other languages in recipes.  The GNU make documentation suggests
using a `define' block, in which the \ are still necessary, but
vanish.  But that separates out the recipe from the rule, and also
demands that the recipe text be given a name.

(Note that .ONESHELL offers an alternative but sadly is not available
on a per-rule basis.  This is even less sensible with non-recursive
make, where you might want different directories to have different
settings.)

So, provide &\ which does the other thing, swallowing the newline and
discarding the &\, even in rules.

Add a test case too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
generate
tests/filter/sub/dir/Subdir.mk.expected
tests/filter/sub/dir/Subdir.sd.mk

diff --git a/README b/README
index fd10056368dfdf7d5679b8440c64d2649cb46395..6d9091b75fe31b036178cce35f5ede9abc7ae249 100644 (file)
--- a/README
+++ b/README
@@ -250,6 +250,7 @@ So pathname syntax is a subset of:
 
 &\&            =>      &               general escaping mechanism
 &\$            =>      $
 
 &\&            =>      &               general escaping mechanism
 &\$            =>      $
+&\NEWLINE                              eats the newline and vanishes
 
 &$VARIABLE     =>      $(sub_dir_VARIABLE)     or $(TOP_VARIABLE)
        VARIABLE is ASCII starting with a letter and matching \w+
 
 &$VARIABLE     =>      $(sub_dir_VARIABLE)     or $(TOP_VARIABLE)
        VARIABLE is ASCII starting with a letter and matching \w+
index e853912d622f0a6aebd007179f3ddaaf36b72692..747bb0cb002d70ee3c7e3635db0504bdc15ea389 100755 (executable)
--- a/generate
+++ b/generate
@@ -165,6 +165,7 @@ sub process_input_mk ($$$$$$$$$) {
            o $1;
            if (s{^\\$esc}{}) { o "$$esclitr" }
            elsif (s{^\\\$}{}) { o '$' }
            o $1;
            if (s{^\\$esc}{}) { o "$$esclitr" }
            elsif (s{^\\\$}{}) { o '$' }
+           elsif (s{^\\\s+$}{}) { }
            elsif (s{^$esc}{}) { o "$$esclitr$$esclitr" }
            elsif (m{^(?=$caps_re)}) { o $var_prefix }
            elsif (s{^\$([A-Za-z]\w+)}{}) { o "\$(${var_prefix}$1)" }
            elsif (s{^$esc}{}) { o "$$esclitr$$esclitr" }
            elsif (m{^(?=$caps_re)}) { o $var_prefix }
            elsif (s{^\$([A-Za-z]\w+)}{}) { o "\$(${var_prefix}$1)" }
index a524ea28fa111595164bb5a44db97108397b5c2b..fbf813f908e261d9a56c4c9120fd12730cb41f39 100644 (file)
@@ -7,6 +7,8 @@ sub/dir/
 sub_dir_TARGETS_sometarget1
 sub_dir_TARGETS_sometarget2
 
 sub_dir_TARGETS_sometarget1
 sub_dir_TARGETS_sometarget2
 
+line joining
+
 # doctests:
 
 sub/dir/all:: $(sub_dir_TARGETS)
 # doctests:
 
 sub/dir/all:: $(sub_dir_TARGETS)
index f2bfa20a837252c3e3ff03b8b59753fa26331bc1..0cba54a517518b95877fae750b8b9ae4d676b592 100644 (file)
@@ -7,5 +7,8 @@
 &TARGETS_sometarget1
 &TARGETS_sometarget2
 
 &TARGETS_sometarget1
 &TARGETS_sometarget2
 
+line &\
+joining
+
 # doctests:
 &:include &doctest.sd.mk
 # doctests:
 &:include &doctest.sd.mk