2
0
Эх сурвалжийг харах

The genmakefile.py now has support for conflicting object files.
You can now have the same name to multiple .cpp files without conflicts in the build process

Panagiotis Christopoulos Charitos 16 жил өмнө
parent
commit
6a1d5ece15

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 74 - 937
build/debug/Makefile


+ 3 - 3
build/debug/gen.cfg.py

@@ -1,9 +1,9 @@
-include_paths = [ "../../src/math/", "../../src/tokenizer/", "../../src/uncategorized/", "../../src/", "../../src/renderer/", "../../src/scene/", "../../src/resources/", "../../src/utility/" ]
+include_paths = [ "../../src/math/", "../../src/tokenizer/", "../../src/uncategorized/", "../../src/", "../../src/renderer/", "../../src/scene/", "../../src/ui/", "../../src/resources/", "../../src/utility/" ]
 #precompiled_headers = ["../../src/uncategorized/common.h"]
 precompiled_headers = []
 project_name = "AnKi"
 compiler = "g++"
 common_flags = ""
-compiler_flags = "-c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -pipe -O0 -g3 -pg `sdl-config --cflags` -D_DEBUG_ -D_TERMINAL_COLORING_ -D_PLATFORM_LINUX_ -I../../../glew/include"
+compiler_flags = "-c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -pipe -O0 -g3 -pg `sdl-config --cflags` -D_DEBUG_ -D_TERMINAL_COLORING_ -D_PLATFORM_LINUX_"
 precompiled_headers_flags = "-x c++-header"
-linker_flags = "-lGL -lGLU -lSDL_image `sdl-config --static-libs` -ljpeg -lGLEW -L../../../glew/lib"
+linker_flags = "-lGL -lGLU -lSDL_image `sdl-config --static-libs` -ljpeg -lGLEW"

+ 93 - 44
build/genmakefile.py

@@ -1,6 +1,5 @@
-#!/usr/bin/python
-print( "Starting..." )
-import sys, os, fnmatch, compiler
+#!/usr/bin/python3.1
+import sys, os, fnmatch, random
 from threading import Thread
 
 
@@ -12,7 +11,7 @@ def GetCommandOutput( command ):
 	data = child.read()
 	err = child.close()
 	if err:
-		print( command + " failed" )
+		print( "GetCommandOutput failed:\n" + command )
 		exit( 0 )
 	return data
 
@@ -20,8 +19,6 @@ def GetCommandOutput( command ):
 #======================================================================================================================================
 # Threads                                                                                                                             =
 #======================================================================================================================================
-THREADS_NUM = 2
-
 thread_list = []
 
 class target_thread_t( Thread ):
@@ -33,50 +30,100 @@ class target_thread_t( Thread ):
 		
 	def run( self ):
 		for i in self.range:
