Browse Source

Add the ability to extend options for a tool.

It's a bit of a kludge, but it will hold us until we get the new build tool.

There is a new .json file entry, "ToolOpts". To use it, name the full path
of the tool, and if you are using that tool, the opts get added.

So, for example, for /usr/bin/clang, you can see we do this:
"ToolOpts": {
	"/usr/bin/clang": [
		"-mno-implicit-float"
	]
}

Tested and correctly invoking clang. Only set for kernel compiles.

We no longer need sys/src/9/amd64/clang.json

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 8 years ago
parent
commit
fee51e6da3
4 changed files with 25 additions and 133 deletions
  1. 5 0
      amd64/include/klib.json
  2. 0 133
      sys/src/9/amd64/clang.json
  3. 5 0
      sys/src/9/amd64/core.json
  4. 15 0
      util/src/harvey/cmd/build/build.go

+ 5 - 0
amd64/include/klib.json

@@ -1,5 +1,10 @@
 {
 	"KernelLibs": {
+		"ToolOpts": {
+			"/usr/bin/clang": [
+				"-mno-implicit-float"
+			]
+		},
 		"Cflags": [
 			"-mcmodel=kernel",
 			"-O0",

+ 0 - 133
sys/src/9/amd64/clang.json

@@ -1,133 +0,0 @@
-{
-	"cpu": {
-		"CFlags": [
-			"-mno-implicit-float"
-		],
-		"Env": [
-			"CONF=cpu"
-		],
-		"Include": [
-			"core.json",
-			"../386/386.json",
-			"../ip/ip.json",
-			"../port/port.json"
-		],
-		"Kernel": {
-			"Config": {
-				"Code": [
-					"int cpuserver = 1;",
-					"uint32_t kerndate = 1;"
-				],
-				"Dev": [
-					"acpi",
-					"arch",
-					"cap",
-					"cons",
-					"coreboot",
-					"draw",
-					"dup",
-					"env",
-					"fdmux",
-					"ether",
-					"ip",
-					"kbin",
-					"kprof",
-					"mnt",
-					"mntn",
-					"mouse",
-					"pci",
-					"pipe",
-					"proc",
-					"regress",
-					"root",
-					"rtc",
-					"sd",
-					"segment",
-					"srv",
-					"ssl",
-					"tls",
-					"uart",
-					"ws",
-					"usb",
-					"vga"
-				],
-				"Ip": [
-					"tcp",
-					"udp",
-					"ipifc",
-					"icmp",
-					"icmp6",
-					"gre"
-				],
-				"Link": [
-					"ether8169",
-					"ether82557",
-					"ether82563",
-					"etherigbe",
-					"ether8139",
-					"ethermedium",
-					"loopbackmedium",
-					"netdevmedium",
-					"usbuhci",
-					"usbohci",
-					"usbehci"
-				],
-				"Sd": [
-					"sdiahci"
-				],
-				"Uart": [
-					"i8250",
-					"pci"
-				],
-				"VGA": [
-					"vgavesa"
-				]
-			},
-			"Ramfiles": {
-				"bind": "/$ARCH/bin/bind",
-				"boot": "/sys/src/9/boot/bootcpu.elf.out",
-				"cat": "/$ARCH/bin/cat",
-				"date": "/$ARCH/bin/date",
-				"echo": "/$ARCH/bin/echo",
-				"factotum": "/$ARCH/bin/auth/factotum",
-				"fdisk": "/$ARCH/bin/disk/fdisk",
-				"fossil": "/$ARCH/bin/fossil/fossil",
-				"ipconfig": "/$ARCH/bin/ip/ipconfig",
-				"ls": "/$ARCH/bin/ls",
-				"mount": "/$ARCH/bin/mount",
-				"nvram": "/util/nvram",
-				"prep": "/$ARCH/bin/disk/prep",
-				"rc": "/$ARCH/bin/rc",
-				"ps": "/$ARCH/bin/ps",
-				"ed": "/$ARCH/bin/ed",
-				"rcmain": "/rc/lib/rcmain",
-				"screenconsole": "/$ARCH/bin/aux/screenconsole",
-				"realemu": "/$ARCH/bin/aux/realemu",
-				"vga": "/$ARCH/bin/aux/vga",
-				"srv": "/$ARCH/bin/srv",
-				"startdisk": "startdisk",
-				"usbd": "/$ARCH/bin/usb/usbd",
-				"venti": "/$ARCH/bin/venti/venti"
-			},
-			"Systab": "/sys/src/libc/9syscall/sys.h"
-		},
-		"Program": "harvey",
-		"SourceFiles": [
-			"cga.c",
-			"devacpi.c",
-			"devusb.c",
-			"devvga.c",
-			"ether8139.c",
-			"ether82563.c",
-			"cpu.c",
-			"mouse.c",
-			"screen.c",
-			"sdata.c",
-			"usbehcipc.c",
-			"usbohci.c",
-			"usbuhci.c",
-			"vga.c",
-			"vgax.c"
-		]
-	}
-}

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

@@ -1,5 +1,10 @@
 {
 	"core": {
+		"ToolOpts": {
+			"/usr/bin/clang": [
+				"-mno-implicit-float"
+			]
+		},
 		"Cflags": [
 			"-mcmodel=kernel",
 			"-O0",

+ 15 - 0
util/src/harvey/cmd/build/build.go

@@ -63,6 +63,7 @@ type build struct {
 	ObjectFiles []string
 	Libs        []string
 	Env         []string
+	ToolOpts    map[string][]string
 	// cmd's
 	SourceFilesCmd []string
 	// Targets.
@@ -81,6 +82,7 @@ func (bf *buildfile) UnmarshalJSON(s []byte) error {
 	if err := json.Unmarshal(s, &r); err != nil {
 		return err
 	}
+
 	for k, b := range r {
 		// we're getting a copy of the struct, remember.
 		b.jsons = make(map[string]bool)
@@ -190,6 +192,9 @@ func process(f, which string, b *build) {
 
 	for n, build := range builds {
 		log.Printf("Merging %v", n)
+		for t,v := range build.ToolOpts {
+			b.ToolOpts[t] = v
+		}
 		b.SourceFiles = append(b.SourceFiles, build.SourceFiles...)
 		b.Cflags = append(b.Cflags, build.Cflags...)
 		b.Oflags = append(b.Oflags, build.Oflags...)
@@ -245,6 +250,7 @@ func process(f string, r []*regexp.Regexp) []build {
 	for n, build := range builds {
 		build.name = n
 		build.jsons = make(map[string]bool)
+		build.ToolOpts = make(map[string][]string)
 		skip := true
 		for _, re := range r {
 			if re.MatchString(build.name) {
@@ -293,6 +299,9 @@ func compile(b *build) {
 		"-I", fromRoot("/sys/include"),
 		"-I", ".",
 	}
+	if toolOpts, ok := b.ToolOpts[tools["cc"]]; ok {
+		args = append(args, toolOpts...)
+	}
 	args = append(args, b.Cflags...)
 	if len(b.SourceFilesCmd) > 0 {
 		for _, i := range b.SourceFilesCmd {
@@ -321,6 +330,9 @@ func link(b *build) {
 			o := f[:len(f)] + ".o"
 			args := []string{"-o", n, o}
 			args = append(args, b.Oflags...)
+			if toolOpts, ok := b.ToolOpts[tools["ld"]]; ok {
+				args = append(args, toolOpts...)
+			}
 			args = append(args, "-L", fromRoot("/$ARCH/lib"))
 			args = append(args, b.Libs...)
 			run(b, *shellhack, exec.Command(tools["ld"], args...))
@@ -328,6 +340,9 @@ func link(b *build) {
 		return
 	}
 	args := []string{"-o", b.Program}
+	if toolOpts, ok := b.ToolOpts[tools["ld"]]; ok {
+		args = append(args, toolOpts...)
+	}
 	args = append(args, b.ObjectFiles...)
 	args = append(args, b.Oflags...)
 	args = append(args, "-L", fromRoot("/$ARCH/lib"))