Split CP up into components that can be called individually

Initial rough checkin that partially works for the ball sim.

refs #86
This commit is contained in:
Alex Lin 2015-07-16 15:36:36 -05:00
parent 0b99667d9b
commit e1c1bbaccf
19 changed files with 1320 additions and 336 deletions

View File

@ -16,7 +16,7 @@ if ( -f "S_define" ) {
print "CP aborted\n" ;
exit 1 ;
}
unlink "Makefile_sim", "makefile" ;
unlink "build/Makefile_sim", "makefile" ;
$makefile_text = do { local $/; <main::DATA> } ;
$makefile_text =~ s/SUB_TRICK_HOME/$trick_home/ ;
$makefile_text =~ s/SUB_TRICK_BIN/$trick_bin/ ;

View File

@ -0,0 +1,20 @@
#!/usr/bin/perl
use FindBin qw($RealBin);
use lib "$RealBin/pm" ;
use strict ;
use get_lib_deps ;
my $header ;
my @resolved_files ;
# Read in the Trick comment to be processed.
while ( <STDIN> ) {
last if ( $_ =~ /END ICG PROCESSING/ ) ;
$header .= $_ ;
}
(@resolved_files) = get_lib_deps($header, @ARGV[0]) ;
print map { "$_\n" } @resolved_files ;

View File

