Create a separate direcotry for simulation compilation.

Moved most generated files into the build directory.  All object code,
io_src realated files, and swig related files are now in build.

Realized that ICG should be creating the makefile for the io_src
code.  ICG knows which files it created.

refs #80
This commit is contained in:
Alex Lin 2015-07-02 10:09:31 -05:00
parent 5fb037aa00
commit 469be90e32
9 changed files with 368 additions and 804 deletions

View File

@ -40,7 +40,7 @@ $| = 1 ;
# set default verbose level
$sim{args}{v} = 2 ;
$sim{args}{o} = "CP_out" ;
$sim{args}{o} = "build/CP_out" ;
$sim{args}{p} = 1 ;
#--------------------------------------------------------------
@ -88,6 +88,10 @@ if ( $cc_found == 0 ) {
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 ;
@ -235,22 +239,17 @@ if ( $sim{args}{v} == 1 ) {
trick_print($sim{fh}, "\nMIS complete\n\n" , "normal_green" , $sim{args}{v}) ;
#--------------------------------------------------------------
# Make Default Data
# 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}) ;
chdir ($cwd) ;
trick_print($sim{fh}, "Creating S_document.xml...", "title_cyan", $sim{args}{v}) ;
print_xml_CP( \%sim ) ;
trick_print( $sim{fh}, " Complete\n", "title_green", $sim{args}{v}) ;
}
#--------------------------------------------------------------
# Make Makefile
# Make Makefile
if ($sim{args}{m}) {
trick_print($sim{fh}, "Creating New Makefile... ", "title_cyan" , $sim{args}{v}) ;

View File

@ -214,7 +214,7 @@ if ( -e $s_library_swig ) {
##
get_headers(\%sim, $s_source_full_path) ;
if ( open ICGNOFOUND , (".icg_no_found") ) {
if ( open ICGNOFOUND , ("build/icg_no_found") ) {
while ( <ICGNOFOUND> ) {
chomp ;
$icg_no{$_} = 1 ;
@ -265,8 +265,7 @@ foreach my $f ( keys %{$sim{final_all_includes}} ) {
$base_file =~ s/\.[^\.]+$// ;
$swig_dir = dirname($f) ;
$swig_dir =~ s/\/include$//g ;
$swig_dir .= "/swig" ;
$swig_dir = "build/$swig_dir" ;
$swig_file = "$swig_dir/${base_file}.i" ;
#print "$swig_file\n" ;
@ -329,6 +328,7 @@ sub process_file($$) {
my ($raw_contents , $contents , $new_contents ) ;
my ($curr_dir) ;
next if ( $f =~ /^$ENV{TRICK_HOME}\/include/ ) ;
next if ( $f =~ /^$ENV{TRICK_HOME}\/trick_source/ ) ;
# clear the processed templates per each file
@ -372,11 +372,11 @@ sub process_file($$) {
# Get the absolute path to this include file... use this from now on.
$file_name = abs_path(dirname($f)) . "/" . $temp_file_name ;
# Re-insert double quotes around include file.
$file_name = "\"" . $file_name . "\"" ;
#$file_name = "\"" . $file_name . "\"" ;
} elsif ( $temp_file_name !~ /^\// ) {
foreach my $i ( dirname($f) , @include_dirs ) {
if ( -e ( "$i/$temp_file_name" ) ) {
$file_name = "\"" . abs_path(dirname("$i/$temp_file_name")) . "/" . basename($temp_file_name) . "\"" ;
$file_name = abs_path(dirname("$i/$temp_file_name")) . "/" . basename($temp_file_name) ;
last ;
}
}
@ -388,15 +388,10 @@ sub process_file($$) {
last ;
}
}
$file_name = "\"build" . $file_name . "\"" ;
if ( $exclude == 0 ) {
if ( $file_name =~ /include\/[^\.]+\.[^\.]+\"/ ) {
$file_name =~ s/(.*)include\/([^\.]+\.)[^\.]+\"/${1}swig\/${2}i\"/ ;
} elsif ( $file_name =~ /\/([^\.\/]+\.)[^\.]+\"/ ) {
$file_name =~ s/\/([^\.\/]+\.)[^\.]+\"/\/swig\/${1}i\"/ ;
} else {
$file_name =~ s/\.[^\.]+\"/\.i\"/ ;
}
$file_name =~ s/\.[^\.]+\"/\.i\"/ ;
}
$contents .= "\%import $file_name\n" ;
} else {
@ -417,11 +412,10 @@ sub process_file($$) {
my $md5_sum = md5_hex($f) ;
my ($out_dir) = dirname($f) ;
$out_file = basename($f) ;
$out_dir = "build$out_dir" ;
$out_file = basename($f) ;
$out_file =~ s/\.h.*$/\.i/ ;
$out_dir =~ s/\/include$// ;
$out_dir .= "/swig" ;
$out_file = "$out_dir/$out_file" ;

View File

@ -145,7 +145,7 @@ sub ICG(\@$$$) {
return -1 ;
}
open SLIB , ".icg_no_found" ;
open SLIB , "build/icg_no_found" ;
while ( <SLIB> ) {
chomp ;
$$sim_ref{icg_no}{$_} = 1 ;

View File

@ -13,8 +13,6 @@ use gte ;
use trick_print ;
use trick_version ;
my %icg_files_hash ;
# bm_build , bm_and and bm_or taken from www.perl.com
sub _bm_build {
my $condition = shift;
@ -31,10 +29,7 @@ sub bm_or { _bm_build('||', @_) }
sub make_makefile($$$) {
my ($h_ref , $sim_ref , $make_cwd ) = @_ ;
my @top_h_files ;
my @all_depends ;
my ($n , $f , $k , $i , $j, $m);
my (%all_icg_depends) = %{$$sim_ref{all_icg_depends}} ;
my %all_mis_depends ;
my %temp_hash ;
my @all_h_files ;
@ -43,17 +38,9 @@ sub make_makefile($$$) {
my @all_compile_libs ;
my %compile_libs ;
my %files_by_dir ;
my ($writable_dirs , $readonly_dirs) ;
my ( $sp_dir , $src_dir , $sp_file , $base_name , $suffix) ;
my ( $print_me_l, $print_me_c, $print_me_clex) ;
my ($lib_size , $num_src_files , $num_icg_files , $num_lib , $num_io_lib );
my $num_src_files ;
my (@temp_array , @temp_array2) ;
my $print_me ;
my %module_files_hash ;
my @inc_paths ;
my @s_inc_paths ;
my @valid_inc_paths ;
my $subme ;
my $sub_multiple ;
my %real_extension_h ;
my %real_extension_cpp ;
@ -62,65 +49,7 @@ sub make_makefile($$$) {
%all_mis_depends = %{$$sim_ref{all_mis_depends}} ;
}
@inc_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS
push @inc_paths , ("$ENV{\"TRICK_HOME\"}/trick_source" , "../include") ;
@valid_inc_paths = () ;
foreach (@inc_paths) {
$_ = q($_) ;
push @valid_inc_paths , $_ if ( -e $_ ) ;
}
@inc_paths = @valid_inc_paths ;
$sub_multiple = bm_or "" , @inc_paths ;
@s_inc_paths = $ENV{"TRICK_SFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS
if ( exists $$sim_ref{sim_libraries} ) {
for ($i = 0 ; $i < scalar @{$$sim_ref{sim_libraries}} ; $i++ ) {
my ( $found ) = 0 ;
foreach my $inc ( @s_inc_paths ) {
if ( -e "$inc/@{$$sim_ref{sim_libraries}}[$i]" ) {
$found = 1 ;
@{$$sim_ref{sim_libraries}}[$i] = "$inc/@{$$sim_ref{sim_libraries}}[$i]" ;
open SLIB , "@{$$sim_ref{sim_libraries}}[$i]/S_library_list" ;
while ( <SLIB> ) {
chomp ;
$$sim_ref{sim_lib_files}{$_} = 1 ;
}
last ;
}
}
if ( $found == 0 ) {
trick_print($$sim_ref{fh}, "Could not find sim_lib @{$$sim_ref{sim_libraries}}[$i]\n" , "title_red" , $$sim_ref{args}{v}) ;
exit ;
}
}
}
open SLIB_EXT, ">.S_library_list_ext" ;
foreach my $f ( sort keys %{$$sim_ref{sim_lib_files}} ) {
print SLIB_EXT "$f\n" ;
}
close SLIB_EXT ;
# make a list of all the header files required by this sim
foreach $n ( @$h_ref ) {
push @all_h_files , $n ;
foreach $k ( keys %{$all_icg_depends{$n}} ) {
push @all_h_files , $k ;
push @all_h_files , @{$all_icg_depends{$n}{$k}} ;
}
}
# remove duplicate elements
undef %temp_hash ;
@all_h_files = grep ++$temp_hash{$_} < 2, @all_h_files ;
# remove headers found in trick_source and ${TRICK_HOME}/include/trick
@all_h_files = sort (grep !/trick_source/ , @all_h_files) ;
@all_h_files = sort (grep !/$ENV{"TRICK_HOME"}\/include\/trick\// , @all_h_files) ;
my @exclude_dirs ;
my @icg_exclude_dirs ;
@exclude_dirs = split /:/ , $ENV{"TRICK_EXCLUDE"};
# See if there are any elements in the exclude_dirs array
@ -136,60 +65,6 @@ sub make_makefile($$$) {
@exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @exclude_dirs ;
}
@icg_exclude_dirs = split /:/ , $ENV{"TRICK_ICG_EXCLUDE"};
# See if there are any elements in the icg_exclude_dirs array
if (scalar @icg_exclude_dirs) {
@icg_exclude_dirs = sort(@icg_exclude_dirs );
# Error check - delete any element that is null
# (note: sort forced all blank names to front of array
@icg_exclude_dirs = map { s/(^\s+|\s+$)//g ; $_ } @icg_exclude_dirs ;
while ( not length @icg_exclude_dirs[0] ) {
# Delete an element from the left side of an array (element zero)
shift @icg_exclude_dirs ;
}
@icg_exclude_dirs = map { (-e $_) ? abs_path($_) : $_ } @icg_exclude_dirs ;
}
# split off the header files by directory
foreach ( @all_h_files ) {
if (exists $$sim_ref{sim_lib_files}{$_}) {
trick_print($$sim_ref{fh}, "CP skipping $_ (sim_lib)\n" , "normal_yellow" , $$sim_ref{args}{v}) ;
next ;
}
if (exists $$sim_ref{icg_no}{$_}) {
trick_print($$sim_ref{fh}, "CP skipping $_ (ICG No found)\n" , "normal_yellow" , $$sim_ref{args}{v}) ;
next ;
}
my ( $continue ) = 1 ;
foreach my $ie ( @icg_exclude_dirs ) {
my $dum = $_ ;
# if file location begins with $ie (an IGC exclude dir)
if ( $dum =~ s/^\Q$ie// ) {
if ( $dum =~ /^\// ) {
trick_print($$sim_ref{fh}, "CP skipping $f (ICG exclude dir $ie)\n" , "normal_yellow" , $$sim_ref{args}{v}) ;
$continue = 0 ;
last ; # break out of loop
}
}
}
next if ( $continue == 0 ) ;
( $sp_dir , $src_dir , $sp_file ) = /(.*?)(?:\/(include))?\/([^\/]+)$/ ;
$src_dir .= "/" if ($src_dir ne "") ;
($base_name = $sp_file) =~ s/hC?$|H$|hh$|h\+\+$|hxx$// ;
if ( $sp_file =~ /(H$|hh$|h\+\+$|hxx$)/ ) {
$real_extension_h{"$sp_dir/$src_dir$base_name"} = $1 ;
}
else {
$real_extension_h{"$sp_dir/$src_dir$base_name"} = "h" ;
}
$files_by_dir{$sp_dir}{include_dir} = $src_dir ;
push @{$files_by_dir{$sp_dir}{h}} , $base_name ;
}
# get a list of all source files required by this file
foreach $n ( @{$$sim_ref{mis_entry_files}} ) {
foreach $k ( grep !/last_look/ , (keys %{$all_mis_depends{$n}}) ) {
@ -211,23 +86,10 @@ sub make_makefile($$$) {
$sp_file = basename($_) ;
$_ = abs_path(dirname($_)) ;
if (exists $$sim_ref{sim_lib_files}{"$_/$sp_file"}) {
trick_print($$sim_ref{fh}, "CP skipping $_ (sim_lib)\n" , "normal_yellow" , $$sim_ref{args}{v}) ;
next ;
}
( $sp_dir , $src_dir ) = /(.*?)(?:\/(src))?$/ ;
$src_dir .= "/" if ($src_dir ne "") ;
($base_name = $sp_file) =~ s/[cfly]$|C$|cc$|cxx$|cpp$|c\+\+$// ;
($base_name , $suffix) = $sp_file =~ /(.*?)([cfly]$|C$|cc$|cxx$|cpp$|c\+\+$)/ ;
# save off the extension used by a c++ file
if ( $sp_file =~ /(C$|cc$|cxx$|cpp$|c\+\+$)/ ) {
$real_extension_cpp{"$sp_dir/$src_dir$base_name"} = $1 ;
$suffix = "cpp" ;
}
else {
($suffix) = $sp_file =~ /([cfly])$/ ;
}
$files_by_dir{$sp_dir}{src_dir} = $src_dir ;
push @{$files_by_dir{$sp_dir}{$suffix}} , $base_name ;
}
@ -249,14 +111,15 @@ sub make_makefile($$$) {
@local_files = grep !/^\.\.\./ , readdir THISDIR;
@local_files = grep /\.[cfly]$|C$|cc$|cxx$|cpp$|c\+\+$/ , @local_files;
foreach $k ( @local_files ) {
if ( $k =~ /(C$|cc$|cxx$|cpp$|c\+\+$)/ ) {
($base_name) = $k =~ /(.*?)(C$|cc$|cxx$|cpp$|c\+\+$)/ ;
$real_extension_cpp{"$sp_dir/$src_dir$base_name"} = $2 ;
$suffix = "cpp" ;
}
else {
($base_name , $suffix) = $k =~ /(.*?)([cfly])$/ ;
}
#if ( $k =~ /(C$|cc$|cxx$|cpp$|c\+\+$)/ ) {
# ($base_name) = $k =~ /(.*?)(C$|cc$|cxx$|cpp$|c\+\+$)/ ;
# $real_extension_cpp{"$sp_dir/$src_dir$base_name"} = $2 ;
# $suffix = "cpp" ;
#}
#else {
# ($base_name , $suffix) = $k =~ /(.*?)([cfly])$/ ;
#}
($base_name , $suffix) = $sp_file =~ /(.*?)([cfly]$|C$|cc$|cxx$|cpp$|c\+\+$)/ ;
push @{$files_by_dir{$sp_dir}{$suffix}} , $base_name ;
}
closedir THISDIR ;
@ -264,7 +127,7 @@ sub make_makefile($$$) {
# sort and weed out duplicate files
foreach $k ( keys %files_by_dir ) {
foreach $n ( qw{ c f l y h cpp} ) {
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}} ;
}
@ -272,7 +135,6 @@ sub make_makefile($$$) {
$i = 0 ;
$num_src_files = 0;
$num_icg_files = 0;
foreach $k ( sort keys %files_by_dir ) {
foreach my $ie ( @exclude_dirs ) {
@ -285,18 +147,15 @@ sub make_makefile($$$) {
}
}
# check to see if each directory is writable and count the number of source files
foreach $k ( sort keys %files_by_dir ) {
$files_by_dir{$k}{writable} = ( -w $k ) ? 1 : 0 ;
$_ = $k ;
&$sub_multiple ;
($files_by_dir{$k}{dir_num} = $_) =~ s#^/## ;
$files_by_dir{$k}{dir_num} =~ s/[\/.]/_/g ;
if ( ! exists $files_by_dir{$k}{full_name} ) {
$num_src_files += $#{$files_by_dir{$k}{c}} + $#{$files_by_dir{$k}{f}} + $#{$files_by_dir{$k}{y}} + 3 ;
$num_src_files += $#{$files_by_dir{$k}{cpp}} + 1 ;
$num_icg_files += $#{$files_by_dir{$k}{h}} + 1;
}
# if a particular directory had an override file, save that into memory
if (open OV_FILE, "$k/makefile_overrides") {
@ -329,10 +188,7 @@ sub make_makefile($$$) {
my $sim_dir_name = basename($wd) ;
$sim_dir_name =~ s/SIM_// ;
my $dt = localtime();
my ($trick_ver, $trick_thread) = get_trick_version() ;
my ($trick_major , $trick_minor ) ;
($trick_major , $trick_minor ) = $trick_ver =~ /(\d+)\.([^\.]+)/ ;
$trick_thread =~ s/\d+\.// ;
my ($trick_ver) = get_trick_version() ;
chomp $trick_ver ;
open MAKEFILE , ">Makefile_sim" or return ;
@ -345,7 +201,7 @@ sub make_makefile($$$) {
#
#############################################################################
# Creation:
# Author: Trick Configuration Processor - CP Version $trick_ver-$trick_thread
# Author: Trick Configuration Processor - trick-CP Version $trick_ver
# Date: $dt
#
#############################################################################
@ -365,111 +221,92 @@ endif" ;
print MAKEFILE "
LIB_DIR = \$(CURDIR)/lib_\${TRICK_HOST_CPU}
OBJECT_DIR = \$(CURDIR)/object_\${TRICK_HOST_CPU}
SIM_LIB = \$(LIB_DIR)/lib_${sim_dir_name}.a
S_OBJECT_FILES = \$(OBJECT_DIR)/S_source.o \\
\$(OBJECT_DIR)/io_S_source.o \\
\$(OBJECT_DIR)/class_map.o \\
\$(OBJECT_DIR)/enum_map.o
S_OBJECT_FILES = build/S_source.o
\$(S_OBJECT_FILES) : | \$(LIB_DIR) \$(OBJECT_DIR)
\n" ;
\$(S_OBJECT_FILES) : | \$(LIB_DIR)\n\n" ;
# print some comments for all of the directories used
foreach ( sort keys %files_by_dir ) {
print MAKEFILE "#MODEL_DIR_$files_by_dir{$_}{dir_num} = $_\n"
}
my $all_model_files ;
my $all_io_cpp_files ;
my %object_files_by_type ;
# list out all of the source and object files
foreach $k ( sort keys %files_by_dir ) {
if ( $#{$files_by_dir{$k}{c}} ne -1 ) {
print MAKEFILE "\n\nMODEL_C_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{c}} ) {
print MAKEFILE " \\\n\t$k/$files_by_dir{$k}{src_dir}$f" . "c" ;
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 ;
}
print MAKEFILE "\n\nMODEL_C_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{c}} ) {
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}/$f" . "o" ;
}
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
$all_model_files .= " \\\n\t\$(MODEL_C_SRC_$files_by_dir{$k}{dir_num})" ;
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 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}) : | build$k/$files_by_dir{$k}{src_dir}$f\n" ;
print MAKEFILE "build$k/$files_by_dir{$k}{src_dir}$f :\n" ;
print MAKEFILE "\tmkdir -p \$\@\n" ;
}
}
if ( $#{$files_by_dir{$k}{cpp}} ne -1 ) {
print MAKEFILE "\n\nMODEL_CPP_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{cpp}} ) {
print MAKEFILE " \\\n\t$k/$files_by_dir{$k}{src_dir}$f" . $real_extension_cpp{"$k/$files_by_dir{$k}{src_dir}$f"} ;
}
print MAKEFILE "\n\nMODEL_CPP_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{cpp}} ) {
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}/$f" . "o" ;
}
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
$all_model_files .= " \\\n\t\$(MODEL_CPP_SRC_$files_by_dir{$k}{dir_num})" ;
}
}
if ( $#{$files_by_dir{$k}{h}} ne -1 ) {
print MAKEFILE "\n\nMODEL_IO_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{h}} ) {
my $path = $k ;
$path .= "/include" if ( -e "$k/include" ) ;
my $final_ext = "cpp" ;
print MAKEFILE " \\\n\t$k/io_src/io_$f" . $final_ext ;
}
print MAKEFILE "\n\nMODEL_IO_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{h}} ) {
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}/io_$f" . "o" ;
}
print MAKEFILE "\n\nMODEL_IO_CPP_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{h}} ) {
my $path = $k ;
$path .= "/include" if ( -e "$k/include" ) ;
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}/io_$f" . "o" ;
}
$all_io_cpp_files .= " \\\n\t\$(MODEL_IO_CPP_OBJ_$files_by_dir{$k}{dir_num})" ;
print MAKEFILE "\n\nMODEL_HEADERS_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{h}} ) {
my $path = $k ;
$path .= "/include" if ( -e "$k/include" ) ;
my $ext = $real_extension_h{"$path/$f"} ;
print MAKEFILE " \\\n\t$path/$f" . $ext ;
}
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
$all_model_files .= " \\\n\t\$(MODEL_HEADERS_$files_by_dir{$k}{dir_num})" ;
}
}
if ( $#{$files_by_dir{$k}{y}} ne -1 ) {
print MAKEFILE "\n\nMODEL_YACC_SRC_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{y}} ) {
print MAKEFILE " \\\n\t$k/$files_by_dir{$k}{src_dir}$f" . "c" ;
}
print MAKEFILE "\n\nMODEL_YACC_OBJ_$files_by_dir{$k}{dir_num} =" ;
foreach $f ( @{$files_by_dir{$k}{y}} ) {
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}/$f" . "o" ;
}
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
$all_model_files .= " \\\n\t\$(MODEL_YACC_SRC_$files_by_dir{$k}{dir_num})" ;
}
}
if ( $#{$files_by_dir{$k}{l}} ne -1 ) {
print MAKEFILE "\n\nMODEL_LEX_SRC_$files_by_dir{$k}{dir_num} =" ;
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\t$k/$files_by_dir{$k}{src_dir}$f" . "clex" ;
print MAKEFILE " \\\n build$k/$files_by_dir{$k}{src_dir}$f" . "clex" ;
}
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
$all_model_files .= " \\\n\t\$(MODEL_LEX_SRC_$files_by_dir{$k}{dir_num})" ;
}
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 build$k/$files_by_dir{$k}{src_dir}$f" . "y.c" ;
}
}
}
print MAKEFILE "\n\n" ;
print MAKEFILE "\n\nDEFAULT_DATA_C_OBJ =" ;
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} : build\%.o : \%.c\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_C_OBJ} : build\%.o : \%.C\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_cc_OBJ} : build\%.o : \%.cc\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_cpp_OBJ} : build\%.o : \%.cpp\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_cxx_OBJ} : build\%.o : \%.cxx\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_CPLUSPLUS_OBJ} : build\%.o : \%.c++\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\${MODEL_clex_SRC} : build\%.clex : \%.l\n" ;
print MAKEFILE "\t\$(LEX) -o\$\@ \$\<\n\n" ;
print MAKEFILE "\${MODEL_y_c_SRC} : build\%.y.c : \%.y\n" ;
print MAKEFILE "\t\$(YACC) -o\$\@ \$\?\n\n" ;
print MAKEFILE "\${MODEL_y_OBJ} : build\%.o : \%.y.c\n" ;
print MAKEFILE "\tcd \$(<D) ; \$(TRICK_CC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${<F} -o \$(CURDIR)/\$\@\n\n" ;
print MAKEFILE "\nDEFAULT_DATA_C_OBJ =" ;
if ( exists $$sim_ref{def_data_c} ) {
foreach my $d ( sort keys %{$$sim_ref{def_data_c}} ) {
print MAKEFILE " \\\n\t$wd/lib_\${TRICK_HOST_CPU}/$$sim_ref{def_data_c}{$d}{file_name}" . ".o" ;
@ -484,29 +321,11 @@ S_OBJECT_FILES = \$(OBJECT_DIR)/S_source.o \\
}
print MAKEFILE "\n\nDEFAULT_DATA_OBJECTS = \$(DEFAULT_DATA_C_OBJ) \$(DEFAULT_DATA_CPP_OBJ)\n\n" ;
print MAKEFILE "\n\nMODEL_ALL_SRC =$all_model_files\n" ;
print MAKEFILE "\n\nMODEL_ALL_IO_CPP_OBJ =$all_io_cpp_files\n" ;
printf MAKEFILE "\n\nOBJECTS =" ;
for( $i = 0 ; $i < $num_src_files ; $i++ ) {
print MAKEFILE " \\\n\t\$(LIB_DIR)/o$i.o" ;
}
# only count to $num_icg_files - 1 because we will skip io_S_source.cpp
print MAKEFILE "\n\nIO_OBJECTS =" ;
for ( $i = 0 ; $i < $num_icg_files - 1 ; $i++ ) {
print MAKEFILE " \\\n\t\$(LIB_DIR)/i$i.o" ;
}
# print out the object dirs if we can write to them.
print MAKEFILE "\n\nMODEL_OBJ_DIRS =" ;
foreach $k ( sort keys %files_by_dir ) {
if ($files_by_dir{$k}{"writable"}) {
print MAKEFILE " \\\n\t$k/object_\${TRICK_HOST_CPU}" ;
}
}
# print out the libraries we build
print MAKEFILE "\n\nBUILD_USER_LIBS = ";
foreach ( sort keys %files_by_dir ) {
@ -523,32 +342,9 @@ S_OBJECT_FILES = \$(OBJECT_DIR)/S_source.o \\
print MAKEFILE " \\\n\t$_" ;
}
# print out the sim directory libraries
print MAKEFILE "\n\nSIM_LIBS = ";
foreach my $l ( @{$$sim_ref{sim_libraries}} ) {
my $lib_name = $l ;
$lib_name =~ s/.*SIM_// ;
print MAKEFILE " \\\n\tlib_\${TRICK_HOST_CPU}/lib_${lib_name}.a" ;
}
print MAKEFILE "\n\n\
TRICK_IO_CXXFLAGS := \\
-Wno-invalid-offsetof \\
-Wno-old-style-cast \\
-Wno-write-strings \\
-Wno-unused-variable
ifeq (\$(IS_CC_CLANG), 0)
GCCVERSIONGTEQ48 := \$(shell perl -e 'printf \"\%d\\n\", (\$(GCC_MAJOR)>4)||((\$(GCC_MAJOR)==4)&&(\$(GCC_MINOR)>=8)) ;' )
ifeq (\$(GCCVERSIONGTEQ48), 1)
TRICK_IO_CXXFLAGS += -Wno-unused-but-set-variable
endif
endif
print MAKEFILE "\n\n
test_all: TRICK_CXXFLAGS += -DTRICK_UNIT_TEST
test_all: TRICK_CFLAGS += -DTRICK_UNIT_TEST
\$(OBJECT_DIR)/io_S_source.o: TRICK_CXXFLAGS += \$(TRICK_IO_CXXFLAGS)\n\n" ;
test_all: TRICK_CFLAGS += -DTRICK_UNIT_TEST\n\n" ;
print MAKEFILE "all: S_main\n\n" ;
@ -560,22 +356,22 @@ test_all: TRICK_CFLAGS += -DTRICK_UNIT_TEST
print MAKEFILE "\t\${TRICK_HOME}/bin/trick-ICG -f -m \${TRICK_CXXFLAGS} S_source.hh\n" ;
print MAKEFILE "
S_main : objects \$(LIB_DIR) \$(S_MAIN) \$(OBJECT_DIR)/S_define.deps S_sie.resource
S_main : objects \$(LIB_DIR) \$(S_MAIN) build/S_define.deps S_sie.resource
\t@ echo \"\"
\t@ echo \"=== Simulation make complete ===\"
objects : \$(MODEL_OBJ_DIRS) model_objects build_user_lib
objects : \$(OBJECTS) build_user_lib
build_user_lib : \$(BUILD_USER_OBJ_DIRS) \$(BUILD_USER_LIBS)
" ;
if ( $num_src_files + $num_icg_files > 1 ) {
if ( $num_src_files > 1 ) {
print MAKEFILE "\
\$(S_MAIN): \$(BUILD_USER_LIBS) \${TRICK_STATIC_LIB} \$(LIB_DIR)/lib_${sim_dir_name}.a \$(S_OBJECT_FILES) \$(SIM_LIBS)
\$(S_MAIN): \$(BUILD_USER_LIBS) \${TRICK_STATIC_LIB} \$(SIM_LIB) \$(S_OBJECT_FILES) \$(SIM_LIBS)
\t\$(TRICK_LD) \$(TRICK_LDFLAGS) -o \$@ \\
\t\t\$(S_OBJECT_FILES)\\
\t\t\$(LD_WHOLE_ARCHIVE) \$(LIB_DIR)/lib_${sim_dir_name}.a \$(LD_NO_WHOLE_ARCHIVE)\\
\t\t\$(LD_WHOLE_ARCHIVE) \$(SIM_LIB) \$(LD_NO_WHOLE_ARCHIVE)\\
\t\t\${BUILD_USER_LIBS} \${TRICK_USER_LINK_LIBS} \${READ_ONLY_LIBS} \\
\t\t\$(LD_WHOLE_ARCHIVE) \$(SIM_LIBS) \${TRICK_LIBS} \$(LD_NO_WHOLE_ARCHIVE)\\
\t\t\$(HDF5_LIB) \${TRICK_EXEC_LINK_LIBS}" ;
@ -583,46 +379,33 @@ build_user_lib : \$(BUILD_USER_OBJ_DIRS) \$(BUILD_USER_LIBS)
print MAKEFILE "\
\$(S_MAIN): \$(BUILD_USER_LIBS) \${TRICK_STATIC_LIB} \$(S_OBJECT_FILES) \$(SIM_LIBS)
\t\$(TRICK_LD) \$(TRICK_LDFLAGS) -o \$@ \\
\t\t\$(OBJECT_DIR)/*.o\\
\t\tbuild/*.o\\
\t\t\${BUILD_USER_LIBS} \${TRICK_USER_LINK_LIBS} \${READ_ONLY_LIBS} \\
\t\t\$(LD_WHOLE_ARCHIVE) \$(SIM_LIBS) \${TRICK_LIBS} \$(LD_NO_WHOLE_ARCHIVE)\\
\t\t\$(HDF5_LIB) \${TRICK_EXEC_LINK_LIBS}" ;
}
print MAKEFILE "\n
\$(OBJECTS) \$(IO_OBJECTS) : | \$(LIB_DIR) \$(OBJECT_DIR)
\$(OBJECTS) : | \$(LIB_DIR)
\$(LIB_DIR) :
\t@ mkdir -p \$@
" ;
print MAKEFILE "
\$(OBJECT_DIR)/S_source.o: S_source.cpp | \$(OBJECT_DIR)
\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c S_source.cpp -o \$(OBJECT_DIR)/S_source.o
\t\@\${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs S_source.cpp
build/S_source.o: S_source.cpp
\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \$\< -o \$\@
#\t\@\${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs S_source.cpp
\$(OBJECT_DIR)/class_map.o: \$(CURDIR)/io_src/class_map.cpp | \$(OBJECT_DIR)
\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \$(CURDIR)/io_src/class_map.cpp -o \$(OBJECT_DIR)/class_map.o
\t\@\${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs class_map.cpp
-include build/S_source.dep
\$(OBJECT_DIR)/enum_map.o: \$(CURDIR)/io_src/enum_map.cpp | \$(OBJECT_DIR)
\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \$(CURDIR)/io_src/enum_map.cpp -o \$(OBJECT_DIR)/enum_map.o
\t\@\${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs enum_map.cpp
-include \$(OBJECT_DIR)/S_source.dep
-include \$(OBJECT_DIR)/class_map.dep
-include \$(OBJECT_DIR)/enum_map.dep
\$(OBJECT_DIR)/S_define.deps: | \$(OBJECT_DIR)
\t\$(TRICK_CPPC) \$(TRICK_SFLAGS) -M -MT Makefile_sim -MF \$(OBJECT_DIR)/S_define.deps -x c++ S_define
#\$(OBJECT_DIR):
#\t@ mkdir -p \$@
build/S_define.deps:
\t\$(TRICK_CPPC) \$(TRICK_SFLAGS) -M -MT Makefile_sim -MF build/S_define.deps -x c++ S_define
" ;
print MAKEFILE "
S_source.cpp S_default.dat: S_define
\t\$(PERL) \${TRICK_HOME}/bin/CP -s -d
\t\$(PERL) \${TRICK_HOME}/bin/trick-CP -s -d
sie: S_sie.resource
@ -631,254 +414,26 @@ S_sie.resource: \$(S_MAIN)
\t\$(S_MAIN) sie
S_define_exp:
\t\$(TRICK_CC) -E -C -xc++ \${TRICK_SFLAGS} S_define > \$@
help:
\t@ echo -e \"\\n\\
Simulation make options:\\n\\
make - Makes everything: S_main, S_sie.resource,\\n\\
\\t\\t\\tand S_default.dat\\n\\
make S_sie.resource - Rebuilds the S_sie.resource file.\\n\\
make S_source.cpp - Rebuilds the S_source.cpp file.\\n\\
make clean - Removes all auto-generated files in\\n\\
\\t\\t\\tsimulation directory\\n\\
make clean_model_io_src - Removes all io_src code in the model directories\\n\\
make clean_model_io_obj - Removes all io_obj code in the model directories\\n\\
make clean_obj - Removes all object code in the model directories\\n\\
make depend - Performs make_depend for the entire simulation\\n\\
make real_clean - Does a make clean and clean_obj and removes\\n\\
\\t\\t\\tall io_src files, flex/bison files and \\n\\
\\t\\t\\tTrick built libraries \\n\\
make spotless - Does everthing in real_clean and\\n\\
\\t\\t\\tremoves all S_mains and lib directories\\n\"
tidy:
\t-rm -rf \$(LIB_DIR) Default_data
\t-rm -rf lib
\t-rm -f S_default.dat S_document.xml S_main_\${TRICK_HOST_CPU}.exe
\t-rm -f S_rif_\${TRICK_HOST_CPU}.exe S_sie.resource S_sie_*.xml S_structures
\t-rm -f DP_Product/DP_rt_frame DP_Product/DP_rt_itimer
\t-rm -f DP_Product/DP_rt_jobs DP_Product/DP_rt_timeline DP_Product/DP_mem_stats
\t-rm -f $$sim_ref{args}{o}
\t-rm -f Makefile_sim MAKE_out S_library_* .S_library_* .icg_no_found
\t-rm -f S_source.cpp S_source.hh
\t-rm -rf io_src xml
\t-rm -rf lib_* object_* S_main* T_main* tags
clean: tidy clean_obj clean_model_io_src clean_lex_yacc_src
real_clean: clean
spotless: clean
\t@ echo \"Removed all S_mains\"\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ($files_by_dir{$k}{"writable"}) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t-cd $k ; rm -rf xml io_src object_*\n" ;
}
}
}
print MAKEFILE "\t@ echo \"Removed all xml and io_src dirs\"
clean_obj: clean_model_c_obj clean_model_cpp_obj clean_model_io_obj clean_lex_yacc_obj
" ;
# write out the clean rules
print MAKEFILE "\nclean_model_c_obj:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{c}} ne -1 ) and $files_by_dir{$k}{"writable"} eq 1 ) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\trm -f \$(MODEL_C_OBJ_$files_by_dir{$k}{dir_num})\n" ;
if ( exists $files_by_dir{$k}{full_name} ) {
print MAKEFILE "\trm -f $files_by_dir{$k}{full_name}\n" ;
}
}
}
}
print MAKEFILE "\t@ echo \"Model c_obj files have been removed\"\n" ;
print MAKEFILE "\nclean_model_cpp_obj:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{cpp}} ne -1 ) and $files_by_dir{$k}{"writable"} eq 1 ) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t@ rm -f \$(MODEL_CPP_OBJ_$files_by_dir{$k}{dir_num})\n" ;
if ( exists $files_by_dir{$k}{full_name} ) {
print MAKEFILE "\t@ rm -f $files_by_dir{$k}{full_name}\n" ;
}
}
}
}
print MAKEFILE "\t@ echo \"Model cpp_obj files have been removed\"\n" ;
print MAKEFILE "\nclean_model_io_src:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{h}} ne -1 ) and $files_by_dir{$k}{"writable"}) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t@ rm -f \$(MODEL_IO_SRC_$files_by_dir{$k}{dir_num})\n" ;
}
}
}
print MAKEFILE "\t@ echo \"Model io_src files have been removed\"\n" ;
print MAKEFILE "\nclean_model_io_obj:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{h}} ne -1 ) and $files_by_dir{$k}{"writable"}) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t@ rm -f \$(MODEL_IO_OBJ_$files_by_dir{$k}{dir_num})\n" ;
}
}
}
print MAKEFILE "\t@ echo \"Model io_obj files have been removed\"\n" ;
print MAKEFILE "\nclean_lex_yacc_obj:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{y}} ne -1 ) and $files_by_dir{$k}{"writable"}) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t@ rm -f \$(MODEL_YACC_OBJ_$files_by_dir{$k}{dir_num})\n" ;
}
}
}
print MAKEFILE "\t@ echo \"Model lex/yacc obj files have been removed\"\n" ;
print MAKEFILE "\nclean_lex_yacc_src:\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ( ($#{$files_by_dir{$k}{y}} ne -1 ) and $files_by_dir{$k}{"writable"}) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
print MAKEFILE "\t@ rm -f \$(MODEL_LEX_SRC_$files_by_dir{$k}{dir_num})\n" ;
print MAKEFILE "\t@ rm -f \$(MODEL_YACC_SRC_$files_by_dir{$k}{dir_num})\n" ;
}
}
}
print MAKEFILE "\t@ echo \"Model lex/yacc src files have been removed\"\n" ;
my $num_src_dirs = 0 ;
foreach $k ( keys %files_by_dir ) {
$num_src_dirs++ if ( ! exists $$sim_ref{dir_src_only}{$k} ) ;
}
print MAKEFILE "\nlib_\${TRICK_HOST_CPU}/libtrick.so:\n" ;
print MAKEFILE "\tln -s -f \$(TRICK_LIB_DIR)/libtrick.so lib_\${TRICK_HOST_CPU}/libtrick.so\n" ;
#print MAKEFILE "\nlib_\${TRICK_HOST_CPU}/libhdf5.so:\n" ;
#print MAKEFILE "\tln -s -f \$(TRICK_LIB_DIR)/libhdf5.so lib_\${TRICK_HOST_CPU}/libhdf5.so\n" ;
\t\$(TRICK_CC) -E -C -xc++ \${TRICK_SFLAGS} S_define > \$@\n\n" ;
# write out the the rules to make the libraries
print MAKEFILE "\n#LIBS\n\n" ;
print MAKEFILE "\$(LIB_DIR)/lib_${sim_dir_name}.a : \$(OBJECTS) \$(IO_OBJECTS) \$(DEFAULT_DATA_OBJECTS)\n" ;
print MAKEFILE "\$(SIM_LIB) : \$(OBJECTS) \$(DEFAULT_DATA_OBJECTS)\n" ;
print MAKEFILE "\t@ echo \"Creating libraries...\"\n" ;
print MAKEFILE "\t\@ rm -rf \$\@\n" ;
print MAKEFILE "\tar crs \$\@ \$(LIB_DIR)/*.o || touch \$\@\n\n" ;
# print out the sim directory libraries
foreach my $l ( @{$$sim_ref{sim_libraries}} ) {
my $lib_name = $l ;
$lib_name =~ s/.*SIM_// ;
print MAKEFILE "\nlib_\${TRICK_HOST_CPU}/lib_${lib_name}.a: $l/lib_\${TRICK_HOST_CPU}/lib_${lib_name}.a\n" ;
print MAKEFILE "\tln -s -f $l/lib_\${TRICK_HOST_CPU}/lib_${lib_name}.a lib_\${TRICK_HOST_CPU}/lib_${lib_name}.a\n" ;
print MAKEFILE "$l/lib_\${TRICK_HOST_CPU}/lib_${lib_name}.a: $l/lib_\${TRICK_HOST_CPU}\n" ;
print MAKEFILE "\t@ echo \"\033[31mSIM lib $l not compiled... touching empty \$@\033[0m\"\n" ;
print MAKEFILE "\t@ touch \$@\n" ;
print MAKEFILE "$l/lib_\${TRICK_HOST_CPU}:\n" ;
print MAKEFILE "\t@ mkdir -p \$\@\n" ;
}
print MAKEFILE "\napocalypse: spotless\n" ;
foreach my $l ( @{$$sim_ref{sim_libraries}} ) {
print MAKEFILE "\t- \$(MAKE) -C $l spotless\n" ;
}
print MAKEFILE "\t\@echo \"\033[31mI love the smell of napalm in the morning\033[0m\"\n" ;
print MAKEFILE "\n" ;
# write out the rules to link objects to lib_${TRICK_HOST_CPU}
$m = 0 ;
foreach $k ( sort keys %files_by_dir ) {
next if ( $k =~ /\/io_src/ ) ;
if ( ! exists $files_by_dir{$k}{full_name} ) {
@temp_array = () ;
push @temp_array , @{$files_by_dir{$k}{c}} , @{$files_by_dir{$k}{cpp}} ,
@{$files_by_dir{$k}{f}} , @{$files_by_dir{$k}{y}} ;
foreach $n ( sort @temp_array ) {
print MAKEFILE "\$(LIB_DIR)/o$m.o : $k/object_\${TRICK_HOST_CPU}/${n}o\n" ;
print MAKEFILE "\tln -f -s $k/object_\${TRICK_HOST_CPU}/${n}o \$@\n" ;
$m++;
}
}
}
# write out the rules to link io_objects to lib_${TRICK_HOST_CPU}
$m = 0;
foreach $k ( sort keys %files_by_dir ) {
if ( ! exists $files_by_dir{$k}{full_name} ) {
foreach $n ( @{$files_by_dir{$k}{h}} ) {
next if ( $n =~ /S_source./ ) ;
print MAKEFILE "\$(LIB_DIR)/i$m.o : $k/object_\${TRICK_HOST_CPU}/io_${n}o\n" ;
print MAKEFILE "\tln -f -s $k/object_\${TRICK_HOST_CPU}/io_${n}o \$@\n" ;
$m++;
}
}
}
print MAKEFILE "\n#MODEL_OBJ_DIRS\n\n" ;
foreach $k ( sort keys %files_by_dir ) {
if ($files_by_dir{$k}{"writable"}) {
print MAKEFILE "$k/object_\${TRICK_HOST_CPU} :\n" ;
print MAKEFILE "\t@ mkdir -p \$\@\n" ;
}
}
$m = 0;
foreach $k ( sort keys %files_by_dir ) {
if ( ! exists $files_by_dir{$k}{full_name} ) {
foreach $n ( @{$files_by_dir{$k}{h}} ) {
print MAKEFILE "lib/i$m.o: $k/object_\${TRICK_HOST_CPU}/io_$n" , "o\n" ;
print MAKEFILE "\tln -f -s \$? \$\@\n" ;
$m++;
}
}
}
# write out the rules to compile a directory
print MAKEFILE "\n\nmodel_objects :" ;
foreach $k ( sort keys %files_by_dir ) {
print MAKEFILE " \\\n\tmodel_obj_$files_by_dir{$k}{dir_num}" ;
}
foreach $k ( sort keys %files_by_dir ) {
print MAKEFILE "\n\nmodel_obj_$files_by_dir{$k}{dir_num} :" ;
foreach ( "c" , "cpp" , "f" , "h" , "y" ) {
if ( $#{$files_by_dir{$k}{$_}} ne -1 ) {
print MAKEFILE " model_$_" . "_obj_$files_by_dir{$k}{dir_num}" ;
}
}
}
foreach $k ( sort keys %files_by_dir ) {
foreach ( "c" , "cpp" , "f" , "y" ) {
if ( $#{$files_by_dir{$k}{$_}} ne -1 ) {
print MAKEFILE "\n\nmodel_$_" . "_obj_$files_by_dir{$k}{dir_num} :" ;
foreach $f ( @{$files_by_dir{$k}{$_}} ) {
print MAKEFILE " \\\n\t$k/object_\$\{TRICK_HOST_CPU\}/$f" . "o" ;
foreach my $ext ( qw{ c C cc cxx cpp c++ y l } ) {
if ( scalar @{$files_by_dir{$k}{$ext}} ne 0 ) {
foreach $f ( @{$files_by_dir{$k}{$ext}} ) {
print MAKEFILE "\$(LIB_DIR)/o$m.o : build$k/$files_by_dir{$k}{src_dir}${f}o\n" ;
print MAKEFILE "\tln -f -s ../\$< \$@\n" ;
$m++;
}
}
}
if ( $#{$files_by_dir{$k}{h}} ne -1 ) {
print MAKEFILE "\n\nmodel_h_obj_$files_by_dir{$k}{dir_num} :" ;
foreach $f ( @{$files_by_dir{$k}{h}} ) {
print MAKEFILE " \\\n\t$k/object_\$\{TRICK_HOST_CPU\}/io_$f" . "o" ;
}
}
}
# write out the rules to compile each individual file
foreach $k ( sort keys %files_by_dir ) {
if ( ! exists $$sim_ref{dir_src_only}{$k} ) {
write_rules($k , \%{$files_by_dir{$k}}, $sim_ref, \%real_extension_h, \%real_extension_cpp ) ;
}
}
print MAKEFILE "\n\n#DEFAULT_DATA_C_OBJ\n\n" ;
@ -903,29 +458,25 @@ clean_obj: clean_model_c_obj clean_model_cpp_obj clean_model_io_obj clean_lex_ya
}
}
print MAKEFILE "\n-include Makefile_io_src\n" ;
print MAKEFILE "\ninclude Makefile_swig\n" ;
print MAKEFILE "\n-include S_overrides.mk\n" ;
close MAKEFILE ;
if ( ! -e "build" ) {
mkdir "build", 0775 ;
}
# write out all of the files we used to S_library_list
open LIB_LIST, ">S_library_list" or die "Could not open S_library_list" ;
open LIB_LIST, ">build/S_library_list" or die "Could not open build/S_library_list" ;
foreach $k ( sort keys %files_by_dir ) {
foreach (@{$files_by_dir{$k}{h}}) {
my $path = $k ;
$path .= "/include" if ( -e "$k/include" ) ;
my $ext = $real_extension_h{"$path/$_"} ;
push @temp_array , "$k/$files_by_dir{$k}{include_dir}$_" . "$ext" ;
}
foreach (@{$files_by_dir{$k}{c}}) {
push @temp_array , "$k/$files_by_dir{$k}{src_dir}$_" . "c" ;
}
foreach (@{$files_by_dir{$k}{cpp}}) {
my $ext = $real_extension_cpp{"$k/$files_by_dir{$k}{src_dir}$_"} ;
push @temp_array , "$k/$files_by_dir{$k}{src_dir}$_" . "$ext" ;
}
foreach (@{$files_by_dir{$k}{f}}) {
push @temp_array , "$k/$files_by_dir{$k}{src_dir}$_" . "f" ;
foreach my $ext ( qw{ c C cc cxx cpp c++ y l } ) {
if ( scalar @{$files_by_dir{$k}{$ext}} ne 0 ) {
foreach $f ( @{$files_by_dir{$k}{$ext}} ) {
push @temp_array, "$k/$files_by_dir{$k}{src_dir}$f$ext" ;
}
}
}
}
@temp_array = sort @temp_array;
@ -947,100 +498,4 @@ clean_obj: clean_model_c_obj clean_model_cpp_obj clean_model_io_obj clean_lex_ya
return ;
}
sub write_rules ($$$$) {
my ($k , $dir_info_ref, $sim_ref, $re_h_ref, $re_cpp_ref ) = @_ ;
my (%dir_info) = %$dir_info_ref ;
my ($n ) ;
# This block of code is pretty similar. Each part writes out the individual compile line
# for a source file
print MAKEFILE "\n\n#MODEL_C_OBJ_$dir_info{dir_num}\n\n" ;
foreach $n ( @{$dir_info{c}} ) {
print MAKEFILE "$k/object_\${TRICK_HOST_CPU}/$n" . "o : $k/$dir_info{src_dir}$n" . "c\n" ;
if ( $dir_info{writable} ) {
print MAKEFILE "\tcd $k/$dir_info{src_dir} ; \$(TRICK_CC) \$(TRICK_CFLAGS) -MMD -MP -c \${\@F:.o=.c} -o \$\@\n" ;
print MAKEFILE "\t\@cd $k/$dir_info{src_dir} ; \${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs ${n}c\n" ;
print MAKEFILE "-include $k/object_\${TRICK_HOST_CPU}/${n}dep\n" ;
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
}
print MAKEFILE "\n\n#MODEL_CPP_OBJ_$dir_info{dir_num}\n\n" ;
foreach $n ( @{$dir_info{cpp}} ) {
my $ext = $$re_cpp_ref{"$k/$dir_info{src_dir}$n"} ;
print MAKEFILE "$k/object_\${TRICK_HOST_CPU}/$n" . "o : $k/$dir_info{src_dir}$n$ext\n" ;
if ( $dir_info{writable} ) {
#print MAKEFILE "\t\@echo \"Compiling $k/$dir_info{src_dir}\${\@F:.o=.$ext}\"\n" ;
print MAKEFILE "\tcd $k/$dir_info{src_dir} ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) -MMD -MP -c \${\@F:.o=.$ext} -o \$\@\n" ;
print MAKEFILE "\t\@cd $k/$dir_info{src_dir} ; \${TRICK_HOME}/\$(LIBEXEC)/trick/depend_objs $n$ext\n" ;
print MAKEFILE "\n-include $k/object_\${TRICK_HOST_CPU}/${n}dep\n\n" ;
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
}
print MAKEFILE "\n\n#MODEL_LEX_YACC_OBJ_$dir_info{dir_num}\n\n" ;
foreach $n ( @{$dir_info{y}} ) {
print MAKEFILE "$k/$dir_info{src_dir}$n" . "clex : $k/$dir_info{src_dir}$n" . "l\n" ;
if ( $dir_info{writable} ) {
print MAKEFILE "\t\$(LEX) -o\$\@ \$\?\n\n"
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
print MAKEFILE "$k/$dir_info{src_dir}$n" . "c : $k/$dir_info{src_dir}$n" . "y\n" ;
if ( $dir_info{writable} ) {
print MAKEFILE "\t\$(YACC) -o\$\@ \$\?\n\n"
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
print MAKEFILE "$k/object_\${TRICK_HOST_CPU}/$n" . "o : $k/$dir_info{src_dir}$n" .
"c $k/$dir_info{src_dir}$n" . "clex\n" ;
if ( $dir_info{writable} ) {
print MAKEFILE "\tcd $k/$dir_info{src_dir} ; \$(TRICK_CC) \$(TRICK_CFLAGS) -c \${\@F:.o=.c} -o \$\@\n\n"
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
}
print MAKEFILE "\n\n#MODEL_IO_OBJ_$dir_info{dir_num}\n\n" ;
foreach $n ( @{$dir_info{h}} ) {
my $full_name = "$k/$dir_info{include_dir}${n}h" ;
my $path = $k ;
$path .= "/include" if ( -e "$k/include" ) ;
my $ext = $$re_h_ref{"$path/$n"} ;
my $extension = "cpp" ;
print MAKEFILE "$k/object_\${TRICK_HOST_CPU}/io_$n" . "o : $k/io_src/io_$n$extension\n";
if ( $dir_info{writable} ) {
print MAKEFILE "\tcd $k ; \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_IO_CXXFLAGS) -c $k/io_src/\${\@F:.o=.$extension} -o \$\@\n\n" ;
}
else {
print MAKEFILE "\t@ echo \"\$\@ is out of date and is in a read-only directory... aborting\"\n" ;
print MAKEFILE "\t@ exit 1\n" ;
}
}
# if this directory is to be a library, addd a rule to make it.
if ( exists $dir_info{full_name} ) {
print MAKEFILE "$dir_info{full_name} : \${MODEL_C_OBJ_$dir_info{dir_num}} \${MODEL_CPP_OBJ_$dir_info{dir_num}} " ,
"\${MODEL_YACC_OBJ_$dir_info{dir_num}} " , "\${MODEL_IO_OBJ_$dir_info{dir_num}}\n" ;
print MAKEFILE "\tar crs \$\@ \$?
\t@ if [ \"\${TRICK_RANLIB}\" != \"\" ] ; then \\
\t echo \${TRICK_RANLIB} $dir_info{full_name} ; \\
\t \${TRICK_RANLIB} $dir_info{full_name} ; \\
\t fi\n\n" ;
}
}
1;

View File

@ -37,8 +37,8 @@ sub make_swig_makefile($$$) {
my ($swig_module_i, $swig_module_source, $py_wrappers) ;
my $s_source_full_path = abs_path("S_source.hh") ;
my $s_source_md5 = md5_hex($s_source_full_path) ;
my $s_library_swig = ".S_library_swig" ;
my $s_library_swig_ext = ".S_library_swig_ext" ;
my $s_library_swig = "build/.S_library_swig" ;
my $s_library_swig_ext = "build/.S_library_swig_ext" ;
($version, $thread) = get_trick_version() ;
($year) = $version =~ /^(\d+)/ ;
@ -134,7 +134,7 @@ sub make_swig_makefile($$$) {
mkdir $swig_sim_dir, 0775 ;
}
$swig_src_dir = abs_path("swig") ;
$swig_src_dir = abs_path("build") ;
if ( ! -e $swig_src_dir ) {
mkdir $swig_src_dir, 0775 ;
@ -237,23 +237,20 @@ sub make_swig_makefile($$$) {
next if ( $continue == 0 ) ;
if ( ! exists $$sim_ref{sim_lib_swig_files}{@temp_array2[$ii]} ) {
if ( @temp_array2[$ii] !~ /S_source/ ) {
print MAKEFILE "\\\n\t\$(LIB_DIR)/p${ii}.o" ;
}
print MAKEFILE "\\\n\t\$(LIB_DIR)/p${ii}.o" ;
}
}
print MAKEFILE "\n\n" ;
print MAKEFILE "SIM_SWIG_OBJECTS = \\\n" ;
print MAKEFILE "\t\$(OBJECT_DIR)/init_swig_modules.o\\\n" ;
print MAKEFILE "\t\$(OBJECT_DIR)/py_S_source.o\\\n" ;
print MAKEFILE "\t\$(OBJECT_DIR)/py_top.o\n" ;
print MAKEFILE " $swig_src_dir/init_swig_modules.o\\\n" ;
print MAKEFILE " $swig_src_dir/py_top.o\n" ;
print MAKEFILE "S_OBJECT_FILES += \$(SIM_SWIG_OBJECTS)\n\n" ;
print MAKEFILE "ALL_SWIG_OBJECTS = \\\n" ;
print MAKEFILE "\t\$(SWIG_MODULE_OBJECTS)\\\n" ;
print MAKEFILE "\t\$(SIM_SWIG_OBJECTS)\n\n" ;
print MAKEFILE "\$(ALL_SWIG_OBJECTS) : | \$(LIB_DIR) \$(OBJECT_DIR)\n\n" ;
print MAKEFILE "\$(ALL_SWIG_OBJECTS) : | \$(LIB_DIR)\n\n" ;
print MAKEFILE "# SWIG_PY_OBJECTS is a convienince list to modify rules for compilation\n" ;
print MAKEFILE "SWIG_PY_OBJECTS =" ;
@ -271,11 +268,9 @@ sub make_swig_makefile($$$) {
my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ;
my ($swig_f) = $f ;
$swig_f =~ s/(?:include\/)?([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx)$/swig\/$1/ ;
$swig_dir = dirname($swig_f) ;
($swig_object_dir = $swig_dir) =~ s/swig$/object_\${TRICK_HOST_CPU}/ ;
$swig_file_only = basename($swig_f) ;
print MAKEFILE" \\\n\t$swig_object_dir/py_${swig_file_only}.o" ;
$swig_object_dir = dirname($f) ;
($swig_file_only) = ($f =~ /([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx)$/) ;
print MAKEFILE" \\\n\tbuild$swig_object_dir/py_${swig_file_only}.o" ;
}
print MAKEFILE"\n\n" ;
@ -321,38 +316,26 @@ sub make_swig_makefile($$$) {
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/(?:include\/)?([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx)$/swig\/$1.i/ ;
$swig_f =~ s/([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx)$/$1.i/ ;
$swig_file_only = $1 ;
$swig_f = "build" . $swig_f ;
$swig_dir = dirname($swig_f) ;
($swig_object_dir = $swig_dir) =~ s/swig$/object_\${TRICK_HOST_CPU}/ ;
$swig_file_only = basename($swig_f) ;
$swig_file_only =~ s/\.i$// ;
$swig_object_dir = dirname($swig_f) ;
$swig_dirs{$swig_dir} = 1 ;
$swig_module_i .= "\\\n $swig_f" ;
$swig_module_source .= "\\\n $swig_dir/py_${swig_file_only}.cpp\\\n $swig_dir/m${md5_sum}.py" ;
$py_wrappers .= " \\\n $swig_sim_dir/${swig_module_dir}m${md5_sum}.py" ;
if ( ! exists $$sim_ref{sim_lib_swig_files}{$f} ) {
print MAKEFILE "$swig_object_dir/py_${swig_file_only}.o : $swig_f\n" ;
print MAKEFILE "\t\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir $swig_dir -o $swig_dir/py_${swig_file_only}.cpp $swig_f\n" ;
print MAKEFILE "\t\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir trick -o $swig_dir/py_${swig_file_only}.cpp \$<\n" ;
print MAKEFILE "\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_IO_CXXFLAGS) \$(SWIG_CFLAGS) -c $swig_dir/py_${swig_file_only}.cpp -o \$@\n\n" ;
if ( @temp_array2[$ii] !~ /S_source/ ) {
print MAKEFILE "\$(LIB_DIR)/p${ii}.o : $swig_object_dir/py_${swig_file_only}.o\n" ;
print MAKEFILE "\tln -s -f \$< \$@\n\n" ;
}
print MAKEFILE "\$(LIB_DIR)/p${ii}.o : $swig_object_dir/py_${swig_file_only}.o\n" ;
print MAKEFILE "\tln -s -f ../\$< \$@\n\n" ;
}
if ( $swig_module_dir ne "" ) {
print MAKEFILE "$swig_sim_dir/${swig_module_dir}m${md5_sum}.py : | $swig_sim_dir/$swig_module_dir\n" ;
}
if ( ! exists $$sim_ref{sim_lib_swig_files}{$f} ) {
print MAKEFILE "$swig_sim_dir/${swig_module_dir}m${md5_sum}.py : | $swig_object_dir/py_${swig_file_only}.o\n" ;
} else {
print MAKEFILE "$swig_sim_dir/${swig_module_dir}m${md5_sum}.py :\n" ;
}
print MAKEFILE "\t/bin/cp $swig_dir/m${md5_sum}.py \$@\n\n" ;
$ii++ ;
}
@ -371,51 +354,33 @@ sub make_swig_makefile($$$) {
$sim_dir_name =~ s/SIM_// ;
print MAKEFILE "
SWIG_SRC_FILES = \$(addprefix $swig_src_dir/,\$(notdir \$(subst .o,.cpp,\$(ALL_SWIG_OBJECTS))))
#SWIG_MODULE_SRC_FILES = \$(filter p%,\$(SWIG_SRC_FILES))
\$(ALL_SWIG_OBJECTS) : TRICK_CXXFLAGS += -Wno-unused-parameter -Wno-redundant-decls
\$(SWIG_SRC_FILES): | $swig_src_dir
.PHONY: swig_objects
\$(S_MAIN) : \$(OBJECT_DIR)/py_top.o \$(OBJECT_DIR)/init_swig_modules.o \$(OBJECT_DIR)/py_S_source.o\n
\$(LIB_DIR)/lib_${sim_dir_name}.a : \$(SWIG_MODULE_OBJECTS)
#\$(LIB_DIR)/lib_${sim_dir_name}.a : \$(SWIG_MODULE_SOURCE) \$(ALL_SWIG_OBJECTS)
#\$(LIB_DIR)/lib_${sim_dir_name}.so : \$(SWIG_MODULE_SOURCE) \$(ALL_SWIG_OBJECTS)\n\n" ;
\$(S_MAIN) : $swig_src_dir/py_top.o $swig_src_dir/init_swig_modules.o\n
\$(SIM_LIB): \$(SWIG_MODULE_OBJECTS)\n\n" ;
print MAKEFILE "$swig_src_dir/py_top.cpp : $swig_src_dir/top.i\n" ;
print MAKEFILE "\t\$(SWIG) \$(TRICK_INCLUDE) \$(TRICK_DEFINES) \$(TRICK_VERSIONS) -c++ -python -includeall -ignoremissing -w201,303,362,389,401,451 -outdir $swig_sim_dir -o \$@ $swig_src_dir/top.i\n\n" ;
print MAKEFILE "\t\$(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 "\$(OBJECT_DIR)/py_top.o : $swig_src_dir/py_top.cpp | \$(OBJECT_DIR)\n" ;
print MAKEFILE "$swig_src_dir/py_top.o : $swig_src_dir/py_top.cpp\n" ;
print MAKEFILE "\t\$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(SWIG_CFLAGS) -c \$< -o \$@\n\n" ;
print MAKEFILE "\$(OBJECT_DIR)/init_swig_modules.o : $swig_src_dir/init_swig_modules.cpp | \$(OBJECT_DIR)\n" ;
print MAKEFILE "$swig_src_dir/init_swig_modules.o : $swig_src_dir/init_swig_modules.cpp\n" ;
print MAKEFILE "\t\$(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" ;
print MAKEFILE "S_main: \$(TRICK_FIXED_PYTHON) \$(PY_WRAPPERS)\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 "$swig_sim_dir/sim_services.py : \${TRICK_HOME}/share/trick/swig/sim_services.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/swig_double.py : \${TRICK_HOME}/share/trick/swig/swig_double.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/swig_int.py : \${TRICK_HOME}/share/trick/swig/swig_int.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/swig_ref.py : \${TRICK_HOME}/share/trick/swig/swig_ref.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/shortcuts.py : \${TRICK_HOME}/share/trick/swig/shortcuts.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/exception.py : \${TRICK_HOME}/share/trick/swig/exception.py\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
print MAKEFILE "$swig_sim_dir/unit_test.py : \${TRICK_HOME}/share/trick/swig/unit_test.py\n" ;
print MAKEFILE "\$(TRICK_FIXED_PYTHON) : $swig_sim_dir/\% : \${TRICK_HOME}/share/trick/swig/\%\n" ;
print MAKEFILE "\t/bin/cp \$< \$@\n\n" ;
foreach (keys %swig_dirs) {
@ -423,19 +388,6 @@ SWIG_SRC_FILES = \$(addprefix $swig_src_dir/,\$(notdir \$(subst .o,.cpp,\$(ALL_S
print MAKEFILE "\tmkdir -p $_\n\n" ;
}
print MAKEFILE "
tidy: tidy_swig
tidy_swig:
\t -rm -rf Makefile_swig $swig_src_dir trick $s_library_swig
clean: clean_swig
clean_swig:\n" ;
foreach (keys %swig_dirs) {
print MAKEFILE "\t-rm -rf $_\n" ;
}
print MAKEFILE "\n" ;
close MAKEFILE ;
@ -456,7 +408,7 @@ clean_swig:\n" ;
}
print TOPFILE "\n\%}\n\n" ;
print TOPFILE "\%import \"S_source.i\"\n\n" ;
print TOPFILE "\%import \"build$wd/S_source.i\"\n\n" ;
foreach my $inst ( @{$$sim_ref{instances}} ) {
print TOPFILE "$$sim_ref{instances_type}{$inst} $inst ;\n" ;
}

View File

@ -12,17 +12,20 @@ ifeq ($(MAKECMDGOALS), debug)
TRICK_CPFLAGS += --debug
endif
all : ${TRICK_LIB_DIR}/libtrick.a Makefile_sim
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt MAKE_out
@$(MAKE) --no-print-directory -f Makefile_sim ICG 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim convert_swig 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim all 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
all : ${TRICK_LIB_DIR}/libtrick.a Makefile_sim build
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt build/MAKE_out
@$(MAKE) --no-print-directory -f Makefile_sim ICG 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim convert_swig 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
test : ${TRICK_LIB_DIR}/libtrick.a Makefile_sim
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt MAKE_out
@$(MAKE) --no-print-directory -f Makefile_sim ICG 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim convert_swig 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim test_all 2>&1 | tee -a MAKE_out ; exit $${PIPESTATUS[0]}
test : ${TRICK_LIB_DIR}/libtrick.a Makefile_sim build
@/bin/cp ${TRICK_HOME}/share/trick/MAKE_out_header.txt build/MAKE_out
@$(MAKE) --no-print-directory -f Makefile_sim ICG 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim convert_swig 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
@$(MAKE) --no-print-directory -f Makefile_sim test_all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]}
build:
mkdir $@
debug : all
@ -37,9 +40,44 @@ Makefile_sim: S_define
model_dirs:
@${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor -z
tidy clean real_clean spotless apocalypse sie ICG force_ICG help convert_swig S_define_exp:
sie ICG force_ICG convert_swig S_define_exp:
@if [ -f Makefile_sim ] ; then $(MAKE) --no-print-directory -f Makefile_sim $@ ; else echo "No Makefile_sim found" ; fi
# Dependencies to other files that may cause a re-CP
-include object_${TRICK_HOST_CPU}/S_define.deps
help:
@ echo -e "\n\
Simulation make options:\n\
make - Makes everything: S_main, S_sie.resource,\n\
\t\t\tand S_default.dat\n\
make S_sie.resource - Rebuilds the S_sie.resource file.\n\
make S_source.cpp - Rebuilds the S_source.cpp file.\n\
make clean - Removes all auto-generated files in\n\
\t\t\tsimulation directory\n\
make real_clean - Performs a clean\n\
make spotless - Performs a clean\n\
make apocalypse - Performs a clean"
tidy:
-rm -rf Default_data S_default.dat
-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.cpp S_source.hh
-rm -rf lib_* S_main* T_main*
-rm -f Makefile_sim
-rm -f Makefile_io_src
-rm -f Makefile_swig
clean: tidy
rm -rf build
-rm -rf trick
@ echo "Removed build directory"
real_clean spotless: clean
apocalypse: clean
@echo "I love the smell of napalm in the morning"
# Dependencies to other files that may cause a re-CP
-include build/S_define.deps

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <limits.h>
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Basic/FileManager.h"
@ -62,6 +63,36 @@ bool PrintAttributes::isIOFileOutOfDate(std::string header_file_name, std::strin
return true ;
}
static void _mkdir(const char *dir) {
char tmp[PATH_MAX];
char *p = NULL;
struct stat buf ;
size_t len;
snprintf(tmp, sizeof(tmp),"%s",dir);
len = strlen(tmp);
if(tmp[len - 1] == '/') {
tmp[len - 1] = 0;
}
for(p = tmp + 1; *p; p++)
if(*p == '/') {
*p = 0;
if ( stat( tmp , &buf ) != 0 ) {
if ( mkdir(tmp, S_IRWXU) != 0 ) {
std::cout << "Unable to create " << tmp << " for writing." << std::endl ;
return ;
}
}
*p = '/';
}
if ( stat( tmp , &buf ) != 0 ) {
if ( mkdir(tmp, S_IRWXU) ) {
std::cout << "Unable to create " << tmp << " for writing." << std::endl ;
return ;
}
}
}
bool PrintAttributes::doesIODirectoryExist(std::string io_file_name) {
// dirname alters the string so make a temporary copy of io_file_name
char * temp_name = strdup(io_file_name.c_str()) ;
@ -71,6 +102,8 @@ bool PrintAttributes::doesIODirectoryExist(std::string io_file_name) {
dir_name = dirname((char *)temp_name) ;
_mkdir(dir_name) ;
/*
if ( stat( dir_name , &buf ) != 0 ) {
if ( mkdir( dir_name , 0755 ) != 0 ) {
// dir does not exist and cannot make the directory.
@ -78,6 +111,7 @@ bool PrintAttributes::doesIODirectoryExist(std::string io_file_name) {
ret = false ;
}
}
*/
free(temp_name) ;
return ret ;
}
@ -122,18 +156,19 @@ bool PrintAttributes::openIOFile(std::string header_file_name) {
// hasICGNo uses original header name, not the real path
if ( ! cs.hasICGNo(header_file_name) ) {
std::string io_file_name = createIOFileName(std::string(rp)) ;
all_io_files[header_file_name] = io_file_name ;
// Does the io_src directory exist or can we successfully mkdir it?
if ( doesIODirectoryExist(io_file_name) ) {
// Is the io_src file out of date or does not exist yet
if ( isIOFileOutOfDate(rp, io_file_name) ) {
// All conditions have been met. Store the io_src file name in io_files.
io_files[header_file_name] = io_file_name ;
// All conditions have been met. Store the io_src file name in out_of_date_io_files.
out_of_date_io_files[header_file_name] = io_file_name ;
free(rp) ;
/* This is the first time we are visiting the file,
open the file and write header information */
outfile.open(io_files[header_file_name].c_str()) ;
outfile.open(out_of_date_io_files[header_file_name].c_str()) ;
printer->printIOHeader(outfile, header_file_name) ;
std::cout << "Writing " << io_files[header_file_name] << "" << std::endl ;
std::cout << "Writing " << out_of_date_io_files[header_file_name] << "" << std::endl ;
// Get all of the ignored types from this file.
ignored_types[header_file_name] = cs.getIgnoreTypes(header_file_name) ;
return true ;
@ -158,8 +193,8 @@ bool PrintAttributes::openIOFile(std::string header_file_name) {
}
} else {
/* We have visited this file before, if there is a valid io_file name, append to the io_file */
if ( io_files.find(header_file_name) != io_files.end() ) {
outfile.open(io_files[header_file_name].c_str(), std::fstream::app) ;
if ( out_of_date_io_files.find(header_file_name) != out_of_date_io_files.end() ) {
outfile.open(out_of_date_io_files[header_file_name].c_str(), std::fstream::app) ;
return true ;
}
}
@ -195,15 +230,22 @@ std::string PrintAttributes::createIOFileName(std::string header_file_name) {
dir_name.replace(dir_name.size() - 8 , dir_name.size() , "") ;
}
}
// 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
if ( ! output_dir.empty() ) {
io_file_name = output_dir + "/io_src/" + base_name ;
} else {
if ( sim_services_flag and (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 ;
// 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.find("er7_utils") == std::string::npos ) {
io_file_name = std::string(getenv("TRICK_HOME")) + "/trick_source/sim_services/include/io_src/" + base_name ;
} else {
io_file_name = dir_name + "/io_src/" + base_name ;
}
} else {
io_file_name = dir_name + "/io_src/" + base_name ;
//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 ;
}
}
return io_file_name ;
@ -281,7 +323,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 = "io_src" ;
map_dir = "build" ;
class_map_function_name = "populate_class_map" ;
enum_map_function_name = "populate_enum_map" ;
}
@ -308,7 +350,7 @@ void PrintAttributes::closeMapFiles() {
enum_map_outfile.close() ;
// If we wrote any new io_src files, move the temporary class and enum map files to new location
if ( io_files.size() > 0 ) {
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()) ;
} else {
@ -317,6 +359,79 @@ void PrintAttributes::closeMapFiles() {
}
}
//TODO: Move this into PrintFileContents10.
void PrintAttributes::printIOMakefile() {
std::ofstream makefile ;
unsigned int ii ;
// Don't create a makefile if we didn't process any files.
if ( out_of_date_io_files.empty() ) {
return ;
}
makefile.open("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" << std::endl ;
makefile << " endif" << std::endl ;
makefile << "endif" << std::endl ;
makefile << 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 " << (*mit).second.substr(0,found) << ".o" ;
}
}
makefile << " \\\n build/class_map.o" ;
makefile << " \\\n build/enum_map.o" ;
makefile << std::endl << std::endl ;
makefile << "IO_OBJECTS =" ;
for ( ii = 0 ; ii < visited_files.size() + 2 ; ii++ ) {
makefile << " \\\n $(LIB_DIR)/i" << ii << ".o" ;
}
makefile << std::endl << std::endl ;
for ( sit = visited_files.begin() , ii = 0 ; sit != visited_files.end() ; sit++ , ii++ ) {
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 << "$(LIB_DIR)/i" << ii << ".o : " << (*mit).second.substr(0,found) << ".o" << std::endl ;
makefile << "\tln -f -s ../$< $@" << std::endl ;
}
}
makefile << "$(LIB_DIR)/i" << ii++ << ".o : " << "build/class_map.o" << std::endl ;
makefile << "\tln -f -s ../$< $@" << std::endl ;
makefile << "$(LIB_DIR)/i" << ii << ".o : " << "build/enum_map.o" << std::endl ;
makefile << "\tln -f -s ../$< $@" << std::endl ;
makefile << "$(IO_OBJECTS) : | $(LIB_DIR)" << std::endl ;
makefile << std::endl ;
makefile << "$(IO_OBJ_FILES) : \%.o : \%.cpp" << std::endl ;
makefile << "\tcd $(<D) ; $(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_IO_CXXFLAGS) -MMD -MP -c ${<F} -o ${@F}" << std::endl ;
makefile << std::endl ;
makefile << "$(SIM_LIB) : $(IO_OBJECTS)" << std::endl ;
makefile << "$(IO_OBJECTS) : | $(LIB_DIR)" << std::endl ;
makefile << std::endl ;
makefile.close() ;
}
void PrintAttributes::printEmptyFiles() {
// this routine loops through all header files that were parsed and creates empty io_src files
// for the headers that have no classes or enums.
@ -340,15 +455,16 @@ void PrintAttributes::printEmptyFiles() {
// hasICGNo uses original header name, not the real path
if ( ! cs.hasICGNo(header_file_name) ) {
std::string io_file_name = createIOFileName(std::string(rp)) ;
all_io_files[header_file_name] = io_file_name ;
// Does the io_src directory exist or can we successfully mkdir it?
if ( doesIODirectoryExist(io_file_name) ) {
// Is the io_src file out of date or does not exist yet
if ( isIOFileOutOfDate(rp, io_file_name) ) {
io_files[header_file_name] = io_file_name ;
out_of_date_io_files[header_file_name] = io_file_name ;
// creates an empty io_src file
outfile.open(io_files[header_file_name].c_str()) ;
outfile.open(out_of_date_io_files[header_file_name].c_str()) ;
outfile.close() ;
std::cout << "Writing " << io_files[header_file_name] << "" << std::endl ;
std::cout << "Writing " << out_of_date_io_files[header_file_name] << "" << std::endl ;
}
} else {
std::cout << "ICG skipping " << rp << " (cannot create io_src dir)" << std::endl ;

View File

@ -42,6 +42,9 @@ class PrintAttributes {
virtual void createMapFiles() ;
virtual void closeMapFiles() ;
/** Create makefile for IO files */
virtual void printIOMakefile() ;
/** Create empty io_files for headers that contain no class/struct information */
virtual void printEmptyFiles() ;
@ -104,8 +107,11 @@ class PrintAttributes {
/** set of all visited files */
std::set< std::string > visited_files ;
/** map of open files to the io_src file */
std::map< std::string , std::string > io_files ;
/** map of all io_files we processed */
std::map< std::string , std::string > all_io_files ;
/** map of open files to the out of date io_src file */
std::map< std::string , std::string > out_of_date_io_files ;
/** List of files that have ICG: No */
std::vector< std::string > icg_no_files ;

View File

@ -189,6 +189,10 @@ int main( int argc , char * argv[] ) {
free(input_file_cp) ;
free(input_file_full_path) ;
if ( ! sim_services_flag ) {
pa.printIOMakefile() ;
}
// Print empty io_src files for headers that we visited, but have no class/struct information.
pa.printEmptyFiles() ;