Grand Make Dependency Graph, part 1

Refs #360
This commit is contained in:
Derek Bankieris 2017-02-23 13:26:28 -06:00
parent 02617bf7da
commit e6ad95f493
6 changed files with 135 additions and 122 deletions

View File

@ -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 > $@

View File

@ -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) ;

21
libexec/trick/create_top_dot_i Executable file
View File

@ -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)

View File

@ -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\$(<D) -I\$(<D)/../include -MMD -MP -c \$< -o \$\@
\t\$(ECHO_CMD)\$(TRICK_CC) \$(TRICK_CFLAGS) \$(TRICK_SYSTEM_CFLAGS) -I\$(<D) -I\$(<D)/../include -MMD -MP -c -o \$\@ \$<
define compile_rule
build/%.o: /%.\$1
define create_compile_rule
build/%.o: /%.\$1 build/%.d
\t\$\$(PRINT_COMPILE)
\t\$\$(ECHO_CMD)\$\$(TRICK_CPPC) \$\$(TRICK_CXXFLAGS) \$\$(TRICK_SYSTEM_CXXFLAGS) -I\$\$(<D) -I\$\$(<D)/../include -MMD -MP -c \$\$< -o \$\$@
\t\$\$(ECHO_CMD)\$\$(TRICK_CPPC) \$\$(TRICK_CXXFLAGS) \$\$(TRICK_SYSTEM_CXXFLAGS) -I\$\$(<D) -I\$\$(<D)/../include -MMD -MP -c -o \$\$@ \$\$<
endef
EXTENSIONS := C cc cpp cxx c++
\$(foreach EXTENSION,\$(EXTENSIONS),\$(eval \$(call compile_rule,\$(EXTENSION))))
\$(foreach EXTENSION,\$(EXTENSIONS),\$(eval \$(call create_compile_rule,\$(EXTENSION))))
-include \$(MODEL_OBJECTS:.o=.d)" ;
\$(MODEL_OBJECTS:.o=.d): ;
-include \$(MODEL_OBJECTS:.o=.d)
LINK_LISTS += \$(LD_FILELIST)build/model_link_list
" ;
# print out the libraries we link
print MAKEFILE "\n\nREAD_ONLY_LIBS =";
print MAKEFILE "
# S_MAIN =======================================================================
READ_ONLY_LIBS =";
foreach ( @all_read_only_libs ) {
print MAKEFILE " \\\n $_" ;
}
print MAKEFILE "
all: S_main
test: TRICK_SYSTEM_CXXFLAGS += -DTRICK_UNIT_TEST
test: TRICK_SYSTEM_CFLAGS += -DTRICK_UNIT_TEST
test: all
S_main: \$(S_MAIN) S_sie.resource
\t\$(info Trick Build Process Complete)
\$(S_MAIN): \$(TRICK_STATIC_LIB) \$(S_OBJECTS) \$(MODEL_OBJECTS)
\t\$(PRINT_EXE_LINK)
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_SYSTEM_LDFLAGS) -o \$@ \$(S_OBJECTS) \$(LINK_LISTS) \$(TRICK_LDFLAGS) \$(TRICK_USER_LINK_LIBS) \$(READ_ONLY_LIBS) \$(LD_WHOLE_ARCHIVE) \$(TRICK_LIBS) \$(LD_NO_WHOLE_ARCHIVE) \$(TRICK_EXEC_LINK_LIBS)
\t\$(ECHO_CMD)\$(TRICK_CPPC) -o \$@ \$(TRICK_SYSTEM_LDFLAGS) \$(S_OBJECTS) \$(LINK_LISTS) \$(TRICK_LDFLAGS) \$(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)
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c \$\< -o \$\@
-include build/S_source.d
# SIE ==========================================================================
sie: S_sie.resource

View File

@ -179,22 +179,8 @@ ifndef TRICK_VERBOSE_BUILD
PRINT_COMPILE_SWIG = \$(info \$(call COLOR,Compiling) \$<)
endif
SWIG_I =" ;
# TRICK_FIXED_PYTHON ===========================================================
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}.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 "
TRICK_FIXED_PYTHON = \\
$swig_sim_dir/swig_double.py \\
$swig_sim_dir/swig_int.py \\
@ -203,7 +189,48 @@ TRICK_FIXED_PYTHON = \\
$swig_sim_dir/unit_test.py \\
$swig_sim_dir/sim_services.py \\
$swig_sim_dir/exception.py
" ;
\$(TRICK_FIXED_PYTHON): $swig_sim_dir/\% : \${TRICK_HOME}/share/trick/swig/\%
\t\$(ECHO_CMD)/bin/cp -f \$< \$@
all: \$(TRICK_FIXED_PYTHON)
# SWIG_I =======================================================================
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/${swig_file_only}_py.i" ;
}
print MAKEFILE "
define create_convert_swig_rule
build/%_py.i: /%.\$1
\t\$(ECHO_CMD)\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \${TRICK_CONVERT_SWIG_FLAGS} \$\$<
endef
EXTENSIONS := H h hh hxx h++ hpp
\$(foreach EXTENSION,\$(EXTENSIONS),\$(eval \$(call create_convert_swig_rule,\$(EXTENSION))))
build/top.i: build/CP_instances
\t\${ECHO_CMD}\${TRICK_HOME}/\${LIBEXEC}/trick/create_top_dot_i
# SWIG_SRC =====================================================================
SWIG_SRC = \$(subst .i,.cpp,\$(SWIG_I)) $swig_src_dir/top.cpp
\$(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 =================================================================
SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o\n" ;
my %python_modules ;
$ii = 0 ;
@ -233,7 +260,7 @@ 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";
my $link_py_obj = "build" . dirname($swig_f) . "/${swig_file_only}_py.o";
print PY_LINK_LIST "$link_py_obj\n" ;
$ii++ ;
@ -250,27 +277,13 @@ TRICK_FIXED_PYTHON = \\
my $wd = abs_path(cwd()) ;
print MAKEFILE "
LINK_LISTS += \$(LD_FILELIST)build/py_link_list
\$(S_MAIN): \$(SWIG_OBJECTS) \$(OTHER_SWIG_OBJECTS)
#\$(SWIG_OBJECTS): TRICK_SYSTEM_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls
S_main: \$(TRICK_FIXED_PYTHON)
\$(TRICK_FIXED_PYTHON): $swig_sim_dir/\% : \${TRICK_HOME}/share/trick/swig/\%
\t\$(ECHO_CMD)/bin/cp -f \$< \$@
\$(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_I) : build/convert_swig_last_run
\$(SWIG_OBJECTS) \$(OTHER_SWIG_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 \$@ \$<
\$(S_MAIN): \$(SWIG_OBJECTS)
LINK_LISTS += \$(LD_FILELIST)build/py_link_list
" ;
close MAKEFILE ;
@ -282,18 +295,6 @@ S_main: \$(TRICK_FIXED_PYTHON)
}
close SWIGLIB ;
open S_INSTANCE , "build/CP_instances" or return ;
my @instances = <S_INSTANCE> ;
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 <Python.h>\n" ;
print INITSWIGFILE "#if PY_VERSION_HEX >= 0x03000000\n" ;

View File

@ -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() ;