Browse Source

build: get rid of sh dependencies

and clean up heinous shell code while we're at it.

Temporarily disable the syscall command. It has obsolete dependencies
on 32-bit ABIs and kenc issues. Someone can fix it someday if they care.

We've lost a few small things as we had to remove shell dependencies.
If we need them we'll have to work out how to get them back.
I doubt most people used the objdump in kernel anyway, however.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 7 years ago
parent
commit
d34b7f7216

+ 2 - 2
sys/src/9/aarch64/core.json

@@ -31,8 +31,8 @@
 			"kernel.ld"
 		],
 		"Pre": [
-			"mksys -o systab.c '-mode=systab.c' $HARVEY/sys/src/sysconf.json",
-			"mksys -o errstr.h '-mode=errstr.h' $HARVEY/sys/src/sysconf.json"
+			"mksys -o systab.c -mode=systab.c /sys/src/sysconf.json",
+			"mksys -o errstr.h -mode=errstr.h /sys/src/sysconf.json"
 		],
 		"Projects": [
 			"clean.json",

+ 1 - 1
sys/src/9/aarch64/inith.json

@@ -20,7 +20,7 @@
 			"-Ttext=0x200000"
 		],
 		"Post": [
-			"elf2c init > init.h"
+			"elf2c init.h init"
 		],
 		"Program": "init",
 		"SourceFiles": [

+ 4 - 5
sys/src/9/amd64/core.json

@@ -78,13 +78,12 @@
 			"kernel.ld"
 		],
 		"Post": [
-			"OBJCOPY=objcopy; $TOOLPREFIX$OBJCOPY -I elf64-x86-64 -O elf32-i386 harvey harvey.32bit",
-			"cp harvey.32bit $HARVEY/cfg/pxe/tftpboot",
-			"OBJDUMP=objdump; $TOOLPREFIX$OBJDUMP -S harvey > harvey.asm"
+			"objcopy -I elf64-x86-64 -O elf32-i386 harvey harvey.32bit",
+			"cp harvey.32bit /cfg/pxe/tftpboot"
 		],
 		"Pre": [
-			"mksys -o systab.c -mode=systab.c $HARVEY/sys/src/sysconf.json",
-			"mksys -o errstr.h -mode=errstr.h $HARVEY/sys/src/sysconf.json"
+			"mksys -o systab.c -mode=systab.c /sys/src/sysconf.json",
+			"mksys -o errstr.h -mode=errstr.h /sys/src/sysconf.json"
 		],
 		"Projects": [
 			"clean.json",

+ 1 - 1
sys/src/9/amd64/inith.json

@@ -22,7 +22,7 @@
 			"-Ttext=0x200020"
 		],
 		"Post": [
-			"elf2c init > init.h"
+			"elf2c init.h init"
 		],
 		"Program": "init",
 		"SourceFiles": [

+ 2 - 2
sys/src/9/boot/boot.json

@@ -17,8 +17,8 @@
 		"Install": "/sys/src/9/boot",
 		"Library": "libboot.a",
 		"Pre": [
-			"mksys -o bootcpu.c '-mode=bootcpu.c' $HARVEY/sys/src/sysconf.json",
-			"[ ! -f bootcpu.elf.out ] || rm *.elf.out"
+			"mksys -o bootcpu.c -mode=bootcpu.c /sys/src/sysconf.json",
+			"rm -f *.elf.out"
 		],
 		"SourceFiles": [
 			"aux.c",

+ 1 - 1
sys/src/9/boot/bootconf.json

@@ -15,7 +15,7 @@
 		],
 		"Post": [
 			"rm *.o *.a",
-			"data2c ramfs_bootcpu_ ../boot/bootcpu.elf.out >> ../$ARCH/cpu.c"
+			"data2c ramfs_bootcpu_ ../boot/bootcpu.elf.out ../$ARCH/cpu.c"
 		],
 		"Program": "bootcpu.elf.out",
 		"Projects": [

+ 1 - 1
sys/src/9/port/port.json

@@ -7,7 +7,7 @@
 			"-fasm"
 		],
 		"Pre": [
-			"mksys -o ../port/error.h -mode=error.h $HARVEY/sys/src/sysconf.json"
+			"mksys -o ../port/error.h -mode=error.h /sys/src/sysconf.json"
 		],
 		"SourceFiles": [
 			"../port/alarm.c",

+ 2 - 2
sys/src/9/riscv/core.json

@@ -36,8 +36,8 @@
 			"kernel.ld"
 		],
 		"Pre": [
-			"mksys -o systab.c '-mode=systab.c' $HARVEY/sys/src/sysconf.json",
-			"mksys -o errstr.h '-mode=errstr.h' $HARVEY/sys/src/sysconf.json"
+			"mksys -o systab.c -mode=systab.c /sys/src/sysconf.json",
+			"mksys -o errstr.h -mode=errstr.h /sys/src/sysconf.json"
 		],
 		"Projects": [
 			"clean.json",

+ 1 - 1
sys/src/9/riscv/inith.json

@@ -22,7 +22,7 @@
 			"-Tdata=0x400000"
 		],
 		"Post": [
-			"elf2c init > init.h"
+			"elf2c init.h init"
 		],
 		"Program": "init",
 		"SourceFiles": [

+ 1 - 1
sys/src/cmd/acme/build.json

@@ -30,7 +30,7 @@
 			"xfid.c"
 		],
 	        "Post": [
-	                "mkdir -p $HARVEY/mnt/acme"
+	                "mkdir -p /mnt/acme"
 	        ]
 	}
 }

