scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 2b9bf4f09bb45f5e12ed6ac5d993e65a62880378
parent c4f9f4dce1736727f2cee789c95ea2d3b9b5a5ec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 28 Oct 2024 21:08:16 +0100

make: Avoid leading spaces in MAKEFLAGS

Write spaces only when it is required because there is
something in the current value of MAKEFLAGS.

Diffstat:
Msrc/cmd/scc-make/main.c | 7++++---
Mtests/make/execute/0012-nflag.sh | 6+++---
Mtests/make/execute/0013-nflag.sh | 6+++---
3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/cmd/scc-make/main.c b/src/cmd/scc-make/main.c @@ -127,13 +127,14 @@ static void appendmakeflags(char *text) { int n; - char *s, *t; + char *s, *t, *fmt; s = getmacro("MAKEFLAGS"); - n = snprintf(NULL, 0, "%s %s", s, text); + fmt = *s ? "%s %s" : "%s%s"; + n = snprintf(NULL, 0, fmt, s, text); t = emalloc(n+1); - snprintf(t, n+1, "%s %s", s, text); + snprintf(t, n+1, fmt, s, text); setmacro("MAKEFLAGS", t, EXPORT); free(t); diff --git a/tests/make/execute/0012-nflag.sh b/tests/make/execute/0012-nflag.sh @@ -6,13 +6,13 @@ tmp1=tmp1.$$ tmp2=tmp2.$$ cat <<EOF > $tmp2 -echo -n +echo -n no-valid-program -corret +correct EOF (set -e scc-make -f test.mk -n print-makeflags error - echo corret) > $tmp1 2>&1 + echo correct) > $tmp1 2>&1 diff $tmp1 $tmp2 diff --git a/tests/make/execute/0013-nflag.sh b/tests/make/execute/0013-nflag.sh @@ -6,13 +6,13 @@ tmp1=tmp1.$$ tmp2=tmp2.$$ cat <<EOF > $tmp2 -echo -n +echo -n no-valid-program -corret +correct EOF (set -e MAKEFLAGS=-n scc-make -f test.mk print-makeflags error - echo corret) > $tmp1 2>&1 + echo correct) > $tmp1 2>&1 diff $tmp1 $tmp2