From 2fb06cf133c569870adeb5c41e8a29d9f08e1491 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Tue, 18 Oct 2016 13:06:42 -0500 Subject: [PATCH] Got rid of the individual io, py, and model conglomerate objects #326 Link all of the objects as part of the S_MAIN target using the link lists. Renamed some variables and files to make them more self-descriptive. --- libexec/trick/make_makefile_src | 46 +++++++----------- libexec/trick/make_makefile_swig | 29 +++++------ .../Interface_Code_Gen/PrintAttributes.cpp | 48 +++++++------------ 3 files changed, 45 insertions(+), 78 deletions(-) diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src index 5eb9d21b..2c96790d 100755 --- a/libexec/trick/make_makefile_src +++ b/libexec/trick/make_makefile_src @@ -235,12 +235,10 @@ ifeq (\$(MAKECMDGOALS), test) S_MAIN = T_main_\${TRICK_HOST_CPU}.exe endif -LIB_DIR = build/lib - ifndef TRICK_VERBOSE_BUILD PRINT_COMPILE = \$(info \$(call COLOR,Compiling) \$<) - PRINT_INC_LINK = \$(info \$(call COLOR,Linking) model objects) PRINT_EXE_LINK = \$(info \$(call COLOR,Linking) \$@) + PRINT_SIE = \$(info \$(call COLOR,Writing) \$@) ifeq (\$(MAKECMDGOALS), all) \$(info \$(call COLOR,Building with the following compilation flags:)) \$(info TRICK_CFLAGS = \$(TRICK_CFLAGS)) @@ -248,33 +246,35 @@ ifndef TRICK_VERBOSE_BUILD endif endif -S_OBJECT_FILES = build/S_source.o +S_OBJECTS = build/S_source.o -\$(S_OBJECT_FILES): | \$(LIB_DIR)\n\n" ; +" ; my %object_files_by_type ; my %model_build_dirs ; $num_inc_objs = 0 ; # List out all of the object files and put the list in a file that we can pass to the linker. # Passing all of them directly to the linker in the command line can exceed the line limit. -open LINK_MODEL_OBJS, ">build/link_model_objs" or die "Could not open build/link_model_objs" ; +open MODEL_LINK_LIST, ">build/model_link_list" or die "Could not open build/model_link_list" ; print MAKEFILE "MODEL_OBJECTS =" ; foreach $k ( sort keys %files_by_dir ) { foreach my $ext ( qw{ c C cc cxx cpp c++ } ) { if ( scalar @{$files_by_dir{$k}{$ext}} ne 0 ) { foreach $f ( @{$files_by_dir{$k}{$ext}} ) { print MAKEFILE " \\\n build$k/$files_by_dir{$k}{src_dir}$f" . "o" ; - print LINK_MODEL_OBJS "build$k/$files_by_dir{$k}{src_dir}$f" . "o\n" ; + print MODEL_LINK_LIST "build$k/$files_by_dir{$k}{src_dir}$f" . "o\n" ; } $num_inc_objs++ ; } } } -close LINK_MODEL_OBJS ; +close MODEL_LINK_LIST ; # Write out the compile rules for each type of file. print MAKEFILE " +LINK_LISTS += \$(LD_FILELIST)build/model_link_list + # These targets should have an order-only dependency on their directories, which would require # moving them to a .SECONDEXPANSION section and would complicate the rules. However, these # directories appear to be created as part of the read_lib_deps function, so I'm leaving it out @@ -293,13 +293,7 @@ endef EXTENSIONS := C cc cpp cxx c++ \$(foreach EXTENSION,\$(EXTENSIONS),\$(eval \$(call compile_rule,\$(EXTENSION)))) --include \$(MODEL_OBJECTS:.o=.d) - -OBJECTS = \$(LIB_DIR)/models.o - -\$(LIB_DIR)/models.o: \$(MODEL_OBJECTS) -\t\$(PRINT_INC_LINK) -\t\$(ECHO_CMD)\$(LD) \$(LD_PARTIAL) -o \$@ \$(LD_FILELIST)build/link_model_objs" ; +-include \$(MODEL_OBJECTS:.o=.d)" ; # print out the libraries we link print MAKEFILE "\n\nREAD_ONLY_LIBS ="; @@ -318,18 +312,9 @@ test: all S_main: \$(S_MAIN) S_sie.resource \t\$(info Trick Build Process Complete) -\$(S_MAIN): \${TRICK_STATIC_LIB} \$(OBJECTS) \$(S_OBJECT_FILES) +\$(S_MAIN): \$(TRICK_STATIC_LIB) \$(S_OBJECTS) \$(MODEL_OBJECTS) \t\$(PRINT_EXE_LINK) -\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_LDFLAGS) -o \$@ \\ -\t\t\$(S_OBJECT_FILES) \$(LIB_DIR)/models.o \$(LINK_OBJECTS)\\ -\t\t\${TRICK_USER_LINK_LIBS} \${READ_ONLY_LIBS} \\ -\t\t\$(LD_WHOLE_ARCHIVE) \${TRICK_LIBS} \$(LD_NO_WHOLE_ARCHIVE)\\ -\t\t\${TRICK_EXEC_LINK_LIBS} - -\$(OBJECTS): | \$(LIB_DIR) - -\$(LIB_DIR): -\t\@mkdir -p \$@ +\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_LDFLAGS) -o \$@ \$(S_OBJECTS) \$(LINK_LISTS) \$(TRICK_USER_LINK_LIBS) \$(READ_ONLY_LIBS) \$(LD_WHOLE_ARCHIVE) \$(TRICK_LIBS) \$(LD_NO_WHOLE_ARCHIVE) \$(TRICK_EXEC_LINK_LIBS) build/S_source.o: build/S_source.cpp \t\$(PRINT_COMPILE) @@ -340,7 +325,7 @@ build/S_source.o: build/S_source.cpp sie: S_sie.resource S_sie.resource: \$(S_MAIN) -\t\$(info Writing S_sie.resource) +\t\$(PRINT_SIE) \t\$(ECHO_CMD)./\$(S_MAIN) sie\n" ; # write out the override files we have read in @@ -351,9 +336,10 @@ foreach $k ( sort keys %files_by_dir ) { } } -print MAKEFILE "\n-include build/Makefile_io_src\n" ; -print MAKEFILE "include build/Makefile_swig\n" ; -print MAKEFILE "-include S_overrides.mk\n" ; +print MAKEFILE " +-include build/Makefile_io_src +include build/Makefile_swig +-include S_overrides.mk" ; close MAKEFILE ; # write out all of files we processed as dependencies to Makefile_src diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 245e2aa8..1756beb4 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -164,11 +164,12 @@ sub make_swig_makefile() { @files_to_process = sort keys %temp_hash ; open MAKEFILE , ">build/Makefile_swig" or return ; - open LINK_PY_OBJS , ">build/link_py_objs" or return ; - print LINK_PY_OBJS "build/init_swig_modules.o\n" ; - print LINK_PY_OBJS "build/py_top.o\n" ; + open PY_LINK_LIST , ">build/py_link_list" or return ; + print PY_LINK_LIST "build/init_swig_modules.o\n" ; + print PY_LINK_LIST "build/py_top.o\n" ; print MAKEFILE "SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers + ifeq (\$(IS_CC_CLANG), 1) SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized -Wno-deprecated-register endif @@ -176,14 +177,9 @@ endif ifndef TRICK_VERBOSE_BUILD PRINT_SWIG = \$(info \$(call COLOR,SWIGing) \$<) PRINT_COMPILE_SWIG = \$(info \$(call COLOR,Compiling) \$<) - PRINT_SWIG_INC_LINK = \$(info \$(call COLOR,Linking) SWIG objects) endif -SWIG_MODULE_OBJECTS = \$(LIB_DIR)/swig_python.o -OBJECTS += \$(SWIG_MODULE_OBJECTS) -LINK_OBJECTS += \$(SWIG_MODULE_OBJECTS) - -SWIG_PY_OBJECTS =" ; +SWIG_OBJECTS =" ; foreach my $f ( @files_to_process ) { my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ; @@ -242,7 +238,7 @@ TRICK_FIXED_PYTHON = \\ $swig_object_dir = dirname($swig_f) ; $swig_dirs{$swig_dir} = 1 ; - print LINK_PY_OBJS "$link_py_obj\n" ; + print PY_LINK_LIST "$link_py_obj\n" ; $ii++ ; } @@ -258,12 +254,11 @@ TRICK_FIXED_PYTHON = \\ my $wd = abs_path(cwd()) ; print MAKEFILE " -\$(S_MAIN): \$(SWIG_MODULE_OBJECTS) +LINK_LISTS += \$(LD_FILELIST)build/py_link_list -\$(SWIG_MODULE_OBJECTS): TRICK_SYSTEM_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls -\$(SWIG_MODULE_OBJECTS): \$(SWIG_PY_OBJECTS) | \$(LIB_DIR) -\t\$(PRINT_SWIG_INC_LINK) -\t\$(ECHO_CMD)\$(LD) \$(LD_PARTIAL) -o \$\@ \$(LD_FILELIST)build/link_py_objs +\$(S_MAIN): \$(SWIG_OBJECTS) + +#\$(SWIG_OBJECTS): TRICK_SYSTEM_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls S_main: \$(TRICK_FIXED_PYTHON) @@ -274,7 +269,7 @@ py_%.cpp: %.i \t\$(PRINT_SWIG) \t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir trick -o \$@ \$< -\$(SWIG_PY_OBJECTS): %.o: %.cpp +\$(SWIG_OBJECTS): %.o: %.cpp \t\$(PRINT_COMPILE_SWIG) \t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) \$(SWIG_CFLAGS) -c -o \$@ \$< @@ -283,7 +278,7 @@ py_%.cpp: %.i .PRECIOUS: py_%.cpp" ; close MAKEFILE ; - close LINK_PY_OBJS ; + close PY_LINK_LIST ; open SWIGLIB , ">build/S_library_swig" or return ; foreach my $f ( @files_to_process ) { diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 29fcb653..84b8d2f2 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -423,7 +423,7 @@ void PrintAttributes::addEmptyFiles() { void PrintAttributes::printIOMakefile() { std::ofstream makefile_io_src ; std::ofstream makefile_ICG ; - std::ofstream link_io_objs ; + std::ofstream io_link_list ; std::ofstream ICG_processed ; std::ofstream ext_lib ; unsigned int ii ; @@ -436,46 +436,33 @@ void PrintAttributes::printIOMakefile() { std::cout << color(INFO, "Writing") << " Makefile_io_src" << std::endl ; makefile_io_src.open("build/Makefile_io_src") ; - makefile_io_src << "TRICK_SYSTEM_CXXFLAGS += \\" << std::endl - << " -std=c++11 \\" << std::endl - << " -Wno-invalid-offsetof \\" << std::endl - << " -Wno-old-style-cast \\" << std::endl - << " -Wno-write-strings \\" << std::endl - << " -Wno-unused-variable" << std::endl + makefile_io_src + << "TRICK_SYSTEM_CXXFLAGS += -std=c++11 -Wno-invalid-offsetof -Wno-old-style-cast -Wno-write-strings -Wno-unused-variable" << std::endl << std::endl << "ifeq ($(IS_CC_CLANG), 0)" << std::endl << " TRICK_SYSTEM_CXXFLAGS += -Wno-unused-local-typedefs -Wno-unused-but-set-variable" << std::endl << "endif" << std::endl << std::endl - << "ifndef TRICK_VERBOSE_BUILD" << std::endl - << " PRINT_IO_INC_LINK = @echo \"$(call COLOR,Linking) IO objects\"" << std::endl - << "endif" << std::endl - << std::endl - << "IO_OBJ_FILES =" ; + << "IO_OBJECTS =" ; std::map< std::string , std::string >::iterator mit ; for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) { size_t found ; found = (*mit).second.find_last_of(".") ; - makefile_io_src << " \\\n $(CURDIR)/" << (*mit).second.substr(0,found) << ".o" ; + makefile_io_src << " \\\n " << (*mit).second.substr(0,found) << ".o" ; } - makefile_io_src << " \\\n $(CURDIR)/build/class_map.o" << std::endl + makefile_io_src << " \\\n build/class_map.o" << std::endl << std::endl - << "$(IO_OBJ_FILES): \%.o : \%.cpp" << std::endl + << "LINK_LISTS += $(LD_FILELIST)build/io_link_list" << std::endl + << std::endl + << "$(S_MAIN): $(IO_OBJECTS)" << std::endl + << std::endl + << "$(IO_OBJECTS): \%.o : \%.cpp" << std::endl << "\t$(PRINT_IO_COMPILE)" << std::endl << "\t$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c $< -o $@" << std::endl << std::endl - << "-include $(IO_OBJ_FILES:.o=.d)" << std::endl - << std::endl - << "OBJECTS += $(LIB_DIR)/io_src.o" << std::endl - << "LINK_OBJECTS += $(LIB_DIR)/io_src.o" << std::endl - << std::endl - << "$(S_MAIN): $(LIB_DIR)/io_src.o" << std::endl - << std::endl - << "$(LIB_DIR)/io_src.o : $(IO_OBJ_FILES) | $(LIB_DIR)" << std::endl - << "\t$(PRINT_IO_INC_LINK)" << std::endl - << "\t$(ECHO_CMD)$(LD) $(LD_PARTIAL) -o $@ $(LD_FILELIST)build/link_io_objs" << std::endl + << "-include $(IO_OBJECTS:.o=.d)" << std::endl << std::endl ; makefile_io_src.close() ; @@ -484,13 +471,12 @@ void PrintAttributes::printIOMakefile() { Makefile_ICG lists all headers as dependencies of Makefile_io_src causing ICG to run if any header file changes. - link_io_objs lists all io_src object files to be partially - linked into a single io_object. + io_link_list lists all io object files to be linked. ICG_process lists all header files to be used by SWIG. */ makefile_ICG.open("build/Makefile_ICG") ; - link_io_objs.open("build/link_io_objs") ; + io_link_list.open("build/io_link_list") ; ICG_processed.open("build/ICG_processed") ; makefile_ICG << "build/Makefile_io_src:" ; @@ -498,7 +484,7 @@ void PrintAttributes::printIOMakefile() { makefile_ICG << " \\\n " << (*mit).first ; size_t found ; found = (*mit).second.find_last_of(".") ; - link_io_objs << (*mit).second.substr(0,found) << ".o" << std::endl ; + io_link_list << (*mit).second.substr(0,found) << ".o" << std::endl ; ICG_processed << (*mit).first << std::endl ; } makefile_ICG.close() ; @@ -511,8 +497,8 @@ void PrintAttributes::printIOMakefile() { } ICG_processed.close() ; - link_io_objs << "build/class_map.o" << std::endl ; - link_io_objs.close() ; + io_link_list << "build/class_map.o" << std::endl ; + io_link_list.close() ; ext_lib.open("build/ICG_ext_lib") ; for ( sit = ext_lib_io_files.begin() ; sit != ext_lib_io_files.end() ; sit++ ) {