+ 0 - 1
sys/src/cmd/build.json

@@ -174,7 +174,6 @@
 			"rio/rio.json",
 			"sam/build.json",
 			"samterm/build.json",
-			"syscall/syscall.json",
 			"usb/build.json",
 			"venti/venti.json"
 		]

+ 1 - 1
sys/src/cmd/bzip2/bzip2.json

@@ -11,7 +11,7 @@
 		],
 		"Install": "/$ARCH/bin",
 		"Post": [
-			"rm $HARVEY/sys/src/cmd/bzip2/lib/libbzip2.a"
+			"rm /sys/src/cmd/bzip2/lib/libbzip2.a"
 		],
 		"Projects": [
 			"lib/libbzip2.json"

+ 1 - 1
sys/src/cmd/disk/9660/9660.json

@@ -4,7 +4,7 @@
 			"../../cmd.json"
 		],
 		"Post": [
-			"cp mk9660.rc $HARVEY/amd64/bin/mk9660"
+			"cp mk9660.rc /$ARCH/bin/mk9660"
 		],
 		"Install": "/$ARCH/bin",
 		"Program": "dump9660",

+ 2 - 6
sys/src/cmd/fossil/fossil.json

@@ -6,14 +6,10 @@
 		"Install": "/$ARCH/bin/fossil/",
 		"Post": [
 			"chmod +x conf",
-			"mv conf $HARVEY/amd64/bin/fossil/"
+			"mv conf /$ARCH/bin/fossil/"
 		],
 		"Pre": [
-			"echo '#!/bin/rc' \u003e\u003e conf",
-			"echo '# THIS FILE IS AUTOMATICALLY GENERATED' \u003e\u003e conf",
-			"echo '# FROM /sys/src/cmd/fossil/conf.rc.  DO NOT EDIT.' \u003e\u003e conf",
-			"echo \u003e\u003e conf",
-			"sed 1d conf.rc \u003e\u003e conf"
+			"cp conf.rc conf"
 		],
 		"Program": "fossil",
 		"Projects": [

+ 1 - 1
sys/src/cmd/hoc/hoc.json

@@ -5,7 +5,7 @@
 		],
 		"Install": "/$ARCH/bin",
 		"Post": [
-			"rm -f $HARVEY/sys/src/cmd/hoc/y.tab.[ch]"
+			"rm -f /sys/src/cmd/hoc/y.tab.[ch]"
 		],
 		"Pre": [
 			"yacc -d hoc.y"

+ 1 - 7
sys/src/cmd/syscall/syscall.json

@@ -2,17 +2,11 @@
 	"syscall": {
 		"Cflags": [
 			"-Wall",
-			"-I$HARVEY/sys/src/libc/9syscall"
+			"-I/sys/src/libc/9syscall"
 		],
 		"Include": [
 			"../cmd.json"
 		],
-		"Post": [
-			"rm tab.h"
-		],
-		"Pre": [
-			"cat $HARVEY/sys/src/libc/9syscall/sys.h|grep -v automatically|grep -v -e '^$'|sed '/#define._X[0-9_]/d;/#define.NSYSCALL/d;'|cut -f 2 -d ' '|xargs -n1 sh -c 'echo \\\"$0\\\", \"(int(*)())\" $0,'|tr A-Z a-z \u003e tab.h"
-		],
 		"Install": "/$ARCH/bin",
 		"Program": "syscall",
 		"SourceFiles": [

+ 2 - 6
sys/src/cmd/venti/srv/srv.json

@@ -9,14 +9,10 @@
 		],
 		"Post": [
 			"chmod +x conf",
-			"mv conf $HARVEY/amd64/bin/venti/"
+			"mv conf /$ARCH/bin/venti/"
 		],
 		"Pre": [
-			"echo '#!/bin/rc' \u003e\u003e conf",
-			"echo '# THIS FILE IS AUTOMATICALLY GENERATED' \u003e\u003e conf",
-			"echo '# FROM /sys/src/cmd/venti/conf.rc.  DO NOT EDIT.' \u003e\u003e conf",
-			"echo \u003e\u003e conf",
-			"sed 1d conf.rc \u003e\u003e conf"
+			"cp conf.rc conf"
 		],
 		"Projects": [
 			"libvs.json"

+ 2 - 2
sys/src/cmd/zenith/build.json

@@ -30,8 +30,8 @@
 			"xfid.c"
 		],
 	        "Post": [
-	                "mkdir -p $HARVEY/mnt/acme",
-			"cp zenith.init $HARVEY/$ARCH/bin"
+	                "mkdir -p /mnt/acme",
+			"cp zenith.init /$ARCH/bin"
 	        ]
 	}
 }

