shithub: mc

Download patch

ref: deb278d26087e1393e1ef1f9bfe0592b4df16298
parent: 040b2c92820949d286a8c94b7dcb8965523549e8
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Sep 28 09:56:54 EDT 2012

use 'myrbuild' to build the standard Myrddin library.

--- a/configure
+++ b/configure
@@ -33,16 +33,18 @@
 OS=`uname`
 
 echo export INST_ROOT=$prefix > config.mk
-echo '#define Instroot "'$prefix'"' > config.h
 
+echo '#define Instroot "'$prefix'"' > config.h
 case $OS in
     *Linux*)
         echo '#define Asmcmd "as -g -o %s %s"' >> config.h
         echo '#define Fprefix ""' >> config.h
+        echo 'export SYS=linux' >> config.mk
         ;;
     *Darwin*)
         echo '#define Asmcmd "as -g -o %s %s"' >> config.h
         echo '#define Fprefix "_"' >> config.h
+        echo 'export SYS=osx' >> config.mk
         ;;
     *)
         echo 'Unknown architecture. Assuming Linux ABI.'
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -1,12 +1,46 @@
+MYRLIB=std
+MYRSRC= \
+    alloc.myr \
+    chartype.myr \
+    die.myr \
+    fmt.myr \
+    rand.myr \
+    sys.myr \
+    types.myr \
+    utf.myr \
+    varargs.myr \
+
+ASMSRC= \
+    start.s \
+    syscall.s
+
 include ../config.mk
 
-all: libstd.a
+all: $(MYRLIB) $(MYRBIN)
 
-libstd.a:
-	./bld.sh
+sys.myr: sys-$(SYS).myr
+	cp sys-$(SYS).myr sys.myr
+
+syscall.s: syscall-$(SYS).s
+	cp syscall-$(SYS).s syscall.s
+
+start.s: start-$(SYS).s
+	cp start-$(SYS).s start.s
+
+
+$(MYRLIB): $(MYRSRC) $(ASMSRC)
+	../myrbuild/myrbuild -C../6/6m -M../muse/muse -l $(MYRLIB) $^
+
+OBJ=$(MYRSRC:.myr=.o) $(ASMSRC:.s=.o)
+JUNKASM=$(MYRSRC:.myr=.s)
+USE=$(MYRSRC:.myr=.use) $(MYRLIB)
 .PHONY: clean
 clean:
-	./bld.sh clean
+	rm -f $(OBJ)
+	rm -f $(USE)
+	rm -f $(JUNKASM)
+	rm -f lib$(MYRLIB).a
+
 
 install:
 	mkdir -p  $(INST_ROOT)/myr/lib/
--- a/libstd/bld.sh
+++ /dev/null
@@ -1,76 +1,0 @@
-#!/bin/bash
-
-# We have no dependency handling yet, so this is done via
-# a shell script. Also, we want to rebuild everything for
-# testing purposes on every run as things stand.
-
-export PATH=.:$PATH
-export MC=../6/6m
-export MU=../muse/muse
-export AS=as
-export LD=ld
-export ASOPT="-g"
-case `uname` in
-    Darwin) export SYS=osx;;
-    Linux) export SYS=linux;;
-esac
-
-function use {
-    for i in $@; do
-        N=`basename $i .myr`
-        N=${N%%-$SYS}
-
-        echo $MU -o $N.use $i && \
-        $MU -o $N.use $i
-    done
-}
-
-function build {
-    for i in $@; do
-        echo $MC $i
-        $MC -I. $i
-    done
-}
-
-function assem {
-    for i in $@; do
-        N=`basename $i .s`
-
-        echo $AS  -o $N.o $ASOPT $i
-        $AS -o $N.o $ASOPT $i
-    done
-}
-
-# Library source.
-ASM="syscall-$SYS.s start-$SYS.s"
-MYR="types.myr \
-    sys-$SYS.myr \
-    die.myr \
-    varargs.myr \
-    alloc.myr\
-    utf.myr \
-    fmt.myr \
-    rand.myr \
-    chartype.myr"
-
-OBJ="$(echo $ASM | sed 's/\.s/.o /g') $(echo $MYR | sed 's/\.myr/.o /g')"
-USE="$(echo $MYR | sed 's/\.myr/.use /g' | sed "s/-$SYS//g")"
-if [ "$1" = "clean" ]; then
-    echo rm -f $OBJ test libstd.a
-    rm -f $OBJ $USE test libstd.a
-else
-    assem $ASM
-    use $MYR
-    build $MYR
-
-    echo $MU -mo std $USE
-    $MU -mo std $USE
-    echo ar -rcs libstd.a $OBJ
-    ar -rcs libstd.a $OBJ
-
-    # build test program
-    build test.myr
-    COMP="$LD -o test test.o -L. -lstd"
-    echo $COMP
-    $COMP
-fi
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -20,6 +20,12 @@
 Node *file;
 char *filename;
 
