-
Notifications
You must be signed in to change notification settings - Fork 4
/
newMake.py
executable file
·147 lines (134 loc) · 4.06 KB
/
newMake.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
#!/usr/bin/python
#Generate MakeFile
import os
import sys
CFLAGS="-O3 -g -fPIC"
gConfigFile = 'config.txt'
if len(sys.argv)>1:
gConfigFile = sys.argv[1]
#CPP="g++-4.8 -std=c++11 "
#C="gcc-4.8 -std=c11 "
CPP="g++ -std=c++11 "
C="gcc -std=c11 "
MIDPATH='build/'
MAIN_PROGRAM=[]
gDepends = []
gDirs = []
gSrcFiles = []
gLinks = []
include_Flag = ''
gHistoryFile = []
with open(gConfigFile) as f:
filc_tt = f.read().split('**********')
for s in filc_tt[0].split(':')[1].split(' '):
include_Flag += '-I' + s + ' '
print include_Flag
contents = filc_tt[1].split('##########')
for c in contents:
lines = c.split('\n')
lines = [l for l in lines if len(l)>2]
MAIN_PROGRAM.append(lines[0].split(':')[1])
gDepends.append(lines[1].split(':')[1])
gDirs.append([c for c in lines[2].split(':')[1].split(' ') if len(c)>1])
gSrcFiles.append([c for c in lines[3].split(':')[1].split(' ') if len(c)>1])
gLinks.append(lines[4].split(':')[1])
print MAIN_PROGRAM
print gDirs
print gSrcFiles
def Generate_Output(outName, srcDirs, srcFiles, CLINK, depend):
#Find all files
include_h = []
sources_cpp = []
sources_c = []
for dir in srcDirs:
cmd = "find include/" + " -name \"*.h\""
include_h_temp = os.popen(cmd).read().split('\n');
for f in include_h_temp:
if len(f) > 0:
include_h.append(f)
cmd = "find " + dir + " -name \"*.cpp\""
temp_cpp = os.popen(cmd).read().split('\n');
for f in temp_cpp:
if len(f) > 0:
sources_cpp.append(f)
cmd = "find " + dir + " -name \"*.c\""
temp_c = os.popen(cmd).read().split('\n');
for f in temp_c:
if len(f) > 0:
sources_c.append(f)
for f in srcFiles:
sources_cpp.append(f)
fileContents = ""
#Head Files
include = "ALL_INCLUES"+outName
fileContents += include+'='
for h in include_h:
if len(h)>0:
fileContents+=(' '+h)
fileContents+='\n'
def getNameWithofO(fileName):
pos = 0
while fileName[pos]=='.':
pos+=1
sta = pos
pos+=1
while fileName[pos]!='.':
pos+=1
result = fileName[sta:pos].replace('/','_')
return result+'.o'
#All cpp c and .o
objs = []
sequences = []
def getSequencesAndAppend(src, program):
obj = getNameWithofO(src)
objs.append(obj)
if src in gHistoryFile:
return
gHistoryFile.append(src)
sequence = MIDPATH + obj + ' : ' + src + " "+depend+" "+' ${'+include + '}\n'
sequence += '\t' + program + CFLAGS + ' -o ' + MIDPATH + obj + ' -c ' + src + ' '+include_Flag+' \n'
sequences.append(sequence)
for cpp in sources_cpp:
if len(cpp)>0:
getSequencesAndAppend(cpp, CPP)
for c in sources_c:
if len(c)>0:
getSequencesAndAppend(c, C)
fileContents+='\n'
main = outName
#objs
fileContents += (main + ': ')
for obj in objs:
fileContents+=' '+MIDPATH+obj
fileContents+= ' ' + depend
fileContents+='\n'
#Program
target = ''
main_files = ""
for obj in objs:
main_files+=(' '+MIDPATH+obj)
if (main.find('.so')>-1):
target = ' --shared '
if (main.find('.a')!=-1):
fileContents+=('\t' + 'ar rcs ' + main+' '+main_files)
else:
fileContents+=('\t' + CPP + " " + main_files + " " + CFLAGS + ' ' + target + ' ' + CLINK + ' -o ' + main)
fileContents+=(' ${SELF_VARIABLES}' + '\n')
#All objs' make
for sequence in sequences:
fileContents+=sequence
return fileContents
files = 'all:'
for program in MAIN_PROGRAM:
files+= (program + ' ')
files+='\n'
for i in range(0, len(gSrcFiles)):
files+='\n'
files+= Generate_Output(MAIN_PROGRAM[i], gDirs[i], gSrcFiles[i], gLinks[i], gDepends[i])
#clean
files+='\nclean:\n\trm '+MIDPATH+'*.o'
for main in MAIN_PROGRAM:
files+='\n\trm '+main
makeFile = open('Makefile','w')
makeFile.write(files)
makeFile.close();