-
Notifications
You must be signed in to change notification settings - Fork 0
/
makescript.py
78 lines (68 loc) · 1.47 KB
/
makescript.py
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
import glob
import os
import sys
from WriteFile import WriteFile
header = """\
#!/usr/bin/python
#
# Don't edit this file. Use conf-* for configuration.
#
# Generated by spac, see http://untroubled.org/spac/
import os
import sys
_mtime_cache = { }
def mtime(filename):
global _mtime_cache
try:
m = _mtime_cache[filename]
except KeyError:
try:
m = os.stat(filename)[8]
except OSError:
m = -1
_mtime_cache[filename] = m
return m
def ne(filename):
try:
m = os.stat(filename)[8]
_mtime_cache[filename] = m
return 0
except:
return 1
def nt(target, deps):
m = mtime(target)
for dep in deps:
if m < mtime(dep):
return 1
return 0
def make(target, commands, deps):
if ne(target) or nt(target, deps):
for command in commands:
print '+', command
if os.system(command) != 0:
sys.exit(1)
"""
done = { }
def recurse(name, targets, out):
global done
target = targets[name]
for dep in target.dependancies:
if dep in targets and dep not in done:
recurse(dep, targets, out)
newcom = [ ]
oldcom = target.commands[:]
oldcom.reverse()
while oldcom:
command = oldcom.pop()
while command[-1] == '\\':
command = command[:-1] + oldcom.pop()
command = command.replace('$$', '$')
newcom.append(command)
out.write("make(%s, %s, %s)\n" % (repr(name), repr(newcom),
repr(target.dependancies)))
done[name] = 1
def write(targets, filename='make.py'):
out = WriteFile(filename)
out.write(header)
recurse('all', targets, out)
out.close()