scc

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

commit ac449d18a971e3e452e3f47cbd2af90b6a55ea18
parent 30255fb57a7b5abf021e417aa34f380ae92bdbbe
Author: Z. Gilboa <writeonce@midipix.org>
Date:   Fri, 13 Jun 2025 20:31:14 +0000

scc-make: parseargv(): properly handle the -- argument, add test.

Diffstat:
MLICENSE | 1+
Msrc/cmd/scc-make/main.c | 9+++++++--
Atests/make/execute/0108-lastopt.sh | 30++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -27,6 +27,7 @@ ISC License (c) 2015 Sören Tempel <soeren+git@soeren-tempel.net> (c) 2022 Xavier Del Campo Romero <xavi.dcr@tutanota.com> (c) 2018-2021 zerous Naveen Narayanan <zerous@nocebo.space> +(c) 2025 Z. Gilboa <writeonce@midipix.org> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/cmd/scc-make/main.c b/src/cmd/scc-make/main.c @@ -228,15 +228,20 @@ static void parseargv(char **argv, char ***targets, int where, int export) { char *s; + char *hm = NULL; for ( ; *argv; ++argv) { s = *argv; - if (s[0] != '-') { + if (hm == NULL && strcmp(s, "--") == 0) { + hm = *argv; + } else if (hm && s[0] == '-') { + break; + } else if (s[0] != '-') { if (!assign(s, where, export)) break; continue; } - while (*++s) + while (hm == NULL && *++s) parseflag(*s, &s, &argv); } diff --git a/tests/make/execute/0108-lastopt.sh b/tests/make/execute/0108-lastopt.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +trap 'rm -f $tmp1 $tmp2' EXIT INT QUIT TERM HUP + +tmp1=tmp1.$$ +tmp2=tmp2.$$ + +cat > $tmp1 <<EOF +hyphen-target +MYVAR is -42 +MYVAR is myval +EOF + +(scc make -f- -- -42 <<'EOF' +-42: + @echo 'hyphen-target' +EOF + +scc make -f- -- MYVAR=-42 <<'EOF' +all: + @@echo MYVAR is $(MYVAR) +EOF + +scc make -f- -- MYVAR=myval -42 <<'EOF' +-42: + @echo MYVAR is $(MYVAR) +EOF +) > $tmp2 + +diff $tmp1 $tmp2