ref: 50502b531fdc5fdfa39c5fe55ebdb69c942075b8
parent: 1db863722e91ee927e932eb6ba65637842e96098
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Oct 6 17:42:56 EDT 2019
[cc] Add meta characters in path definitions These meta characters help to use paths that depend of the current configuration of the driver. With these new definitions SCCPREFIX or different architectures are supported.
--- a/include/scc/scc/Makefile
+++ b/include/scc/scc/Makefile
@@ -3,11 +3,12 @@
PROJECTDIR = ../../..
include $(PROJECTDIR)/scripts/rules.mk
-SYSHDR = ldflags.h\
- syscrts.h\
- sysincludes.h\
- syslibs.h \
- cstd.h \
+SYSHDR =\
+ ldflags.h\
+ syscrts.h\
+ sysincludes.h\
+ syslibs.h\
+ cstd.h\
all: $(SYSHDR)
@@ -15,28 +16,16 @@
cp cstd-$(STD).h $@
ldflags.h:
- rm -f $@ ; \
- trap "rm -f $$$$.h" 0 2 3; \
- cat < ldflags.def.h > $$$$.h; \
- mv $$$$.h $@
+ cp ldflags.def.h $@
syscrts.h:
- rm -f $@ ; \
- trap "rm -f $$$$.h" 0 2 3; \
- sed 's,PREFIX,"$(PREFIX)",g' < syscrts.def.h > $$$$.h && \
- mv $$$$.h $@
+ cp syscrts.def.h $@
sysincludes.h:
- rm -f $@ ; \
- trap "rm -f $$$$.h" 0 2 3; \
- sed 's,PREFIX,"$(PREFIX)",g' < sysincludes.def.h > $$$$.h && \
- mv $$$$.h $@
+ cp sysincludes.def.h $@
syslibs.h:
- rm -f $@ ; \
- trap "rm -f $$$$.h" 0 2 3; \
- sed 's,PREFIX,"$(PREFIX)",g' < syslibs.def.h > $$$$.h && \
- mv $$$$.h $@
+ cp syslibs.def.h $@
distclean:
rm -f $(SYSHDR)
--- a/include/scc/scc/syscrts.def.h
+++ b/include/scc/scc/syscrts.def.h
@@ -1,5 +1,4 @@
+/* configure below your system crts */
char *syscrts[] = {
- /* configure below your system crts */
- /* PREFIX "/lib/scc/crt.o", */
NULL
};
--- a/include/scc/scc/sysincludes.def.h
+++ b/include/scc/scc/sysincludes.def.h
@@ -1,8 +1,6 @@
+/* configure below your standard sys include paths */
char *sysincludes[] = {
- PREFIX "/include/scc/" ,
- PREFIX "/include/scc/bits/" ARCH "-" ABI "/",
- /* configure below your standard sys include paths */
- PREFIX "/include/",
- PREFIX "/local/include/",
+ "%p/include/scc/",
+ "%p/include/scc/bits/%a-%s",
NULL
};
--- a/include/scc/scc/syslibs.def.h
+++ b/include/scc/scc/syslibs.def.h
@@ -1,9 +1,5 @@
-#define MAX_LIB_PATHS 32
-
-char *syslibs[MAX_LIB_PATHS + 1] = {
- PREFIX "/lib/scc/" ,
- /* configure below your standard sys include paths */
- PREFIX "/lib/",
- PREFIX "/local/lib/",
+/* configure below your standard sys include paths */
+char *syslibs[] = {
+ "%p/lib/scc/%a-%s",
NULL
};
--- a/src/cmd/cc/posix/Makefile
+++ b/src/cmd/cc/posix/Makefile
@@ -6,10 +6,11 @@
# SYSLST is a list of backend-arch-abi-sys. First
# element of the list becomes the default target
-SYSLST = amd64-sysv-linux-elf z80-scc-none-none \
- i386-sysv-linux-elf amd64-sysv-openbsd-elf
-
-STDCFLAGS =
+SYSLST =\
+ amd64-sysv-linux-elf\
+ z80-scc-none-none\
+ i386-sysv-linux-elf\
+ amd64-sysv-openbsd-elf\
TARGETS = $(BINDIR)/scc $(BINDIR)/scpp
--- a/src/cmd/cc/posix/scc.c
+++ b/src/cmd/cc/posix/scc.c
@@ -76,6 +76,50 @@
}
}
+static char *
+path(char *s)
+{
+ char *arg, buff[FILENAME_MAX];
+ size_t len, cnt;
+
+ for ( ; *s && cnt < FILENAME_MAX; ++s) {
+ if (*s != '%') {
+ buff[cnt++] = *s;
+ continue;
+ }
+
+ switch (*++s) {
+ case 'a':
+ arg = arch;
+ break;
+ case 's':
+ arg = sys;
+ break;
+ case 'p':
+ arg = prefix;
+ break;
+ case 'b':
+ arg = abi;
+ break;
+ default:
+ buff[cnt++] = *s;
+ continue;
+ }
+
+ len = strlen(arg);
+ if (len + cnt >= FILENAME_MAX)
+ goto too_long;
+ memcpy(buff+cnt, arg, len);
+ cnt += len;
+ }
+
+ if (cnt != FILENAME_MAX)
+ return xstrdup(buff);
+
+too_long:
+ die("scc: too long pathname");
+}
+
static void
addarg(int tool, char *arg)
{
@@ -124,7 +168,7 @@
addarg(tool, "-w");
for (n = 0; sysincludes[n]; ++n) {
addarg(tool, "-I");
- addarg(tool, sysincludes[n]);
+ addarg(tool, path(sysincludes[n]));
}
case CC2:
fmt = (qbe(tool)) ? "%s-qbe_%s-%s" : "%s-%s-%s";
@@ -145,13 +189,10 @@
addarg(tool, t->outfile);
for (n = 0; syslibs[n]; ++n) {
addarg(tool, "-L");
- addarg(tool, syslibs[n]);
+ addarg(tool, path(syslibs[n]));
}
- if (syscrts[0]) {
- for (n = 0; syscrts[n]; ++n)
- addarg(tool, syscrts[n]);
- break;
- }
+ for (n = 0; syscrts[n]; ++n)
+ addarg(tool, path(syscrts[n]));
break;
case AS:
addarg(tool, "-o");
--- a/src/cmd/ld/deps.mk
+++ b/src/cmd/ld/deps.mk
@@ -1,5 +1,4 @@
#deps
-./main.o: $(INCDIR)/scc/scc/syslibs.h
./main.o: ./ld.h
./pass1.o: $(INCDIR)/scc/scc/ar.h
./pass1.o: $(INCDIR)/scc/scc/mach.h
--- a/src/cmd/ld/ld.h
+++ b/src/cmd/ld/ld.h
@@ -25,6 +25,7 @@
extern void debugsec(void);
/* globals */
+extern char *libpaths[];
extern char *filename, *membname;
extern int sflag;
extern int xflag;
--- a/src/cmd/ld/main.c
+++ b/src/cmd/ld/main.c
@@ -5,10 +5,11 @@
#include <string.h>
#include <scc/mach.h>
-#include <scc/syslibs.h>
#include "ld.h"
+#define MAX_LIB_PATHS 12
+
int sflag; /* discard all the symbols */
int xflag; /* discard local symbols */
int Xflag; /* discard locals starting with 'L' */
@@ -26,6 +27,8 @@
Segment bss = {.type = 'B'};
Segment debug = {.type = 'N'};
+char *libpaths[MAX_LIB_PATHS];
+
char *output = "a.out", *entry = "start";
static int status;
@@ -83,8 +86,8 @@
{
char **bp, **end;
- end = &syslibs[MAX_LIB_PATHS];
- for (bp = syslibs; bp < end && *bp; ++bp)
+ end = &libpaths[MAX_LIB_PATHS];
+ for (bp = libpaths; bp < end && *bp; ++bp)
;
if (bp == end) {
fputs("ld: too many -L options\n", stderr);
--- a/src/cmd/ld/pass1.c
+++ b/src/cmd/ld/pass1.c
@@ -214,7 +214,6 @@
char **bp;
char libname[FILENAME_MAX];
static char buffer[FILENAME_MAX];
- extern char *syslibs[];
filename = name;
membname = NULL;
@@ -235,7 +234,7 @@
if ((fp = fopen(buffer, "rb")) != NULL)
return fp;
- for (bp = syslibs; *bp; ++bp) {
+ for (bp = libpaths; *bp; ++bp) {
pathlen = strlen(*bp);
if (pathlen + len > FILENAME_MAX-1)
continue;