+/* binaries we call out to */
+char *mc = "6m";
+char *as = "as";
+char *ar = "ar";
+char *ld = "ld";
+char *muse = "muse";
 /* the name of the output file */
 char *libname;
 char *binname;
@@ -171,13 +177,13 @@
         }
         swapsuffix(buf, sizeof buf, file, ".myr", ".use");
         if (isfresh(file, buf)) {
-            gencmd(&cmd, &ncmd, "muse", file, NULL, 0);
+            gencmd(&cmd, &ncmd, muse, file, NULL, 0);
             run(cmd);
         }
 
         swapsuffix(buf, sizeof buf, file, ".myr", ".o");
         if (isfresh(file, buf)) {
-            gencmd(&cmd, &ncmd, "6m", file, NULL, 0);
+            gencmd(&cmd, &ncmd, mc, file, NULL, 0);
             run(cmd);
         }
     } else if (hassuffix(file, ".s")) {
@@ -184,7 +190,7 @@
         swapsuffix(buf, sizeof buf, file, ".s", ".o");
         if (isfresh(file, buf)) {
             extra[1] = buf;
-            gencmd(&cmd, &ncmd, "as", file, extra, 2);
+            gencmd(&cmd, &ncmd, as, file, extra, 2);
             run(cmd);
         }
     }
@@ -198,7 +204,7 @@
 
     args = NULL;
     nargs = 0;
-    lappend(&args, &nargs, strdup("muse"));
+    lappend(&args, &nargs, strdup(muse));
     lappend(&args, &nargs, strdup("-mo"));
     lappend(&args, &nargs, strdup(libname));
     for (i = 0; i < nfiles; i++) {
@@ -228,7 +234,7 @@
     args = NULL;
     nargs = 0;
     snprintf(buf, sizeof buf, "lib%s.a", libname);
-    lappend(&args, &nargs, strdup("ar"));
+    lappend(&args, &nargs, strdup(ar));
     lappend(&args, &nargs, strdup("-rcs"));
     lappend(&args, &nargs, strdup(buf));
     for (i = 0; i < nfiles; i++) {
@@ -260,7 +266,7 @@
 
     args = NULL;
     nargs = 0;
-    lappend(&args, &nargs, strdup("ld"));
+    lappend(&args, &nargs, strdup(ld));
     lappend(&args, &nargs, strdup("-o"));
     lappend(&args, &nargs, strdup(binname));
     for (i = 0; i < nfiles; i++) {
@@ -297,15 +303,16 @@
     int opt;
     int i;
 
-    while ((opt = getopt(argc, argv, "hb:l:I:")) != -1) {
+    while ((opt = getopt(argc, argv, "hb:l:I:C:A:M:L:R:")) != -1) {
         switch (opt) {
-            case 'b':
-                binname = optarg;
-                break;
-            case 'l':
-                libname = optarg;
-                break;
-            case 'I':
+            case 'b': binname = optarg; break;
+            case 'l': libname = optarg; break;
+            case 'C': mc = optarg; break;
+            case 'A': as = optarg; break;
+            case 'M': muse = optarg; break;
+            case 'L': ld = optarg; break;
+            case 'R': ar = optarg; break;
+            case 'I': 
                 lappend(&incpaths, &nincpaths, optarg);
                 break;
             case 'h':