@ -12,32 +12,18 @@ use FindBin qw($RealBin);
use lib "$RealBin/pm" ;
use parse_s_define ;
use get_headers ;
use ICG ;
use MIS ;
use mis_dep ;
use make_makefile ;
use make_swig_makefile ;
use make_no_swig_makefile ;
use gte ;
use s_source ;
use auto_doc ;
use default_data ;
use trick_print ;
use trick_version ;
my %sim ;
my $cwd = cwd();
my $saved_cflags ;
my (@paths , $cc , $cc_found) ;
my $make_cmd;
# override the print format for help message
*Pod::Text::seq_i = sub { return "" . $_[1] . "" } ;
# set stdout to unbuffered so we see printout immediately.
$| = 1 ;
# set default verbose level
$sim{args}{v} = 2 ;
$sim{args}{o} = "build/CP_out" ;
@ -46,44 +32,16 @@ $sim{args}{p} = 1 ;
#--------------------------------------------------------------
# Process command line arguments
Getopt::Long::Configure ("bundling");
GetOptions ( "d" => \$sim{args}{d} ,
"e" => \$sim{args}{e} ,
"f" => \$sim{args}{f} ,
"model_dirs|z" => \$sim{args}{z} ,
"no_python|p" => sub { $sim{args}{p} = 0 } ,
GetOptions ( "no_python|p" => sub { $sim{args}{p} = 0 } ,
"debug|g" => sub { $sim{args}{v} = 3 ; } ,
"help|h|?" => \$sim{args}{h} ,
"m" => \$sim{args}{m} ,
"outfile|o=s" => \$sim{args}{o} ,
"r" => \$sim{args}{r} ,
"s" => \$sim{args}{s} ,
"t" => \$sim{args}{t} ,
"verbose|v=i" => \$sim{args}{v}
) or pod2usage(1) ;
pod2usage(1) if $sim{args}{h} ;
$ENV{TRICK_HOST_CPU} = gte("TRICK_HOST_CPU") ;
chomp $ENV{TRICK_HOST_CPU} ;
# look to see if TRICK_CC set properly
@paths = split /:/ , $ENV{PATH} ;
$cc = gte("TRICK_CC") ;
chomp $cc ;
$cc =~ s/.*?ccache\s+// ;
$cc_found = 0 ;
foreach my $p ( @paths ) {
if ( -x "$p/$cc" or -x $cc ) {
$cc_found = 1 ;
last ;
}
}
if ( $cc_found == 0 ) {
trick_print( $sim{fh}, "CP can't find TRICK_CC = $cc.\n", "title_red", $sim{args}{v} ) ;
exit ;
}
# Get Trick version
my ($version, $thread) = get_trick_version() ;
$thread =~ s/\d+\.// ;
@ -98,10 +56,6 @@ $sim{fh} = *OUTFILE ;
print OUTFILE "Output for $0 version $version-$thread at " . localtime() . "\n\n" ;
if ( !( $sim{args}{e} || $sim{args}{s} || $sim{args}{m} || $sim{args}{d} ) ) {
$sim{args}{e} = $sim{args}{s} = $sim{args}{m} = $sim{args}{d} = 1 ;
}
# if no python is specified, turn off the python InputProcessor sim_object in S_define.
if ( $sim{args}{p} == 0 ) {
$ENV{TRICK_SFLAGS} .= " -DTRICK_NO_INPUTPROCESSOR" ;
@ -117,158 +71,34 @@ parse_s_define(\%sim) ;
trick_print( $sim{fh}, "\nCompleted parsing S_define\n\n" , "normal_green" , $ sim{args}{v} ) ;
#--------------------------------------------------------------
# If this is CP -z|model_dirs, print model dirs and exit
if ( $sim{args}{z} ) {
my %model_dirs ;
foreach ( keys %{$sim{headers_full_path}} ) {
$model_dirs{dirname($_)} = 1 ;
}
foreach ( @{$sim{mis_entry_files}} ) {
$model_dirs{dirname($_)} = 1 ;
}
trick_print($sim{fh}, "Model directory listing\n", "title_cyan", $sim{args}{v});
foreach ( sort keys %model_dirs ) {
trick_print($sim{fh}, "$_\n", "normal_white", $sim{args}{v});
}
exit ;
}
#--------------------------------------------------------------
# Make S_source.c
if ($sim{args}{s}) {
trick_print($sim{fh}, "Creating S_source.c...", "title_cyan", $sim{args}{v});
s_source( \%sim ) ;
trick_print($sim{fh}, " Complete\n", "title_green", $sim{args}{v}) ;
}
#--------------------------------------------------------------
# Get all headers used by the sim and their modification dates
get_headers(\%sim, abs_path("S_source.hh")) ;
#--------------------------------------------------------------
# ICG all headers that S_define references
# ICG will return:
# -> Hash of types (used to create S_source.c)
# %types{type_name} -> {name,value,xml}
# value == 102 means enumerated type
# value == 103 means struct type
# -> Hash of dependencies (used to create Makefile)
my @files_to_mis ;
my ($new_mis_depends_ref , $rcs_tags_ref) ;
my @mis_entry_files ;
my @headers_to_ICG ;
my @all_headers_to_ICG ;
chdir ($cwd) ;
trick_print($sim{fh}, "Determining structure dependencies.\n" , "normal_cyan" , $sim{args}{v}) ;
@all_headers_to_ICG = (sort keys %{$sim{headers_full_path}}) ;
foreach ( @all_headers_to_ICG ) {
if ( !/trick_source/ ) {
push @headers_to_ICG , $_ ;
}
}
if ( scalar @headers_to_ICG ) {
trick_print( $sim{fh}, "ICG'ing header files to get all header file dependencies..." , "title_cyan" , $sim{args}{v} ) ;
trick_print( $sim{fh}, "\n" , "title_white" , $sim{args}{v} ) if ( $sim{args}{v} != 1 ) ;
}
my @defs ;
my @temp_array = ( abs_path("S_source.hh")) ;
ICG ( @temp_array , "CP" , \@defs, \%sim ) ;
if ( $sim{args}{v} == 1 ) {
print " Complete\n" ;
}
if ( scalar @headers_to_ICG ) {
trick_print( $sim{fh}, "\nAll header file dependencies found.\n" , "normal_green" , $sim{args}{v} ) ;
}
foreach my $h ( @all_headers_to_ICG ) {
# push the header dependencies for c++ files onto the lists for mis processing
foreach ( keys %{$sim{all_icg_depends}{$h}} ) {
if ( exists $sim{head_deps}{$_} and defined $sim{head_deps}{$_}{files} ) {
push @mis_entry_files , @{$sim{head_deps}{$_}{files}} ;
push @{$sim{mis_entry_files}} , @{$sim{head_deps}{$_}{files}} ;
}
}
}
trick_print( $sim{fh}, "Determining module dependencies.\n", "normal_cyan" , $sim{args}{v}) ;
push @mis_entry_files , (grep !/trick_source/ , @{$sim{mis_entry_files}}) ;
foreach ( @mis_entry_files ) {
if ( ! exists $sim{src_only}{$_} ) {
if ( !/trick_source/ ) {
push @files_to_mis , $_ ;
}
}
}
my %temp_hash ;
@files_to_mis = grep ++$temp_hash{$_} < 2, @files_to_mis ;
$new_mis_depends_ref = mis_dep(\%sim , @files_to_mis) ;
# Add the object only listings
mis_catalog_dep(\%sim , $new_mis_depends_ref) ;
foreach my $k ( keys %$new_mis_depends_ref ) {
$sim{all_mis_depends}{$k} = $$new_mis_depends_ref{$k} ;
}
my @all_src_files ;
foreach my $n ( @{$sim{mis_entry_files}} ) {
foreach my $k ( grep !/last_look/ ,
(keys %{$sim{all_mis_depends}{$n}}) ) {
push @all_src_files ,
@{$sim{all_mis_depends}{$n}{$k}} ;
}
}
undef %temp_hash ;
@all_src_files = grep ++$temp_hash{$_} < 2, @all_src_files ;
@all_src_files = grep !/trick_source|\.a$|^\-/ , @all_src_files ;
if ( $sim{args}{v} == 1 ) {
print " Complete\n" ;
}
trick_print($sim{fh}, "\nMIS complete\n\n" , "normal_green" , $sim{args}{v}) ;
trick_print($sim{fh}, "Creating S_source.c...", "title_cyan", $sim{args}{v});
s_source( \%sim ) ;
trick_print($sim{fh}, " Complete\n", "title_green", $sim{args}{v}) ;
#--------------------------------------------------------------
# Make Default Data
if ($sim{args}{d}) {
chdir ($cwd) ;
trick_print($sim{fh}, "Creating Default_data...", "title_cyan" , $sim{args}{v}) ;
make_default_data( \%sim ) ;
trick_print($sim{fh}, " Complete\n", "title_green", $sim{args}{v}) ;
}
#--------------------------------------------------------------
# Make Makefile
if ($sim{args}{m}) {
trick_print($sim{fh}, "Creating New Makefile... ", "title_cyan" , $sim{args}{v}) ;
make_makefile( \@temp_array , \%sim , $cwd) ;
trick_print($sim{fh}, " Complete\n" , "title_green" , $sim{args}{v}) ;
if ( $sim{args}{p} == 1 ) {
trick_print($sim{fh}, "Creating SWIG Makefile... ", "title_cyan" , $sim{args}{v}) ;
make_swig_makefile( \@temp_array , \%sim , $cwd) ;
trick_print($sim{fh}, " Complete\n" , "title_green" , $sim{args}{v}) ;
} else {
trick_print($sim{fh}, "Creating No-python Makefile... ", "title_cyan" , $sim{args}{v}) ;
make_no_swig_makefile() ;
trick_print($sim{fh}, " Complete\n" , "title_green" , $sim{args}{v}) ;
}
}
chdir ($cwd) ;
trick_print($sim{fh}, "Creating Default_data...", "title_cyan" , $sim{args}{v}) ;
make_default_data( \%sim ) ;
trick_print($sim{fh}, " Complete\n", "title_green", $sim{args}{v}) ;
close OUTFILE ;
#--------------------------------------------------------------
# Write out the library dependencies found in the S_define file.
open LIBDEP, ">build/S_define.lib_deps" ;
foreach my $file ( @{$sim{mis_entry_files}} ) {
if ( $file ne "" ) {
$file = abs_path(dirname($file)) . "/" . basename($file) ;
print LIBDEP "$file\n" ;
}
}
close LIBDEP ;
################################################################################
# END MAIN
################################################################################
@ -324,22 +154,10 @@ output all CP output to an external file
Create a simulation without python input processor.
=item B<-s>
S_source.c (Simulation specific executive source code)
=item B<-r>
S_sie.resource (Smart Input Editor data base)
=item B<-v> I<level> | B<--verbose>=I<level>
Set the verbose level. Valid entries are 0-3.
=item B<-z> | B<--model_dirs>
Print out the model directories this S_define depends on.
=item B<-DTRICK_VER=x.x>
Note: -DTRICK_VER=x.x is automatically used when parsing header files and the S_define file

423
libexec/trick/make_makefile_src Executable file
View File

@ -0,0 +1,423 @@
#!/usr/bin/perl
use FindBin qw($RealBin);
use lib "$RealBin/pm" ;
use strict ;
use File::Basename ;
use Cwd ;
use Cwd 'abs_path';
use trick_version ;
use get_lib_deps ;
my %processed_files ;
my %non_lib_processed_files ;
sub read_lib_deps(@) {
my (@files_to_process) = @_ ;
foreach my $l ( @files_to_process ) {
next if ( $l eq "" ) ;
if ( ! exists $processed_files{$l} ) {
$processed_files{$l} = 1 ;
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}.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) = <FH> ;
close FH ;
chomp @all_lines ;
read_lib_deps(@all_lines) ;
} else {
print "Getting Dependencies for $l\n" ;
if ( -e $l ) {
my $contents ;
my @resolved_files ;
@resolved_files = write_lib_deps($l) ;
read_lib_deps(@resolved_files) ;
}
}
}
}
}
for my $f ( @ARGV ) {
print "Updating Dependencies for $f\n" ;
write_lib_deps($f) ;
}
open FILE, "build/header_lib_deps_files" or die 'cannot open build/header_lib_deps_files' ;
my (@top_lib_dep_file_names) = <FILE> ;
close FILE ;
chomp @top_lib_dep_file_names ;
push @top_lib_dep_file_names, "build/S_define.lib_deps" ;
foreach my $f ( @top_lib_dep_file_names ) {
my @all_lines ;
next if ( $f eq "" ) ;
open FH, "$f" or die 'cannot open $f' ;
@all_lines = <FH> ;
close FH ;
chomp @all_lines ;
read_lib_deps(@all_lines) ;
}
#print map {"$_\n"} (sort keys %processed_files) ;
my ($n , $f , $k , $i , $m);
my $num_inc_objs ;
my %all_mis_depends ;
my %temp_hash ;
my @all_cfly_files ;
my @all_read_only_libs ;
my @all_compile_libs ;
my %files_by_dir ;
my ( $sp_dir , $src_dir , $sp_file , $base_name , $suffix) ;
my @temp_array ;
my @exclude_dirs ;
@exclude_dirs = split /:/ , $ENV{"TRICK_EXCLUDE"};
# See if there are any elements in the exclude_dirs array
if (scalar @exclude_dirs) {
@exclude_dirs = sort(@exclude_dirs );
# Error check - delete any element that is null
# (note: sort forced all blank names to front of array
@exclude_dirs = map { s/(^\s+|\s+$)//g ; $_ } @exclude_dirs ;
while ( not length @exclude_dirs[0] ) {
# Delete an element from the left side of an array (element zero)
shift @exclude_dirs ;
}
@exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @exclude_dirs ;
}
@all_cfly_files = keys %processed_files ;
@all_read_only_libs = sort (grep /^-/ , @all_cfly_files) ;
@all_compile_libs = grep /\.a$/ , @all_cfly_files ;
@all_compile_libs = sort (grep !/trick_source/ , @all_compile_libs) ;
@all_cfly_files = sort (grep !/^-|trick_source|a$/ , @all_cfly_files) ;
# split off files by directory
foreach ( @all_cfly_files ) {
$sp_file = basename($_) ;
$_ = abs_path(dirname($_)) ;
( $sp_dir , $src_dir ) = /(.*?)(?:\/(src))?$/ ;
$src_dir .= "/" if ($src_dir ne "") ;
($base_name , $suffix) = $sp_file =~ /(.*?)([cfly]$|C$|cc$|cxx$|cpp$|c\+\+$)/ ;
$files_by_dir{$sp_dir}{src_dir} = $src_dir ;
push @{$files_by_dir{$sp_dir}{$suffix}} , $base_name ;
}
# get all of the files required by compiled libraries
# compile all files as normal files, we're not going to make a library anymore.
foreach $n ( @all_compile_libs ) {
my @local_files ;
$sp_file = basename($n) ;
$sp_dir = dirname($n) ;
$sp_dir =~ s/\/object_\$\{TRICK_HOST_CPU\}?$// ;
$sp_dir = abs_path($sp_dir) ;
$src_dir = ( -e "$sp_dir/src" ) ? "src/" : "" ;
$files_by_dir{$sp_dir}{src_dir} = $src_dir ;
opendir THISDIR, "$sp_dir/$src_dir" or die "Could not open the directory $sp_dir/$src_dir";
@local_files = grep !/^\.\.\./ , readdir THISDIR;
@local_files = grep /\.[cfly]$|C$|cc$|cxx$|cpp$|c\+\+$/ , @local_files;
foreach $k ( @local_files ) {
($base_name , $suffix) = $k =~ /(.*?)([cfly]$|C$|cc$|cxx$|cpp$|c\+\+$)/ ;
push @{$files_by_dir{$sp_dir}{$suffix}} , $base_name ;
}
closedir THISDIR ;
}
# sort and weed out duplicate files
foreach $k ( keys %files_by_dir ) {
foreach $n ( qw{ c f l y h C cc cxx cpp c++} ) {
undef %temp_hash ;
@{$files_by_dir{$k}{$n}} = sort grep ++$temp_hash{$_} < 2, @{$files_by_dir{$k}{$n}} ;
}
}
foreach $k ( sort keys %files_by_dir ) {
foreach my $ie ( @exclude_dirs ) {
# if file location begins with $ie (an exclude dir)
if ( $k =~ /^\Q$ie/ ) {
delete $files_by_dir{$k} ;
print "excluding $k from build\n" ;
last ; # break out of loop
}
}
}
# set the "dir_num" of each directory.
foreach $k ( sort keys %files_by_dir ) {
$_ = $k ;
($files_by_dir{$k}{dir_num} = $_) =~ s#^/## ;
$files_by_dir{$k}{dir_num} =~ s/[\/.]/_/g ;
# if a particular directory had an override file, save that into memory
if (open OV_FILE, "$k/makefile_overrides") {
while ( <OV_FILE> ) {
s/(#.*)// ;
my ($comment) = $1 ;
s/\$[{(]CURDIR[})]\/(\S+)/$k\/$1/g ;
s/(?:\$[{(]CURDIR[})]\/)?(\S*)\$[{(]OBJ_DIR[})]/$k\/$1object_\${TRICK_HOST_CPU}/g ;
s/\$[{(]CURDIR[})]/$k/g ;
while ( s,/[^/]+/\.\.,, ) {}
s//$comment/ ;
if ( s/^objects\s*:\s*// ) {
foreach my $ext ( qw{c C cc cxx cpp CPLUSPLUS l y} ) {
$files_by_dir{$k}{overrides} .= "\$(MODEL_${ext}_OBJ_$files_by_dir{$k}{dir_num}): $_" ;
}
}
elsif ( s/^depend\s*:\s*// ) {
$files_by_dir{$k}{overrides} .= "depend_$files_by_dir{$k}{dir_num}: $_" ;
}
elsif ( s/([cfhy]|C|cc|cxx|cpp|CPLUSPLUS)_objects\s*:\s*// ) {
$files_by_dir{$k}{overrides} .= "\$(MODEL_$1_OBJ_$files_by_dir{$k}{dir_num}): $_" ;
}
else {
$files_by_dir{$k}{overrides} .= $_ ;
}
}
}
}
my $wd = abs_path(cwd()) ;
my $dt = localtime();
my ($trick_ver) = get_trick_version() ;
chomp $trick_ver ;
open MAKEFILE , ">build/Makefile_src" or return ;
print MAKEFILE "\
#############################################################################
# Makefile:
# This is a makefile for maintaining the
# '$wd'
# simulation directory. This make file was automatically generated by trick-CP
#
#############################################################################
# Creation:
# Author: Trick Configuration Processor - trick-CP Version $trick_ver
# Date: $dt
#
#############################################################################
include \${TRICK_HOME}/share/trick/makefiles/Makefile.common
S_MAIN = \$(CURDIR)/S_main_\${TRICK_HOST_CPU}.exe
ifeq (\$(MAKECMDGOALS), test_all)
TRICK_HOST_CPU := \$(shell \$(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)_test
S_MAIN = \$(CURDIR)/T_main_\${TRICK_HOST_CPU}.exe
endif
LIB_DIR = \$(CURDIR)/build/lib
ifdef TRICK_VERBOSE_BUILD
PRINT_COMPILE =
PRINT_INC_LINK =
PRINT_EXE_LINK =
PRINT_S_DEF_DEPS =
ECHO_CMD =
else
PRINT_COMPILE = \@echo \"Compiling  \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_INC_LINK = \@echo \"Partial link \$(subst \$(CURDIR)/build,build,\${<D})\"
PRINT_EXE_LINK = \@echo \"Final link  \$(subst \$(CURDIR)/,,\$(S_MAIN))\"
PRINT_S_DEF_DEPS = \@echo \"Get depends  for S_define\"
ECHO_CMD = \@
ifeq (\$(MAKECMDGOALS), all)
\$(info Performing build with these compilation flags)
\$(info TRICK_CFLAGS = \$(TRICK_CFLAGS))
\$(info TRICK_CXXFLAGS = \$(TRICK_CXXFLAGS))
endif
endif
S_OBJECT_FILES = \$(CURDIR)/build/S_source.o
\$(S_OBJECT_FILES) : | \$(LIB_DIR)\n\n" ;
my %object_files_by_type ;
$num_inc_objs = 0 ;
# list out all of the source and object files
foreach $k ( sort keys %files_by_dir ) {
foreach my $ext ( qw{ c C cc cxx cpp c++ l y} ) {
my $print_ext ;
if ( $ext eq "c++" ) {
$print_ext = "CPLUSPLUS" ;
} else {
$print_ext = $ext ;
}
if ( scalar @{$files_by_dir{$k}{$ext}} ne 0 ) {
print MAKEFILE "MODEL_${print_ext}_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{$ext}} ) {
print MAKEFILE " \\\n \$(CURDIR)/build$k/$files_by_dir{$k}{src_dir}$f" . "o" ;
}
push @{$object_files_by_type{$ext}}, "MODEL_${print_ext}_OBJ_$files_by_dir{$k}{dir_num}" ;
print MAKEFILE "\n\n\$(MODEL_${print_ext}_OBJ_$files_by_dir{$k}{dir_num}) : | \$(CURDIR)/build$k/$files_by_dir{$k}{src_dir}$f\n" ;
print MAKEFILE "\$(CURDIR)/build$k/$files_by_dir{$k}{src_dir}$f :\n" ;
print MAKEFILE "\t@ mkdir -p \$\@\n\n" ;
print MAKEFILE "\$(CURDIR)/build/lib/o${num_inc_objs}.o : \$(MODEL_${print_ext}_OBJ_$files_by_dir{$k}{dir_num})\n" ;
print MAKEFILE "\t\$(PRINT_INC_LINK)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)cd \${<D} ; ld \$(LD_PARTIAL) -o \$\@ \$(notdir \$^)\n\n" ;
$num_inc_objs++ ;
}
}
if ( scalar @{$files_by_dir{$k}{l}} ne 0 ) {
print MAKEFILE "MODEL_clex_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{l}} ) {
print MAKEFILE " \\\n \$(CURDIR)/build$k/$files_by_dir{$k}{src_dir}$f" . "clex" ;
}
print MAKEFILE "\n\n" ;
}
if ( scalar @{$files_by_dir{$k}{y}} ne 0 ) {
print MAKEFILE "MODEL_y_c_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{y}} ) {
print MAKEFILE " \\\n \$(CURDIR)/build$k/$files_by_dir{$k}{src_dir}$f" . "y.c" ;
}
print MAKEFILE "\n\n" ;
}
}
foreach my $ext ( sort keys %object_files_by_type ) {
my $print_ext ;
if ( $ext eq "c++" ) {
$print_ext = "CPLUSPLUS" ;
} else {
$print_ext = $ext ;
}
print MAKEFILE "MODEL_${print_ext}_OBJ =" ;
foreach $f ( @{$object_files_by_type{$print_ext}} ) {
print MAKEFILE " \\\n \$($f)" ;
}
print MAKEFILE "\n\n" ;
}
# Write out the compile rules for each type of file.
print MAKEFILE "\${MODEL_c_OBJ} : \$(CURDIR)/build\%.o : \%.c\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CC) \$(TRICK_CFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_C_OBJ} : \$(CURDIR)/build\%.o : \%.C\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_cc_OBJ} : \$(CURDIR)/build\%.o : \%.cc\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_cpp_OBJ} : \$(CURDIR)/build\%.o : \%.cpp\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_cxx_OBJ} : \$(CURDIR)/build\%.o : \%.cxx\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_CPLUSPLUS_OBJ} : \$(CURDIR)/build\%.o : \%.c++\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -I\${<D} -I\${<D}/../include -MMD -MP -c \$< -o \$\@\n\n" ;
print MAKEFILE "\${MODEL_clex_SRC} : \$(CURDIR)/build\%.clex : \%.l\n" ;
print MAKEFILE "\t\$(LEX) -o\$\@ \$<\n\n" ;
print MAKEFILE "\${MODEL_y_c_SRC} : \$(CURDIR)/build\%.y.c : \%.y\n" ;
print MAKEFILE "\t\$(YACC) -o\$\@ \$<\n\n" ;
print MAKEFILE "\${MODEL_y_OBJ} : \$(CURDIR)/build\%.o : \%.y.c\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE)\n\n" ;
print MAKEFILE "\t\$(ECHO_CMD)cd \$(<D) ; \$(TRICK_CC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$\@\n\n" ;
# Include all of the dependency files for each object code file
print MAKEFILE "-include \$(MODEL_c_OBJ:.o=.d)\n" ;
print MAKEFILE "-include \$(MODEL_C_OBJ:.o=.d)\n" ;
print MAKEFILE "-include \$(MODEL_cc_OBJ:.o=.d)\n" ;
print MAKEFILE "-include \$(MODEL_cpp_OBJ:.o=.d)\n" ;
print MAKEFILE "-include \$(MODEL_cxx_OBJ:.o=.d)\n" ;
print MAKEFILE "-include \$(MODEL_CPLUSPLUS_OBJ:.o=.d)\n\n" ;
printf MAKEFILE "\n\nOBJECTS =" ;
for( $i = 0 ; $i < $num_inc_objs ; $i++ ) {
print MAKEFILE " \\\n\t\$(LIB_DIR)/o$i.o" ;
}
# print out the libraries we link
print MAKEFILE "\n\nREAD_ONLY_LIBS = ";
foreach ( @all_read_only_libs ) {
print MAKEFILE " \\\n\t$_" ;
}
print MAKEFILE "\n\n
test_all: TRICK_CXXFLAGS += -DTRICK_UNIT_TEST
test_all: TRICK_CFLAGS += -DTRICK_UNIT_TEST
all: S_main
test_all: all
S_main : \$(S_MAIN) build/S_define.deps S_sie.resource
\t@ echo \"\"
\t@ echo \"=== Simulation make complete ===\"
#\t\t\$(S_OBJECT_FILES) build/lib/*.o
\$(S_MAIN): \${TRICK_STATIC_LIB} \$(OBJECTS) \$(S_OBJECT_FILES)
\t\$(PRINT_EXE_LINK)
\t\$(ECHO_CMD)\$(TRICK_LD) \$(TRICK_LDFLAGS) -o \$@ \\
\t\t\$(S_OBJECT_FILES) \$(OBJECTS) \\
\t\t\${TRICK_USER_LINK_LIBS} \${READ_ONLY_LIBS} \\
\t\t\$(LD_WHOLE_ARCHIVE) \${TRICK_LIBS} \$(LD_NO_WHOLE_ARCHIVE)\\
\t\t\${TRICK_EXEC_LINK_LIBS}
\$(OBJECTS) : | \$(LIB_DIR)
\$(LIB_DIR) :
\t@ mkdir -p \$@
\$(CURDIR)/build/S_source.o: \$(CURDIR)/build/S_source.cpp
\t\$(PRINT_COMPILE)
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \$\< -o \$\@
-include build/S_source.d
build/S_define.deps:
\t\$(PRINT_S_DEF_DEPS)
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_SFLAGS) -M -MT Makefile_sim -MF build/S_define.deps -x c++ S_define
\$(CURDIR)/build/S_source.cpp S_default.dat: S_define
\t\$(PERL) \${TRICK_HOME}/bin/trick-CP -s -d
sie: S_sie.resource
S_sie.resource: \$(S_MAIN)
\t@ echo \"Generating S_sie.resource...\"
\t\$(ECHO_CMD)\$(S_MAIN) sie
S_define_exp:
\t\$(TRICK_CC) -E -C -xc++ \${TRICK_SFLAGS} S_define > \$@\n\n" ;
# write out the override files we have read in
foreach $k ( sort keys %files_by_dir ) {
if ( exists $files_by_dir{$k}{overrides} ) {
print MAKEFILE "\n# Overrides from $k\n\n" ;
print MAKEFILE "$files_by_dir{$k}{overrides}\n" ;
}
}
print MAKEFILE "\n-include build/Makefile_io_src\n" ;
print MAKEFILE "include build/Makefile_swig\n" ;
print MAKEFILE "-include S_overrides.mk\n" ;
close MAKEFILE ;
# write out all of files 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 :" ;
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" ;
print LIB_LIST map {"$_\n"} (sort keys %processed_files) ;
close LIB_LIST ;

