|
|
@@ -3,12 +3,12 @@ import sys, os, fnmatch, random, re
|
|
|
from threading import Thread
|
|
|
|
|
|
|
|
|
-#======================================================================================================================================
|
|
|
-# GLOBAL VARS =
|
|
|
-#======================================================================================================================================
|
|
|
+#=======================================================================================================================
|
|
|
+# GLOBAL VARS =
|
|
|
+#=======================================================================================================================
|
|
|
sourcePaths = []
|
|
|
precompiledHeaders = []
|
|
|
-executableName = "unamed_project"
|
|
|
+executableName = "unamed-project"
|
|
|
compiler = ""
|
|
|
compilerFlags = ""
|
|
|
precompiledHeadersFlags = ""
|
|
|
@@ -17,54 +17,54 @@ sourceFilesRegExpr = r".*\.[c++|cpp|cc|cxx|C|c]"
|
|
|
includePaths = []
|
|
|
|
|
|
|
|
|
-#======================================================================================================================================
|
|
|
-# getCommandOutput =
|
|
|
-#======================================================================================================================================
|
|
|
-def getCommandOutput( command ):
|
|
|
+#=======================================================================================================================
|
|
|
+# getCommandOutput =
|
|
|
+#=======================================================================================================================
|
|
|
+def getCommandOutput(command):
|
|
|
child = os.popen(command)
|
|
|
data = child.read()
|
|
|
err = child.close()
|
|
|
if err:
|
|
|
- print( "getCommandOutput failed:\n" + command )
|
|
|
- exit( 0 )
|
|
|
+ print("getCommandOutput failed:\n" + command)
|
|
|
+ exit(0)
|
|
|
return data
|
|
|
|
|
|
|
|
|
-#======================================================================================================================================
|
|
|
-# Threads =
|
|
|
-#======================================================================================================================================
|
|
|
+#=======================================================================================================================
|
|
|
+# Threads =
|
|
|
+#=======================================================================================================================
|
|
|
threadList = []
|
|
|
|
|
|
-class TargetThread( Thread ):
|
|
|
- def __init__( self, tid, range ):
|
|
|
- Thread.__init__( self )
|
|
|
+class TargetThread(Thread):
|
|
|
+ def __init__(self, tid, range):
|
|
|
+ Thread.__init__(self)
|
|
|
self.tid = tid
|
|
|
self.range = range
|
|
|
self.out_str = ""
|
|
|
|
|
|
- def run( self ):
|
|
|
+ def run(self):
|
|
|
for i in self.range:
|
|
|
source_file = sourceFiles[i]
|
|
|
- self.out_str += getCommandOutput( compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile )
|
|
|
+ self.out_str += getCommandOutput(compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile)
|
|
|
self.out_str += "\t@echo Compiling " + source_file.cppFile + "...\n"
|
|
|
self.out_str += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.cppFile + " -o " + \
|
|
|
source_file.objFile + "\n\n"
|
|
|
- #print( "Im thread %d and I will make depends for %s" %(self.tid, source_file.fname) )
|
|
|
- #print( "Im thread %d and my i is %d" %(self.tid, i) )
|
|
|
+ #print("Im thread %d and I will make depends for %s" %(self.tid, source_file.fname))
|
|
|
+ #print("Im thread %d and my i is %d" %(self.tid, i))
|
|
|
|
|
|
|
|
|
-#======================================================================================================================================
|
|
|
-# SourceFile =
|
|
|
-#======================================================================================================================================
|
|
|
+#=======================================================================================================================
|
|
|
+# SourceFile =
|
|
|
+#=======================================================================================================================
|
|
|
class SourceFile:
|
|
|
- def __init__( self ):
|
|
|
+ def __init__(self):
|
|
|
self.cppFile = ""
|
|
|
self.objFile = ""
|
|
|
|
|
|
|
|
|
-#======================================================================================================================================
|
|
|
-# main =
|
|
|
-#======================================================================================================================================
|
|
|
+#=======================================================================================================================
|
|
|
+# main =
|
|
|
+#=======================================================================================================================
|
|
|
|
|
|
# Read the arguments
|
|
|
inputCfgFile = ""
|
|
|
@@ -77,12 +77,12 @@ while 1:
|
|
|
|
|
|
arg = sys.argv[i]
|
|
|
if arg == "-h" or arg == "-help" or arg == "--help":
|
|
|
- print( "Makefile generator by GODlike" )
|
|
|
- print( "usage: " + sys.argv[0] + " [options] [-i input] [-o output]" )
|
|
|
- print( "options:" )
|
|
|
- print( "-h, -help, --help Print this text" )
|
|
|
- print( "-i Input config file. Default: gen.cfg.py" )
|
|
|
- print( "-o Output makefile. Default: Makefile" )
|
|
|
+ print("Makefile generator by GODlike")
|
|
|
+ print("usage: " + sys.argv[0] + " [options] [-i input] [-o output]")
|
|
|
+ print("options:")
|
|
|
+ print("-h, -help, --help Print this text")
|
|
|
+ print("-i Input config file. Default: gen.cfg.py")
|
|
|
+ print("-o Output makefile. Default: Makefile")
|
|
|
exit(0)
|
|
|
elif arg == "-i":
|
|
|
inputCfgFile = sys.argv[i+1]
|
|
|
@@ -91,7 +91,7 @@ while 1:
|
|
|
outputMakefile = sys.argv[i+1]
|
|
|
i = i+1
|
|
|
else:
|
|
|
- print( "Unrecognized argument " + arg )
|
|
|
+ print("Unrecognized argument " + arg)
|
|
|
|
|
|
|
|
|
if outputMakefile == "":
|
|
|
@@ -101,52 +101,52 @@ if inputCfgFile == "":
|
|
|
|
|
|
|
|
|
# Check if cfg exists
|
|
|
-if not os.path.exists( inputCfgFile ):
|
|
|
- print( "File " + inputCfgFile + " doesn't exist" )
|
|
|
+if not os.path.exists(inputCfgFile):
|
|
|
+ print("File " + inputCfgFile + " doesn't exist")
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
# compile the cfg
|
|
|
source = ""
|
|
|
-f = open( inputCfgFile, "r" )
|
|
|
+f = open(inputCfgFile, "r")
|
|
|
for line in f.readlines():
|
|
|
source += line
|
|
|
|
|
|
-exec( compile( source, inputCfgFile, "exec" ) )
|
|
|
+exec(compile(source, inputCfgFile, "exec"))
|
|
|
|
|
|
|
|
|
# find the cpp files
|
|
|
sourceFiles = []
|
|
|
-regexpr = re.compile( sourceFilesRegExpr )
|
|
|
+regexpr = re.compile(sourceFilesRegExpr)
|
|
|
for sourceDir in sourcePaths:
|
|
|
- files = os.listdir( sourceDir )
|
|
|
+ files = os.listdir(sourceDir)
|
|
|
for file_ in files:
|
|
|
- if not regexpr.match( file_ ): continue
|
|
|
+ if not regexpr.match(file_): continue
|
|
|
|
|
|
sfile = SourceFile()
|
|
|
|
|
|
- (fname_wo_ext, ext) = os.path.splitext( file_ )
|
|
|
+ (fname_wo_ext, ext) = os.path.splitext(file_)
|
|
|
sfile.cppFile = sourceDir + "/" + file_
|
|
|
sfile.objFile = fname_wo_ext + ".o"
|
|
|
|
|
|
# search all the source files and resolve conflicts in .o
|
|
|
for sfile1 in sourceFiles:
|
|
|
if sfile1.objFile == sfile.objFile:
|
|
|
- print( "There is a naming conflict between \"" + sfile1.cppFile + "\" and \"" + sfile.cppFile + "\" but dont worry." )
|
|
|
+ print("There is a naming conflict between \"" + sfile1.cppFile + "\" and \"" + sfile.cppFile + "\" but dont worry.")
|
|
|
random.seed()
|
|
|
sfile.objFile = str(random.randint(1,99)) + "." + sfile.objFile;
|
|
|
|
|
|
- sourceFiles.append( sfile )
|
|
|
+ sourceFiles.append(sfile)
|
|
|
|
|
|
|
|
|
# now the precompiled headers
|
|
|
phFiles = []
|
|
|
for header in precompiledHeaders:
|
|
|
sFile = SourceFile()
|
|
|
- (fnameWoExt, ext) = os.path.splitext( header )
|
|
|
+ (fnameWoExt, ext) = os.path.splitext(header)
|
|
|
sFile.cppFile = header
|
|
|
sFile.objFile = os.path.basename(fnameWoExt) + ".gch"
|
|
|
- phFiles.append( sFile )
|
|
|
+ phFiles.append(sFile)
|
|
|
|
|
|
|
|
|
# build the string
|
|
|
@@ -188,8 +188,8 @@ masterStr += "\t@echo All Done!\n\n"
|
|
|
|
|
|
|
|
|
for header in phFiles:
|
|
|
- # getCommandOutput( compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile )
|
|
|
- dependStr = getCommandOutput( compiler + " -MM " + compilerFlags + " " + header.cppFile + " -MT " + header.objFile )
|
|
|
+ # getCommandOutput(compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile)
|
|
|
+ dependStr = getCommandOutput(compiler + " -MM " + compilerFlags + " " + header.cppFile + " -MT " + header.objFile)
|
|
|
masterStr += dependStr
|
|
|
masterStr += "\t@echo Pre-compiling header " + header.cppFile + "...\n"
|
|
|
masterStr += "\t@$(CXX) $(INCPATH) $(PHFLAGS) " + header.objFile + "\n\n"
|
|
|
@@ -197,7 +197,7 @@ for header in phFiles:
|
|
|
|
|
|
# write source file target
|
|
|
threadsNum = os.sysconf('SC_NPROCESSORS_ONLN')
|
|
|
-print( "I will invoke %d threads to make the dependencies..." % threadsNum )
|
|
|
+print("I will invoke %d threads to make the dependencies..." % threadsNum)
|
|
|
num = len(sourceFiles);
|
|
|
itemsPerThread = num // threadsNum;
|
|
|
|
|
|
@@ -207,9 +207,9 @@ for i in range(0, threadsNum):
|
|
|
end = num
|
|
|
else:
|
|
|
end = begin + itemsPerThread
|
|
|
- thread = TargetThread( i, range( int(begin), int(end) ) )
|
|
|
+ thread = TargetThread(i, range(int(begin), int(end)))
|
|
|
thread.start()
|
|
|
- threadList.append( thread )
|
|
|
+ threadList.append(thread)
|
|
|
|
|
|
for thread in threadList:
|
|
|
thread.join()
|
|
|
@@ -219,7 +219,7 @@ for thread in threadList:
|
|
|
|
|
|
#for source_file in sourceFiles:
|
|
|
#masterStr += source_file.fname_wo_ext + ".o: " + source_file.path + source_file.fname_wo_ext + ".cpp"
|
|
|
- #masterStr += getCommandOutput( compiler + " -M " + compilerFlags + " " + source_file.path + "/" + source_file.fname )
|
|
|
+ #masterStr += getCommandOutput(compiler + " -M " + compilerFlags + " " + source_file.path + "/" + source_file.fname)
|
|
|
#masterStr += "\t@echo Compiling " + source_file.fname + "...\n"
|
|
|
#masterStr += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.path + "/" + source_file.fname + "\n\n"
|
|
|
|
|
|
@@ -232,6 +232,6 @@ masterStr += "\trm -f $(EXECUTABLE)\n\n"
|
|
|
|
|
|
|
|
|
# write file
|
|
|
-f = open( outputMakefile, "w" )
|
|
|
-f.write( masterStr )
|
|
|
-print( "File \"" + outputMakefile + "\" created!" )
|
|
|
+f = open(outputMakefile, "w")
|
|
|
+f.write(masterStr)
|
|
|
+print("File \"" + outputMakefile + "\" created!")
|