From e6ad95f493d6218dc8528969af637a114c6af04d Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Thu, 23 Feb 2017 13:26:28 -0600 Subject: [PATCH] Grand Make Dependency Graph, part 1 Refs #360 --- bin/trick-CP | 47 +++++---- libexec/trick/convert_swig | 22 +---- libexec/trick/create_top_dot_i | 21 ++++ libexec/trick/make_makefile_src | 57 ++++++----- libexec/trick/make_makefile_swig | 95 ++++++++++--------- .../Interface_Code_Gen/PrintAttributes.cpp | 15 +-- 6 files changed, 135 insertions(+), 122 deletions(-) create mode 100755 libexec/trick/create_top_dot_i diff --git a/bin/trick-CP b/bin/trick-CP index d708ebae..da3322d8 100755 --- a/bin/trick-CP +++ b/bin/trick-CP @@ -70,18 +70,18 @@ ifndef TRICK_VERBOSE_BUILD 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 +all: $(S_MAIN) S_sie.resource + $(info Trick Build Process Complete) + +test: TRICK_SYSTEM_CFLAGS += -DTRICK_UNIT_TEST +test: TRICK_SYSTEM_CXXFLAGS += -DTRICK_UNIT_TEST +test: all + +debug: TRICK_CPFLAGS += --debug +debug: all build: - @mkdir $@ - -debug: all -debug: TRICK_CPFLAGS += --debug + @mkdir -p $@ $(TRICK_STATIC_LIB): $(info Cannot find $@. Please build Trick for this platform.) @@ -95,10 +95,6 @@ S_source.hh: S_define | build $(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 @@ -107,30 +103,31 @@ 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 IO code +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} $< + # Create makefile for source code +#build/Makefile_src: build/ICG_processed build/ICG_no_found build/S_define.lib_deps build/Makefile_src: build/Makefile_io_src S_source.hh $(PRINT_MAKEFILE_SRC) $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $? # Create makefile for SWIG code +#build/Makefile_swig: build/ICG_processed build/Makefile_swig: build/Makefile_io_src $(PRINT_MAKEFILE_SWIG) - $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_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) +# Forcibly (re)create all SWIG input (.i) files. This rule is never run by the normal +# build process. +.PHONY: convert_swig +convert_swig: build/S_library_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 > $@ diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index 712055bb..2d1a5454 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -146,21 +146,10 @@ if ( scalar @ARGV == 0 ) { $swig_dir = dirname($f) ; $swig_dir = "build/$swig_dir" ; - $swig_file = "$swig_dir/py_${base_file}.i" ; + $swig_file = "$swig_dir/${base_file}_py.i" ; #print "$swig_file\n" ; - if ( -e $swig_file ) { - if ( !exists $sim{mod_date}{$f} ) { - $sim{mod_date}{$f} = (stat $f)[9] ; - } - $sim{swig_mod_date}{$f} = (stat $swig_file)[9] ; - if ( $sim{mod_date}{$f} > $sim{swig_mod_date}{$f} ) { - $out_of_date{$f} = 1 ; - } - } else { - $out_of_date{$f} = 1 ; - $sim{swig_mod_date}{$f} = 0 ; - } + $out_of_date{$f} = 1 ; } } else { #print "HERE I AM @ARGV\n" ; @@ -274,8 +263,7 @@ sub process_file() { $file_name = "\"build" . $file_name . "\"" ; if ( $exclude == 0 ) { - $file_name =~ s/\.[^\.]+\"/\.i\"/ ; - $file_name = dirname($file_name) . "/py_" . basename($file_name) ; + $file_name =~ s/\.[^\.]+\"/\_py.i\"/ ; } $contents .= "\%import $file_name\n" ; } else { @@ -300,9 +288,9 @@ sub process_file() { my $out_file ; $out_file = basename($f) ; - $out_file =~ s/\.h.*$/\.i/ ; + $out_file =~ s/\.h.*$/_py\.i/ ; - $out_file = "$out_dir/py_$out_file" ; + $out_file = "$out_dir/${out_file}" ; if ( ! -e $out_dir ) { make_path($out_dir) ; diff --git a/libexec/trick/create_top_dot_i b/libexec/trick/create_top_dot_i new file mode 100755 index 00000000..404c9940 --- /dev/null +++ b/libexec/trick/create_top_dot_i @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import os + +path = os.path.abspath(os.getcwd()) + +with open('build/CP_instances') as cp_instances: + with open('build/top.i', 'w') as top: + instances = ''.join(cp_instances.readlines()) + top.write( + '%module top\n' + '\n' + '%{\n' + '#include "../S_source.hh"\n' + '\n' + + instances + '\n' + '%}\n' + '\n' + '%import "build' + path + '/S_source_py.i"\n' + '\n' + + instances) diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src index 1229481b..d2e7565b 100755 --- a/libexec/trick/make_makefile_src +++ b/libexec/trick/make_makefile_src @@ -261,8 +261,17 @@ ifndef TRICK_VERBOSE_BUILD endif endif +# S_OBJECTS ==================================================================== + S_OBJECTS = build/S_source.o +build/S_source.o: build/S_source.cpp build/S_source.d +\t\$(PRINT_COMPILE) +\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c -o \$\@ \$\< + +build/S_source.d: ; + +-include build/S_source.d " ; my %object_files_by_type ; @@ -271,7 +280,10 @@ $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 MODEL_LINK_LIST, ">build/model_link_list" or die "Could not open build/model_link_list" ; -print MAKEFILE "MODEL_OBJECTS =" ; +print MAKEFILE " +# MODEL_OBJECTS ================================================================ + +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 ) { @@ -288,54 +300,47 @@ 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 # for now. -build/%.o : /%.c +build/%.o : /%.c build/%.d \t\$(PRINT_COMPILE) -\t\$(ECHO_CMD)\$(TRICK_CC) \$(TRICK_CFLAGS) \$(TRICK_SYSTEM_CFLAGS) -I\$( ; - close S_INSTANCE ; - open TOPFILE , ">build/top.i" or return ; - print TOPFILE "\%module top\n\n" ; - print TOPFILE "\%{\n#include \"../S_source.hh\"\n\n" ; - print TOPFILE @instances ; - print TOPFILE "\n\%}\n\n" ; - print TOPFILE "\%import \"build$wd/py_S_source.i\"\n\n" ; - print TOPFILE @instances ; - close TOPFILE ; - open INITSWIGFILE , ">build/init_swig_modules.cpp" or return ; print INITSWIGFILE "#include \n" ; print INITSWIGFILE "#if PY_VERSION_HEX >= 0x03000000\n" ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index d1125c06..e8237134 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -454,16 +454,17 @@ void PrintAttributes::printIOMakefile() { makefile_io_src << " \\\n build/class_map.o" << std::endl << std::endl - << "LINK_LISTS += $(LD_FILELIST)build/io_link_list" << std::endl + << "$(IO_OBJECTS): \%.o : \%.cpp \%.d" << std::endl + << "\t$(PRINT_COMPILE)" << std::endl + << "\t$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c -o $@ $<" << std::endl + << std::endl + << "$(IO_OBJECTS:.o=.d): \%.d: ;" << std::endl + << std::endl + << "-include $(IO_OBJECTS:.o=.d)" << std::endl << std::endl << "$(S_MAIN): $(IO_OBJECTS)" << std::endl << std::endl - << "$(IO_OBJECTS): \%.o : \%.cpp" << std::endl - << "\t$(PRINT_COMPILE)" << std::endl - << "\t$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c $< -o $@" << std::endl - << std::endl - << "-include $(IO_OBJECTS:.o=.d)" << std::endl - << std::endl ; + << "LINK_LISTS += $(LD_FILELIST)build/io_link_list" << std::endl; makefile_io_src.close() ;