-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenmake.py
executable file
·86 lines (61 loc) · 2.05 KB
/
genmake.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
#!/usr/bin/env python
"""
Python script parses the source files and automatically generates a Makefile
appropriate for compiling on Linux.
"""
compiler = 'g++'
cflags = '-g `root-config --cflags` -O2 -Wall'
lflags = '`root-config --ldflags --glibs` -O1'
objpath = 'obj'
srcpath = 'src'
executable = 'tbConverter'
ext_source = '.cpp'
ext_header = '.h'
sources = []
objects = []
makefile = None
import os
def find_sources():
global sources
global objects
path = '.'
if len(srcpath) > 0:
path = srcpath + '/'
for root, dir, files in os.walk(path):
for file in files:
if len(file) < len(ext_source):
continue
if file[-len(ext_source):] != ext_source:
continue
source = os.path.join(root[len(path):], file)
object = file[:-len(ext_source)] + '.o'
objects.append(object)
sources.append(source)
def write_preamble():
makefile.write('CC = ' + compiler + '\n')
makefile.write('CFLAGS = ' + cflags + '\n')
makefile.write('LFLAGS = ' + lflags + '\n')
makefile.write('OBJPATH = ' + objpath + '\n')
makefile.write('SRCPATH = ' + srcpath + '\n')
makefile.write('EXECUTABLE = ' + executable + '\n')
makefile.write('OBJECTS = ')
for object in objects:
makefile.write('$(OBJPATH)/' + object + ' ')
makefile.write('\n\n')
def write_targets():
makefile.write('all: ' + executable + '\n\n')
makefile.write(
executable + ': $(OBJECTS)\n'
'\t$(CC) $(LFLAGS) $(LIBS) $(OBJECTS) -o $(EXECUTABLE)\n\n')
for (object, source) in zip(objects, sources):
makefile.write(
'$(OBJPATH)/' + object + ': $(SRCPATH)/' + source + '\n'
'\t$(CC) $(CFLAGS) $(INCLUDES) -c $(SRCPATH)/' + source +
' -o $(OBJPATH)/' + object + '\n\n')
makefile.write('clean:\n\t rm $(OBJPATH)/*.o '+executable)
if __name__ == "__main__":
makefile = open('Makefile', 'w')
find_sources()
write_preamble()
write_targets()
makefile.close()