1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
use std
use thread
use "config"
pkg bld =
var opt_arch : byte[:]
var opt_sys : byte[:]
var opt_sysvers : (int, int, int)
var opt_cpufeatures : uint64
var opt_runtime : byte[:]
var opt_genasm : bool
var opt_incpaths : byte[:][:]
var opt_alltags : byte[:][:]
var opt_mcflags : byte[:][:]
var opt_museflags : byte[:][:]
var opt_ldflags : byte[:][:]
var opt_instbase : byte[:]
var opt_destdir : byte[:]
var opt_objdir : byte[:]
var opt_maxproc : std.size
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))
/* not exactly portable, but good enough for now */
const CpuidSSE4 : uint64= 0x180000
/*
Intel manuals (vol 1, 14.5.3) say AVX, OSXSAVE also
needed. For full portability, XGETBV also needs to be
checked, though it isn't right now.
*/
const CpuidFMA : uint64= 0x18001000
extern const cpufeatures : (-> uint64)
;;
var opt_arch = ""
var opt_sys = ""
var opt_binname = ""
var opt_cpufeatures = 0ul
var opt_libname = ""
var opt_runtime = ""
var opt_incpaths = [][:]
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_mcflags = [][:]
var opt_museflags = [][:]
var opt_ldflags = [][:]
var opt_alltags = [][:]
var opt_objdir = "obj"
var opt_genasm = false
var opt_silent = false
var opt_maxproc = 1
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)
;;
/* from cpuid with EAX=1; EDX at top, ECX at bottom */
opt_cpufeatures = cpufeatures()
opt_maxproc = 2*(thread.ncpu() : std.size)
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", "")
match std.getenv("MYR_MCFLAGS")
| `std.Some s: opt_mcflags = std.strtok(s)
| `std.None: /* ok */
;;
match std.getenv("MYR_MUSEFLAGS")
| `std.Some s: opt_mcflags = std.strtok(s)
| `std.None: /* ok */
;;
match std.getenv("MYR_LDFLAGS")
| `std.Some s: opt_ldflags = std.strtok(s)
| `std.None: /* ok */
;;
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 : 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])
}
|