429
libexec/trick/make_makefile_swig Executable file
View File

@ -0,0 +1,429 @@
#!/usr/bin/perl
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 strict ;
my @exclude_dirs ;
my @swig_exclude_dirs ;
my @files_to_process ;
sub get_exclude_dirs() {
@exclude_dirs = split /:/ , $ENV{"TRICK_EXCLUDE"};
# See if there are any elements in the exclude_dirs array
if (scalar @exclude_dirs) {
@exclude_dirs = sort(@exclude_dirs );
# Error check - delete any element that is null
# (note: sort forced all blank names to front of array
@exclude_dirs = map { s/(^\s+|\s+$)//g ; $_ } @exclude_dirs ;
while ( not length @exclude_dirs[0] ) {
# Delete an element from the left side of an array (element zero)
shift @exclude_dirs ;
}
@exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @exclude_dirs ;
}
@swig_exclude_dirs = split /:/ , $ENV{"TRICK_SWIG_EXCLUDE"};
# See if there are any elements in the swig_exclude_dirs array
if (scalar @swig_exclude_dirs) {
@swig_exclude_dirs = sort(@swig_exclude_dirs );
# Error check - delete any element that is null
# (note: sort forced all blank names to front of array
@swig_exclude_dirs = map { s/(^\s+|\s+$)//g ; $_ } @swig_exclude_dirs ;
while ( not length @swig_exclude_dirs[0] ) {
# Delete an element from the left side of an array (element zero)
shift @swig_exclude_dirs ;
}
@swig_exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @swig_exclude_dirs ;
}
# If there were no directories listed in TRICK_SWIG_EXCLUDE then copy the ones from ICG_EXCLUDE.
if ( scalar @swig_exclude_dirs == 0 ) {
@swig_exclude_dirs = split /:/ , $ENV{"TRICK_ICG_EXCLUDE"};
# See if there are any elements in the swig_exclude_dirs array
if (scalar @swig_exclude_dirs) {
@swig_exclude_dirs = sort(@swig_exclude_dirs );
# Error check - delete any element that is null
# (note: sort forced all blank names to front of array
@swig_exclude_dirs = map { s/(^\s+|\s+$)//g ; $_ } @swig_exclude_dirs ;
while ( not length @swig_exclude_dirs[0] ) {
# Delete an element from the left side of an array (element zero)
shift @swig_exclude_dirs ;
}
@swig_exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @swig_exclude_dirs ;
}
}
}
sub read_files_to_process() {
open FILE, "build/ICG_processed" or die 'could not open build/ICG_processed' ;
@files_to_process = <FILE> ;
close FILE ;
chomp @files_to_process ;
}
sub make_swig_makefile() {
my ($n , $f , $k , $m);
my %temp_hash ;
my (@temp_array , @temp_array2) ;
my ($ii) ;
my ($swig_sim_dir, $swig_src_dir) ;
my (%py_module_map) ;
my (@include_paths) ;
my (@defines) ;
my ($version, $thread, $year) ;
my $s_source_full_path = abs_path("S_source.hh") ;
my $s_source_md5 = md5_hex($s_source_full_path) ;
($version, $thread) = get_trick_version() ;
($year) = $version =~ /^(\d+)/ ;
(my $cc = gte("TRICK_CC")) =~ s/\n// ;
@include_paths = $ENV{"TRICK_CFLAGS"} =~ /(-I\s*\S+)/g ; # get include paths from TRICK_CFLAGS
push @include_paths , ("-I".$ENV{"TRICK_HOME"}."/trick_source" , "-I../include") ;
@defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS
push @defines , "-DTRICK_VER=$year" ;
push @defines , "-DSWIG" ;
$swig_sim_dir = "\$(CURDIR)/trick" ;
$swig_src_dir = "\$(CURDIR)/build" ;
undef @temp_array2 ;
foreach $n (@files_to_process) {
undef @temp_array ;
# check to see if the parent directory of each file is writable.
# If it isn't, then don't add it to the list of files to requiring ICG
$f = abs_path(dirname($n)) . "/" . basename($n) ;
my ($continue) = 1 ;
foreach my $ie ( @swig_exclude_dirs ) {
# if file location begins with $ie (an IGC exclude dir)
if ( $f =~ /^\Q$ie/ ) {
print "CP(swig) skipping $f (ICG exclude dir $ie)\n" ;
$continue = 0 ;
last ; # break out of loop
}
}
next if ( $continue == 0 ) ;
push @temp_array2 , $f ;
}
open MAKEFILE , ">build/Makefile_swig" or return ;
open LINK_PY_OBJS , ">build/link_py_objs" or return ;
print LINK_PY_OBJS "build/init_swig_modules.o\n" ;
print LINK_PY_OBJS "build/py_top.o\n" ;
print MAKEFILE "\
# SWIG rule
SWIG_FLAGS =
SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers
ifeq (\$(IS_CC_CLANG), 1)
SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized
endif
ifdef TRICK_VERBOSE_BUILD
PRINT_SWIG =
PRINT_COMPILE_SWIG =
PRINT_SWIG_INC_LINK =
#PRINT_CONVERT_SWIG =
else
PRINT_SWIG = \@echo \"Swig  \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_COMPILE_SWIG = \@echo \"Compiling  \$(subst .o,.cpp,\$(subst \$(CURDIR)/build,build,\$@))\"
PRINT_SWIG_INC_LINK = \@echo \"Partial link swig objects\"
#PRINT_CONVERT_SWIG = \@echo \"Running convert_swig\"
endif
SWIG_MODULE_OBJECTS = \$(LIB_DIR)/swig_python.o
SWIG_PY_OBJECTS =" ;
foreach my $f ( @temp_array2 ) {
my ($continue) = 1 ;
foreach my $ie ( @exclude_dirs ) {
# if file location begins with $ie (an IGC exclude dir)
if ( $f =~ /^\Q$ie/ ) {
$continue = 0 ;
$ii++ ;
last ; # break out of loop
}
}
next if ( $continue == 0 ) ;
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)$/) ;
print MAKEFILE" \\\n \$(CURDIR)/build$swig_object_dir/py_${swig_file_only}.o" ;
}
print MAKEFILE "\\\n $swig_src_dir/init_swig_modules.o" ;
print MAKEFILE "\\\n $swig_src_dir/py_top.o\n\n" ;
print MAKEFILE "\$(SWIG_PY_OBJECTS) : | trick\n" ;
print MAKEFILE "trick :\n" ;
print MAKEFILE "\t\@mkdir \$\@\n" ;
#print MAKEFILE "convert_swig:\n" ;
#print MAKEFILE "\t\$(PRINT_CONVERT_SWIG)\n" ;
#print MAKEFILE "\t\$(ECHO_CMD)\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \${TRICK_CONVERT_SWIG_FLAGS} S_source.hh\n" ;
#print MAKEFILE "\n\n" ;
my %swig_dirs ;
my %python_modules ;
$ii = 0 ;
foreach my $f ( @temp_array2 ) {
my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ;
my ($swig_f) = $f ;
# TODO: Add back python modules
# if ( $$sim_ref{python_module}{$f} ne "" ) {
# #print "python module for $f = $$sim_ref{python_module}{$f}\n" ;
# my ($temp_str) = $$sim_ref{python_module}{$f} ;
# $temp_str =~ s/\./\//g ;
# $swig_module_dir = "$temp_str/" ;
# $temp_str =~ $$sim_ref{python_module}{$f} ;
# $temp_str =~ s/\\/\./g ;
# push @{$python_modules{$temp_str}} , $f ;
# } else {
# $swig_module_dir = "" ;
push @{$python_modules{"root"}} , $f ;
# }
my ($continue) = 1 ;
foreach my $ie ( @exclude_dirs ) {
# if file location begins with $ie (an IGC exclude dir)
if ( $f =~ /^\Q$ie/ ) {
$continue = 0 ;
$ii++ ;
last ; # break out of loop
}
}
next if ( $continue == 0 ) ;
my $md5_sum = md5_hex($f) ;
# check if .sm file was accidentally ##included instead of #included
if ( rindex($swig_f,".sm") != -1 ) {
#trick_print($$sim_ref{fh}, "\nError: $swig_f should be in a #include not a ##include \n\n", "title_red", $$sim_ref{args}{v}) ;
exit -1 ;
}
$swig_f =~ s/([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx)$/$1.i/ ;
$swig_file_only = $1 ;
my $link_py_obj = "build" . dirname($swig_f) . "/py_${swig_file_only}.o";
$swig_f = "\$(CURDIR)/build" . $swig_f ;
$swig_dir = dirname($swig_f) ;
$swig_object_dir = dirname($swig_f) ;
$swig_dirs{$swig_dir} = 1 ;
print MAKEFILE "$swig_object_dir/py_${swig_file_only}.o : $swig_f\n" ;
print MAKEFILE "\t\$(PRINT_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) \$(SWIG_FLAGS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir trick -o $swig_dir/py_${swig_file_only}.cpp \$<\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_IO_CXXFLAGS) \$(SWIG_CFLAGS) -c $swig_dir/py_${swig_file_only}.cpp -o \$@\n\n" ;
print LINK_PY_OBJS "$link_py_obj\n" ;
$ii++ ;
}
foreach $m ( keys %python_modules ) {
next if ( $m eq "root") ;
my ($temp_str) = $m ;
$temp_str =~ s/\./\//g ;
print MAKEFILE "$swig_sim_dir/$m:\n" ;
print MAKEFILE "\tmkdir -p \$@\n\n" ;
}
my $wd = abs_path(cwd()) ;
print MAKEFILE "
\$(SWIG_MODULE_OBJECTS) : TRICK_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls
OBJECTS += \$(SWIG_MODULE_OBJECTS)
\$(S_MAIN): \$(SWIG_MODULE_OBJECTS)
\$(SWIG_MODULE_OBJECTS) : \$(SWIG_PY_OBJECTS) | \$(LIB_DIR)
\t\$(PRINT_SWIG_INC_LINK)
\t\$(ECHO_CMD)ld \$(LD_PARTIAL) -o \$\@ \$(LD_FILELIST)build/link_py_objs
\n\n" ;
print MAKEFILE "$swig_src_dir/py_top.cpp : $swig_src_dir/top.i\n" ;
print MAKEFILE "\t\$(PRINT_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir $swig_sim_dir -o \$@ \$<\n\n" ;
print MAKEFILE "$swig_src_dir/py_top.o : $swig_src_dir/py_top.cpp\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(SWIG_CFLAGS) -c \$< -o \$@\n\n" ;
print MAKEFILE "$swig_src_dir/init_swig_modules.o : $swig_src_dir/init_swig_modules.cpp\n" ;
print MAKEFILE "\t\$(PRINT_COMPILE_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(SWIG_CFLAGS) -c \$< -o \$@\n\n" ;
print MAKEFILE "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\n\n" ;
print MAKEFILE "S_main: \$(TRICK_FIXED_PYTHON)\n\n" ;
print MAKEFILE "\$(TRICK_FIXED_PYTHON) : $swig_sim_dir/\% : \${TRICK_HOME}/share/trick/swig/\%\n" ;
print MAKEFILE "\t\$(ECHO_CMD)/bin/cp \$< \$@\n\n" ;
foreach (keys %swig_dirs) {
print MAKEFILE "$_:\n" ;
print MAKEFILE "\tmkdir -p $_\n\n" ;
}
print MAKEFILE "\n" ;
close MAKEFILE ;
close LINK_PY_OBJS ;
open SWIGLIB , ">build/S_library_swig" or return ;
foreach my $f ( @temp_array2 ) {
print SWIGLIB "$f\n" ;
}
close SWIGLIB ;
open S_INSTANCE , "build/S_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 map { "extern $_" } @instances ;
print TOPFILE "\n\%}\n\n" ;
print TOPFILE "\%import \"build$wd/S_source.i\"\n\n" ;
print TOPFILE @instances ;
close TOPFILE ;
open INITSWIGFILE , ">build/init_swig_modules.cpp" or return ;
print INITSWIGFILE "extern \"C\" {\n\n" ;
foreach $f ( @temp_array2 ) {
my $md5_sum = md5_hex($f) ;
print INITSWIGFILE "void init_m${md5_sum}(void) ; /* $f */\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 $f ( @temp_array2 ) {
next if ( $f =~ /S_source.hh/ ) ;
my $md5_sum = md5_hex($f) ;
print INITSWIGFILE " init_m${md5_sum}() ;\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" ;
close INITSWIGFILE ;
open INITFILE , ">trick/__init__.py" or return ;
print INITFILE "import sys\n" ;
print INITFILE "import os\n" ;
print INITFILE "sys.path.append(os.getcwd() + \"/trick\")\n" ;
foreach $m ( keys %python_modules ) {
next if ( $m eq "root") ;
my ($temp_str) = $m ;
$temp_str =~ s/\./\//g ;
print INITFILE "sys.path.append(os.getcwd() + \"/trick/$temp_str\")\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 $m ( keys %python_modules ) {
next if ( $m eq "root") ;
my ($temp_str) = $m ;
$temp_str =~ s/\//\./g ;
print INITFILE "import $temp_str\n" ;
}
print INITFILE "\n" ;
foreach $f ( @{$python_modules{"root"}} ) {
next if ( $f =~ /S_source.hh/ ) ;
my $md5_sum = md5_hex($f) ;
print INITFILE "# $f\n" ;
print INITFILE "import _m${md5_sum}\n" ;
print INITFILE "from m${md5_sum} import *\n" ;
print INITFILE "combine_cvars(all_cvars, cvar)\n" ;
print INITFILE "cvar = None\n\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 $m ( keys %python_modules ) {
next if ( $m eq "root") ;
my ($temp_str) = $m ;
$temp_str =~ s/\./\//g ;
if ( ! -e "trick/$temp_str" ) {
mkpath("trick/$temp_str", {mode=>0775}) ;
}
open INITFILE , ">trick/$temp_str/__init__.py" or return ;
foreach $f ( @{$python_modules{$m}} ) {
next if ( $f =~ /S_source.hh/ ) ;
my $md5_sum = md5_hex($f) ;
print INITFILE "# $f\n" ;
print INITFILE "import _m${md5_sum}\n" ;
print INITFILE "from m${md5_sum} import *\n\n" ;
}
close INITFILE ;
while ( $temp_str =~ s/\/.*?$// ) {
open INITFILE , ">trick/$temp_str/__init__.py" or return ;
close INITFILE ;
}
}
open MAKEFILECONV , ">build/Makefile_convert_swig" or return ;
print MAKEFILECONV "\$(CURDIR)/build/convert_swig_last_run :" ;
foreach $f ( @temp_array2 ) {
print MAKEFILECONV " \\\n $f" ;
}
close MAKEFILECONV ;
return ;
}
get_exclude_dirs() ;
read_files_to_process() ;
make_swig_makefile() ;

View File

@ -0,0 +1,110 @@
package get_lib_deps ;
use File::Basename ;
use Cwd 'abs_path';
use File::Path qw(make_path) ;
use Exporter ();
@ISA = qw(Exporter);
@EXPORT = qw(get_lib_deps write_lib_deps);
use strict ;
sub get_lib_deps ($$) {
my ($contents, $source_file_name) = @_ ;
my ($lib_deps) ;
my (@lib_list) ;
my (@inc_paths) ;
($lib_deps) = $contents =~ /LIBRARY[ _]DEPENDENC(?:Y|IES):[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ;
@lib_list = split /\)[ \t\n\r\*]*\(/ , $lib_deps ;
@inc_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS
# Get only the include paths that exist
my @valid_inc_paths ;
foreach (@inc_paths) {
push @valid_inc_paths , $_ if ( -e $_ ) ;
}
@inc_paths = @valid_inc_paths ;
my ($file_path_dir) = dirname($source_file_name) ;
$file_path_dir =~ s/\/+$// ; # remove trailing slash
$file_path_dir =~ s/\/include$// ;
my @resolved_files ;
foreach my $l (@lib_list) {
my $found = 0 ;
$l =~ s/\(|\)|\s+//g ;
$l =~ s/\${(.+?)}/$ENV{$1}/eg ;
next if ( $l eq "" ) ;
if ( $l =~ /\.a$/ ) {
my ($rel_dir) = dirname($l) ;
foreach my $inc ( dirname($source_file_name) , @inc_paths) {
if ( -e "$inc/$rel_dir" ) {
my $f = abs_path("$inc/$rel_dir") . "/" . basename($l) ;
push @resolved_files, $f ;
$found = 1 ;
last ;
}
}
} elsif ( $l !~ /\.o$/ ) {
foreach my $inc ( dirname($source_file_name) , @inc_paths) {
if ( -e "$inc/$l" ) {
#print "found $inc/$l$ext\n" ;
my $f = abs_path(dirname("$inc/$l")) . "/" . basename("$inc/$l") ;
push @resolved_files, $f ;
$found = 1 ;
last ;
}
}
} else {
$l =~ s/o$// ;
foreach my $inc ( $file_path_dir , @inc_paths) {
foreach my $ext ( "cpp" , "cc" , "c" , "c++" , "cxx" , "C" ) {
if ( -e "$inc/$l$ext" ) {
#print "found $inc/$l$ext\n" ;
my $f = abs_path(dirname("$inc/$l$ext")) . "/" . basename("$inc/$l$ext") ;
push @resolved_files, $f ;
$found = 1 ;
last ;
}
elsif ( -e "$inc/src/$l$ext" ) {
#print "found $inc/src/$l$ext\n" ;
my $f = abs_path(dirname("$inc/src/$l$ext")) . "/" . basename("$inc/src/$l$ext") ;
push @resolved_files, $f ;
$found = 1 ;
last ;
}
}
last if ( $found == 1 ) ;
}
}
if ( $found == 0 ) {
print STDERR "@ARGV[0]: Warning: Could not find dependency $l\n" ;
}
}
return @resolved_files ;
}
sub write_lib_deps($) {
my ($source_file_name) = @_ ;
local $/ = undef ;
open SOURCE, $source_file_name or warn 'cannot read $source_file_name' ;
my ($contents) = <SOURCE> ;
close SOURCE ;
my (@resolved_files) = get_lib_deps($contents, $source_file_name) ;
my ( $file, $dir, $suffix) = fileparse($source_file_name, qr/\.[^.]*/) ;
my ($lib_dep_file_name) = "build$dir${file}.lib_deps" ;
if ( ! -e "build$dir" ) {
make_path("build$dir") ;
}
open LIBDEP, ">$lib_dep_file_name" ;
print LIBDEP map {"$_\n"} (sort @resolved_files) ;
close LIBDEP ;
return @resolved_files ;
}
1

View File

@ -102,7 +102,7 @@ sub make_makefile($$$) {
foreach $k ( sort keys %files_by_dir ) {
foreach my $ie ( @exclude_dirs ) {
# if file location begins with $ie (an ICG exclude dir)
# if file location begins with $ie (an exclude dir)
if ( $k =~ /^\Q$ie/ ) {
delete $files_by_dir{$k} ;
print "excluding $k from build\n" ;
@ -177,18 +177,16 @@ endif
LIB_DIR = \$(CURDIR)/build/lib
ifdef TRICK_VERBOSE_BUILD
PRINT_ICG =
PRINT_COMPILE =
PRINT_INC_LINK =
PRINT_EXE_LINK =
PRINT_S_DEF_DEPS =
ECHO_CMD =
else
PRINT_ICG = \@echo \"Running ICG\"
PRINT_COMPILE = \@echo \"Compiling \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_INC_LINK = \@echo \"Partial linking \$(subst \$(CURDIR)/build,build,\${<D})\"
PRINT_EXE_LINK = \@echo \"Final linking \$(subst \$(CURDIR)/,,\$(S_MAIN))\"
PRINT_S_DEF_DEPS = \@echo \"Generating dependencies for S_define\"
PRINT_COMPILE = \@echo \"Compiling  \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_INC_LINK = \@echo \"Partial link \$(subst \$(CURDIR)/build,build,\${<D})\"
PRINT_EXE_LINK = \@echo \"Final link  \$(subst \$(CURDIR)/,,\$(S_MAIN))\"
PRINT_S_DEF_DEPS = \@echo \"Get depends  for S_define\"
ECHO_CMD = \@
ifeq (\$(MAKECMDGOALS), all)
\$(info Performing build with these compilation flags)
@ -321,14 +319,6 @@ all: S_main
test_all: all
ICG:
\t\$(PRINT_ICG)
\t\$(ECHO_CMD)\${TRICK_HOME}/bin/trick-ICG -m \${TRICK_CXXFLAGS} S_source.hh
force_ICG:
\t\$(PRINT_ICG)
\t\$(ECHO_CMD)\${TRICK_HOME}/bin/trick-ICG -f -m \${TRICK_CXXFLAGS} S_source.hh
S_main : \$(S_MAIN) build/S_define.deps S_sie.resource
\t@ echo \"\"
\t@ echo \"=== Simulation make complete ===\"
@ -377,7 +367,7 @@ S_define_exp:
}
print MAKEFILE "\n-include build/Makefile_io_src\n" ;
print MAKEFILE "include build/Makefile_swig\n" ;
print MAKEFILE "-include build/Makefile_swig\n" ;
print MAKEFILE "-include S_overrides.mk\n" ;
close MAKEFILE ;

View File

@ -212,12 +212,12 @@ ifdef TRICK_VERBOSE_BUILD
PRINT_SWIG =
PRINT_COMPILE_SWIG =
PRINT_SWIG_INC_LINK =
PRINT_CONVERT_SWIG =
#PRINT_CONVERT_SWIG =
else
PRINT_SWIG = \@echo \"Swig \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_COMPILE_SWIG = \@echo \"Compiling swig \$(subst .o,.cpp,\$(subst \$(CURDIR)/build,build,\$@))\"
PRINT_SWIG_INC_LINK = \@echo \"Partial linking swig objects\"
PRINT_CONVERT_SWIG = \@echo \"Running convert_swig\"
PRINT_SWIG = \@echo \"Swig  \$(subst \$(CURDIR)/build,build,\$<)\"
PRINT_COMPILE_SWIG = \@echo \"Compiling  \$(subst .o,.cpp,\$(subst \$(CURDIR)/build,build,\$@))\"
PRINT_SWIG_INC_LINK = \@echo \"Partial link swig objects\"
#PRINT_CONVERT_SWIG = \@echo \"Running convert_swig\"
endif
SWIG_MODULE_OBJECTS = \$(LIB_DIR)/swig_python.o
@ -245,10 +245,10 @@ SWIG_PY_OBJECTS =" ;
print MAKEFILE "\\\n $swig_src_dir/init_swig_modules.o" ;
print MAKEFILE "\\\n $swig_src_dir/py_top.o\n\n" ;
print MAKEFILE "convert_swig:\n" ;
print MAKEFILE "\t\$(PRINT_CONVERT_SWIG)\n" ;
print MAKEFILE "\t\$(ECHO_CMD)\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \${TRICK_CONVERT_SWIG_FLAGS} S_source.hh\n" ;
print MAKEFILE "\n\n" ;
#print MAKEFILE "convert_swig:\n" ;
#print MAKEFILE "\t\$(PRINT_CONVERT_SWIG)\n" ;
#print MAKEFILE "\t\$(ECHO_CMD)\${TRICK_HOME}/\$(LIBEXEC)/trick/convert_swig \${TRICK_CONVERT_SWIG_FLAGS} S_source.hh\n" ;
#print MAKEFILE "\n\n" ;
my %swig_dirs ;
my %python_modules ;
@ -389,7 +389,6 @@ SWIG_PY_OBJECTS =" ;
open INITSWIGFILE , ">build/init_swig_modules.cpp" or return ;
print INITSWIGFILE "extern \"C\" {\n\n" ;
foreach $f ( @temp_array2 ) {
my $md5_sum = md5_hex($f) ;
print INITSWIGFILE "void init_m${md5_sum}(void) ; /* $f */\n" ;
}
@ -494,8 +493,14 @@ SWIG_PY_OBJECTS =" ;
}
}
return ;
open MAKEFILECONV , ">build/Makefile_convert_swig" or return ;
print MAKEFILECONV "\$(CURDIR)/build/convert_swig_last_run :" ;
foreach $f ( @temp_array2 ) {
print MAKEFILECONV " \\\n $f" ;
}
close MAKEFILECONV ;
return ;
}
1;

View File

@ -8,6 +8,7 @@ use Cwd ;
use File::Basename ;
use strict ;
use Cwd 'abs_path';
use File::Path 'make_path';
use trick_print ;
use gte ;
@ -35,6 +36,15 @@ sub mis_dep ($@) {
@fileList = grep !/\.h$|\.H$|\.hh$|\.h\+\+$/ , @fileList ;
#open FL, ">build/S_source.fl" ;
#foreach $file ( @fileList ) {
# if ( $file ne "" ) {
# $file = abs_path(dirname($file)) . "/" . basename($file) ;
# print FL "$file\n" ;
# }
#}
#close FL ;
foreach $file ( @fileList ) {
if ( $file ne "" ) {
undef %mis_depends_tree ;
@ -43,6 +53,15 @@ sub mis_dep ($@) {
get_depends($file, $sim_ref);
%{$all_depend_trees{$file}} = %mis_depends_tree ;
$all_depend_trees{$file}{last_look} = time ;
#my @file_list ;
#my %temp_hash ;
#my ( $name, $path, $suffix) = fileparse($file,, qr/\.[^.]*/);
#make_path("build" . $path) ;
#open FL, ">build$path/${name}.lib_deps" ;
#@file_list = grep ++$temp_hash{$_} < 2, @{$mis_depends_tree{$file}} ;
#print FL map { "$_\n" } @file_list ;
#close FL ;
}
}

View File

@ -317,6 +317,13 @@ PURPOSE:
close S_SOURCE ;
open S_INSTANCE, ">build/S_instances" or die "Couldn't open build/S_instances!\n";
print S_INSTANCE $$sim_ref{instance_declarations} ;
foreach my $integ_loop ( @{$$sim_ref{integ_loop}} ) {
print S_INSTANCE "IntegLoopSimObject $$integ_loop{name} ;\n" ;
}
close S_INSTANCE ;
}
#--------------------------------------------------------------

View File

@ -1,6 +1,22 @@
include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
ifdef TRICK_VERBOSE_BUILD
PRINT_CP =
PRINT_ICG =
PRINT_CONVERT_SWIG =
PRINT_MAKEFILE_SRC =
PRINT_MAKEFILE_SWIG =
ECHO_CMD =
else
PRINT_CP = @echo "Running configuration_processor"
PRINT_ICG = @echo "Running ICG"
PRINT_CONVERT_SWIG = @echo "Running convert_swig"
PRINT_MAKEFILE_SRC = @echo "Creating source Makefile"
PRINT_MAKEFILE_SWIG = @echo "Creating swig Makefile"
ECHO_CMD = @
endif
.NOTPARALLEL: all test
export TRICK_ICG_EXCLUDE
@ -8,38 +24,63 @@ export TRICK_ICG_EXCLUDE
# Use /bin/bash as the shell so we can use PIPESTATUS
SHELL = /bin/bash
ifeq ($(MAKECMDGOALS), debug)
TRICK_CPFLAGS += --debug
endif
all : ${TRICK_LIB_DIR}/libtrick.a build/Makefile_sim
all : ${TRICK_LIB_DIR}/libtrick.a S_source.hh build/Makefile_io_src build/Makefile_src build/Makefile_swig
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt build/MAKE_out
@$(MAKE) --no-print-directory -f build/Makefile_sim ICG 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f build/Makefile_sim convert_swig 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f build/Makefile_sim all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f build/Makefile_src all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
test : ${TRICK_LIB_DIR}/libtrick.a build/Makefile_sim
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt build/MAKE_out
@$(MAKE) --no-print-directory -f build/Makefile_sim ICG 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f build/Makefile_sim convert_swig 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f build/Makefile_sim test_all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
#test : ${TRICK_LIB_DIR}/libtrick.a build/Makefile_sim $(CURDIR)/build/class_map.cpp $(CURDIR)/build/convert_swig_last_run
# @/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt build/MAKE_out
# @$(MAKE) --no-print-directory -f build/Makefile_sim test_all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
build:
mkdir $@
debug : all
debug : TRICK_CPFLAGS += --debug
${TRICK_LIB_DIR}/libtrick.a:
@echo "Cannot find $@. Please build Trick for this platfrom"
@exit -1
build/Makefile_sim: S_define | build
@${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor $(TRICK_CPFLAGS)
S_source.hh : S_define | build
$(PRINT_CP)
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor $(TRICK_CPFLAGS)
model_dirs:
@${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor -z
# Create makefile for source code
build/Makefile_src: | build/Makefile_io_src
$(PRINT_MAKEFILE_SRC)
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $?
sie ICG force_ICG convert_swig S_define_exp:
# ICG rules
build/Makefile_io_src : | S_source.hh
$(PRINT_ICG)
$(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -m ${TRICK_CXXFLAGS} S_source.hh
ICG:
$(PRINT_ICG)
$(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -m ${TRICK_CXXFLAGS} S_source.hh
force_ICG:
$(PRINT_ICG)
$(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -f -m ${TRICK_CXXFLAGS} S_source.hh
# SWIG rules
build/Makefile_swig : | build/Makefile_io_src
$(PRINT_MAKEFILE_SWIG)
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_swig $?
# convert_swig rules
#$(CURDIR)/build/convert_swig_last_run : | build/Makefile_sim
# $(PRINT_CONVERT_SWIG)
# $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} S_source.hh
# @ touch $@
convert_swig:
$(PRINT_CONVERT_SWIG)
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} S_source.hh
@ touch $(CURDIR)/build/convert_swig_last_run
sie S_define_exp:
@if [ -f build/Makefile_sim ] ; then $(MAKE) --no-print-directory -f build/Makefile_sim $@ ; else echo "No build/Makefile_sim found" ; fi
help:
@ -53,16 +94,15 @@ Simulation make options:\n\
make apocalypse - Performs a clean"
tidy:
-rm -f S_sie.resource
-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 -f S_source.hh S_sie.resource
-rm -f S_main* T_main*
-rm -f build/Makefile_*
-rm -rf S_default.dat
clean: tidy
-rm -rf Default_data S_default.dat
rm -f S_source.hh
rm -rf build
-rm -rf trick
-rm -f DP_Product/DP_rt_frame DP_Product/DP_rt_itimer
-rm -f DP_Product/DP_rt_jobs DP_Product/DP_rt_timeline DP_Product/DP_mem_stats
-rm -rf build trick
@ echo "Removed build directory"
spotless: clean
@ -73,4 +113,7 @@ apocalypse: clean
# Dependencies to other files that may cause a re-CP
-include build/S_define.deps
-include build/Makefile_ICG
-include build/Makefile_convert_swig
-include build/Makefile_src_deps

View File

@ -54,7 +54,7 @@ std::string CommentSaver::getTrickHeaderComment( std::string file_name ) {
std::string comment_str = getComment((*cit).second) ;
std::transform(comment_str.begin(), comment_str.end(), comment_str.begin(), ::toupper) ;
if ( comment_str.find("PURPOSE") != std::string::npos ) {
trick_header_comments[file_name] = comment_str ;
trick_header_comments[file_name] = getComment((*cit).second) ;
break ;
}
}
@ -72,6 +72,7 @@ void CommentSaver::getICGField( std::string file_name ) {
std::string th_str = getTrickHeaderComment(file_name) ;
if ( ! th_str.empty() ) {
std::transform(th_str.begin(), th_str.end(), th_str.begin(), ::toupper) ;
int ret ;
regex_t reg_expr ;
regmatch_t pmatch[10] ;
@ -148,6 +149,8 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) {
std::string th_str = getTrickHeaderComment(file_name) ;
if ( ! th_str.empty() ) {
//std::cout << "here in getIgnoreTypes\n" << th_str << std::endl ;
std::transform(th_str.begin(), th_str.end(), th_str.begin(), ::toupper) ;
int ret ;
regex_t reg_expr ;
regmatch_t pmatch[10] ;
@ -193,3 +196,68 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) {
return ignore_types ;
}
#include <unistd.h>
#include <sys/wait.h>
/*
As of right now I call a perl script to parse the header comment and return
the library dependencies because perl is awesome!
TODO: Someday when C++11 is working on all the platforms we support we should
rewrite this using the language built in regular expressions.
TODO: Only fork and exec a single instance of the script.
*/
std::vector< std::string > CommentSaver::getLibraryDependencies( std::string file_name ) {
pid_t pid ;
int pipes[4] ;
// Open two pipes to allow us to write to and read from child process.
pipe(&pipes[0]) ;
pipe(&pipes[2]) ;
if (( pid = fork()) == 0 ) {
// child pipes: read = pipe[2], write = pipe[1]
close(pipes[0]) ;
close(pipes[3]) ;
dup2(pipes[2], STDIN_FILENO) ;
dup2(pipes[1], STDOUT_FILENO) ;
// exec the perl script that parses header comments.
std::string parse_lib_deps_path = std::string(getenv("TRICK_HOME")) + "/libexec/trick/ICG_lib_deps_helper" ;
execl(parse_lib_deps_path.c_str(), parse_lib_deps_path.c_str(), file_name.c_str(), (char *)NULL) ;
exit(1) ;
}
// parent pipes: read = pipe[0], write = pipe[3]
close(pipes[1]) ;
close(pipes[2]) ;
// get the header comment and send it with a end delimiter to the perl script
std::string header = getTrickHeaderComment(file_name) + "\nEND ICG PROCESSING\n" ;
write(pipes[3], header.c_str() , header.size()) ;
// wait for the child process to end
int status ;
waitpid(pid, &status, 0) ;
// read the result from the perl script
int num_read ;
char buf[4096] ;
std::string response ;
while (( num_read = read(pipes[0], buf, sizeof(buf) - 1) ) > 0 ) {
buf[num_read] = 0 ;
response += buf ;
}
// parse the single string result into a vector of strings.
std::vector< std::string > lib_deps ;
std::string::size_type pos = 0;
std::string::size_type prev = 0;
while ((pos = response.find("\n", prev)) != std::string::npos)
{
lib_deps.push_back(response.substr(prev, pos - prev));
prev = pos + 1;
}
lib_deps.push_back(response.substr(prev));
return lib_deps ;
}

View File

@ -4,6 +4,7 @@
#include <map>
#include <set>
#include <vector>
#include "clang/Lex/Preprocessor.h"
#include "clang/Frontend/CompilerInstance.h"
@ -76,6 +77,12 @@ class CommentSaver : public clang::CommentHandler {
*/
std::set< std::string > getIgnoreTypes( std::string file_name ) ;
/** Returns a vector of library dependencies from the Trick comment
@param file_name = File name to search
@return vector of library dependency strings
*/
std::vector< std::string > getLibraryDependencies( std::string file_name ) ;
private:
/** The compiler's source manager. Holds file/line info for everything. */
clang::CompilerInstance & ci ;

View File

@ -221,18 +221,18 @@ std::string PrintAttributes::createIOFileName(std::string header_file_name) {
free(temp_str) ;
if ( hsd.isPathInUserDir( dir_name ) ) {
if ( dir_name.length() >= 8 and ! dir_name.compare(dir_name.size() - 8 , dir_name.size() , "/include" )) {
if ( dir_name.length() < 13 or dir_name.compare(dir_name.size() - 13 , dir_name.size() , "trick/include" )) {
dir_name.replace(dir_name.size() - 8 , dir_name.size() , "") ;
}
}
if ( ! output_dir.empty() ) {
io_file_name = output_dir + "/io_src/" + base_name ;
io_file_name = output_dir + "/" + base_name ;
} else {
// Put all of the sim_services io_files in ${TRICK_HOME}/trick_source/sim_services/include/io_src unless
// it is in er7_utils. The er7_utils io_files have duplicate file names so the overwrite each other
// leave those in their respective directories.
if ( sim_services_flag ) {
if ( dir_name.length() >= 8 and ! dir_name.compare(dir_name.size() - 8 , dir_name.size() , "/include" )) {
if ( dir_name.length() < 13 or dir_name.compare(dir_name.size() - 13 , dir_name.size() , "trick/include" )) {
dir_name.replace(dir_name.size() - 8 , dir_name.size() , "") ;
}
}
if ( dir_name.find("er7_utils") == std::string::npos ) {
io_file_name = std::string(getenv("TRICK_HOME")) + "/trick_source/sim_services/include/io_src/" + base_name ;
} else {
@ -241,7 +241,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 + "/io_src/" + base_name ;
io_file_name = std::string("build") + dir_name + "/" + base_name ;
}
}
return io_file_name ;
@ -347,8 +347,10 @@ void PrintAttributes::closeMapFiles() {
// If we wrote any new io_src files, move the temporary class and enum map files to new location
if ( out_of_date_io_files.size() > 0 ) {
rename( std::string(map_dir + "/.class_map.cpp").c_str(), std::string(map_dir + "/class_map.cpp").c_str()) ;
rename( std::string(map_dir + "/.enum_map.cpp").c_str(), std::string(map_dir + "/enum_map.cpp").c_str()) ;
std::ifstream class_map(std::string(map_dir + "/.class_map.cpp").c_str()) ;
std::ifstream enum_map(std::string(map_dir + "/.enum_map.cpp").c_str()) ;
std::ofstream combined_map(std::string(map_dir + "/class_map.cpp").c_str()) ;
combined_map << class_map.rdbuf() << enum_map.rdbuf() ;
} else {
remove( std::string(map_dir + "/.class_map.cpp").c_str() ) ;
remove( std::string(map_dir + "/.enum_map.cpp").c_str() ) ;
@ -357,8 +359,10 @@ void PrintAttributes::closeMapFiles() {
//TODO: Move this into PrintFileContents10.
void PrintAttributes::printIOMakefile() {
std::ofstream makefile ;
std::ofstream makefile_io_src ;
std::ofstream makefile_ICG ;
std::ofstream link_io_objs ;
std::ofstream ICG_processed ;
unsigned int ii ;
// Don't create a makefile if we didn't process any files.
@ -366,71 +370,115 @@ void PrintAttributes::printIOMakefile() {
return ;
}
makefile.open("build/Makefile_io_src") ;
makefile_io_src.open("build/Makefile_io_src") ;
makefile << "TRICK_IO_CXXFLAGS := \\" << std::endl ;
makefile << " -Wno-invalid-offsetof \\" << std::endl ;
makefile << " -Wno-old-style-cast \\" << std::endl ;
makefile << " -Wno-write-strings \\" << std::endl ;
makefile << " -Wno-unused-variable" << std::endl ;
makefile << std::endl ;
makefile << "ifeq ($(IS_CC_CLANG), 0)" << std::endl ;
makefile << " GCCVERSIONGTEQ48 := $(shell perl -e 'printf \"\%d\\n\", ($(GCC_MAJOR)>4)||(($(GCC_MAJOR)==4)&&($(GCC_MINOR)>=8)) ;' )" << std::endl ;
makefile << " ifeq ($(GCCVERSIONGTEQ48), 1)" << std::endl ;
makefile << " TRICK_IO_CXXFLAGS += -Wno-unused-but-set-variable -Wno-unused-local-typedefs" << std::endl ;
makefile << " endif" << std::endl ;
makefile << "endif" << std::endl ;
makefile << std::endl ;
makefile << "ifdef TRICK_VERBOSE_BUILD" << std::endl ;
makefile << "PRINT_IO_COMPILE =" << std::endl ;
makefile << "PRINT_IO_INC_LINK =" << std::endl ;
makefile << "else" << std::endl ;
makefile << "PRINT_IO_COMPILE = @echo \"Compiling io $(subst $(CURDIR)/build,build,$<)\"" << std::endl ;
makefile << "PRINT_IO_INC_LINK = @echo \"Partial linking io objects\"" << std::endl ;
makefile << "endif" << std::endl ;
makefile << std::endl ;
makefile_io_src << "TRICK_IO_CXXFLAGS := \\" << std::endl ;
makefile_io_src << " -Wno-invalid-offsetof \\" << std::endl ;
makefile_io_src << " -Wno-old-style-cast \\" << std::endl ;
makefile_io_src << " -Wno-write-strings \\" << std::endl ;
makefile_io_src << " -Wno-unused-variable" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src << "ifeq ($(IS_CC_CLANG), 0)" << std::endl ;
makefile_io_src << " TRICK_IO_CXXFLAGS += -Wno-unused-local-typedefs" << std::endl ;
makefile_io_src << " GCCVERSIONGTEQ48 := $(shell perl -e 'printf \"\%d\\n\", " <<
"($(GCC_MAJOR)>4)||(($(GCC_MAJOR)==4)&&($(GCC_MINOR)>=8)) ;' )" << std::endl ;
makefile_io_src << " ifeq ($(GCCVERSIONGTEQ48), 1)" << std::endl ;
makefile_io_src << " TRICK_IO_CXXFLAGS += -Wno-unused-but-set-variable" << std::endl ;
makefile_io_src << " endif" << std::endl ;
makefile_io_src << "endif" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src << "ifdef TRICK_VERBOSE_BUILD" << std::endl ;
makefile_io_src << "PRINT_ICG =" << std::endl ;
makefile_io_src << "PRINT_IO_COMPILE =" << std::endl ;
makefile_io_src << "PRINT_IO_INC_LINK =" << std::endl ;
makefile_io_src << "else" << std::endl ;
makefile_io_src << "PRINT_ICG = @echo \"Running ICG\"" << std::endl ;
makefile_io_src << "PRINT_IO_COMPILE = @echo \"Compiling  $(subst $(CURDIR)/build,build,$<)\"" << std::endl ;
makefile_io_src << "PRINT_IO_INC_LINK = @echo \"Partial link io objects\"" << std::endl ;
makefile_io_src << "endif" << std::endl ;
makefile_io_src << std::endl ;
//TODO: create the io_file name if it doesn't exist
makefile << "IO_OBJ_FILES =" ;
std::set<std::string>::iterator sit ;
for ( sit = visited_files.begin() ; sit != visited_files.end() ; sit++ ) {
std::map< std::string , std::string >::iterator mit = all_io_files.find(*sit) ;
if ( mit != all_io_files.end() ) {
size_t found ;
found = (*mit).second.find_last_of(".") ;
makefile << " \\\n $(CURDIR)/" << (*mit).second.substr(0,found) << ".o" ;
}
makefile_io_src << "IO_OBJ_FILES =" ;
std::map< std::string , std::string >::iterator mit ;
for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) {
size_t found ;
found = (*mit).second.find_last_of(".") ;
makefile_io_src << " \\\n $(CURDIR)/" << (*mit).second.substr(0,found) << ".o" ;
}
makefile << " \\\n $(CURDIR)/build/class_map.o" ;
makefile << " \\\n $(CURDIR)/build/enum_map.o" << std::endl ;
makefile << std::endl ;
makefile << "$(IO_OBJ_FILES) : \%.o : \%.cpp" << std::endl ;
makefile << "\t$(PRINT_IO_COMPILE)" << std::endl ;
makefile << "\t$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_IO_CXXFLAGS) -MMD -MP -c $< -o $@" << std::endl ;
makefile << std::endl ;
makefile << "-include $(IO_OBJ_FILES:.o=.d)" << std::endl ;
makefile << std::endl ;
makefile << "$(S_MAIN) : $(LIB_DIR)/io_src.o" << std::endl ;
makefile << std::endl ;
makefile << "$(LIB_DIR)/io_src.o : $(IO_OBJ_FILES) | $(LIB_DIR)" << std::endl ;
makefile << "\t$(PRINT_IO_INC_LINK)" << std::endl ;
makefile << "\t$(ECHO_CMD)ld $(LD_PARTIAL) -o $@ $(LD_FILELIST)build/link_io_objs" << std::endl ;
makefile_io_src << " \\\n $(CURDIR)/build/class_map.o" << std::endl ;
makefile_io_src << std::endl ;
makefile.close() ;
makefile_io_src << "$(IO_OBJ_FILES) : \%.o : \%.cpp" << std::endl ;
makefile_io_src << "\t$(PRINT_IO_COMPILE)" << std::endl ;
makefile_io_src << "\t$(ECHO_CMD)$(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_IO_CXXFLAGS) -MMD -MP -c $< -o $@" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src << "-include $(IO_OBJ_FILES:.o=.d)" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src << "OBJECTS += $(LIB_DIR)/io_src.o" << std::endl ;
makefile_io_src << "$(S_MAIN) : $(LIB_DIR)/io_src.o" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src << "$(LIB_DIR)/io_src.o : $(IO_OBJ_FILES) | $(LIB_DIR)" << std::endl ;
makefile_io_src << "\t$(PRINT_IO_INC_LINK)" << std::endl ;
makefile_io_src << "\t$(ECHO_CMD)ld $(LD_PARTIAL) -o $@ $(LD_FILELIST)build/link_io_objs" << std::endl ;
makefile_io_src << std::endl ;
makefile_io_src.close() ;
/*
Makefile_ICG lists all headers as dependencies of class_map.cpp
causing ICG to run if any header file changes.
link_io_objs lists all io_src object files to be partially
linked into a single io_object.
ICG_process lists all header files to be used by SWIG.
*/
makefile_ICG.open("build/Makefile_ICG") ;
link_io_objs.open("build/link_io_objs") ;
for ( sit = visited_files.begin() ; sit != visited_files.end() ; sit++ ) {
std::map< std::string , std::string >::iterator mit = all_io_files.find(*sit) ;
if ( mit != all_io_files.end() ) {
ICG_processed.open("build/ICG_processed") ;
makefile_ICG << "$(CURDIR)/build/class_map.cpp :" ;
for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) {
makefile_ICG << "\\\n " << (*mit).first ;
size_t found ;
found = (*mit).second.find_last_of(".") ;
link_io_objs << (*mit).second.substr(0,found) << ".o" << std::endl ;
ICG_processed << (*mit).first << std::endl ;
}
makefile_ICG << std::endl << std::endl ;
makefile_ICG.close() ;
link_io_objs << "build/class_map.o" << std::endl ;
link_io_objs.close() ;
ICG_processed.close() ;
}
void PrintAttributes::printHeaderLibraryDependencies() {
std::ofstream header_lib_deps ;
header_lib_deps.open("build/header_lib_deps_files") ;
std::map< std::string , std::string >::iterator mit ;
for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) {
if ( out_of_date_io_files.find((*mit).first) != out_of_date_io_files.end()) {
size_t found ;
found = (*mit).second.find_last_of(".") ;
link_io_objs << (*mit).second.substr(0,found) << ".o" << std::endl ;
found = (*mit).first.find_last_of(".") ;
std::string lib_dep_file = std::string("build") + (*mit).first.substr(0,found) + ".lib_deps" ;
header_lib_deps << lib_dep_file << std::endl ;
std::ofstream file_list ;
file_list.open(lib_dep_file) ;
std::vector< std::string > lib_deps = cs.getLibraryDependencies((*mit).first) ;
std::vector< std::string >::iterator vit ;
for ( vit = lib_deps.begin() ; vit != lib_deps.end() ; vit++ ) {
file_list << *vit << std::endl ;
}
file_list.close() ;
}
}
link_io_objs << "build/class_map.o" << std::endl ;
link_io_objs << "build/enum_map.o" << std::endl ;
link_io_objs.close() ;
header_lib_deps.close() ;
}
void PrintAttributes::printICGNoFiles() {

View File

@ -45,6 +45,9 @@ class PrintAttributes {
/** Create makefile for IO files */
virtual void printIOMakefile() ;
/** Print header library dependencies */
virtual void printHeaderLibraryDependencies() ;
/** Prints list of files that contain ICG:(No) in the Trick header */
virtual void printICGNoFiles() ;

View File

@ -452,6 +452,7 @@ void PrintFileContents10::printClassMapHeader( std::ofstream & outfile , std::st
"#include <map>\n"
"#include <string>\n\n"
"#include \"trick/AttributesMap.hh\"\n"
"#include \"trick/EnumAttributesMap.hh\"\n"
"#include \"trick/attributes.h\"\n\n"
"void " << function_name << "() {\n\n"
" Trick::AttributesMap * class_attribute_map = Trick::AttributesMap::attributes_map();\n\n" ;
@ -474,19 +475,11 @@ void PrintFileContents10::printClassMap( std::ofstream & outfile , ClassValues *
}
void PrintFileContents10::printClassMapFooter( std::ofstream & outfile ) {
outfile << "}" << std::endl ;
outfile << "}" << std::endl << std::endl ;
}
void PrintFileContents10::printEnumMapHeader( std::ofstream & outfile , std::string function_name ) {
outfile <<
"/*\n"
" * This file was automatically generated by the ICG\n"
" * This file contains the map from enum names to attributes\n"
" */\n\n"
"#include <map>\n"
"#include <string>\n\n"
"#include \"trick/EnumAttributesMap.hh\"\n"
"#include \"trick/attributes.h\"\n\n"
"void " << function_name << "() {\n"
" Trick::EnumAttributesMap * enum_attribute_map __attribute__((unused)) = Trick::EnumAttributesMap::attributes_map();\n\n" ;
}
@ -507,5 +500,5 @@ void PrintFileContents10::printEnumMap( std::ofstream & outfile , EnumValues * e
}
void PrintFileContents10::printEnumMapFooter( std::ofstream & outfile ) {
outfile << "}" << std::endl ;
outfile << "}" << std::endl << std::endl ;
}

View File

@ -191,6 +191,7 @@ int main( int argc , char * argv[] ) {
if ( ! sim_services_flag ) {
pa.printIOMakefile() ;
pa.printHeaderLibraryDependencies() ;
}
// Close the map files

View File

@ -4,7 +4,7 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
CC := $(shell $(LLVM_HOME)/bin/llvm-config --bindir)/clang
CXX := $(shell $(LLVM_HOME)/bin/llvm-config --bindir)/clang++
CXXFLAGS := -g -I$(shell $(LLVM_HOME)/bin/llvm-config --includedir) -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti
CXXFLAGS := -g -I$(shell $(LLVM_HOME)/bin/llvm-config --includedir) -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -std=c++11
CLANG_MINOR_GTEQ5 := $(shell expr `$(LLVM_HOME)/bin/llvm-config --version | cut -f2 -d. ` \>= 5 )

View File

@ -93,23 +93,23 @@ clean :
# Builds gtest.a and gtest_main.a.
io_MM_user_defined_types.o : MM_user_defined_types.hh
${TRICK_HOME}/bin/trick-ICG -s -o . $(TRICK_CPPFLAGS) $<
${TRICK_HOME}/bin/trick-ICG -s -o ./io_src $(TRICK_CPPFLAGS) $<
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c io_src/io_MM_user_defined_types.cpp
io_MM_alloc_deps.o : MM_alloc_deps.hh
${TRICK_HOME}/bin/trick-ICG -s -o . $(TRICK_CPPFLAGS) $<
${TRICK_HOME}/bin/trick-ICG -s -o ./io_src $(TRICK_CPPFLAGS) $<
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c io_src/io_MM_alloc_deps.cpp
io_MM_write_checkpoint.o : MM_write_checkpoint.hh
${TRICK_HOME}/bin/trick-ICG -s -o . $(TRICK_CPPFLAGS) $<
${TRICK_HOME}/bin/trick-ICG -s -o ./io_src $(TRICK_CPPFLAGS) $<
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c io_src/io_MM_write_checkpoint.cpp
io_MM_get_enumerated.o : MM_get_enumerated.hh
${TRICK_HOME}/bin/trick-ICG -s -o . $(TRICK_CPPFLAGS) $<
${TRICK_HOME}/bin/trick-ICG -s -o ./io_src $(TRICK_CPPFLAGS) $<
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c io_src/io_MM_get_enumerated.cpp
io_MM_ref_name_from_address.o : MM_ref_name_from_address.hh
${TRICK_HOME}/bin/trick-ICG -s -o . $(TRICK_CPPFLAGS) $<
${TRICK_HOME}/bin/trick-ICG -s -o ./io_src $(TRICK_CPPFLAGS) $<
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c io_src/io_MM_ref_name_from_address.cpp
MM_creation_unittest.o : MM_creation_unittest.cc