From 337139cacb8716dba495281fa5117c6fb3d345dd Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 9 Feb 2017 09:42:16 -0600 Subject: [PATCH] S_overrides.mk is included twice when building #360 A different approach. Instead of trying to limit the number of times S_overrides.mk is included, combine the makefiles so only one call to make is made. --- bin/trick-CP | 110 ++++++++++++++++-- libexec/trick/convert_swig | 5 +- libexec/trick/make_makefile_src | 14 --- libexec/trick/make_makefile_swig | 34 +++--- share/trick/makefiles/Makefile.common | 7 ++ share/trick/makefiles/trickify.mk | 4 +- .../Interface_Code_Gen/FindTrickICG.cpp | 10 +- 7 files changed, 137 insertions(+), 47 deletions(-) diff --git a/bin/trick-CP b/bin/trick-CP index 66457e4e..39a64b47 100755 --- a/bin/trick-CP +++ b/bin/trick-CP @@ -52,13 +52,108 @@ ifndef TRICK_HOME export TRICK_HOME := SUB_TRICK_HOME endif --include ${TRICK_HOME}/share/trick/makefiles/Makefile.sim --include S_overrides.mk +ifneq ($(wildcard ${TRICK_HOME}/share/trick/makefiles/Makefile.common),) +include ${TRICK_HOME}/share/trick/makefiles/Makefile.common -ifndef CLEAN_RULES_DEFINED -no_makefile_sim: - @echo ${TRICK_HOME}/share/trick/makefiles/Makefile.sim not found - exit -1 +ifndef TRICK_VERBOSE_BUILD + PRINT_CP = $(info $(call COLOR,Running) configuration_processor) + PRINT_ICG = $(info $(call COLOR,Running) ICG) + PRINT_S_DEF_DEPS = $(info $(call COLOR,Tracing) S_define) + PRINT_CONVERT_SWIG = $(info $(call COLOR,Running) convert_swig) + PRINT_MAKEFILE_SRC = $(info $(call COLOR,Writing) Makefile_src) + PRINT_MAKEFILE_SWIG = $(info $(call COLOR,Writing) Makefile_swig) +endif + +all test: $(TRICK_STATIC_LIB) S_source.hh \ + build/Makefile_io_src \ + build/Makefile_src \ + build/Makefile_swig \ + build/convert_swig_last_run \ + S_main + +build: + @mkdir $@ + +debug: all +debug: TRICK_CPFLAGS += --debug + +$(TRICK_STATIC_LIB): + $(info Cannot find $@. Please build Trick for this platform.) + @exit -1 + +# CP creates S_source.hh required for ICG and SWIG processing +S_source.hh build/S_define.lib_deps: S_define | build + $(PRINT_CP) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor $(TRICK_CPFLAGS) + $(PRINT_S_DEF_DEPS) + $(ECHO_CMD)$(TRICK_CPPC) $(TRICK_SFLAGS) $(TRICK_SYSTEM_SFLAGS) -M -MT S_source.hh -MF build/S_define.deps -x c++ S_define + +# Automatic and manual ICG rules +build/Makefile_io_src: | S_source.hh build + $(PRINT_ICG) + $(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} S_source.hh + +ICG: + $(PRINT_ICG) + $(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} S_source.hh + +force_ICG: + $(PRINT_ICG) + $(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -f -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} S_source.hh + +# Create makefile for source code +build/Makefile_src: | build/Makefile_io_src build/S_define.lib_deps + $(PRINT_MAKEFILE_SRC) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $? + +# Create makefile for SWIG code +build/Makefile_swig: | build/Makefile_io_src + $(PRINT_MAKEFILE_SWIG) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_swig $? + +# Automatic and manual convert_swig rules +build/convert_swig_last_run: | build/Makefile_swig + $(PRINT_CONVERT_SWIG) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} + @touch $@ + +convert_swig: + $(PRINT_CONVERT_SWIG) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} + @touch build/convert_swig_last_run + +# Force S_define_exp to be remade each time this rule runs +.PHONY: S_define_exp + +S_define_exp: + $(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} $(TRICK_SYSTEM_SFLAGS) S_define > $@ + +help: + @echo -e "\ +Simulation make options:\n\ + make [debug] [TRICK_VERBOSE_BUILD=1] - Makes everything: S_main and S_sie.resource\n\ + make sie - Builds the S_sie.resource file.\n\ + make clean - Removes all object files in simulation directory\n\ + make spotless - Performs a clean\n\ + make apocalypse - Performs a clean" + +CLEAN_TARGETS = tidy clean spotless distclean apocalypse +ifeq ($(findstring ${MAKECMDGOALS},$(CLEAN_TARGETS)),) +-include S_overrides.mk +-include build/S_define.deps +-include build/Makefile_src +-include build/Makefile_src_deps +-include build/Makefile_io_src +-include build/Makefile_swig +-include build/Makefile_ICG +-include build/Makefile_convert_swig +-include build/Makefile_src_deps +endif + +else +all: + $(error error with TRICK_HOME, cannot find ${TRICK_HOME}/share/trick/makefiles/Makefile.common) +endif tidy: -rm -f S_source.hh S_sie.resource @@ -70,7 +165,6 @@ clean: tidy -rm -f DP_Product/DP_rt_frame DP_Product/DP_rt_itimer -rm -f DP_Product/DP_rt_jobs DP_Product/DP_rt_timeline DP_Product/DP_mem_stats -rm -rf build trick - @ echo "Removed build directory" spotless: clean @@ -79,4 +173,4 @@ distclean: clean apocalypse: distclean @echo "I love the smell of napalm in the morning" -endif + diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index f07942db..712055bb 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -146,7 +146,7 @@ if ( scalar @ARGV == 0 ) { $swig_dir = dirname($f) ; $swig_dir = "build/$swig_dir" ; - $swig_file = "$swig_dir/${base_file}.i" ; + $swig_file = "$swig_dir/py_${base_file}.i" ; #print "$swig_file\n" ; if ( -e $swig_file ) { @@ -275,6 +275,7 @@ sub process_file() { if ( $exclude == 0 ) { $file_name =~ s/\.[^\.]+\"/\.i\"/ ; + $file_name = dirname($file_name) . "/py_" . basename($file_name) ; } $contents .= "\%import $file_name\n" ; } else { @@ -301,7 +302,7 @@ sub process_file() { $out_file = basename($f) ; $out_file =~ s/\.h.*$/\.i/ ; - $out_file = "$out_dir/$out_file" ; + $out_file = "$out_dir/py_$out_file" ; if ( ! -e $out_dir ) { make_path($out_dir) ; diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src index 669e5104..6a6a95ac 100755 --- a/libexec/trick/make_makefile_src +++ b/libexec/trick/make_makefile_src @@ -227,14 +227,6 @@ print MAKEFILE # ################################################################################ -include \${TRICK_HOME}/share/trick/makefiles/Makefile.common - -S_MAIN = S_main_\${TRICK_HOST_CPU}.exe -ifeq (\$(MAKECMDGOALS), test) - TRICK_HOST_CPU := \$(shell \$(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)_test - S_MAIN = T_main_\${TRICK_HOST_CPU}.exe -endif - ifndef TRICK_VERBOSE_BUILD PRINT_COMPILE = \$(info \$(call COLOR,Compiling) \$<) PRINT_EXE_LINK = \$(info \$(call COLOR,Linking) \$@) @@ -336,12 +328,6 @@ foreach $k ( sort keys %files_by_dir ) { } } -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 open MAKEFILEDEPS, ">build/Makefile_src_deps" or die "Could not open build/Makefile_src_deps" ; print MAKEFILEDEPS "build/Makefile_src:" ; diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index addc2a0e..d0ca7c91 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -166,7 +166,7 @@ sub make_swig_makefile() { open MAKEFILE , ">build/Makefile_swig" or return ; 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 PY_LINK_LIST "build/top.o\n" ; print MAKEFILE "SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers @@ -179,17 +179,20 @@ ifndef TRICK_VERBOSE_BUILD PRINT_COMPILE_SWIG = \$(info \$(call COLOR,Compiling) \$<) endif -SWIG_OBJECTS =" ; +SWIG_I =" ; foreach my $f ( @files_to_process ) { my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ; my ($swig_f) = $f ; $swig_object_dir = dirname($f) ; ($swig_file_only) = ($f =~ /([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx|\.hpp)$/) ; - print MAKEFILE" \\\n build$swig_object_dir/py_${swig_file_only}.o" ; + print MAKEFILE" \\\n build$swig_object_dir/py_${swig_file_only}.i" ; } + print MAKEFILE "\\\n $swig_src_dir/top.i\n" ; + print MAKEFILE "\nSWIG_SRC = \$(subst .i,.cpp,\$(SWIG_I))\n" ; + print MAKEFILE "\nSWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC))\n" ; + print MAKEFILE "OTHER_SWIG_OBJECTS =" ; print MAKEFILE "\\\n $swig_src_dir/init_swig_modules.o" ; - print MAKEFILE "\\\n $swig_src_dir/py_top.o\n" ; print MAKEFILE " TRICK_FIXED_PYTHON = \\ @@ -202,12 +205,11 @@ TRICK_FIXED_PYTHON = \\ $swig_sim_dir/exception.py " ; - my %swig_dirs ; my %python_modules ; $ii = 0 ; foreach my $f ( @files_to_process ) { - my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ; + my ($swig_module_dir , $swig_file_only) ; my ($swig_f) = $f ; # TODO: Add back python modules @@ -224,7 +226,6 @@ TRICK_FIXED_PYTHON = \\ push @{$python_modules{"root"}} , $f ; # } - my $md5_sum = md5_hex($f) ; # check if .sm file was accidentally ##included instead of #included if ( rindex($swig_f,".sm") != -1 ) { #trick_print($$sim_ref{fh}, "\nError: $swig_f should be in a #include not a ##include \n\n", "title_red", $$sim_ref{args}{v}) ; @@ -233,11 +234,6 @@ TRICK_FIXED_PYTHON = \\ $swig_f =~ s/([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx|\.hpp)$/$1.i/ ; $swig_file_only = $1 ; my $link_py_obj = "build" . dirname($swig_f) . "/py_${swig_file_only}.o"; - $swig_f = "build" . $swig_f ; - $swig_dir = dirname($swig_f) ; - $swig_object_dir = dirname($swig_f) ; - $swig_dirs{$swig_dir} = 1 ; - print PY_LINK_LIST "$link_py_obj\n" ; $ii++ ; @@ -256,7 +252,7 @@ TRICK_FIXED_PYTHON = \\ print MAKEFILE " LINK_LISTS += \$(LD_FILELIST)build/py_link_list -\$(S_MAIN): \$(SWIG_OBJECTS) +\$(S_MAIN): \$(SWIG_OBJECTS) \$(OTHER_SWIG_OBJECTS) #\$(SWIG_OBJECTS): TRICK_SYSTEM_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls @@ -265,17 +261,17 @@ S_main: \$(TRICK_FIXED_PYTHON) \$(TRICK_FIXED_PYTHON): $swig_sim_dir/\% : \${TRICK_HOME}/share/trick/swig/\% \t\$(ECHO_CMD)/bin/cp -f \$< \$@ -py_%.cpp: %.i +\$(SWIG_SRC) : %.cpp: %.i \t\$(PRINT_SWIG) \t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir trick -o \$@ \$< -\$(SWIG_OBJECTS): %.o: %.cpp +\$(SWIG_I) : build/convert_swig_last_run + +\$(SWIG_OBJECTS) \$(OTHER_SWIG_OBJECTS): %.o: %.cpp \t\$(PRINT_COMPILE_SWIG) \t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) \$(SWIG_CFLAGS) -c -o \$@ \$< -# We don't really need to keep these, but make prints out a huge \"rm -f\" when it automatically -# deletes intermediate files, and I don't know how to silence that. -.PRECIOUS: py_%.cpp" ; +" ; close MAKEFILE ; close PY_LINK_LIST ; @@ -294,7 +290,7 @@ py_%.cpp: %.i print TOPFILE "\%{\n#include \"../S_source.hh\"\n\n" ; print TOPFILE @instances ; print TOPFILE "\n\%}\n\n" ; - print TOPFILE "\%import \"build$wd/S_source.i\"\n\n" ; + print TOPFILE "\%import \"build$wd/py_S_source.i\"\n\n" ; print TOPFILE @instances ; close TOPFILE ; diff --git a/share/trick/makefiles/Makefile.common b/share/trick/makefiles/Makefile.common index b8176f51..653f8e94 100644 --- a/share/trick/makefiles/Makefile.common +++ b/share/trick/makefiles/Makefile.common @@ -58,11 +58,18 @@ export TRICK_SYSTEM_SFLAGS export TRICK_SYSTEM_LDFLAGS export SWIG_FLAGS +S_MAIN = S_main_${TRICK_HOST_CPU}.exe +ifeq ($(MAKECMDGOALS), test) + TRICK_HOST_CPU := $(shell $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)_test + S_MAIN = T_main_${TRICK_HOST_CPU}.exe +endif + IO_SRC_DIR := io_src/ OBJ_DIR := object_${TRICK_HOST_CPU} TRICK_STATIC_LIB := ${TRICK_LIB_DIR}/libtrick.a TRICK_RANLIB = + ifndef CONFIG_MK ifneq ($(MAKECMDGOALS), clean) $(error Please run $(TRICK_HOME)/configure before running make) diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index ee01cfef..4b24ff12 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -78,7 +78,7 @@ TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../../..) ifneq ($(wildcard build),) OBJECTS := $(shell find build -name "*.i") - OBJECTS := $(join $(dir $(OBJECTS)),$(patsubst %.i,py_%.cpp,$(notdir $(OBJECTS)))) + OBJECTS := $(join $(dir $(OBJECTS)),$(patsubst %.i,%.cpp,$(notdir $(OBJECTS)))) OBJECTS += $(shell find build -name "*.cpp") OBJECTS := $(OBJECTS:.cpp=.o) endif @@ -158,7 +158,7 @@ icg: $(dir $(TRICKIFY_LIB_NAME)) $(TRICKIFY_PYTHON_DIR): @mkdir -p $@ -py_%.cpp: %.i | $(TRICKIFY_PYTHON_DIR) +%.cpp: %.i | $(TRICKIFY_PYTHON_DIR) $(info $(call COLOR,SWIGing) $<) @$(SWIG) $(TRICK_INCLUDE) $(TRICK_DEFINES) $(TRICK_VERSIONS) $(SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,325,362,389,401,451 -outdir $(TRICKIFY_PYTHON_DIR) -o $@ $< diff --git a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp index 7c653a44..9f3d5a42 100644 --- a/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FindTrickICG.cpp @@ -54,8 +54,14 @@ void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRan if ( print_msgs ) { print_header() ; std::string loc_str = Loc.printToString(ci.getSourceManager()) ; - std::cout << color(WARNING, - std::string("Warning: TRICK_ICG used in preprocessor conditional ") + loc_str) << std::endl ; + char * rpath = almostRealPath(loc_str.c_str()) ; + if ( rpath ) { + std::cout << color(WARNING, + std::string("Warning: TRICK_ICG used in preprocessor conditional ") + rpath) << std::endl ; + } else { + std::cout << color(WARNING, + std::string("Warning: TRICK_ICG used in preprocessor conditional ") + loc_str) << std::endl ; + } } } }