ref: 82532ed187c6041e7dff5505de21e95d7fd380d9
dir: /main.myr/
use std use "build.use" use "clean.use" use "config.use" use "install.use" use "opts.use" use "parse.use" use "types.use" const main = {args : byte[:][:] var p : bld.parser# var optctx optctx = std.optinit("hb:l:s:r:I:C:A:M:L:R:d", args) bld.initopts() while !std.optdone(optctx) match std.optnext(optctx) | ('h', arg): usage(args[0]) | ('b', arg): bld.opt_binname = arg | ('l', arg): bld.opt_libname = arg | ('s', arg): bld.opt_ldscript = arg | ('f', arg): bld.opt_bldfile = arg | ('I', arg): bld.opt_incpaths = std.slpush(bld.opt_incpaths, arg) | ('r', arg): if std.sleq(arg, "none") bld.opt_runtime = "" else bld.opt_runtime = arg ;; | ('R', arg): bld.opt_instroot = arg | ('d', arg): bld.opt_debug = true /* internal undocumented args; used by compiler suite for building with an uninstalled compiler. */ | ('C', arg): bld.opt_mc = arg | ('A', arg): bld.opt_as = arg | ('M', arg): bld.opt_muse = arg | ('L', arg): bld.opt_ld = arg | ('R', arg): bld.opt_ar = arg ;; ;; if bld.opt_binname.len != 0 bld.buildbin(bld.opt_binname, optctx.args, bld.opt_ldscript, bld.opt_runtime) elif bld.opt_libname.len != 0 bld.buildlib(bld.opt_libname, optctx.args) else p = loadbuild(bld.opt_bldfile) p.cmd = args /*bld.configure()*/ /* default: buildall */ if optctx.args.len == 0 bld.buildall(p) else for cmd in optctx.args match cmd | "all": bld.buildall(p) | "clean": bld.cleanall(p) | "install": bld.install(p) | "uninstall": bld.uninstall(p) | "test": bld.test(p) | target: bld.build(p, target) ;; ;; ;; ;; } const loadbuild = {path var p p = std.zalloc() p.line = 1 p.fname = path match std.slurp(path) | `std.Ok d: p.data = d | `std.Fail _: std.fatal(1, "could not open file 'bldfile'\n") ;; p.rest = p.data bld.parse(p) -> p } const usage = {prog std.put("%s [-h] [-I path] [-l lib] [-b bin] inputs...\n", prog) std.put("\t-h\tprint this help\n") std.put("\t-b bin\tBuild a binary called 'bin'\n") std.put("\t-l lib\tBuild a library called 'name'\n") std.put("\t-s script\tUse the linker script 'script' when linking\n") std.put("\t-I path\tAdd 'path' to use search path\n") std.exit(0) }