-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEasyBuild
executable file
·75 lines (60 loc) · 2.28 KB
/
EasyBuild
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
#!/usr/bin/env python3
import tempfile
import os
import os.path
import shutil
import subprocess as sp
def set_type_creator(f, t, c, **kwargs):
sp.run(['SetFile', '-t', t, '-c', c, f], stdout=sp.DEVNULL, stderr=sp.DEVNULL, **kwargs)
thisdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(thisdir)
asmfiles = [f for f in os.listdir() if f.endswith('.s') and os.path.isfile(f)]
try:
buildtime = os.path.getmtime('Build/NanoKernel.xcoff')
except FileNotFoundError:
pass
else:
if max(os.path.getmtime(f) for f in asmfiles) < buildtime:
print('already built')
exit()
print('building...', flush=True)
with tempfile.TemporaryDirectory() as tmpdir:
for asmfile in asmfiles:
with open(asmfile, 'rb') as i, open(os.path.join(tmpdir, asmfile), 'wb') as o:
o.write(i.read().replace(b'\n', b'\r'))
sp.run(['mpw', 'PPCAsm', 'Main.s'], check=True, cwd=tmpdir)
with open(os.path.join(tmpdir, 'Main.s.o'), 'rb') as f:
xcoff = f.read()
xcoffsecstart = 0x3C
xcoffsecstop = xcoffsecstart + int.from_bytes(xcoff[0x24:0x28], byteorder='big')
raw = xcoff[xcoffsecstart:xcoffsecstop]
builddir = os.path.join(thisdir, 'Build')
os.makedirs(builddir, exist_ok=True)
os.chdir(builddir)
with open('NanoKernel.xcoff', 'wb') as f:
f.write(xcoff)
set_type_creator('NanoKernel.xcoff', 'XCOF', 'MPS ', check=False)
with open('NanoKernel.raw', 'wb') as f:
f.write(raw)
print('created raw and xcoff files', flush=True)
step = 64
starts = range(0, len(raw), step)
with open('NanoKernel.r', 'w') as f:
print("data 'krnl' (0, locked) {", file=f)
for i in starts:
print(' $"%s"' % raw[i:i+step].hex(), file=f)
print('};', file=f)
set_type_creator('NanoKernel.r', 'TEXT', 'MPS ', check=False)
print('created Rez file', flush=True)
try:
sp.run(['Rez', '-a', '-o', 'NanoKernel.rsrc', 'NanoKernel.r'], stdout=sp.DEVNULL, stderr=sp.DEVNULL, check=True)
print('created resource file with krnl resource', flush=True)
set_type_creator('NanoKernel.rsrc', 'rsrc', 'RSED', check=True)
try:
os.unlink('NanoKernel.hqx')
except:
pass
sp.run(['binhex', 'encode', '-o', 'NanoKernel.hqx', 'NanoKernel.rsrc'], stdout=sp.DEVNULL, stderr=sp.DEVNULL, check=True)
print('created BinHex of resource file', flush=True)
except:
pass