diff --git a/bin/trick-CP b/bin/trick-CP index 024bd7187..5d918450c 100755 --- a/bin/trick-CP +++ b/bin/trick-CP @@ -1,17 +1,33 @@ #!/usr/bin/perl +########## +# +# INPUTS: +# S_define in cwd +# +# OUTPUTS: +# Main sim makefile under TRICK_BUILD_DIR (if empty, cwd) +# +# PURPOSE: +# Start of the sim build process. Constructs the sims primary makefile and kicks it off. +# Also does command line parsing and attempts to run rebuild_trickify if available. +# +########## + # It is so hard getting the absolute path of the current script in bash # so I converted CP back to perl. :) use File::Basename ; +use File::Spec ; +use File::Path qw(make_path) ; use Cwd ; use Cwd 'abs_path'; use Pod::Usage ; use Pod::Text ; +$my_cwd = getcwd(); $trick_bin = dirname(abs_path($0)) ; $trick_home = dirname($trick_bin) ; - ### Set TRICK_VERBOSE_BUILD if VERBOSE is defined (synonyms) ### if(defined $ENV{'VERBOSE'}) { $ENV{'TRICK_VERBOSE_BUILD'} = 1; @@ -22,8 +38,8 @@ $numArgs = $#ARGV + 1; $makefileAddArgs = ' '; $sdefine_dir = "."; $sdefine = "S_define"; -$makefile = "makefile"; -foreach $argnum (0 .. $#ARGV) { +$trick_build_dir = "./"; +for $argnum (0 .. $#ARGV) { $arg = $ARGV[$argnum]; if ($arg =~ /(\w+)=(\w+)/ ) { $makefileAddArgs = $makefileAddArgs . $1 . "=" . $2 . " "; @@ -39,42 +55,61 @@ foreach $argnum (0 .. $#ARGV) { $makefileAddArgs = $makefileAddArgs . " test "; } elsif($arg=~ /-h/ ) { pod2usage(-sections => "NAME|SYNOPSIS|DESCRIPTION|OPTIONS|FILES", -verbose => 99) ; - } else { + } elsif($arg=~ /-b/ ) { + $trick_build_dir = File::Spec->catdir($ARGV[$argnum+1], '') . "/" ; + }else { $ENV{TRICK_CPFLAGS} .= " $arg" ; } } +$makefile = "${trick_build_dir}makefile"; + +# Ensure build dir exists +unless(-d $trick_build_dir) +{ + make_path($trick_build_dir) or die "Could not create build dir: $trick_build_dir, $!\n"; +} if ( -f $sdefine ) { - if ( not -w $sdefine_dir ) { + if ( not -w $trick_build_dir ) { print $sdefine_dir , " is not writable\n" ; print "trick-CP aborted\n" ; exit 1 ; } - unlink "build/Makefile_sim", $makefile ; - $makefile_text = do { local $/; } ; - $makefile_text =~ s/SUB_TRICK_HOME/$trick_home/ ; - $makefile_text =~ s/SUB_TRICK_BIN/$trick_bin/ ; - open MAKEFILE, ">$makefile" ; - print MAKEFILE $makefile_text ; - close MAKEFILE ; - - #Rebuild trickified libraries - if(not defined $ENV{'AM_I_TRICKIFYING'} and -e "trickify.mk") - { - my $cmd_ret = `make -f trickify.mk rebuild_trickify 2>&1` ; - if($cmd_ret ne "") - { - print "$cmd_ret" ; - } - } - - system("make -f makefile " . $makefileAddArgs) ; - exit $? >> 8; } else { print "S_define does not exist\n" ; exit 1 ; } +#If build dir starts with cwd dot remove it. +#We have to default to the cwd dot, otherwise -w fails. +$trick_build_dir =~ s/^\.\/// ; + +unlink "$trick_build_dir/Makefile_sim", $makefile ; +$makefile_text = do { local $/; } ; +$makefile_text =~ s/SUB_TRICK_HOME/$trick_home/ ; +$makefile_text =~ s/SUB_TRICK_BIN/$trick_bin/ ; +$ENV{'TRICK_SIM_DIR'} = "$my_cwd/" ; +$ENV{'TRICK_BUILD_DIR'} = $trick_build_dir ; + +open MAKEFILE, ">$makefile" ; +print MAKEFILE $makefile_text ; +close MAKEFILE ; + +#Rebuild trickified libraries +if(not defined $ENV{'AM_I_TRICKIFYING'} and -e "trickify.mk") +{ + my $cmd_ret = `make -f trickify.mk rebuild_trickify 2>&1` ; + if($cmd_ret ne "") + { + print "$cmd_ret" ; + } +} + +system("make -f ${trick_build_dir}makefile " . $makefileAddArgs) ; +# Dump the build dir readme +system("cp $trick_home/share/doc/trick/data/build_dir_readme ${trick_build_dir}build/README") ; +exit $? >> 8; + # trick-CP help message =pod @@ -185,7 +220,14 @@ test: all debug: TRICK_CPFLAGS += --debug debug: all -build: +ifneq ($(TRICK_BUILD_DIR),) + TRICK_CXXFLAGS += -I $(TRICK_BUILD_DIR) + TRICK_CXXFLAGS += -I $(dir $(TRICK_BUILD_DIR)) + TRICK_CFLAGS += -I $(TRICK_BUILD_DIR) + TRICK_CFLAGS += -I $(dir $(TRICK_BUILD_DIR)) +endif + +$(TRICK_BUILD_DIR)build/: @mkdir -p $@ $(TRICK_STATIC_LIB): @@ -193,53 +235,59 @@ $(TRICK_STATIC_LIB): @exit -1 # CP creates S_source.hh required for ICG and SWIG processing -S_source.hh: S_define | build +$(TRICK_BUILD_DIR)S_source.hh: S_define | $(TRICK_BUILD_DIR)build/ $(PRINT_CP) $(call ECHO_AND_LOG,${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor $(TRICK_CPFLAGS)) -build/Makefile_S_define: S_source.hh +# Some developers add rules for S_define (as in the literal string S_define). +# In order to make things simple on their end, we allow them to reference the literal string S_define instead of $(TRICK_SIM_DIR)S_define +# By listing S_define as a S_source.hh dependency, we ensure the user's S_define rules are always invoked. +# The following rule checks that the actual S_define file exists in the sim dir. +S_define: $(TRICK_SIM_DIR)S_define + +$(TRICK_BUILD_DIR)build/Makefile_S_define: $(TRICK_BUILD_DIR)S_source.hh $(PRINT_S_DEF_DEPS) - $(call ECHO_AND_LOG,$(TRICK_CXX) $(TRICK_SFLAGS) $(TRICK_SYSTEM_SFLAGS) -MM -MT S_source.hh -MF build/Makefile_S_define -x c++ S_define) + $(call ECHO_AND_LOG,$(TRICK_CXX) $(TRICK_SFLAGS) $(TRICK_SYSTEM_SFLAGS) -MM -MT S_source.hh -MF $(TRICK_BUILD_DIR)build/Makefile_S_define -x c++ $(TRICK_SIM_DIR)S_define) # Automatic and manual ICG rules ICG: $(PRINT_ICG) - $(call ECHO_AND_LOG,${TRICK_HOME}/bin/trick-ICG -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} S_source.hh) + $(call ECHO_AND_LOG,${TRICK_HOME}/bin/trick-ICG -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} $(TRICK_BUILD_DIR)S_source.hh) force_ICG: $(PRINT_ICG) - $(call ECHO_AND_LOG,${TRICK_HOME}/bin/trick-ICG -force -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} S_source.hh) + $(call ECHO_AND_LOG,${TRICK_HOME}/bin/trick-ICG -force -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} $(TRICK_BUILD_DIR)S_source.hh) # Create makefile for IO code -build/Makefile_io_src: S_source.hh | build +$(TRICK_BUILD_DIR)build/Makefile_io_src: $(TRICK_BUILD_DIR)S_source.hh | $(TRICK_BUILD_DIR)build/ $(PRINT_ICG) $(call ECHO_AND_LOG,${TRICK_HOME}/bin/trick-ICG -m ${TRICK_ICGFLAGS} ${TRICK_CXXFLAGS} ${TRICK_SYSTEM_CXXFLAGS} $<) # Create makefile for source code -build/Makefile_src: build/Makefile_src_deps build/Makefile_io_src S_source.hh +$(TRICK_BUILD_DIR)build/Makefile_src: $(TRICK_BUILD_DIR)build/Makefile_src_deps $(TRICK_BUILD_DIR)build/Makefile_io_src $(TRICK_BUILD_DIR)S_source.hh $(PRINT_MAKEFILE_SRC) $(call ECHO_AND_LOG,${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $? 2>&1) -build/Makefile_src_deps: ; +$(TRICK_BUILD_DIR)build/Makefile_src_deps: ; # Create makefile for SWIG code -build/Makefile_swig: S_source.hh build/Makefile_swig_deps +$(TRICK_BUILD_DIR)build/Makefile_swig: $(TRICK_BUILD_DIR)S_source.hh $(TRICK_BUILD_DIR)build/Makefile_swig_deps $(PRINT_MAKEFILE_SWIG) $(call ECHO_AND_LOG,${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_swig) -build/Makefile_swig_deps: ; +$(TRICK_BUILD_DIR)build/Makefile_swig_deps: ; # 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 +convert_swig: $(TRICK_BUILD_DIR)build/S_library_swig $(call ECHO_AND_LOG,${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS}) # 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 > $@ + $(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} $(TRICK_SYSTEM_SFLAGS) $(TRICK_SIM_DIR)S_define > $@ # prints the value of a makefile variable, example invocation "make print-TRICK_CXXFLAGS" # This rule is used by trick-config @@ -258,21 +306,21 @@ Simulation make options:\n\ CLEAN_TARGETS = tidy clean spotless distclean apocalypse ifdef AM_I_TRICKIFYING -include build/Makefile_S_define -include build/Makefile_src +include $(TRICK_BUILD_DIR)build/Makefile_S_define +include $(TRICK_BUILD_DIR)build/Makefile_src else ifeq ($(findstring ${MAKECMDGOALS},$(CLEAN_TARGETS)),) -include build/Makefile_S_define -include build/Makefile_src -include build/Makefile_src_deps -include build/Makefile_io_src -include build/Makefile_swig -include build/Makefile_swig_deps --include build/Makefile_ICG +include $(TRICK_BUILD_DIR)build/Makefile_S_define +include $(TRICK_BUILD_DIR)build/Makefile_src +include $(TRICK_BUILD_DIR)build/Makefile_src_deps +include $(TRICK_BUILD_DIR)build/Makefile_io_src +include $(TRICK_BUILD_DIR)build/Makefile_swig +include $(TRICK_BUILD_DIR)build/Makefile_swig_deps +-include $(TRICK_BUILD_DIR)build/Makefile_ICG endif --include build/Makefile_overrides --include S_overrides.mk --include trickify.mk --include S_post.mk +-include $(TRICK_BUILD_DIR)build/Makefile_overrides +-include $(TRICK_SIM_DIR)S_overrides.mk +-include $(TRICK_BUILD_DIR)trickify.mk +-include $(TRICK_SIM_DIR)S_post.mk ifndef MAKE_RESTARTS REMOVE_MAKE_OUT := $(shell rm -f $(MAKE_OUT)) @@ -289,21 +337,21 @@ all: endif tidy: - -rm -f S_source.hh S_sie.resource S_sie.json - -rm -f S_main* T_main* - -rm -f build/Makefile_* + -rm -f $(TRICK_BUILD_DIR)S_source.hh $(TRICK_BUILD_DIR)S_sie.resource $(TRICK_BUILD_DIR)S_sie.json + -rm -f $(TRICK_BUILD_DIR)S_main* $(TRICK_BUILD_DIR)T_main* + -rm -f $(TRICK_BUILD_DIR)build/Makefile_* 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 trick.zip - -rm -f makefile + -rm -f $(TRICK_BUILD_DIR)DP_Product/DP_rt_frame DP_Product/DP_rt_itimer + -rm -f $(TRICK_BUILD_DIR)DP_Product/DP_rt_jobs DP_Product/DP_rt_timeline DP_Product/DP_mem_stats + -rm -rf $(TRICK_BUILD_DIR)build/ $(TRICK_BUILD_DIR).trick $(TRICK_BUILD_DIR)trick.zip + -rm -f $(TRICK_BUILD_DIR)makefile spotless: clean distclean: clean -apocalypse: clean clean_trickify +apocalypse: spotless clean_trickify @echo "I love the smell of napalm in the morning <3" clean_trickify: ; diff --git a/bin/trick-ify b/bin/trick-ify index a18a6b1b9..a9b771865 100755 --- a/bin/trick-ify +++ b/bin/trick-ify @@ -215,28 +215,26 @@ my @lib_deps_header; my @lib_deps_source; if($s_define ne "") { + #Clean up tmp build if it already exists + if (-d "$build_dir/tmp_build") + { + chdir Cwd::abs_path("$build_dir/tmp_build") or die "Error changing to the build directory: $build_dir/tmp_build\n" ; + system('make clean'); + chdir Cwd::abs_path("$build_dir") or die "Error changing to the build directory: $build_dir\n" ; + system('rm -r tmp_build'); + } $s_define_dir = dirname($s_define) ; chdir Cwd::abs_path($s_define_dir) or die "Error changing to the s_define directory: $s_define_dir\n" ; - - # If the user has already built the sim, push it somewhere else - map - { - if(-e $_) - { - system("mv $_ $tmp_trick_build$_") == 0 or die "Could not move $_\n" ; - } - } - @trick_build_files; - my $cmd_ret = `$my_path/trick-CP 2>&1` ; + my $cmd_ret = `$my_path/trick-CP -b $build_dir/tmp_build 2>&1` ; if($cmd_ret ne "") { print "$cmd_ret" ; } - -e "build/trickify_deps" or die "Failed to create trickify_deps from S_define.\n" ; + -e "$build_dir/tmp_build/build/trickify_deps" or die "Failed to create trickify_deps from S_define.\n" ; - open (my $fh, "build/trickify_deps") or die "Could not open trickify_deps" ; + open (my $fh, "$build_dir/tmp_build/build/trickify_deps") or die "Could not open trickify_deps" ; while (my $line = <$fh>) { chomp $line ; @@ -254,18 +252,6 @@ if($s_define ne "") } } close ($fh) ; - - # Clear up the partial build dir we just made - system("make clean") == 0 or die "Could not clean up tmp build dir\n" ; - - map - { - if(-e "$tmp_trick_build$_") - { - system("mv $tmp_trick_build$_ $_") == 0 or die "Could not move $_\n" ; - } - } - @trick_build_files; } my @filters = split ' ', $s_define_filter ; filter_paths(\@lib_deps_source, \@filters) ; @@ -359,7 +345,7 @@ open (my $fh, ">", "S_overrides_trickify.mk") or die "Could not open S_overrides print $fh "ifndef AM_I_TRICKIFYING\n" ; # Only want these parameters if we are doing normal sim builds, otherwise the ext libs will butcher the trickify_deps print $fh "SOT_LOCAL_DIR_$name := \$(abspath \$(dir \$(lastword \$(MAKEFILE_LIST))))\n\n" ; print $fh "include $build_dir/trickify_dep.mk\n\n" ; -print $fh "TRICKIFY_LDFLAGS := " . Cwd::abs_path($ENV{'TRICKIFY_OBJECT_NAME'}) . "\n" ; +print $fh "TRICKIFY_LDFLAGS += " . Cwd::abs_path($ENV{'TRICKIFY_OBJECT_NAME'}) . "\n" ; print $fh "TRICK_EXT_LIB_DIRS += $ext_lib_dir\n" ; print $fh "TRICK_EXT_LIB_DIRS_OVERRIDES += ",$ext_lib_dir_overrides ,"\n" ; print $fh "TRICK_PYTHON_PATH += :" . $my_cwd . "/python\n" ; @@ -392,6 +378,8 @@ print $fh "\t-rm -f python\n" ; print $fh "\t-rm -f *.a\n" ; print $fh "\t-rm -f *.o\n" ; print $fh "\t-rm -f *.so\n" ; +print $fh "\t-rm -rf tmp_build\n" ; +print $fh "\t-rm -f full_file\n" ; print $fh "\nnuke_trickify: clean_trickify\n" ; print $fh "\t-rm -f S_overrides_trickify.mk\n" ; print $fh "\t-rm -f *.mk\n" ; @@ -595,7 +583,7 @@ print "Begin Trickification...\n" ; if($s_overrides_dir ne "") { chdir Cwd::abs_path($s_overrides_dir) or die "Error changing to s_overrides directory: $s_overrides_dir\n" ; - dump_makefile_vars($s_overrides, $build_dir, \%SHELL_ENV, ("TRICKIFY_BUILD_TYPE", "TRICKIFY_OBJECT_NAME", "TRICKIFY_PYTHON_DIR", "TRICK_CFLAGS", "TRICK_CXXFLAGS", "TRICK_SYSTEM_SWIG_CFLAGS", "TRICK_SWIG_CFLAGS")) ; + dump_makefile_vars($s_overrides, $build_dir, \%SHELL_ENV, ("TRICKIFY_BUILD_TYPE", "TRICKIFY_OBJECT_NAME", "TRICKIFY_PYTHON_DIR", "TRICK_CFLAGS", "TRICK_CXXFLAGS", "TRICK_SFLAGS", "TRICK_SYSTEM_CXXFLAGS", "TRICK_SYSTEM_SWIG_CFLAGS", "TRICK_SWIG_CFLAGS", "TRICK_EXCLUDE")) ; chdir Cwd::abs_path($build_dir) or die "Error changing to build directory: $build_dir\n" ; $ENV{"TRICKIFY_MAKE_DUMP"} = Cwd::abs_path("var_dump.mk") ; } diff --git a/libexec/trick/configuration_processor b/libexec/trick/configuration_processor index b3a130b2d..ff4c7f679 100755 --- a/libexec/trick/configuration_processor +++ b/libexec/trick/configuration_processor @@ -30,7 +30,7 @@ my @ext_lib_paths_overrides = get_paths( "TRICK_EXT_LIB_DIRS_OVERRIDES" ) ; # set default verbose level $sim{args}{v} = 2 ; -$sim{args}{o} = "build/CP_out" ; +$sim{args}{o} = "$ENV{TRICK_BUILD_DIR}build/CP_out" ; $sim{args}{p} = 1 ; #-------------------------------------------------------------- @@ -50,10 +50,6 @@ pod2usage(1) if $sim{args}{h} ; my ($version, $thread) = get_trick_version() ; $thread =~ s/\d+\.// ; -if ( ! -e "build" ) { - mkdir "build", 0755 ; -} - local *OUTFILE ; open OUTFILE , ">$sim{args}{o}" or warn "CP cannot open $sim{args}{o} for writing\n" ; $sim{fh} = *OUTFILE ; @@ -92,7 +88,7 @@ close OUTFILE ; #-------------------------------------------------------------- # Write out the library dependencies found in the S_define file. -open LIBDEP, ">build/S_define.lib_deps" ; +open LIBDEP, ">$ENV{TRICK_BUILD_DIR}build/S_define.lib_deps" ; foreach my $file ( @{$sim{mis_entry_files}} ) { if ( $file ne "" ) { $file = abs_path(dirname($file)) . "/" . basename($file) ; diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index 62ac68f1e..85c28d2a9 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -18,6 +18,7 @@ use get_paths ; use verbose_build ; use parse_s_define 'index_comments' ; + ## ## ================================================================================ ## Program: convert_swig @@ -138,7 +139,7 @@ if ( "$ENV{'TRICK_CFLAGS'} $ENV{'TRICK_CXXFLAGS'}" !~ /DTRICK_VER=/ ) { } if ( scalar @ARGV == 0 ) { - my ($s_library_swig) = "build/S_library_swig" ; + my ($s_library_swig) = "$ENV{TRICK_BUILD_DIR}build/S_library_swig" ; open FILE_LIST, $s_library_swig or die "Could not open $s_library_swig" ; while ( ) { chomp ; @@ -150,7 +151,7 @@ if ( scalar @ARGV == 0 ) { $base_file =~ s/\.[^\.]+$// ; $swig_dir = dirname($f) ; - $swig_dir = "build/$swig_dir" ; + $swig_dir = "$ENV{TRICK_BUILD_DIR}build/$swig_dir" ; $swig_file = "$swig_dir/${base_file}_py.i" ; #print "$swig_file\n" ; @@ -172,6 +173,7 @@ if ( scalar keys %out_of_date == 0 ) { ## Finally, call process_file() to create SWIG interface files for each of the out_of_date headers. ## + process_file() ; ## @@ -277,7 +279,7 @@ sub process_file() { next outer ; } } - $file_name = "build" . $file_name ; + $file_name = "$ENV{TRICK_BUILD_DIR}build" . $file_name ; $file_name =~ s/\.[^\.]+?$/\_py.i/ ; $contents .= "\%import \"$file_name\"\n" ; } else { @@ -294,7 +296,7 @@ sub process_file() { my $md5_sum = md5_hex($f) ; my ($out_dir) = dirname($f) ; - $out_dir = "build$out_dir" ; + $out_dir = "$ENV{TRICK_BUILD_DIR}build$out_dir" ; my $out_file ; $out_file = basename($f) ; diff --git a/libexec/trick/create_top_dot_i b/libexec/trick/create_top_dot_i index 7b0b8310f..8d788e316 100755 --- a/libexec/trick/create_top_dot_i +++ b/libexec/trick/create_top_dot_i @@ -2,8 +2,13 @@ import os -with open('build/CP_instances') as cp_instances: - with open('build/top.i', 'w') as top: +try: + trick_build_dir = os.environ["TRICK_BUILD_DIR"] +except KeyError: + trick_build_dir = "" + +with open(trick_build_dir + 'build/CP_instances') as cp_instances: + with open(trick_build_dir + 'build/top.i', 'w') as top: path = os.path.abspath(os.getcwd()) instances = ''.join(cp_instances.readlines()) top.write( @@ -15,6 +20,6 @@ with open('build/CP_instances') as cp_instances: instances + '\n' '%}\n' '\n' - '%import "build' + path + '/S_source_py.i"\n' + '%import "' + trick_build_dir + 'build' + path + "/" + trick_build_dir + 'S_source_py.i"\n' '\n' + instances) diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src index 18002568f..92fa943bc 100755 --- a/libexec/trick/make_makefile_src +++ b/libexec/trick/make_makefile_src @@ -16,6 +16,12 @@ my %non_lib_processed_files ; my $any_deps_changed = 0 ; my $verbose_build = verbose_build() ; +my $trick_build_dir = "./"; +if ( exists $ENV{'TRICK_BUILD_DIR'} ) +{ + $trick_build_dir = $ENV{'TRICK_BUILD_DIR'} ; +} + sub exist_lib_deps(@) { my (@files_to_process) = @_ ; foreach my $l ( @files_to_process ) { @@ -23,7 +29,7 @@ sub exist_lib_deps(@) { next if ( $l =~ /^-|\.a$/ ) ; next if ( ! -e $l ) ; my ( $file, $dir, $suffix) = fileparse($l, qr/\.[^.]*/) ; - my ($lib_dep_file_name) = "build$dir${file}${suffix}.lib_deps" ; + my ($lib_dep_file_name) = "$ENV{TRICK_BUILD_DIR}build/${dir}${file}${suffix}.lib_deps" ; if ( ! -e $lib_dep_file_name ) { $any_deps_changed = 1 ; print "New Dep $l\n" ; @@ -42,7 +48,7 @@ sub read_lib_deps($@) { next if ( $l =~ /^-|\.a$/ ) ; $non_lib_processed_files{$l} = 1 ; my ( $file, $dir, $suffix) = fileparse($l, qr/\.[^.]*/) ; - my ($lib_dep_file_name) = "build$dir${file}${suffix}.lib_deps" ; + my ($lib_dep_file_name) = "$ENV{TRICK_BUILD_DIR}build/${dir}${file}${suffix}.lib_deps" ; if ( -e $lib_dep_file_name ) { open FH, "$lib_dep_file_name" or die 'cannot open $lib_dep_file_name' ; my (@all_lines) = ; @@ -73,7 +79,7 @@ if ( scalar @ARGV ) { # Filter out Makefile_io_src_deps, Makefie_io_src, and S_source.hh from the argument list. # These are dependencies in the makefile. # S_source.hh will be passed in as a full path again if the file has changed. - next if ( $f eq "build/Makefile_src_deps" or $f eq "build/Makefile_io_src" or $f eq "S_source.hh") ; + next if ( $f eq "$ENV{TRICK_BUILD_DIR}build/Makefile_src_deps" or $f eq "$ENV{TRICK_BUILD_DIR}build/Makefile_io_src" or $f eq "$ENV{TRICK_BUILD_DIR}S_source.hh") ; my $deps_changed ; my @resolved_files ; print "DepTracing " , "$f\n" ; @@ -85,20 +91,20 @@ if ( scalar @ARGV ) { $any_deps_changed = 1 ; } -if ( ! -e "build/Makefile_src") { +if ( ! -e "$ENV{TRICK_BUILD_DIR}build/Makefile_src") { $any_deps_changed = 1 ; } # Read in dependency tree starting at the roots. The dependency tree starts with all of the # header files ICG processed and the lib deps listed in the S_define file. -open FILE, "build/ICG_processed" or die 'cannot open build/ICG_processed' ; +open FILE, "$ENV{TRICK_BUILD_DIR}build/ICG_processed" or die "cannot open $ENV{TRICK_BUILD_DIR}build/ICG_processed" ; my (@top_file_names) = ; close FILE ; -open FILE, "build/ICG_no_found" or die 'cannot open build/ICG_no_found' ; +open FILE, "$ENV{TRICK_BUILD_DIR}build/ICG_no_found" or die "cannot open $ENV{TRICK_BUILD_DIR}build/ICG_no_found" ; my (@ICG_no_file_names) = ; close FILE ; push @top_file_names , @ICG_no_file_names ; -open FILE, "build/S_define.lib_deps" or die 'cannot open build/S_define.lib_deps' ; +open FILE, "$ENV{TRICK_BUILD_DIR}build/S_define.lib_deps" or die "cannot open $ENV{TRICK_BUILD_DIR}build/S_define.lib_deps" ; my (@s_define_lib_deps) = ; close FILE ; push @top_file_names , @s_define_lib_deps ; @@ -109,7 +115,7 @@ $any_deps_changed |= exist_lib_deps(@top_file_names) ; # if no dependencies have changed, "touch" Makefile_src and exit if ( $any_deps_changed == 0 ) { - utime(undef, undef, "build/Makefile_src") ; + utime(undef, undef, "$ENV{TRICK_BUILD_DIR}build/Makefile_src") ; exit ; } @@ -174,7 +180,7 @@ my $dt = localtime(); my ($trick_ver) = get_trick_version() ; chomp $trick_ver ; -open MAKEFILE , ">build/Makefile_src" or return ; +open MAKEFILE , ">$ENV{TRICK_BUILD_DIR}build/Makefile_src" or return ; print MAKEFILE "################################################################################ @@ -200,42 +206,42 @@ ifndef TRICK_VERBOSE_BUILD PRINT_SIE = \$(info \$(call COLOR,Writing) \$@) endif -S_MAIN = S_main_\${TRICK_HOST_CPU}.exe +S_MAIN = $ENV{TRICK_BUILD_DIR}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 + S_MAIN = $ENV{TRICK_BUILD_DIR}T_main_\${TRICK_HOST_CPU}.exe endif # S_OBJECTS ==================================================================== -S_OBJECTS = build/S_source.o +S_OBJECTS = $ENV{TRICK_BUILD_DIR}build/S_source.o -build/S_source.o: build/S_source.cpp | build/S_source.d +$ENV{TRICK_BUILD_DIR}build/S_source.o: $ENV{TRICK_BUILD_DIR}build/S_source.cpp | $ENV{TRICK_BUILD_DIR}build/S_source.d \t\$(PRINT_COMPILE) \t\$(call ECHO_AND_LOG,\$(TRICK_CXX) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) -MMD -MP -c -o \$\@ \$\<) -build/S_source.d: ; +$ENV{TRICK_BUILD_DIR}build/S_source.d: ; --include build/S_source.d +-include $ENV{TRICK_BUILD_DIR}build/S_source.d # MODEL_OBJECTS ================================================================ # This function allows users to specify target-specific variables for individual # or groups of source files. For example: # \$(call FIND_MODEL_OBJECTS, /path/to/file /path/to/directory \$(LIST_OF_PATHS)): TRICK_CXXFLAGS += -Werror -FIND_MODEL_OBJECTS = \$(foreach PATH, \$1, \$(filter \$(addprefix build, \$(addsuffix %, \$(PATH))), \$(MODEL_OBJECTS))) +FIND_MODEL_OBJECTS = \$(foreach PATH, \$1, \$(filter \$(addprefix $ENV{TRICK_BUILD_DIR}build, \$(addsuffix %, \$(PATH))), \$(MODEL_OBJECTS))) " ; # 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" ; +open MODEL_LINK_LIST, ">$ENV{TRICK_BUILD_DIR}build/model_link_list" or die "Could not open $ENV{TRICK_BUILD_DIR}build/model_link_list" ; my %files_by_extension ; foreach my $directory ( keys %files_by_dir ) { foreach my $extension ( grep { /^\.(c|cc|C|cxx|cpp|c\+\+)$/ } keys %{$files_by_dir{$directory}} ) { foreach my $file ( @{$files_by_dir{$directory}{$extension}} ) { - push @{$files_by_extension{$extension}} , "build$directory$file.o" ; + push @{$files_by_extension{$extension}} , "$ENV{TRICK_BUILD_DIR}build${directory}${file}.o" ; } } } @@ -271,7 +277,7 @@ foreach my $extension ( keys %files_by_extension ) { my $command = "\$($compiler) \$(TRICK_${flags}FLAGS) \$(TRICK_SYSTEM_${flags}FLAGS) -I\$(build/Makefile_overrides" or die "Could not open build/Makefile_overrides" ; +open MAKEFILEOVER, ">$ENV{TRICK_BUILD_DIR}build/Makefile_overrides" or die "Could not open $ENV{TRICK_BUILD_DIR}build/Makefile_overrides" ; foreach $k ( sort keys %files_by_dir ) { # Look for makefile_overrides in the current directory. # If no such file exists AND this directory is named "src", look for it one level up. @@ -339,7 +345,7 @@ foreach $k ( sort keys %files_by_dir ) { if ( s/^objects\s*:\s*// ) { foreach my $extension ( keys %files_by_extension ) { foreach my $file (@{$files_by_dir{$k}{$extension}}) { - $files_by_dir{$k}{overrides} .= "build$k${file}.o \\\n" ; + $files_by_dir{$k}{overrides} .= "$ENV{TRICK_BUILD_DIR}build/${k}${file}.o \\\n" ; } } $files_by_dir{$k}{overrides} .= ": $_" @@ -347,7 +353,7 @@ foreach $k ( sort keys %files_by_dir ) { elsif ( s/(.+)_objects\s*:\s*// ) { if (scalar @{$files_by_dir{$k}{".$1"}}) { foreach my $file (@{$files_by_dir{$k}{".$1"}}) { - $files_by_dir{$k}{overrides} .= "build$k$file.o \\\n" ; + $files_by_dir{$k}{overrides} .= "$ENV{TRICK_BUILD_DIR}build/${k}${file}.o \\\n" ; } $files_by_dir{$k}{overrides} .= ": $_" } @@ -365,23 +371,37 @@ foreach $k ( sort keys %files_by_dir ) { } close MAKEFILEOVER ; -open TRICKIFYDEPS, ">build/trickify_deps" or die "Could not open build/trickify_deps" ; -print TRICKIFYDEPS map {"$_\n"} (sort keys %non_lib_processed_files) ; +if($ENV{'AM_I_TRICKIFYING'}) { + # %non_lib_processed_files consists of the #include tree starting from S_source.hh, plus listed lib dependencies. + # not included are the #include trees of library dependencies. + my %trickify_deps = %non_lib_processed_files ; + + # to ensure trickify deps include ALL files needed to build the sim, we must grab the headers missing from %non_lib_processed_files + # get_s_source_deps() is the function used by make_makefile_swig to grabe its dep list. + # this function traverses the #includes of lib dependencies, so it will fill in the gaps in our list. + (my $files_to_process) = get_s_source_deps() ; + foreach my $ftp (@$files_to_process) { + $trickify_deps{$ftp} = 1 ; + } + + open TRICKIFYDEPS, ">$ENV{TRICK_BUILD_DIR}build/trickify_deps" or die "Could not open $ENV{TRICK_BUILD_DIR}build/trickify_deps" ; + print TRICKIFYDEPS map {"$_\n"} (sort keys %trickify_deps) ; + close TRICKIFYDEPS ; +} # 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:" ; +open MAKEFILEDEPS, ">$ENV{TRICK_BUILD_DIR}build/Makefile_src_deps" or die "Could not open $ENV{TRICK_BUILD_DIR}build/Makefile_src_deps" ; +print MAKEFILEDEPS "$ENV{TRICK_BUILD_DIR}build/Makefile_src:" ; print MAKEFILEDEPS map {"\\\n $_"} (sort keys %non_lib_processed_files) ; print MAKEFILEDEPS "\n\n" ; print MAKEFILEDEPS map {"$_:\n"} (sort keys %non_lib_processed_files) ; close MAKEFILEDEPS ; # write out all of the files we used to S_library_list -open LIB_LIST, ">build/S_library_list" or die "Could not open build/S_library_list" ; +open LIB_LIST, ">$ENV{TRICK_BUILD_DIR}build/S_library_list" or die "Could not open $ENV{TRICK_BUILD_DIR}build/S_library_list" ; print LIB_LIST map {"$_\n"} (sort keys %processed_files) ; close LIB_LIST ; -if($ENV{'AM_I_TRICKIFYING'}) -{ - 0 or die; +if($ENV{'AM_I_TRICKIFYING'}) { + 0 or exit 1; } diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 9dbb88385..785e1c0d4 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -3,389 +3,20 @@ use FindBin qw($RealBin); use lib "$RealBin/pm" ; -use File::Basename ; -use Cwd ; -use Cwd 'abs_path'; -use gte ; -use Digest::MD5 qw(md5_hex) ; -use trick_version ; -use html ; -use verbose_build ; -use get_paths ; -use strict ; - -my @exclude_paths ; -my @swig_exclude_paths ; -my @ext_lib_paths ; -my @ext_lib_paths_overrides ; -my @files_to_process ; -my @ext_lib_files ; -my %md5s ; -my $verbose_build = verbose_build() ; -my %trick_headers ; -my %python_modules ; -my %python_module_dirs ; - -sub read_files_to_process() { - (my $version, my $thread) = get_trick_version() ; - (my $year) = $version =~ /^(\d+)/ ; - (my $cc = gte("TRICK_CC")) =~ s/\n// ; - - # Prepend -I to each include path before we pass them to the compiler - my @include_paths = map("-I$_", (get_include_paths(), "$ENV{TRICK_HOME}", "$ENV{TRICK_HOME}/include", "$ENV{TRICK_HOME}/include/trick/compat", "$ENV{TRICK_HOME}/trick_source", "../include")) ; - my @defines = (get_defines(), "-DTRICK_VER=$year", "-DSWIG") ; - - # get the list of header files from the compiler - open FILE_LIST, "$cc -MM @include_paths @defines S_source.hh |" ; - my $dir = dirname(abs_path("S_source.hh")) ; - my %files ; - my %ext_libs ; - while ( ) { - next if ( /^#/ or /^\s+\\/ ) ; - outer: - foreach my $word ( split ) { - next if ( $word eq "\\" or $word =~ /o:/ ) ; - - # skip unsupported extensions - next if not $word =~ /\.(H|h|hh|hxx|h++|hpp)$/ ; - - # get the absolute path - if ( $word !~ /^\// and $dir ne "\/" ) { - $word = "$dir/$word" ; - } - $word = abs_path(dirname($word)) . "/" . basename($word) ; - - # skip duplicate files - next if (exists($md5s{$word})) ; - $md5s{$word} = md5_hex($word) ; - - # skip system headers that are missed by the compiler -MM flag - next if ( $word =~ /^\/usr\/include/ ) ; - next if ( $word =~ /^\/usr\/local\/include/ ) ; - - # skip Trick headers - my $trick_home = $ENV{'TRICK_HOME'} ; - next if ( $word =~ /^\Q$trick_home\/include/ ) ; - next if ( $word =~ /^\Q$trick_home\/trick_source/ ) ; - - # skip paths in TRICK_EXCLUDE - foreach my $path ( @exclude_paths ) { - if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { - print "SWIG Skip TRICK_EXCLUDE: $path$1\n" if $verbose_build ; - next outer ; - } - } - - # skip paths in TRICK_SWIG_EXCLUDE - foreach my $path ( @swig_exclude_paths ) { - if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { - print "SWIG Skip TRICK_SWIG_EXCLUDE: $path$1\n" if $verbose_build ; - next outer ; - } - } - - # separate paths in TRICK_EXT_LIB_DIRS - foreach my $path ( @ext_lib_paths ) { - if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { - if ( get_containing_path( $word, @ext_lib_paths_overrides) eq 0 ) { - print "SWIG Skip TRICK_EXT_LIB_DIRS: $path$1\n" if $verbose_build ; - $ext_libs{$word} = 1 ; - next outer ; - } - } - } - $files{$word} = 1 ; - } - } - @ext_lib_files = sort keys %ext_libs ; - @files_to_process = sort keys %files ; -} - -sub write_makefile_swig_deps() { - open DEPENDENCIES_FILE , ">build/Makefile_swig_deps" or die "Could not open build/Makefile_swig_deps for writing" ; - print DEPENDENCIES_FILE "build/Makefile_swig:" ; - foreach my $file ( @files_to_process, @ext_lib_files ) { - print DEPENDENCIES_FILE " \\\n " . $file ; - } - close DEPENDENCIES_FILE ; -} - -sub get_trick_headers() { - foreach my $f ( @files_to_process, @ext_lib_files) { - my %trick_header = extract_trick_header( $f, do { local( @ARGV, $/ ) = $f ; <> }, 0, 0 ) ; - if ( exists $trick_header{python_module} ) { - $trick_headers{$f}{python_module} = $trick_header{python_module}; - ($trick_headers{$f}{python_module_dir} = $trick_header{python_module}) =~ s/\./\//g; - $python_modules{$trick_headers{$f}{python_module}} = 1; - $python_module_dirs{$trick_headers{$f}{python_module_dir}} = 1; - } - $trick_headers{$f}{swig} = $trick_header{swig} if ( exists $trick_header{swig} ); - } -} - -sub has_swig_no { - my $result = $trick_headers{$_[0]}{swig} =~ /^NO$/i ; - print "SWIG Skip SWIG: (NO): $_[0]\n" if $verbose_build and $result ; - return $result ; -} - -sub purge_swig_no_files() { - @files_to_process = grep { !has_swig_no($_) } @files_to_process ; - @ext_lib_files = grep { !has_swig_no($_) } @ext_lib_files ; -} - -sub write_makefile_swig() { - my $s_source_md5 = md5_hex(abs_path("S_source.hh")) ; - my $swig_sim_dir = ".trick" ; - my $swig_sim_zip = "trick.zip" ; - my $swig_src_dir = "build" ; - - open MAKEFILE , ">build/Makefile_swig" or die "Could not open build/Makefile_swig for writing" ; - open PY_LINK_LIST , ">build/py_link_list" or die "Could not open build/py_link_list for writing" ; - open TRICKIFY_PY_LINK_LIST , ">build/trickify_py_link_list" or die "Could not open build/trickify_py_link_list for writing" ; - print PY_LINK_LIST "build/init_swig_modules.o\n" ; - print PY_LINK_LIST "build/top.o\n" ; - - print MAKEFILE "TRICK_SYSTEM_SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers - -ifeq (\$(IS_CC_CLANG), 1) - TRICK_SYSTEM_SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized -Wno-deprecated-register -Wno-unused-variable -Wno-unused-but-set-variable -Wno-cast-function-type-mismatch -else - TRICK_SYSTEM_SWIG_CFLAGS += -Wno-unused-but-set-variable -Wno-maybe-uninitialized - ifeq (\$(shell test \$(GCC_MAJOR) -ge 8; echo \$\$?), 0) - TRICK_SYSTEM_SWIG_CFLAGS += -Wno-cast-function-type - endif -endif - -ifndef TRICK_VERBOSE_BUILD - PRINT_SWIG = \$(info \$(call COLOR,SWIGing) \$<) - PRINT_COMPILE_SWIG = \$(info \$(call COLOR,Compiling) \$<) -endif - -# TRICK_FIXED_PYTHON =========================================================== - -TRICK_FIXED_PYTHON = \\ - $swig_sim_dir/swig_double.py \\ - $swig_sim_dir/swig_int.py \\ - $swig_sim_dir/swig_ref.py \\ - $swig_sim_dir/shortcuts.py \\ - $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\$(call ECHO_AND_LOG,/bin/cp -f \$< \$@) - -# SWIG_I ======================================================================= - -SWIG_I =" ; - - foreach my $file ( @files_to_process ) { - (my $swig_file = $file) =~ s/(\.[^.]*)?$/_py/ ; - print MAKEFILE " \\\n build$swig_file.i" ; - print PY_LINK_LIST "build$swig_file.o\n" ; - if ( !($swig_file =~ /(.*)S_source_py$/) ) { - print TRICKIFY_PY_LINK_LIST "build$swig_file.o\n" ; - } - } - - print MAKEFILE " - -define create_convert_swig_rule -build/%_py.i: /%.\$1 -\t\$\$(call ECHO_AND_LOG,\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \$\${TRICK_CONVERT_SWIG_FLAGS} \$\$<) -endef - -\$(foreach EXTENSION,H h hh hxx h++ hpp,\$(eval \$(call create_convert_swig_rule,\$(EXTENSION)))) - -build/top.i: build/CP_instances -\t\$(call ECHO_AND_LOG,\${PYTHON} \${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 | %.d \$(SWIG_I) -\t\$(PRINT_SWIG) -\t\$(call ECHO_AND_LOG,\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201 -w303 -w315 -w325 -w362 -w389 -w401 -w451 -MMD -MP -outdir $swig_sim_dir -o \$@ \$<) +use swig_make ; -\$(SWIG_SRC:.cpp=.d): ; - --include \$(SWIG_SRC:.cpp=.d) - -# SWIG_OBJECTS ================================================================= - -SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o - -\$(SWIG_OBJECTS): %.o: %.cpp -\t\$(PRINT_COMPILE_SWIG) -\t\$(call ECHO_AND_LOG,\$(TRICK_CXX) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) \$(TRICK_SWIG_CFLAGS) \$(TRICK_SYSTEM_SWIG_CFLAGS) -Wno-unused-parameter -c -o \$@ \$<) - -\$(S_MAIN): \$(SWIG_OBJECTS) - -LINK_LISTS += \$(LD_FILELIST)build/py_link_list - -# $swig_sim_zip =================================================================== - -$swig_sim_zip: \$(SWIG_SRC) \$(TRICK_FIXED_PYTHON) $swig_sim_dir/__init__.py -\t\$(info \$(call COLOR,Compiling) Python modules) -\t\$(call ECHO_AND_LOG,\$(PYTHON) -m compileall -q $swig_sim_dir) -\t\$(info \$(call COLOR,Zipping) Python modules into \$@) -\t\$(call ECHO_AND_LOG,ln -sf $swig_sim_dir trick) -\t\$(call ECHO_AND_LOG,zip -rq $swig_sim_zip trick) -\t\$(call ECHO_AND_LOG,rm -f trick) - - -all: $swig_sim_zip -" ; - - close MAKEFILE ; - close PY_LINK_LIST ; - close TRICKIFY_PY_LINK_LIST ; - - open SWIGLIB , ">build/S_library_swig" or die "Could not open build/S_library_swig for writing" ; - foreach my $file ( @files_to_process ) { - print SWIGLIB "$file\n" ; - } - close SWIGLIB ; - - open INITSWIGFILE , ">build/init_swig_modules.cpp" or die "Could not open build/init_swig_modules.cpp for writing" ; - print INITSWIGFILE "#include \n" ; - print INITSWIGFILE "#if PY_VERSION_HEX >= 0x03000000\n" ; - print INITSWIGFILE "extern \"C\" {\n\n" ; - - foreach my $file ( @files_to_process, @ext_lib_files ) { - print INITSWIGFILE "PyObject * PyInit__m$md5s{$file}(void) ; /* $file */\n" ; - } - - print INITSWIGFILE "PyObject * PyInit__sim_services(void) ;\n" ; - print INITSWIGFILE "PyObject * PyInit__top(void) ;\n" ; - print INITSWIGFILE "PyObject * PyInit__swig_double(void) ;\n" ; - print INITSWIGFILE "PyObject * PyInit__swig_int(void) ;\n" ; - print INITSWIGFILE "PyObject * PyInit__swig_ref(void) ;\n" ; - - print INITSWIGFILE "\nvoid init_swig_modules(void) {\n\n" ; - foreach my $file ( @files_to_process, @ext_lib_files ) { - next if ( $file =~ /S_source.hh/ ) ; - print INITSWIGFILE " PyImport_AppendInittab(\"_m$md5s{$file}\", PyInit__m$md5s{$file}) ;\n" ; - } - print INITSWIGFILE " PyImport_AppendInittab(\"_m${s_source_md5}\", PyInit__m${s_source_md5}) ;\n" ; - print INITSWIGFILE " PyImport_AppendInittab(\"_sim_services\", PyInit__sim_services) ;\n" ; - print INITSWIGFILE " PyImport_AppendInittab(\"_top\", PyInit__top) ;\n" ; - print INITSWIGFILE " PyImport_AppendInittab(\"_swig_double\", PyInit__swig_double) ;\n" ; - print INITSWIGFILE " PyImport_AppendInittab(\"_swig_int\", PyInit__swig_int) ;\n" ; - print INITSWIGFILE " PyImport_AppendInittab(\"_swig_ref\", PyInit__swig_ref) ;\n" ; - print INITSWIGFILE " return ;\n}\n\n}\n" ; - print INITSWIGFILE "#else\n" ; - - print INITSWIGFILE "extern \"C\" {\n\n" ; - - foreach my $file ( @files_to_process, @ext_lib_files ) { - print INITSWIGFILE "void init_m$md5s{$file}(void) ; /* $file */\n" ; - } - - print INITSWIGFILE "void init_sim_services(void) ;\n" ; - print INITSWIGFILE "void init_top(void) ;\n" ; - print INITSWIGFILE "void init_swig_double(void) ;\n" ; - print INITSWIGFILE "void init_swig_int(void) ;\n" ; - print INITSWIGFILE "void init_swig_ref(void) ;\n" ; - - print INITSWIGFILE "\nvoid init_swig_modules(void) {\n\n" ; - foreach my $file ( @files_to_process, @ext_lib_files) { - next if ( $file =~ /S_source.hh/ ) ; - print INITSWIGFILE " init_m$md5s{$file}() ;\n" ; - } - print INITSWIGFILE " init_m${s_source_md5}() ;\n" ; - print INITSWIGFILE " init_sim_services() ;\n" ; - print INITSWIGFILE " init_top() ;\n" ; - print INITSWIGFILE " init_swig_double() ;\n" ; - print INITSWIGFILE " init_swig_int() ;\n" ; - print INITSWIGFILE " init_swig_ref() ;\n" ; - print INITSWIGFILE " return ;\n}\n\n}\n" ; - print INITSWIGFILE "#endif\n" ; - close INITSWIGFILE ; - - if ( ! -e $swig_sim_dir) { - mkdir $swig_sim_dir ; - } - open INITFILE , ">$swig_sim_dir/__init__.py" or die "Could not open $swig_sim_dir/__init__.py for writing" ; - - print INITFILE "from pkgutil import extend_path\n" ; - print INITFILE "__path__ = extend_path(__path__, __name__)\n" ; - print INITFILE "import sys\n" ; - print INITFILE "import os\n" ; - print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick\")\n" ; - foreach my $dir ( keys %python_module_dirs ) { - print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick/$dir\")\n" ; - } - - print INITFILE "\n" ; - print INITFILE "import _sim_services\n" ; - print INITFILE "from sim_services import *\n\n" ; - - print INITFILE "# create \"all_cvars\" to hold all global/static vars\n" ; - print INITFILE "all_cvars = new_cvar_list()\n" ; - print INITFILE "combine_cvars(all_cvars, cvar)\n" ; - print INITFILE "cvar = None\n\n" ; - - foreach my $file ( @files_to_process, @ext_lib_files ) { - print INITFILE "# $file\n" ; - print INITFILE "import _m$md5s{$file}\n" ; - print INITFILE "combine_cvars(all_cvars, cvar)\n" ; - print INITFILE "cvar = None\n\n" ; - } - - foreach my $file ( @files_to_process, @ext_lib_files ) { - print INITFILE "# $file\n" ; - print INITFILE "from m$md5s{$file} import *\n" ; - } - - foreach my $mod ( keys %python_modules ) { - print INITFILE "import trick.$mod\n" ; - } - - print INITFILE "\n" ; - print INITFILE "# S_source.hh\n" ; - print INITFILE "import _m${s_source_md5}\n" ; - print INITFILE "from m${s_source_md5} import *\n\n" ; - print INITFILE "import _top\n" ; - print INITFILE "import top\n\n" ; - print INITFILE "import _swig_double\n" ; - print INITFILE "import swig_double\n\n" ; - print INITFILE "import _swig_int\n" ; - print INITFILE "import swig_int\n\n" ; - print INITFILE "import _swig_ref\n" ; - print INITFILE "import swig_ref\n\n" ; - print INITFILE "from shortcuts import *\n\n" ; - print INITFILE "from exception import *\n\n" ; - print INITFILE "cvar = all_cvars\n\n" ; - close INITFILE ; - - foreach my $dir ( keys %python_module_dirs ) { - system("mkdir -p $swig_sim_dir/$dir"); - open MODULE_INITFILE, ">$swig_sim_dir/$dir/__init__.py"; - foreach my $file ( @files_to_process ) { - if ( exists $trick_headers{$file}{python_module_dir} and $trick_headers{$file}{python_module_dir} eq $dir ) { - print MODULE_INITFILE "# $file\n" ; - print MODULE_INITFILE "import _m$md5s{$file}\n" ; - print MODULE_INITFILE "from m$md5s{$file} import *\n" ; - } - } - close MODULE_INITFILE; - } - - return ; -} +use strict ; -@exclude_paths = get_paths( "TRICK_EXCLUDE" ) ; -@swig_exclude_paths = get_paths( "TRICK_SWIG_EXCLUDE" ) ; -@ext_lib_paths = get_paths( "TRICK_EXT_LIB_DIRS" ) ; -@ext_lib_paths_overrides = get_paths( "TRICK_EXT_LIB_DIRS_OVERRIDES" ) ; read_files_to_process() ; + write_makefile_swig_deps() ; get_trick_headers() ; + # Remove SWIG: (NO) files, but not before they're written to the dependency file. # If SWIG: (NO) is removed, Makefile_swig needs to be regenerated. purge_swig_no_files() ; + write_makefile_swig() ; + +write_lib_files() ; diff --git a/libexec/trick/pm/get_lib_deps.pm b/libexec/trick/pm/get_lib_deps.pm index 1ccdd28dd..4bb375b26 100644 --- a/libexec/trick/pm/get_lib_deps.pm +++ b/libexec/trick/pm/get_lib_deps.pm @@ -7,8 +7,10 @@ use Exporter (); use gte ; use get_paths ; use verbose_build ; +use trick_version ; +use Digest::MD5 qw(md5_hex) ; @ISA = qw(Exporter); -@EXPORT = qw(get_lib_deps write_lib_deps); +@EXPORT = qw(get_lib_deps write_lib_deps get_s_source_deps trickify_map_fake_deps) ; use strict ; @@ -190,9 +192,9 @@ sub write_lib_deps($) { # Build the library dependencies file name to store results my ( $file, $dir, $suffix) = fileparse($source_file_name, qr/\.[^.]*/) ; - my ($lib_dep_file_name) = "build$dir${file}${suffix}.lib_deps" ; + my ($lib_dep_file_name) = "$ENV{TRICK_BUILD_DIR}build$dir${file}${suffix}.lib_deps" ; if ( ! -e "build$dir" ) { - make_path("build$dir") ; + make_path("$ENV{TRICK_BUILD_DIR}build$dir") ; } if ( -e $lib_dep_file_name ) { @@ -226,4 +228,85 @@ sub write_lib_deps($) { return $deps_changed , @resolved_files ; } +sub get_s_source_deps() { + (my $version, my $thread) = get_trick_version() ; + (my $year) = $version =~ /^(\d+)/ ; + (my $cc = gte("TRICK_CC")) =~ s/\n// ; + + # Prepend -I to each include path before we pass them to the compiler + my @include_paths = map("-I$_", (get_include_paths(), "$ENV{TRICK_HOME}", "$ENV{TRICK_HOME}/include", "$ENV{TRICK_HOME}/include/trick/compat", "$ENV{TRICK_HOME}/trick_source", "../include")) ; + my @defines = (get_defines(), "-DTRICK_VER=$year", "-DSWIG") ; + + my @exclude_paths = get_paths( "TRICK_EXCLUDE" ) ; + my @swig_exclude_paths = get_paths( "TRICK_SWIG_EXCLUDE" ) ; + my %local_md5s ; + + # get the list of header files from the compiler + open FILE_LIST, "$cc -MM @include_paths @defines $ENV{'TRICK_BUILD_DIR'}S_source.hh |" ; + my $dir = dirname(abs_path("S_define")) ; + my %files ; + my %ext_libs ; + while ( ) { + next if ( /^#/ or /^\s+\\/ ) ; + outer: + foreach my $word ( split ) { + next if ( $word eq "\\" or $word =~ /o:/ ) ; + + # skip unsupported extensions + next if not $word =~ /\.(H|h|hh|hxx|h++|hpp)$/ ; + + # get the absolute path + if ( $word !~ /^\// and $dir ne "\/" ) { + $word = "$dir/$word" ; + } + $word = abs_path(dirname($word)) . "/" . basename($word) ; + + # skip duplicate files + next if (exists($local_md5s{$word})) ; + $local_md5s{$word} = md5_hex($word) ; + + # skip system headers that are missed by the compiler -MM flag + next if ( $word =~ /^\/usr\/include/ ) ; + next if ( $word =~ /^\/usr\/local\/include/ ) ; + + # skip Trick headers + my $trick_home = $ENV{'TRICK_HOME'} ; + next if ( $word =~ /^\Q$trick_home\/include/ ) ; + next if ( $word =~ /^\Q$trick_home\/trick_source/ ) ; + + # skip paths in TRICK_EXCLUDE + foreach my $path ( @exclude_paths ) { + if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { + print "SWIG Skip TRICK_EXCLUDE: $path$1\n" if $verbose_build ; + next outer ; + } + } + + # skip paths in TRICK_SWIG_EXCLUDE + foreach my $path ( @swig_exclude_paths ) { + if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { + print "SWIG Skip TRICK_SWIG_EXCLUDE: $path$1\n" if $verbose_build ; + next outer ; + } + } + + # separate paths in TRICK_EXT_LIB_DIRS + foreach my $path ( @ext_lib_paths ) { + if ( $word =~ /^\Q$path\E(.*)/ or abs_path($word) =~ /^\Q$path\E(.*)/ ) { + if ( get_containing_path( $word, @ext_lib_paths_overrides) eq 0 ) { + print "SWIG Skip TRICK_EXT_LIB_DIRS: $path$1\n" if $verbose_build ; + $ext_libs{$word} = 1 ; + next outer ; + } + } + } + $files{$word} = 1 ; + } + } + my @local_ext_lib_files = sort keys %ext_libs ; + my @local_files_to_process = sort keys %files ; + + return (\@local_files_to_process, \@local_ext_lib_files, \%local_md5s) ; +} + 1 diff --git a/libexec/trick/pm/parse_s_define.pm b/libexec/trick/pm/parse_s_define.pm index 88ecf2adc..f4a769e63 100644 --- a/libexec/trick/pm/parse_s_define.pm +++ b/libexec/trick/pm/parse_s_define.pm @@ -137,7 +137,7 @@ $create_connections_def = qr/ /sx ; $job_class_order_def = qr/ - job_class_order # the word sim_object + job_class_order\s*{ # the word sim_object (?:.*? # everything })\s*; # to end of obj def /sx ; @@ -378,7 +378,7 @@ sub parse_s_define ($) { my @preprocess_output; - @{$$sim_ref{inc_paths}} = (get_include_paths(), $ENV{TRICK_SYSTEM_CFLAGS} =~ /-(?:I|isystem)(\S+)/g, "$ENV{TRICK_HOME}/trick_source" , "../include") ; + @{$$sim_ref{inc_paths}} = (get_include_paths(), $ENV{TRICK_SYSTEM_CFLAGS} =~ /-(?:I|isystem)(\S+)/g, "$ENV{TRICK_HOME}/trick_source" , "../include", $ENV{'TRICK_BUILD_DIR'}) ; my @valid_inc_paths ; foreach (@{$$sim_ref{inc_paths}}) { @@ -397,7 +397,7 @@ sub parse_s_define ($) { $_ = quotemeta (abs_path(dirname($_)) . "/" . basename($_)) ; } - $s_define_file = "S_define" ; + $s_define_file = "$ENV{TRICK_SIM_DIR}S_define" ; $$sim_ref{line_num} = 1 ; diff --git a/libexec/trick/pm/s_source.pm b/libexec/trick/pm/s_source.pm index efdc25c14..379bc9481 100644 --- a/libexec/trick/pm/s_source.pm +++ b/libexec/trick/pm/s_source.pm @@ -15,9 +15,9 @@ sub s_source($) { #-------------------------------------------------------------- # Generate S_source.c - open S_SOURCE, ">build/S_source.cpp" or die "Couldn't open build/S_source.cpp!\n"; - open S_SOURCE_H, ">S_source.hh" or die "Couldn't open S_source.hh!\n"; - open TOP_LEVEL_OBJECTS_RESOURCE, ">build/top_level_objects.resource" or die "Couldn't open top_level_objects.resource!"; + open S_SOURCE, ">$ENV{'TRICK_BUILD_DIR'}build/S_source.cpp" or die "Couldn't open $ENV{'TRICK_BUILD_DIR'}build/S_source.cpp!\n"; + open S_SOURCE_H, ">$ENV{'TRICK_BUILD_DIR'}S_source.hh" or die "Couldn't open $ENV{'TRICK_BUILD_DIR'}S_source.hh!\n"; + open TOP_LEVEL_OBJECTS_RESOURCE, ">$ENV{'TRICK_BUILD_DIR'}build/top_level_objects.resource" or die "Couldn't open $ENV{'TRICK_BUILD_DIR'}top_level_objects.resource!"; # Get Trick version my ($version, $thread) = get_trick_version() ; @@ -330,7 +330,7 @@ PURPOSE: close S_SOURCE ; - open S_INSTANCE, ">build/CP_instances" or die "Couldn't open build/CP_instances!\n"; + open S_INSTANCE, ">$ENV{TRICK_BUILD_DIR}build/CP_instances" or die "Couldn't open $ENV{TRICK_BUILD_DIR}build/CP_instances!\n"; print S_INSTANCE $$sim_ref{extern_instance_declarations} ; foreach my $integ_loop ( @{$$sim_ref{integ_loop}} ) { print S_INSTANCE "extern IntegLoopSimObject $$integ_loop{name} ;\n" ; diff --git a/libexec/trick/pm/swig_make.pm b/libexec/trick/pm/swig_make.pm new file mode 100644 index 000000000..191e8d9a8 --- /dev/null +++ b/libexec/trick/pm/swig_make.pm @@ -0,0 +1,446 @@ +package swig_make ; + +use FindBin qw($RealBin); +use lib "$RealBin/" ; + +use File::Basename ; +use File::Path qw(make_path); +use Cwd ; +use Cwd 'abs_path'; +use gte ; +use html ; +use verbose_build ; +use get_lib_deps ; +use get_paths ; +use Digest::MD5 qw(md5_hex) ; + +@ISA = qw(Exporter); +@EXPORT = qw(read_files_to_process write_makefile_swig_deps get_trick_headers purge_swig_no_files write_makefile_swig write_lib_files trickify_map_fake_deps replace_files_to_process write_fake_deps_map) ; + +use strict ; + +my @files_to_process ; +my @ext_lib_files ; +my %md5s ; +my $verbose_build = verbose_build() ; +my %trick_headers ; +my %python_modules ; +my %python_module_dirs ; + +#trickify vars +my %trickify_files_to_replace ; + +sub read_files_to_process() +{ + my ($files_to_process, $ext_lib_files, $md5s) = get_s_source_deps() ; + @files_to_process = @$files_to_process ; + @ext_lib_files = @$ext_lib_files ; + %md5s = %$md5s ; +} + +sub write_makefile_swig_deps() +{ + open DEPENDENCIES_FILE , ">$ENV{TRICK_BUILD_DIR}build/Makefile_swig_deps" or die "Could not open $ENV{TRICK_BUILD_DIR}build/Makefile_swig_deps for writing" ; + print DEPENDENCIES_FILE "$ENV{TRICK_BUILD_DIR}build/Makefile_swig:" ; + foreach my $file ( @files_to_process, @ext_lib_files ) + { + print DEPENDENCIES_FILE " \\\n " . $file ; + } + close DEPENDENCIES_FILE ; +} + +sub get_trick_headers() +{ + foreach my $f ( @files_to_process, @ext_lib_files ) + { + my %trick_header = extract_trick_header( $f, do { local( @ARGV, $/ ) = $f ; <> }, 0, 0 ) ; + if ( exists $trick_header{python_module} ) + { + $trick_headers{$f}{python_module} = $trick_header{python_module} ; + ($trick_headers{$f}{python_module_dir} = $trick_header{python_module}) =~ s/\./\//g ; + $python_modules{$trick_headers{$f}{python_module}} = 1 ; + $python_module_dirs{$trick_headers{$f}{python_module_dir}} = 1 ; + } + } +} + +sub has_swig_no +{ + my $result = $trick_headers{$_[0]}{swig} =~ /^NO$/i ; + print "SWIG Skip SWIG: (NO): $_[0]\n" if $verbose_build and $result ; + return $result ; +} + +sub purge_swig_no_files() +{ + @files_to_process = grep { !has_swig_no($_) } @files_to_process ; + @ext_lib_files = grep { !has_swig_no($_) } @ext_lib_files ; +} + +sub write_makefile_swig() +{ + my $s_source_md5 = md5_hex(abs_path("$ENV{TRICK_BUILD_DIR}S_source.hh")) ; + my $swig_sim_dir = "$ENV{'TRICK_BUILD_DIR'}.trick" ; + my $swig_sim_zip = "trick.zip" ; + my $swig_src_dir = "$ENV{'TRICK_BUILD_DIR'}build" ; + + open MAKEFILE , ">$ENV{TRICK_BUILD_DIR}build/Makefile_swig" or die "Could not open $ENV{TRICK_BUILD_DIR}build/Makefile_swig for writing" ; + print MAKEFILE "TRICK_SYSTEM_SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers + +ifeq (\$(IS_CC_CLANG), 1) + TRICK_SYSTEM_SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized -Wno-deprecated-register -Wno-unused-variable -Wno-unused-but-set-variable -Wno-cast-function-type-mismatch +else + TRICK_SYSTEM_SWIG_CFLAGS += -Wno-unused-but-set-variable -Wno-maybe-uninitialized + ifeq (\$(shell test \$(GCC_MAJOR) -ge 8; echo \$\$?), 0) + TRICK_SYSTEM_SWIG_CFLAGS += -Wno-cast-function-type + endif +endif + +ifndef TRICK_VERBOSE_BUILD + PRINT_SWIG = \$(info \$(call COLOR,SWIGing) \$<) + PRINT_COMPILE_SWIG = \$(info \$(call COLOR,Compiling) \$<) +endif + +# TRICK_FIXED_PYTHON =========================================================== + +TRICK_FIXED_PYTHON = \\ + $swig_sim_dir/swig_double.py \\ + $swig_sim_dir/swig_int.py \\ + $swig_sim_dir/swig_ref.py \\ + $swig_sim_dir/shortcuts.py \\ + $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\$(call ECHO_AND_LOG,/bin/cp -f \$< \$@) + +# SWIG_I ======================================================================= + +SWIG_I =" ; + + foreach my $file ( @files_to_process ) + { + (my $swig_file = $file) =~ s/(\.[^.]*)?$/_py/ ; + print MAKEFILE " \\\n $ENV{TRICK_BUILD_DIR}build$swig_file.i" ; + } + + print MAKEFILE " + +define create_convert_swig_rule +$ENV{TRICK_BUILD_DIR}build/%_py.i: /%.\$1 +\t\$\$(call ECHO_AND_LOG,\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \$\${TRICK_CONVERT_SWIG_FLAGS} \$\$<) +endef + +\$(foreach EXTENSION,H h hh hxx h++ hpp,\$(eval \$(call create_convert_swig_rule,\$(EXTENSION)))) + +$ENV{TRICK_BUILD_DIR}build/top.i: $ENV{TRICK_BUILD_DIR}build/CP_instances +\t\$(call ECHO_AND_LOG,\${PYTHON} \${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 | %.d \$(SWIG_I) +\t\$(PRINT_SWIG) +\t\$(call ECHO_AND_LOG,\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(TRICK_SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201 -w303 -w315 -w325 -w362 -w389 -w401 -w451 -MMD -MP -outdir $swig_sim_dir -o \$@ \$<) + +\$(SWIG_SRC:.cpp=.d): ; + +-include \$(SWIG_SRC:.cpp=.d) + +# SWIG_OBJECTS ================================================================= + +SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) ${swig_src_dir}/init_swig_modules.o + +\$(SWIG_OBJECTS): %.o: %.cpp +\t\$(PRINT_COMPILE_SWIG) +\t\$(call ECHO_AND_LOG,\$(TRICK_CXX) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) \$(TRICK_SWIG_CFLAGS) \$(TRICK_SYSTEM_SWIG_CFLAGS) -Wno-unused-parameter -c -o \$@ \$<) + +\$(S_MAIN): \$(SWIG_OBJECTS) + +LINK_LISTS += \$(LD_FILELIST)$ENV{TRICK_BUILD_DIR}build/py_link_list + +# $ENV{'TRICK_BUILD_DIR'}$swig_sim_zip =================================================================== + +$ENV{'TRICK_BUILD_DIR'}$swig_sim_zip: \$(SWIG_SRC) \$(TRICK_FIXED_PYTHON) $swig_sim_dir/__init__.py +\t\$(info \$(call COLOR,Compiling) Python modules) +\t\$(call ECHO_AND_LOG,\$(PYTHON) -m compileall -q $swig_sim_dir) +\t\$(info \$(call COLOR,Zipping) Python modules into \$@) +\t\$(call ECHO_AND_LOG,ln -sf $swig_sim_dir trick) +\t\$(call ECHO_AND_LOG,zip -rq $ENV{'TRICK_BUILD_DIR'}$swig_sim_zip trick) +\t\$(call ECHO_AND_LOG,rm -f trick) + + +all: $ENV{'TRICK_BUILD_DIR'}$swig_sim_zip +" ; + + open INITSWIGFILE , ">$ENV{TRICK_BUILD_DIR}build/init_swig_modules.cpp" or die "Could not open $ENV{TRICK_BUILD_DIR}build/init_swig_modules.cpp for writing" ; + print INITSWIGFILE "#include \n" ; + print INITSWIGFILE "#if PY_VERSION_HEX >= 0x03000000\n" ; + print INITSWIGFILE "extern \"C\" {\n\n" ; + + foreach my $file ( @files_to_process, @ext_lib_files ) + { + print INITSWIGFILE "PyObject * PyInit__m$md5s{$file}(void) ; /* $file */\n" ; + } + + print INITSWIGFILE "PyObject * PyInit__sim_services(void) ;\n" ; + print INITSWIGFILE "PyObject * PyInit__top(void) ;\n" ; + print INITSWIGFILE "PyObject * PyInit__swig_double(void) ;\n" ; + print INITSWIGFILE "PyObject * PyInit__swig_int(void) ;\n" ; + print INITSWIGFILE "PyObject * PyInit__swig_ref(void) ;\n" ; + + print INITSWIGFILE "\nvoid init_swig_modules(void) {\n\n" ; + foreach my $file ( @files_to_process, @ext_lib_files ) + { + next if ( $file =~ /S_source.hh/ ) ; + print INITSWIGFILE " PyImport_AppendInittab(\"_m$md5s{$file}\", PyInit__m$md5s{$file}) ;\n" ; + } + print INITSWIGFILE " PyImport_AppendInittab(\"_m${s_source_md5}\", PyInit__m${s_source_md5}) ;\n" ; + print INITSWIGFILE " PyImport_AppendInittab(\"_sim_services\", PyInit__sim_services) ;\n" ; + print INITSWIGFILE " PyImport_AppendInittab(\"_top\", PyInit__top) ;\n" ; + print INITSWIGFILE " PyImport_AppendInittab(\"_swig_double\", PyInit__swig_double) ;\n" ; + print INITSWIGFILE " PyImport_AppendInittab(\"_swig_int\", PyInit__swig_int) ;\n" ; + print INITSWIGFILE " PyImport_AppendInittab(\"_swig_ref\", PyInit__swig_ref) ;\n" ; + print INITSWIGFILE " return ;\n}\n\n}\n" ; + print INITSWIGFILE "#else\n" ; + + print INITSWIGFILE "extern \"C\" {\n\n" ; + + foreach my $file ( @files_to_process, @ext_lib_files ) + { + print INITSWIGFILE "void init_m$md5s{$file}(void) ; /* $file */\n" ; + } + + print INITSWIGFILE "void init_sim_services(void) ;\n" ; + print INITSWIGFILE "void init_top(void) ;\n" ; + print INITSWIGFILE "void init_swig_double(void) ;\n" ; + print INITSWIGFILE "void init_swig_int(void) ;\n" ; + print INITSWIGFILE "void init_swig_ref(void) ;\n" ; + + print INITSWIGFILE "\nvoid init_swig_modules(void) {\n\n" ; + foreach my $file ( @files_to_process, @ext_lib_files) + { + next if ( $file =~ /S_source.hh/ ) ; + print INITSWIGFILE " init_m$md5s{$file}() ;\n" ; + } + print INITSWIGFILE " init_m${s_source_md5}() ;\n" ; + print INITSWIGFILE " init_sim_services() ;\n" ; + print INITSWIGFILE " init_top() ;\n" ; + print INITSWIGFILE " init_swig_double() ;\n" ; + print INITSWIGFILE " init_swig_int() ;\n" ; + print INITSWIGFILE " init_swig_ref() ;\n" ; + print INITSWIGFILE " return ;\n}\n\n}\n" ; + print INITSWIGFILE "#endif\n" ; + close INITSWIGFILE ; + + if ( ! -e $swig_sim_dir) + { + mkdir $swig_sim_dir ; + } + open INITFILE , ">$swig_sim_dir/__init__.py" or die "Could not open $swig_sim_dir/__init__.py for writing" ; + + print INITFILE "from pkgutil import extend_path\n" ; + print INITFILE "__path__ = extend_path(__path__, __name__)\n" ; + print INITFILE "import sys\n" ; + print INITFILE "import os\n" ; + print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick\")\n" ; + foreach my $dir ( keys %python_module_dirs ) + { + print INITFILE "sys.path.append(os.getcwd() + \"/$swig_sim_zip/trick/$dir\")\n" ; + } + + print INITFILE "\n" ; + print INITFILE "import _sim_services\n" ; + print INITFILE "from sim_services import *\n\n" ; + + print INITFILE "# create \"all_cvars\" to hold all global/static vars\n" ; + print INITFILE "all_cvars = new_cvar_list()\n" ; + print INITFILE "combine_cvars(all_cvars, cvar)\n" ; + print INITFILE "cvar = None\n\n" ; + + foreach my $file ( @files_to_process, @ext_lib_files ) + { + print INITFILE "# $file\n" ; + print INITFILE "import _m$md5s{$file}\n" ; + print INITFILE "combine_cvars(all_cvars, cvar)\n" ; + print INITFILE "cvar = None\n\n" ; + } + + foreach my $file ( @files_to_process, @ext_lib_files ) + { + print INITFILE "# $file\n" ; + print INITFILE "from m$md5s{$file} import *\n" ; + } + + foreach my $mod ( keys %python_modules ) + { + print INITFILE "import trick.$mod\n" ; + } + + print INITFILE "\n" ; + print INITFILE "# S_source.hh\n" ; + print INITFILE "import _m${s_source_md5}\n" ; + print INITFILE "from m${s_source_md5} import *\n\n" ; + print INITFILE "import _top\n" ; + print INITFILE "import top\n\n" ; + print INITFILE "import _swig_double\n" ; + print INITFILE "import swig_double\n\n" ; + print INITFILE "import _swig_int\n" ; + print INITFILE "import swig_int\n\n" ; + print INITFILE "import _swig_ref\n" ; + print INITFILE "import swig_ref\n\n" ; + print INITFILE "from shortcuts import *\n\n" ; + print INITFILE "from exception import *\n\n" ; + print INITFILE "cvar = all_cvars\n\n" ; + close INITFILE ; + + foreach my $dir ( keys %python_module_dirs ) + { + system("mkdir -p $swig_sim_dir/$dir"); + open MODULE_INITFILE, ">$swig_sim_dir/$dir/__init__.py"; + foreach my $file ( @files_to_process ) + { + if ( exists $trick_headers{$file}{python_module_dir} and $trick_headers{$file}{python_module_dir} eq $dir ) + { + print MODULE_INITFILE "# $file\n" ; + print MODULE_INITFILE "import _m$md5s{$file}\n" ; + print MODULE_INITFILE "from m$md5s{$file} import *\n" ; + } + } + close MODULE_INITFILE; + } + + return ; +} + +sub write_lib_files() +{ + open PY_LINK_LIST , ">$ENV{TRICK_BUILD_DIR}build/py_link_list" or die "Could not open $ENV{TRICK_BUILD_DIR}build/py_link_list for writing" ; + open TRICKIFY_PY_LINK_LIST , ">$ENV{TRICK_BUILD_DIR}build/trickify_py_link_list" or die "Could not open $ENV{TRICK_BUILD_DIR}build/trickify_py_link_list for writing" ; + open SWIGLIB , ">$ENV{TRICK_BUILD_DIR}build/S_library_swig" or die "Could not open $ENV{TRICK_BUILD_DIR}build/S_library_swig for writing" ; + + print PY_LINK_LIST "$ENV{TRICK_BUILD_DIR}build/init_swig_modules.o\n" ; + print PY_LINK_LIST "$ENV{TRICK_BUILD_DIR}build/top.o\n" ; + + foreach my $file ( @files_to_process ) + { + print SWIGLIB "$file\n" ; + + (my $swig_file = $file) =~ s/(\.[^.]*)?$/_py/ ; + print PY_LINK_LIST "$ENV{TRICK_BUILD_DIR}build$swig_file.o\n" ; + if ( !($swig_file =~ /(.*)S_source_py$/) ) + { + print TRICKIFY_PY_LINK_LIST "$ENV{TRICK_BUILD_DIR}build$swig_file.o\n" ; + } + } + + close MAKEFILE ; + close PY_LINK_LIST ; + close TRICKIFY_PY_LINK_LIST ; + close SWIGLIB ; +} + +# Read in the list of all trickify deps, so that we can make sure no fake python dependencies are listed. +# This problem occurs when users use -I voodoo to make their local model files take precdent over a libraries files. +# When trickiying the respective library, trick will list the libraries version of the swig module as a dependency, which will cause mayhem at run time. +# Only do this on the trickify.mk passthrough +sub trickify_map_fake_deps() +{ + + # Generate the true list of dependencies + my %src_deps ; + open SRC_DEPS , "$ENV{TRICK_BUILD_DIR}tmp_build/build/trickify_deps" or die "Failed to open $ENV{TRICK_BUILD_DIR}tmp_build/build/trickify_deps\n"; + while ( ) + { + my $key = s/\s*$//; + my $key = s/^\s*//; + $src_deps{$_} = 1 ; + } + close SRC_DEPS ; + + # Grab our includes, for validating the replacement path + my @includes = get_include_paths() ; + + my @new_file_list ; + my %replacements ; + foreach my $file (@files_to_process) + { + # file is fine, keep it + if ($src_deps{$file} == 1 or $file =~ /S_source.hh/) + { + push @new_file_list, $file ; + } + # fake dependency, find the real one + else + { + print "SKIPPING: $file\n"; + my (@src_dep, @file, @common, $tmp_src_dep, $tmp_file) ; + my $found_match = 0 ; + my %possible_replacements = (); + foreach my $src_dep (sort keys %src_deps) + { + @src_dep = File::Spec->splitdir($src_dep) ; + @file = File::Spec->splitdir($file) ; + + # search for the real dependencies, by checking the file path starting at the filename + # if at least the file name matches, we have a match. Otherwise move onto the next dependency + # for a match, split the paths into matching and non matching portions + $found_match = 0 ; + do { + $tmp_src_dep = pop @src_dep ; + $tmp_file = pop @file ; + if ($tmp_src_dep eq $tmp_file) + { + unshift @common, $tmp_file ; + $found_match = 1 ; + } + else + { + push @src_dep, $tmp_src_dep ; + push @file, $tmp_file ; + if ($found_match) { + $possible_replacements{$src_dep} = join '/', @common ; + } + } + } while ($tmp_src_dep eq $tmp_file and @src_dep and @file) ; + } + + if( (scalar (keys %possible_replacements)) == 1) + { + print "WE'VE GOT A MATCH: \n\t", keys %possible_replacements, " | $file\n" ; + my ($key) = (keys %possible_replacements) ; + $trickify_files_to_replace{$file} = $key ; + push @new_file_list, $key ; + } + else + { + print "You did something bad...\n" ; + } + } + } +} + +sub replace_files_to_process() +{ + foreach my $old_file (keys %trickify_files_to_replace) + { + foreach (@files_to_process) + { + $_ = $trickify_files_to_replace{$old_file} if $_ eq $old_file ; + } + } + +} + +sub write_fake_deps_map() +{ + make_path("$ENV{TRICK_BUILD_DIR}build/trickify/swig/") unless -d "$ENV{TRICK_BUILD_DIR}build/trickify/swig/" ; + + open FAKEDEPSMAP, ">$ENV{TRICK_BUILD_DIR}build/trickify/fake_deps_map" or die "Could not open $ENV{TRICK_BUILD_DIR}build/trickify/fake_deps_map" ; + print FAKEDEPSMAP map { "$_:$trickify_files_to_replace{$_}\n" } (sort keys %trickify_files_to_replace) ; + close FAKEDEPSMAP ; +} + +1 ; diff --git a/libexec/trick/sie_concat b/libexec/trick/sie_concat index afac248e7..b28a6cbee 100755 --- a/libexec/trick/sie_concat +++ b/libexec/trick/sie_concat @@ -8,13 +8,13 @@ use get_paths ; my @trick_python_paths = get_paths( "TRICK_PYTHON_PATH") ; -open(my $S_sie_resource, ">", "./S_sie.resource") - or die "cannot open S_sie.resource $!"; +open(my $S_sie_resource, ">", "$ENV{TRICK_BUILD_DIR}S_sie.resource") + or die "cannot open $ENV{TRICK_BUILD_DIR}S_sie.resource $!"; print $S_sie_resource "\n\n\n\n"; -open(my $classes_resource, "<", "build/classes.resource") - or die "cannot open build/classes.resource"; +open(my $classes_resource, "<", "$ENV{TRICK_BUILD_DIR}build/classes.resource") + or die "cannot open $ENV{TRICK_BUILD_DIR}build/classes.resource"; while(my $line = <$classes_resource>) { print $S_sie_resource $line; } @@ -32,8 +32,8 @@ foreach my $path ( @trick_python_paths ) { } } -open(my $top_level_objects_resource, "<", "build/top_level_objects.resource") - or die "cannot open build/top_level_objects.resource"; +open(my $top_level_objects_resource, "<", "$ENV{TRICK_BUILD_DIR}build/top_level_objects.resource") + or die "cannot open $ENV{TRICK_BUILD_DIR}build/top_level_objects.resource"; while(my $line = <$top_level_objects_resource>) { print $S_sie_resource $line; } diff --git a/libexec/trick/trickify_get_swig_data b/libexec/trick/trickify_get_swig_data new file mode 100755 index 000000000..c36ce7887 --- /dev/null +++ b/libexec/trick/trickify_get_swig_data @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use FindBin qw($RealBin); +use lib "$RealBin/pm" ; + +use File::Path qw(make_path); +use swig_make ; + +use strict ; + +read_files_to_process() ; + +# Only want to run this with trickify-25. This check is to prevent this script from executing using the old trickify.mk method. +#TODO: Come up with a more elegant solution. Or drop this check when oldschool trickify.mk is no longer supported. +if($ENV{'AM_I_TRICKIFYING'}) +{ + trickify_map_fake_deps() ; + + replace_files_to_process() ; +} + +get_trick_headers() ; + +purge_swig_no_files() ; + +write_lib_files() ; + +# Only want to run this with trickify-25. This check is to prevent this script from executing using the old trickify.mk method. +#TODO: Come up with a more elegant solution. Or drop this check when oldschool trickify.mk is no longer supported. +if($ENV{'AM_I_TRICKIFYING'}) +{ + write_fake_deps_map() ; +} diff --git a/share/doc/trick/data/build_dir_readme b/share/doc/trick/data/build_dir_readme new file mode 100644 index 000000000..d04eb03a9 --- /dev/null +++ b/share/doc/trick/data/build_dir_readme @@ -0,0 +1,4 @@ +S_library_swig + Generated by: make_makefile_swig->write_lib_files() + Use: Metadata only, not used internally by Trick + Contents: The list of headers swigged by Trick. The list is initially generated by get_lib_deps.pm->get_s_source_deps(), using gcc -MM on S_source.hh. The resulting dependency tree is pruned for any paths under TRICK_EXT_LIB_DIRS. Finally, the list is pruned of any "SWIG: (NO)" files. diff --git a/share/trick/makefiles/Makefile.common b/share/trick/makefiles/Makefile.common index 4db13de63..ca44dbb93 100644 --- a/share/trick/makefiles/Makefile.common +++ b/share/trick/makefiles/Makefile.common @@ -3,8 +3,8 @@ CD := cd MV := /bin/mv RM := /bin/rm CP := /bin/cp -MAKE_OUT := $(abspath build/MAKE_out) -MAKE_ERR := $(abspath build/MAKE_err) +MAKE_OUT := $(abspath $(TRICK_BUILD_DIR)build/MAKE_out) +MAKE_ERR := $(abspath $(TRICK_BUILD_DIR)build/MAKE_err) PWD = $(shell /bin/pwd) COLOR = $(1) diff --git a/share/trick/makefiles/trickify.mk b/share/trick/makefiles/trickify.mk index 5c236022e..e02e10361 100644 --- a/share/trick/makefiles/trickify.mk +++ b/share/trick/makefiles/trickify.mk @@ -88,6 +88,8 @@ # For more information, see: # https://nasa.github.io/trick/documentation/building_a_simulation/Trickified-Project-Libraries +export AM_I_TRICKIFYING_MK=1 + MY_HOME := $(dir $(lastword $(MAKEFILE_LIST))) -include $(TRICKIFY_MAKE_DUMP) @@ -236,7 +238,7 @@ $(TRICKIFY_PYTHON_DIR): $(SWIG_OBJECTS:.o=.cpp) | $(dir $(TRICKIFY_PYTHON_DIR)) $(BUILD_DIR)S_source.d: | $(BUILD_DIR) $(call ECHO_AND_LOG,$(TRICK_HOME)/bin/trick-ICG $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_ICGFLAGS) S_source.hh) - $(call ECHO_AND_LOG,$(TRICK_HOME)/$(LIBEXEC)/trick/make_makefile_swig) + $(call ECHO_AND_LOG,$(TRICK_HOME)/$(LIBEXEC)/trick/trickify_get_swig_data) $(call ECHO_AND_LOG,$(TRICK_CC) -MM -MP -MT $@ -MF $@ $(TRICK_CXXFLAGS) S_source.hh) -include $(BUILD_DIR)S_source.d diff --git a/test/SIM_build_dir/RUN_test/unit_test.py b/test/SIM_build_dir/RUN_test/unit_test.py new file mode 100644 index 000000000..f74fee0bf --- /dev/null +++ b/test/SIM_build_dir/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_build_dir/S_define b/test/SIM_build_dir/S_define new file mode 100644 index 000000000..f770e2a73 --- /dev/null +++ b/test/SIM_build_dir/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_build_dir/S_overrides.mk b/test/SIM_build_dir/S_overrides.mk new file mode 100644 index 000000000..6a7455940 --- /dev/null +++ b/test/SIM_build_dir/S_overrides.mk @@ -0,0 +1 @@ +TRICK_CXXFLAGS += -I$(CURDIR)/models diff --git a/test/SIM_build_dir/models/Bar.hh b/test/SIM_build_dir/models/Bar.hh new file mode 100644 index 000000000..18ea38410 --- /dev/null +++ b/test/SIM_build_dir/models/Bar.hh @@ -0,0 +1,12 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add() {} + void remove() {} + void restart() {} + +}; diff --git a/test/SIM_build_dir/models/Baz.hh b/test/SIM_build_dir/models/Baz.hh new file mode 100644 index 000000000..fc91c1b21 --- /dev/null +++ b/test/SIM_build_dir/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_build_dir/models/Foo.hh b/test/SIM_build_dir/models/Foo.hh new file mode 100644 index 000000000..be7e761a2 --- /dev/null +++ b/test/SIM_build_dir/models/Foo.hh @@ -0,0 +1,15 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo() { + std::cout << i++ << '\n'; + } + +}; diff --git a/test_sims.yml b/test_sims.yml index 6d4c924a4..29ae9f61d 100644 --- a/test_sims.yml +++ b/test_sims.yml @@ -3,6 +3,9 @@ SIM_alloc_test: path: test/SIM_alloc_test SIM_alloc_test: path: test/SIM_alloc_test +SIM_build_dir: + path: test/SIM_build_dir + build_args: "-b Trick_Build_Dir" SIM_anon_enum: path: test/SIM_anon_enum SIM_default_member_initializer: diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 9aa72ab0c..54db55fc3 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -33,6 +33,34 @@ PrintAttributes::PrintAttributes(int in_attr_version , HeaderSearchDirs & in_hsd output_dir( in_output_dir ) { printer = new PrintFileContents10() ; + + const char* trick_build_dir_ptr = std::getenv("TRICK_BUILD_DIR"); + if( !trick_build_dir_ptr ) { + trick_build_dir_ptr = ""; + } + trick_build_dir = trick_build_dir_ptr; + + trickifying = false; + trickifying_mk = false; + if( std::getenv("AM_I_TRICKIFYING") && std::getenv("AM_I_TRICKIFYING_MK") ) { + trickifying = true; + trickifying_mk = true; + std::ifstream trickify_deps(trick_build_dir + "build/trickify/fake_deps_map") ; + if ( !trickify_deps.fail() ) { + std::string input; + while ( std::getline(trickify_deps, input) ) { + trickify_src_deps_map.push_back(input); + } + } + else { + std::cout << trick_build_dir + "build/trickify/fake_deps_map no exist =(" << std::endl; + } + } + else + { + std::cout << "NO AM_I_TRICKIFYING_MK!" << std::endl; + } + } void PrintAttributes::addIgnoreTypes() { @@ -54,7 +82,6 @@ void PrintAttributes::addIgnoreTypes() { /** @details - In order for us to create an io_src file for an include the header must: 1. Reside in a user directory ( not system dirs like /usr/include @@ -134,6 +161,19 @@ bool PrintAttributes::openIOFile(const std::string& header_file_name) { return false; } + if (trickifying && trickifying_mk) { + bool found = false; + for (int itr = 0; itr < trickify_src_deps_map.size(); itr++) { + if (trickify_src_deps_map[itr] == header_file_name) { + found = true; + } + } + if (!found) { + std::cout << "|" << header_file_name << "|" << std::endl; + return false; + } + } + // map the header to its IO file char* realPath = almostRealPath(header_file_name.c_str()); const std::string io_file_name = createIOFileName(realPath) ; @@ -209,7 +249,7 @@ std::string PrintAttributes::createIOFileName(std::string header_file_name) { } else { //TODO: only use build directory if we are ICG'ing a sim // All files go into a build directory based in the current directory. - io_file_name = std::string("build") + dir_name + "/" + base_name ; + io_file_name = trick_build_dir + std::string("build") + dir_name + "/" + base_name ; } } return io_file_name ; @@ -282,7 +322,7 @@ void PrintAttributes::printSieClass( ClassValues * cv ) { xmlFileName = std::string(getenv("TRICK_HOME")) + "/share/trick/xml/sim_services_classes.resource"; #endif } else { - xmlFileName = "build/classes.resource"; + xmlFileName = trick_build_dir + "build/classes.resource"; } std::ofstream ostream(xmlFileName, std::ofstream::app); ostream << " getFullyQualifiedMangledTypeName("__")) << "\">\n"; @@ -349,7 +389,7 @@ void PrintAttributes::createMapFiles() { class_map_function_name = "populate_sim_services_class_map" ; enum_map_function_name = "populate_sim_services_enum_map" ; } else { - map_dir = "build" ; + map_dir = trick_build_dir + "build" ; class_map_function_name = "populate_class_map" ; enum_map_function_name = "populate_enum_map" ; } @@ -435,7 +475,7 @@ void PrintAttributes::printIOMakefile() { std::cout << color(INFO, "Writing") << " Makefile_io_src" << std::endl ; - makefile_io_src.open("build/Makefile_io_src") ; + makefile_io_src.open(trick_build_dir + "build/Makefile_io_src") ; makefile_io_src << "TRICK_IO_CXXFLAGS += -Wno-invalid-offsetof -Wno-old-style-cast -Wno-write-strings -Wno-unused-variable" << std::endl << std::endl @@ -458,7 +498,7 @@ void PrintAttributes::printIOMakefile() { makefile_io_src << " \\\n " << (*mit).second.substr(0,found) << ".o" ; } - makefile_io_src << " \\\n build/class_map.o" << std::endl + makefile_io_src << " \\\n $(TRICK_BUILD_DIR)build/class_map.o" << std::endl << std::endl << "$(IO_OBJECTS): \%.o : \%.cpp | \%.d" << std::endl << "\t$(PRINT_COMPILE)" << std::endl @@ -470,7 +510,7 @@ void PrintAttributes::printIOMakefile() { << std::endl << "$(S_MAIN): $(IO_OBJECTS)" << std::endl << std::endl - << "LINK_LISTS += $(LD_FILELIST)build/io_link_list" << std::endl; + << "LINK_LISTS += $(LD_FILELIST)" + trick_build_dir + "build/io_link_list" << std::endl; makefile_io_src.close() ; @@ -484,12 +524,12 @@ void PrintAttributes::printIOMakefile() { ICG_process lists all header files to be used by SWIG. */ - makefile_ICG.open("build/Makefile_ICG") ; - io_link_list.open("build/io_link_list") ; - trickify_io_link_list.open("build/trickify_io_link_list") ; - ICG_processed.open("build/ICG_processed") ; + makefile_ICG.open(trick_build_dir + "build/Makefile_ICG") ; + io_link_list.open(trick_build_dir + "build/io_link_list") ; + trickify_io_link_list.open(trick_build_dir + "build/trickify_io_link_list") ; + ICG_processed.open(trick_build_dir + "build/ICG_processed") ; - makefile_ICG << "build/Makefile_io_src:" ; + makefile_ICG << trick_build_dir + "build/Makefile_io_src:" ; for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; ++mit ) { makefile_ICG << " \\\n " << (*mit).first ; size_t found ; @@ -497,7 +537,8 @@ void PrintAttributes::printIOMakefile() { io_link_list << (*mit).second.substr(0,found) << ".o" << std::endl ; std::string ssrc = (*mit).second.substr(0,found) ; if(ssrc.substr( ssrc.length()-11, ssrc.length()) != "io_S_source" ) - { + { + //TODO: class_map.o appears to be missing? trickify_io_link_list << (*mit).second.substr(0,found) << ".o" << std::endl ; } ICG_processed << (*mit).first << std::endl ; @@ -510,11 +551,11 @@ void PrintAttributes::printIOMakefile() { } ICG_processed.close() ; - io_link_list << "build/class_map.o" << std::endl ; + io_link_list << trick_build_dir + "build/class_map.o" << std::endl ; io_link_list.close() ; trickify_io_link_list.close() ; - ext_lib.open("build/ICG_ext_lib") ; + ext_lib.open(trick_build_dir + "build/ICG_ext_lib") ; for ( auto& file : ext_lib_io_files ) { ext_lib << file << std::endl ; } @@ -522,9 +563,10 @@ void PrintAttributes::printIOMakefile() { } void PrintAttributes::printICGNoFiles() { + if ( ! sim_services_flag ) { std::vector< std::string >::iterator it ; - std::ofstream icg_no_outfile("build/ICG_no_found") ; + std::ofstream icg_no_outfile(trick_build_dir + "build/ICG_no_found") ; for ( it = icg_no_files.begin() ; it != icg_no_files.end() ; ++it ) { icg_no_outfile << (*it) << std::endl ; } diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh index 94796aa95..d4424c98c 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh @@ -145,7 +145,14 @@ class PrintAttributes { std::map< std::string , std::set< std::string > > processed_classes ; /** map of processed enums sorted by file */ std::map< std::string , std::set< std::string > > processed_enums ; - + /** Local copy of the environment variable TRICK_BUILD_DIR */ + std::string trick_build_dir ; + /** Local copy of the environment variable AM_I_TRICKIFYING */ + bool trickifying ; + /** Local copy of the environment variable AM_I_TRICKIFYING_MK */ + bool trickifying_mk ; + /** Used for trickify only, will be empty otherwise. Copy of the base sims dependency list */ + std::vector trickify_src_deps_map; } ; #endif