This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbuild.py
executable file
·198 lines (139 loc) · 4.36 KB
/
cbuild.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python3
import os, sys, fnmatch
from subprocess import Popen
from datetime import datetime
folderIgnore={
"data", "doc" , ".git"
, "SDL", "shader"
, "demos_curses", "tools_curses", "tools_tisk", "tools_curses"
, "logic", "ztorg", "map_old", "tile_old", "zse_all", "zse_test"}
IgnoreNames={"cave_hunter.c", "zse.c", "vector-style.c"}
ignorePatternFront = ["."]
ignorePatternEnd = []
onlyTakePatternEnd = [".c"]
CC="gcc"
ERRFLAGS = ["-Wall"]
CFLAGS=["-std=c99", "-ffunction-sections", "-fdata-sections", "-ftrack-macro-expansion=2", "-Os", "-O2"] + ERRFLAGS
#LDFLAGS=["-lm", "-lncurses", "-lraylib"]
LDFLAGS=["-I/usr/local/include" ,"-lm", "-lvulkan", "-lraylib", "-lncursesw", "-lzkcollection", "-framework","opengl", "-Wl,-rpath", "-Wl,/usr/local/lib"]
OUTEXE="build/z"
gSource = "./"
gCleanEnabled = 0
gTestEnabled = 1
gTestCommands = [""]
#-----G-END-----#
TREE_SYNTX = {'E':'├', 'C':'│', 'S':'─', 'N':'└'}
def run(commands):
Popen(commands).wait()
def log(msg):
print(msg, end='')
def checkIfNameFound(name, nArray):
for i in nArray:
if fnmatch.fnmatch(name, "*"+i):
return 1
return 0
def compile(cfiles):
cf = cfiles.split(" ")
run_command = [ CC ] + CFLAGS + LDFLAGS
for i in cf:
run_command.append(i)
run_command.append('-o')
run_command.append(OUTEXE)
run([ "rm","-rf","build" ])
run(["mkdir", "build"])
run(run_command)
def getallFiles(dirName):
log("Getting C files...")
listOfFiles = list()
for (dirpath, dirnames, filenames) in os.walk(dirName):
dirnames[:] = [d for d in dirnames if d not in folderIgnore]
listOfFiles += [os.path.join(dirpath, file) for file in filenames]
log("DONE\n\n")
return listOfFiles
def drawTree(outstr):
lso = outstr.split(" ")
prev = ""
for i in lso:
sin = i.split("/")
try:
now = sin[-2]
if prev == now:
log('\t')
prev = sin[-2]
except:
pass
log("\n\t\tGot: " + sin[-1])
def filterListintoFile(ls):
log("Filtering Files...")
outstr = ""
prev = ""
for elem in ls:
if elem[2] != ".":
if elem[-1] == "c":
if checkIfNameFound(elem, IgnoreNames) != 1:
outstr += elem + " "
log("\n\t\tGot: " + elem)
#drawTree(outstr)
log("\nCOMPLETED\n\n")
return outstr
def do_clean():
log("Cleaning...\r")
run(["rm", "-rf", "build"])
log("COMPLETED\n")
def checkforfileExistance(source):
try:
fp = open(source, "rb")
fp.close()
return True
except:
return False
def main(source, clean, TestEnabled, testCommands):
if clean:
do_clean()
return
log("Running At ... " + source + "\n")
# Get the list of all files in directory tree at given path
outstr = filterListintoFile(getallFiles(source))
log("Compiling...")
compile(outstr[0:-1])
if checkforfileExistance(OUTEXE):
log("SUCCESS\n\n")
else:
log("FAILED\n\n")
log("Executable: " + OUTEXE + "\n\n")
if TestEnabled:
log("Testing...\n")
try:
run([ "./"+OUTEXE] + testCommands)
log("\nSUCCESS\n")
except:
log("FAILED\n")
return
def argp(arg):
global gSource, gCleanEnabled, gTestCommands, gTestEnabled
count = 1
for i in arg:
if i[0] == '-':
if i[1:] == "-clean" or i[1:] == 'c':
gCleanEnabled= 1
elif i[1:] == "-build" or i[1:] == 'b':
gSource = arg[count+1]
elif i[1:] == "-testdisable" or i[1:] == 't':
gTestEnabled = 0
elif i[1:] == "-testCommands" or i[1:] == 'm':
gTestCommands = arg[count+1::]
main(gSource, gCleanEnabled, gTestEnabled ,gTestCommands)
return
else:
pass
count += 1
main(gSource, gCleanEnabled, gTestEnabled ,gTestCommands)
return
if __name__ == '__main__':
now = datetime.now()
timestamp = datetime.timestamp(now)
log("Starting...\n\n")
argp(sys.argv)
log("\nEND\n")
timest1 = datetime.timestamp(datetime.now())
print("Time Elasped...{:.3} total".format(timest1 - timestamp) )