commit 6035e8511b69b44b65eb8771c3dd84ed21e50cb3
parent 527601ad4c29e586f0ce307353583c5c09f3c321
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 11 Feb 2024 11:57:55 +0100
as: Add driver command
The different as libexecs are designed to be used with a driver
that selects the correct executable to be used for every
architecture.
Diffstat:
5 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/scripts/proto.all b/scripts/proto.all
@@ -3,6 +3,7 @@ f 755 bin/gcc-scc
f 755 bin/scc
f 755 bin/scc-addr2line
f 755 bin/scc-ar
+f 755 bin/scc-as
f 755 bin/scc-cc
f 755 bin/scc-cpp
f 755 bin/scc-ld
diff --git a/scripts/rules.mk b/scripts/rules.mk
@@ -122,6 +122,9 @@ $(DIRS) DUMMY : FORCE
.pdf .ps .eps .puml\
.ms .1 .2 .3 .4 .5 .6 .7\
+.c:
+ $(CC) $(PROJ_CPPFLAGS) $(PROJ_CFLAGS) -o $@ $<
+
.s.o:
$(AS) $(PROJ_ASFLAGS) $< -o $@
diff --git a/src/cmd/as/.gitignore b/src/cmd/as/.gitignore
@@ -1 +1,2 @@
lexh
+as
diff --git a/src/cmd/as/Makefile b/src/cmd/as/Makefile
@@ -13,6 +13,7 @@ OBJS = \
expr.o\
TARGET =\
+ $(BINDIR)/scc-as\
$(LIBEXEC)/scc/as-powerpc64\
$(LIBEXEC)/scc/as-powerpc\
$(LIBEXEC)/scc/as-amd64\
@@ -24,8 +25,8 @@ all: $(TARGET)
$(TARGET): $(LIBSCC)
-clean:
- rm -f target/*/*.o target/*/*tbl.c lexh
+$(BINDIR)/scc-as: as
+ cp as $@
genhash.o: ../../libscc/genhash.c
$(HOSTCC) -c ../../libscc/genhash.c
@@ -36,6 +37,10 @@ lexh.o: lexh.c
lexh: lexh.o genhash.o
$(HOSTCC) -o $@ lexh.o genhash.o
+clean:
+ rm -f target/*/*.o target/*/*tbl.c lexh
+ rm -f as
+
include target/powerpc/powerpc64.mk
include target/powerpc/powerpc.mk
include target/x86/amd64.mk
diff --git a/src/cmd/as/as.c b/src/cmd/as/as.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <scc/arg.h>
+#include <scc/config.h>
+#include <scc/scc.h>
+
+#define MAXCMD 400
+
+char *argv0;
+
+static char *arch, *format, *prefix, *outfile;
+static int debug;
+
+static void
+usage(void)
+{
+ fputs("usage: as [-o outfile][-m arch][-f format] file ...\n",
+ stderr);
+ exit(EXIT_FAILURE);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int cnt, len, rem, r;
+ char cmd[MAXCMD];
+
+ if (!(arch = getenv("ARCH")))
+ arch = ARCH;
+ if (!(format = getenv("FORMAT")))
+ format = FORMAT;
+ if (!(prefix = getenv("SCCPREFIX")))
+ prefix = PREFIX;
+
+ ARGBEGIN {
+ case 'o':
+ outfile = EARGF(usage());
+ break;
+ case 'm':
+ arch = EARGF(usage());
+ break;
+ case 'f':
+ format = EARGF(usage());
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ } ARGEND
+
+ if (argc < 1)
+ usage();
+
+ r = snprintf(cmd, sizeof(cmd), "%s/libexec/scc/as-%s", prefix, arch);
+ if (r < 0 || r >= sizeof(cmd))
+ goto toolong;
+
+ cnt = r;
+ rem = sizeof(cmd) - cnt;
+ if (outfile) {
+ r = snprintf(cmd + cnt, rem, " -o %s", outfile);
+ if (r < 0 || r >= rem)
+ goto toolong;
+ rem -= r;
+ cnt += r;
+ }
+
+ for ( ; *argv; ++argv) {
+ r = snprintf(cmd + cnt, rem, " %s", *argv);
+ if (r < 0 || r >= rem)
+ goto toolong;
+ rem -= r;
+ cnt += r;
+ }
+
+ if (debug)
+ fprintf(stderr, "as: command line '%s'\n", cmd);
+
+ r = system(cmd);
+ if (r == 0)
+ return 0;
+ if (r < 0)
+ perror("as");
+ exit(EXIT_FAILURE);
+
+toolong:
+ fputs("as: too long command line\n", stderr);
+ exit(EXIT_FAILURE);
+}