ref: 722f307b48dabe6984334c0b40e995fdead9baf2
parent: 2d4241c939e10e96105a9d5db549dffae6e8e413
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 23 12:52:53 EDT 2014
Populate options correctly.
--- a/build.myr
+++ b/build.myr
@@ -23,8 +23,10 @@
buildbin(b, leaves)
| `Lib (l, leaves):
buildlib(l, leaves)
- | `Sub sub:
- dosub(sub)
+ | `Sub subs:
+ for s in subs
+ dosub(s)
+ ;;
| `Man m:
/* nothing needed */
;;
@@ -48,23 +50,36 @@
}
const build = {p, targ
+ var built
+
+ built = false
for t in p.targs
match t
| `Bin (b, leaves):
if std.sleq(b, targ)
buildbin(b, leaves)
+ built = true
;;
| `Lib (l, leaves):
if std.sleq(l, targ)
buildlib(l, leaves)
+ built = true
;;
- | `Sub sub:
- dosub(sub)
+ | `Sub subs:
+ for s in subs
+ if std.sleq(s, targ)
+ dosub(s)
+ built = true
+ ;;
+ ;;
| `Man m:
/* nothing needed */
;;
;;
- -> true
+ if !built
+ std.fatal(1, "%s: no such target\n", targ)
+ ;;
+ -> built
}
const buildbin = {bin, inputs
@@ -101,10 +116,8 @@
;;
}
-const dosub = {subs
- for s in subs
- std.put("subdir %s\n", s)
- ;;
+const dosub = {sub
+ std.put("subdir %s\n", sub)
}
const builddep = {dg, dep, out
@@ -141,7 +154,7 @@
cmd = std.slpush(cmd, std.sldup(ldscript))
;;
- cmd = std.slpush(cmd, std.fmt("%s/%s", config.Instroot, "/lib/myr/_myrrt.o"))
+ cmd = std.slpush(cmd, std.fmt("%s/%s", opt_instroot, "/lib/myr/_myrrt.o"))
/* input.o list.o... */
for f in srcfiles
@@ -162,7 +175,7 @@
for inc in opt_incpaths
cmd = std.slpush(cmd, std.fmt("-L%s", inc))
;;
- cmd = std.slpush(cmd, std.fmt("-L%s%s", config.Instroot, "/lib/myr"))
+ cmd = std.slpush(cmd, std.fmt("-L%s%s", opt_instroot, "/lib/myr"))
/*
/* special for OSX: it warns if we don't add this */
--- a/deps.myr
+++ b/deps.myr
@@ -180,7 +180,7 @@
-> file
;;
;;
- path = std.fmt("%s/%s/%s", config.Instroot, "/lib/myr", lib)
+ path = std.fmt("%s/%s/%s", opt_instroot, "/lib/myr", lib)
match bio.open(path, bio.Rd)
| `std.Some file:
-> file
--- a/main.myr
+++ b/main.myr
@@ -4,6 +4,7 @@
use "build.use"
use "clean.use"
use "opts.use"
+use "config.use"
const main = {args : byte[:][:]
var p : bld.parser#
@@ -10,6 +11,7 @@
var optctx
optctx = std.optinit("hb:l:s:r:I:C:A:M:L:R:", args)
+ bld.initopts()
while !std.optdone(optctx)
match std.optnext(optctx)
| ('h', arg): usage(args[0])
@@ -24,6 +26,7 @@
else
bld.opt_runtime = arg
;;
+ | ('R', arg): bld.opt_instroot = arg
/*
internal undocumented args; used by compiler suite for
building with an uninstalled compiler.
--- a/opts.myr
+++ b/opts.myr
@@ -1,12 +1,17 @@
+use std
+
+use "config.use"
+
pkg bld =
var opt_arch : byte[:]
var opt_sys : byte[:]
- var opt_targ : byte[:]
var opt_binname : byte[:]
var opt_libname : byte[:]
var opt_runtime : byte[:]
var opt_ldscript : byte[:]
var opt_incpaths : byte[:][:]
+ var opt_instroot : byte[:]
+ var opt_destdir : byte[:]
var opt_bldfile : byte[:]
/* undocumented/unsupported opts */
@@ -15,16 +20,19 @@
var opt_muse : byte[:]
var opt_ld : byte[:]
var opt_ar : byte[:]
+
+ const initopts : (-> void)
;;
-var opt_arch
-var opt_sys
-var opt_targ
-var opt_binname
-var opt_libname
-var opt_runtime
-var opt_ldscript
-var opt_incpaths
+var opt_arch = ""
+var opt_sys = ""
+var opt_binname = ""
+var opt_libname = ""
+var opt_runtime = ""
+var opt_ldscript = ""
+var opt_incpaths /* FIXME: taking a constant slice is a nonconstant initializer */
+var opt_instroot = ""
+var opt_destdir = ""
var opt_bldfile = "bldfile"
var opt_mc = "6m"
var opt_as = "as"
@@ -31,3 +39,41 @@
var opt_muse = "muse"
var opt_ld = "ld"
var opt_ar = "ar"
+
+const initopts = {
+ var un
+
+ std.uname(&un)
+ match cstr2myr(un.system[:])
+ | "Linux": opt_sys = "linux"
+ | "Darwin": opt_sys = "osx"
+ | "FreeBSD": opt_sys = "freebsd"
+ | unknown: std.fatal(1, "unknown system \"%s\"\n", unknown)
+ ;;
+
+ match cstr2myr(un.machine[:])
+ | "x86_64": opt_arch = "x64"
+ | unknown: std.fatal(1, "unknown architecture \"%s\"\n", unknown)
+ ;;
+
+ opt_incpaths = [][:]
+ opt_instroot = config.Instroot
+ opt_destdir = std.getenvv("DESTDIR", "")
+ opt_mc = std.getenvv("MYR_MC", "6m")
+ opt_as = std.getenvv("MYR_AS", "as")
+ opt_ld = std.getenvv("MYR_LD", "ld")
+ opt_ar = std.getenvv("MYR_AR", "ar")
+ opt_muse = std.getenvv("MYR_MUSE", "muse")
+ opt_runtime = std.fmt(config.Instroot, "/lib/myr/_myrrt.o")
+}
+
+const cstr2myr = {cstr
+ var i
+
+ for i = 0; i < cstr.len; i++
+ if cstr[i] == 0
+ break
+ ;;
+ ;;
+ -> cstr[:i]
+}