+ 2 - 2
sys/src/libc/9syscall/9syscall.json

@@ -2,8 +2,8 @@
 	"KernelLibc": {
 		"Library": "klibc.a",
 		"Pre": [
-			"mksys -o sys.h -mode=sys.h $HARVEY/sys/src/sysconf.json",
-			"mksys -o . -mode=syscallfiles $HARVEY/sys/src/sysconf.json"
+			"mksys -o sys.h -mode=sys.h /sys/src/sysconf.json",
+			"mksys -o . -mode=syscallfiles /sys/src/sysconf.json"
 		]
 	}
 }

+ 1 - 1
sys/src/regress/fs/build.json

@@ -11,7 +11,7 @@
 			"filecreate.c"
 		],
 		"Post": [
-			"cp fs.rc $HARVEY/$ARCH/bin/regress"
+			"cp fs.rc /$ARCH/bin/regress"
 		]
 	}
 }

+ 19 - 7
util/src/harvey/cmd/build/build.go

@@ -435,6 +435,23 @@ func dirPush(s string) {
 	fmt.Printf("Entering directory `%v'\n", s)
 	failOn(os.Chdir(s))
 }
+
+func runCmds(b*build, s []string) {
+		for _, c := range s {
+			args := adjust(strings.Split(c, " "))
+			var exp []string
+			for _, v := range args {
+				e, err := filepath.Glob(v)
+				debug("glob %v to %v err %v", v, e, err)
+				if len(e) == 0 || err != nil {
+					exp = append(exp, v)
+				} else {
+					exp = append(exp, e...)
+				}
+			}
+			run(b, *shellhack, exec.Command(exp[0], exp[1:]...))
+		}
+}
 // assumes we are in the wd of the project.
 func project(bf string, which []*regexp.Regexp) {
 	cwd, err := os.Getwd()
@@ -450,10 +467,7 @@ func project(bf string, which []*regexp.Regexp) {
 	for _, b := range builds {
 		debug("Processing %v: %v", b.name, b)
 		projects(&b, regexpAll)
-		for _, c := range b.Pre {
-			// this is a hack: we just pass the command through as an exec.Cmd
-			run(&b, true, exec.Command(c))
-		}
+		runCmds(&b, b.Pre)
 		buildkernel(&b)
 		if len(b.SourceFiles) > 0 || len(b.SourceFilesCmd) > 0 {
 			compile(&b)
@@ -462,9 +476,7 @@ func project(bf string, which []*regexp.Regexp) {
 			link(&b)
 		}
 		install(&b)
-		for _, c := range b.Post {
-			run(&b, true, exec.Command(c))
-		}
+		runCmds(&b, b.Post)
 	}
 	install(b)
 	run(b, b.Post)

+ 13 - 6
util/src/harvey/cmd/data2c/data2c.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bytes"
 	"flag"
 	"fmt"
 	"io/ioutil"
@@ -10,8 +11,8 @@ import (
 func main() {
 	flag.Parse()
 	a := flag.Args()
-	if len(a) != 2 {
-		fmt.Fprintf(os.Stderr, "[%v]usage: data2s name input-file (writes to stdout)\n", a)
+	if len(a) != 3 {
+		fmt.Fprintf(os.Stderr, "[%v]usage: data2s name input-file output-file\n", a)
 		os.Exit(1)
 	}
 
@@ -25,15 +26,21 @@ func main() {
 
 	total := len(in)
 
-	fmt.Printf("unsigned char %vcode[] = {\n", n)
+	o := a[2]
+	b := &bytes.Buffer{}
+	fmt.Fprintf(b, "unsigned char %vcode[] = {\n", n)
 	for len(in) > 0 {
 		for j := 0; j < 16 && len(in) > 0; j++ {
-			fmt.Printf("0x%02x, ", in[0])
+			fmt.Fprintf(b, "0x%02x, ", in[0])
 			in = in[1:]
 		}
-		fmt.Printf("\n")
+		fmt.Fprintf(b, "\n")
 
 	}
 
-	fmt.Printf("0,\n};\nint %vlen = %v;\n", n, total)
+	fmt.Fprintf(b, "0,\n};\nint %vlen = %v;\n", n, total)
+
+	if err := ioutil.WriteFile(o, b.Bytes(), 0644); err != nil {
+		fmt.Fprintf(os.Stderr, "Write to %s failed: %v\n", o, err)
+	}
 }

+ 7 - 5
util/src/harvey/cmd/elf2c/elf2c.go

@@ -1,11 +1,12 @@
 package main
 
 import (
-	"bufio"
+	"bytes"
 	"debug/elf"
 	"flag"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"math"
 	"os"
 	"path"
@@ -30,7 +31,8 @@ func gencode(w io.Writer, n, t string, m []byte, start, end uint64) {
 func main() {
 	flag.Parse()
 	a := flag.Args()
-	for _, n := range a {
+	w := &bytes.Buffer{}
+	for _, n := range a[1:] {
 		f, err := elf.Open(n)
 		if err != nil {
 			fmt.Printf("%v %v\n", n, err)
@@ -102,13 +104,13 @@ func main() {
 			fmt.Fprintf(os.Stderr, "Processed %v\n", v)
 		}
 		fmt.Fprintf(os.Stderr, "gencode\n")
-		// Gen code to stdout. For each file, create an array, a start, and an end variable.
-		w := bufio.NewWriter(os.Stdout)
 		_, file := path.Split(n)
 		fmt.Fprintf(w, "uintptr_t %v_main = %v;\n", n, f.Entry)
 		gencode(w, file, "code", mem, codestart, codeend)
 		gencode(w, file, "data", mem, datastart, dataend)
-		w.Flush()
+	}
+	if err := ioutil.WriteFile(a[0], w.Bytes(), 0444); err != nil {
+		fmt.Fprintf(os.Stderr, "elf2c: write %s failed: %v\n", a[0], err)
 	}
 
 }

+ 1 - 0
util/src/harvey/cmd/mksys/mksys.go

@@ -57,6 +57,7 @@ var mode = flag.String("mode", "", "must be one of: sys.h, sysdecl.h, syscallfil
 var outpath = flag.String("o", "", "path/to/output.c")
 
 func usage(msg string) {
+	fmt.Fprintf(os.Stderr, "mksys: invoked via %v\n", os.Args)
 	fmt.Fprintln(os.Stderr, msg)
 	fmt.Fprint(os.Stderr, "Usage: mksys [-o outpath] -mode=MODE path/to/sysconf.json\n")
 	flag.PrintDefaults()