-			source_file = source_files[i]			
-			self.out_str += GetCommandOutput( compiler + " -M " + compiler_flags + " " + source_file.path + "/" + source_file.fname )
-			self.out_str += "\t@echo Compiling " + source_file.fname + "...\n"
-			self.out_str += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.path + "/" + source_file.fname + "\n\n"
+			source_file = source_files[i]
+			self.out_str += GetCommandOutput( compiler + " -MM " + compiler_flags + " " + source_file.cpp_file + " -MT" + source_file.obj_file )
+			self.out_str += "\t@echo Compiling " + source_file.cpp_file + "...\n"
+			self.out_str += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.cpp_file + " -o " + \
+			                source_file.obj_file + "\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) )
 
 
-# read config
-if len(sys.argv) == 2:
-	f = open( sys.argv[1] )
-else:
-	f = open( "gen.cfg.py" )
+#======================================================================================================================================
+# source_file_t                                                                                                                       =
+#======================================================================================================================================
+class source_file_t:
+	def __init__( self ):	
+		self.cpp_file = ""
+		self.obj_file = ""
+
+
+#======================================================================================================================================
+# main                                                                                                                                =
+#======================================================================================================================================
+
+# Read the arguments
+input_cfgfile = ""
+output_makefile = ""
+
+i = 0
+while 1:
+	i = i+1
+	if i>=len(sys.argv): break
+
+	arg = sys.argv[i]
+	if arg == "-h" or arg == "-help" or arg == "--help":
+		print( "Makefile generator by GODlike" )
+		print( "usage: genmakefile.py [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":
+		input_cfgfile = sys.argv[i+1]
+		i = i+1
+	elif arg == "-o":
+		output_makefile = sys.argv[i+1]
+		i = i+1
+	else:
+		print( "Unrecognized argument " + arg )
 	
-str = ""
-for line in f.readlines():
-	str += line + "\n"
-eval( compiler.compile( str, "err.log", "exec" ) )
 
+if output_makefile == "":
+	output_makefile = "Makefile"
+if input_cfgfile == "":
+	input_cfgfile = "gen.cfg.py"
 
-# class source_file_t
-class source_file_t:
-	def __init__( self, fullfname ):
-		(path, fname) = os.path.split( fullfname )
-		(fname_wo_ext, ext) = os.path.splitext( fname )
-		ext = ext[:-len(ext)]
-		
-		self.path = path
-		self.fname = fname
-		self.fname_wo_ext = fname_wo_ext
-		self.ext = ext
 
-source_files = []
-ph_files = []
+# Check if cfg exists
+if not os.path.exists( input_cfgfile ):
+	print( "File " + input_cfgfile + " doesn't exist" )
+	exit(0)
+
+
+# compile the cfg
+source = ""
+f = open( input_cfgfile, "r" )
+for line in f.readlines():
+	source += line
+	
+exec( compile( source, input_cfgfile, "exec" ) )
 
 
 # find the cpp files
+source_files = []
 for source_dir in include_paths:
 	files = os.listdir( source_dir )
 	for file_ in fnmatch.filter( files, "*.cpp" ):
-		source_files.append( source_file_t( source_dir + file_ ) )
+		sfile = source_file_t()
+		
+		(fname_wo_ext, ext) = os.path.splitext( file_ )
+		sfile.cpp_file = source_dir + "/" + file_
+		sfile.obj_file = fname_wo_ext + ".o"
 		
+		# search all the source files and resolve conflicts in .o
+		for sfile1 in source_files:
+			if sfile1.obj_file == sfile.obj_file:
+				print( "There is a conflict with \"" + sfile1.cpp_file + "\" and \"" + sfile.cpp_file + "\" but dont worry." )
+				random.seed()
+				sfile.obj_file = str(random.randint(1,99)) + "." + sfile.obj_file;
+	
+		source_files.append( sfile )
+	
 
 # now the precompiled headers
+ph_files = []
 for header in precompiled_headers:
 	ph_files.append( source_file_t( header ) )
 
@@ -99,12 +146,12 @@ master_str += "\n"
 
 master_str += "SOURCES = "
 for source_file in source_files:
-	master_str += source_file.path + "/" + source_file.fname_wo_ext + ".cpp "
+	master_str += source_file.cpp_file + " "
 master_str += "\n"
 
 master_str += "OBJECTS = "
 for source_file in source_files:
-	master_str += source_file.fname_wo_ext + ".o "
+	master_str += source_file.obj_file + " "
 master_str += "\n"
 
 master_str += "PRECOMPILED_HEADERS = "
@@ -121,20 +168,22 @@ master_str += "\t@echo All Done!\n\n"
 
 
 for header in ph_files:
-	depend_str = GetCommandOutput( compiler + " -M " + compiler_flags + " " + precompiled_headers_flags + " " + header.path + "/" + header.fname )
+	depend_str = GetCommandOutput( compiler + " -MM " + compiler_flags + " " + precompiled_headers_flags + " " + header.path + "/" + 
+	                               header.fname )
 	master_str += depend_str.replace( header.fname_wo_ext + ".o", header.fname + ".gch" )
 	master_str += "\t@echo Pre-compiling header " + header.fname + "...\n"
 	master_str += "\t@$(CXX) $(INCPATH) $(PHFLAGS) " + header.path + "/" + header.fname + "\n\n"
 
 
 # write source file target
-print( "I will invoke %d threads to make the dependencies..." % THREADS_NUM )
+threads_num = os.sysconf('SC_NPROCESSORS_ONLN')
+print( "I will invoke %d threads to make the dependencies..." % threads_num )
 num = len(source_files);
-items_per_thread = num // THREADS_NUM;
+items_per_thread = num // threads_num;
 
-for i in range(0, THREADS_NUM):
+for i in range(0, threads_num):
 	begin = i*items_per_thread
-	if i == THREADS_NUM-1:
+	if i == threads_num-1:
 		end = num
 	else:
 		end = begin + items_per_thread	
@@ -153,8 +202,8 @@ for thread in thread_list:
 	#master_str += GetCommandOutput( compiler + " -M " + compiler_flags + " " + source_file.path + "/" + source_file.fname )
 	#master_str += "\t@echo Compiling " + source_file.fname + "...\n"
 	#master_str += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.path + "/" + source_file.fname + "\n\n"
-	
-	
+
+
 master_str += "clean:\n"
 master_str += "\trm -f *.o\n"
 master_str += "\trm -f *.gch\n"
@@ -163,6 +212,6 @@ master_str += "\trm -f $(EXECUTABLE)\n\n"
 
 
 # write file
-f = open( "Makefile", "w" )
+f = open( output_makefile, "w" )
 f.write( master_str )
-print( "File \"Makefile\" created!" )
+print( "File \"" + output_makefile + "\" created!" )

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 86 - 968
build/release/Makefile


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 140 - 869
build/release_llvm/Makefile


+ 2 - 2
build/release_llvm/gen.cfg.py

@@ -1,8 +1,8 @@
-include_paths = [ "../../src/math/", "../../src/renderer/", "../../src/tokenizer/", "../../src/", "../../src/uncategorized/" ]
+include_paths = [ "../../src/math/", "../../src/tokenizer/", "../../src/uncategorized/", "../../src/", "../../src/renderer/", "../../src/scene/", "../../src/resources/", "../../src/utility/", "../../src/ui/" ]
 precompiled_headers = []
 project_name = "AnKi"
 compiler = "/usr/lib/llvm/llvm/gcc-4.2/bin/llvm-g++"
-common_flags = ""
+common_flags = "-emit-llvm"
 compiler_flags = "-c `sdl-config --cflags` -O3 -D_TERMINAL_COLORING_ -D_PLATFORM_LINUX_"
 precompiled_headers_flags = ""
 linker_flags = "-lGL -lGLU -lGLEW -lSDL_image `sdl-config --static-libs` -ljpeg -lgomp"

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно