shithub: mc

ref: 3cdb85952401e2284ecd285742174b8f774bf18b
dir: /mbld/opts.myr/

View raw version
use std

use "config"

pkg bld =
	var opt_arch 	: byte[:]
	var opt_sys	: byte[:]
	var opt_sysvers	: (int, int, int)
	var opt_runtime	: byte[:]
	var opt_genasm	: bool
	var opt_incpaths	: byte[:][:]
	var opt_instbase	: byte[:]
	var opt_destdir	: byte[:]
	var opt_outdir	: byte[:]
	var opt_debug	: bool
	var opt_silent	: bool

	/* undocumented/unsupported opts */
	var opt_mc	: byte[:]
	var opt_muse	: byte[:]

	var sysarchstr	: byte[:]
	var archstr	: byte[:]
	var sysstr	: byte[:]

	const initopts	: (-> void)
	const parseversion	: (v : byte[:] -> (int, int, int))
;;

var opt_arch 	= ""
var opt_sys	= ""
var opt_binname	= ""
var opt_libname	= ""
var opt_runtime	= ""
var opt_incpaths	/* FIXME: taking a constant slice is a nonconstant initializer */
var opt_instbase	= ""
var opt_destdir	= ""
var opt_sysvers
var opt_debug	= false
var opt_mc	= "6m"
var opt_as	= "as"
var opt_muse	= "muse"
var opt_ld	= "ld"
var opt_ar	= "ar"
var opt_genasm  = false
var opt_silent	= false

const initopts = {
	var si

	std.getsysinfo(&si)
	match si.system
	| "Linux":	opt_sys = "linux"
	| "Darwin":	opt_sys = "osx"
	| "FreeBSD":	opt_sys = "freebsd"
	| "NetBSD":	opt_sys = "netbsd"
	| "OpenBSD":	opt_sys = "openbsd"
	| "Plan9":	opt_sys = "plan9"
	| unknown:	std.fatal("unknown systemy \"{}\"\n", unknown)
	;;

	opt_sysvers = parseversion(si.release)

	match si.arch
	| "x86_64":	opt_arch = "x64"
	| "amd64":	opt_arch = "x64"
	| unknown:	std.fatal("unknown architecture \"{}\"\n", unknown)
	;;

	opt_incpaths = [][:]
	opt_instbase = config.Instroot
	opt_destdir = std.getenvv("DESTDIR", "")
	opt_mc = std.getenvv("MYR_MC", "6m")
	opt_muse = std.getenvv("MYR_MUSE", "muse")
	opt_runtime = std.getenvv("MYR_RT", "")
	if opt_runtime.len == 0
		opt_runtime = std.pathjoin([opt_instbase, config.Libpath, config.Runtime][:]) 
	;;
}

const parseversion = {v
	var a
	var i

	i = 0
	a = [0, 0, 0]
	for e in std.bysplit(v, ".")
		match std.intparse(e)
		| `std.Some n:	a[i++] = n
		| `std.None:	continue
		;;
		if i == 3
			break
		;;
	;;
	-> (a[0], a[1], a[2])
}