commit 7c107f7208d33678855fb5ff8197d2a085cc4617
parent 42b50c811c8ad0f6db4fca6088bc67f33cce224e
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 18 Feb 2026 10:16:48 +0100
driver/posix: Improve command line compatibility
Sadly, the world is out of any hope, and accepting to ignore flags used
by some mainstream compilers help a lot.
Diffstat:
3 files changed, 143 insertions(+), 92 deletions(-)
diff --git a/doc/man1/scc.1 b/doc/man1/scc.1
@@ -3,7 +3,7 @@
scc \- simple C compiler with magic
.SH SYNOPSIS
.B scc
-.RB [ \-cdgkqQsWw ]
+.RB [ \-cdgkqQsw ]
.RB [ \-M | \-E | \-S ]
.RB [ \-D
.IR def[=val] ] ...
@@ -15,7 +15,7 @@ scc \- simple C compiler with magic
.IR def ] ...
.RB [ \-l
.IR lib ]
-.RB [ \-m
+.RB [ \-a
.IR arch ]
.RB [ \-o
.IR outfile ]
@@ -71,7 +71,7 @@ Define a library
to resolve dependencies from. This directory is used before the standard
paths.
.TP
-.BI \-m " architecture"
+.BI \-a " architecture"
Define the
.I architecture
to compile for (i.e. amd64, i386 ...).
@@ -115,11 +115,27 @@ Undefine a previously defined
.I define
by the -D parameter.
.TP
-.B \-W
-Show warning messages.
-.TP
+.BI \-W " param"
+or
.B \-w
-Do not show warning messages (default).
+Show warning messages.
+The parameter of
+.B \-W
+is ignored for compatibility reasons.
+.TP
+.BI \-f " param"
+and
+.BI \-m " param"
+are ignored for compatibility with other compiler command lines.
+In the same way,
+the options
+.BI \-static ,
+.BI \-dynamic ,
+.BI \-pedantic ,
+.B \-ansi
+and any option beginning with
+.B \-std=
+are ignored for the same reason.
.SH ENVIRONMENT VARIABLES
Certain environment variables control the behaviour of scc.
.TP
diff --git a/src/cmd/scc-cc/posix/cc.c b/src/cmd/scc-cc/posix/cc.c
@@ -25,7 +25,6 @@
#include <stdlib.h>
#include <string.h>
-#include <scc/arg.h>
#include <scc/config.h>
#include <scc/scc.h>
#include <scc/sys.h>
@@ -60,7 +59,6 @@ static struct tool {
[LD] = {.bin = LDBIN},
};
-char *argv0;
static char *arch, *sys, *abi, *format;
static char *objfile, *outfile;
static char *prefix, *libprefix;
@@ -556,10 +554,28 @@ build(struct items *chain, int link)
static void
usage(void)
{
- fputs("usage: cc [options] file...\n", stderr);
+ fputs("usage: scc-cc [options] file...\n", stderr);
exit(1);
}
+static char *
+param(char **argp, char ***argv)
+{
+ char *s;
+
+ if ((*argp)[1] != '\0') {
+ s = (*argp) + 1;
+ *argp += strlen(*argp) - 1;
+ } else if ((*argv)[1] != NULL) {
+ s = (*argv)[1];
+ (*argv)++;
+ } else {
+ usage();
+ }
+
+ return s;
+}
+
int
main(int argc, char *argv[])
{
@@ -584,88 +600,107 @@ main(int argc, char *argv[])
if (!(libprefix = getenv("SCCLIBPREFIX")))
libprefix = LIBPREFIX;
- ARGBEGIN {
- case 'D':
- newitem(&cc1args, "-D");
- newitem(&cc1args, EARGF(usage()));
- break;
- case 'M':
- Mflag = 1;
- break;
- case 'E':
- Eflag = 1;
- break;
- case 'I':
- newitem(&cc1args, "-I");
- newitem(&cc1args, EARGF(usage()));
- break;
- case 'L':
- newitem(&linkargs, "-L");
- newitem(&linkargs, EARGF(usage()));
- break;
- case 'O':
- EARGF(usage());
- break;
- case 'S':
- Sflag = 1;
- break;
- case 'U':
- newitem(&cc1args, "-U");
- newitem(&cc1args, EARGF(usage()));
- break;
- case 'c':
- cflag = 1;
- break;
- case 'd':
- dflag = 1;
- break;
- case 'g':
- gflag = 1;
- break;
- case 'k':
- kflag = 1;
- break;
- case 'l':
- newitem(&linkchain, "-l");
- newitem(&linkchain, EARGF(usage()));
- break;
- case 'm':
- arch = EARGF(usage());
- break;
- case 'o':
- outfile = EARGF(usage());
- break;
- case 's':
- sflag = 1;
- break;
- case 't':
- sys = EARGF(usage());
- break;
- case 'w':
- Wflag = 0;
- break;
- case 'W':
- Wflag = 1;
- break;
- case 'q':
- Qflag = 0;
- break;
- case 'Q':
- Qflag = 1;
- break;
- case '-':
- fprintf(stderr,
- "scc-cc: ignored parameter --%s\n", EARGF(usage()));
- break;
- default:
- usage();
- } ARGOPERAND {
-operand:
- newitem(&linkchain, ARGOP());
- } ARGEND
+ for (++argv; *argv; ++argv) {
+ char *arg = *argv;
+ if (arg[0] == '-' && arg[1] == '-')
+ break;
+ if (arg[0] != '-') {
+ newitem(&linkchain, arg);
+ continue;
+ }
+
+ if (!strcmp(arg, "-static") ||
+ !strcmp(arg, "-dynamic") ||
+ !strcmp(arg, "-pedantic") ||
+ !strcmp(arg, "-ansi") ||
+ !strncmp(arg, "-std=", 5)) {
+ continue;
+ }
+
+ for (++arg; *arg; ++arg) {
+ switch (*arg) {
+ case 'D':
+ newitem(&cc1args, "-D");
+ newitem(&cc1args, param(&arg, &argv));
+ break;
+ case 'M':
+ Mflag = 1;
+ break;
+ case 'E':
+ Eflag = 1;
+ break;
+ case 'I':
+ newitem(&cc1args, "-I");
+ newitem(&cc1args, param(&arg, &argv));
+ break;
+ case 'L':
+ newitem(&linkargs, "-L");
+ newitem(&linkargs, param(&arg, &argv));
+ break;
+ case 'O':
+ param(&arg, &argv);
+ break;
+ case 'S':
+ Sflag = 1;
+ break;
+ case 'U':
+ newitem(&cc1args, "-U");
+ newitem(&cc1args, param(&arg, &argv));
+ break;
+ case 'c':
+ cflag = 1;
+ break;
+ case 'd':
+ dflag = 1;
+ break;
+ case 'g':
+ gflag = 1;
+ break;
+ case 'k':
+ kflag = 1;
+ break;
+ case 'l':
+ newitem(&linkchain, "-l");
+ newitem(&linkchain, param(&arg, &argv));
+ break;
+ case 'a':
+ arch = param(&arg, &argv);
+ break;
+ case 't':
+ sys = param(&arg, &argv);
+ break;
+ case 'o':
+ outfile = param(&arg, &argv);
+ break;
+ case 's':
+ sflag = 1;
+ break;
+ case 'w':
+ Wflag = 1;
+ break;
+ case 'W':
+ param(&arg, &argv);
+ Wflag = 1;
+ break;
+ case 'q':
+ Qflag = 0;
+ break;
+ case 'Q':
+ Qflag = 1;
+ break;
+ case 'm':
+ case 'f':
+ /* ignore any -f or -m option */
+ param(&arg, &argv);
+ break;
+ default:
+ usage();
+ }
+ }
+ }
- for (; *argv; --argc, ++argv)
- goto operand;
+ for (; *argv; ++argv)
+ newitem(&linkchain, *argv);
if (Eflag && linkchain.n == 0)
newitem(&linkchain, "-");
diff --git a/tests/cc/error/chktest.sh b/tests/cc/error/chktest.sh
@@ -13,7 +13,7 @@ do
echo $i >> test.log
state=${state:-""}
- (SCCPREFIX=$SCCPREFIX $CC $CFLAGS -W -c $i) 2> $err
+ (SCCPREFIX=$SCCPREFIX $CC $CFLAGS -w -c $i) 2> $err
(echo "/^PATTERN/+;/^\./-w $chk" | ed -s $i) >/dev/null 2>&1
(diff -u $chk $err >> test.log && printf '[PASS]' || printf '[FAIL]'
printf "\t%s\t%s\n" $i $state) | tee -a test.log