From e1c1bbaccfab90a355fee2e6ab4c2383211a2cf7 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 16 Jul 2015 15:36:36 -0500 Subject: [PATCH 1/5] Split CP up into components that can be called individually Initial rough checkin that partially works for the ball sim. refs #86 --- bin/trick-CP | 2 +- libexec/trick/ICG_lib_deps_helper | 20 + libexec/trick/configuration_processor | 220 +-------- libexec/trick/make_makefile_src | 423 +++++++++++++++++ libexec/trick/make_makefile_swig | 429 ++++++++++++++++++ libexec/trick/pm/get_lib_deps.pm | 110 +++++ libexec/trick/pm/make_makefile.pm | 22 +- libexec/trick/pm/make_swig_makefile.pm | 27 +- libexec/trick/pm/mis_dep.pm | 19 + libexec/trick/pm/s_source.pm | 7 + share/trick/makefiles/Makefile.sim | 93 +++- .../Interface_Code_Gen/CommentSaver.cpp | 70 ++- .../Interface_Code_Gen/CommentSaver.hh | 7 + .../Interface_Code_Gen/PrintAttributes.cpp | 178 +++++--- .../Interface_Code_Gen/PrintAttributes.hh | 3 + .../PrintFileContents10.cpp | 13 +- .../codegen/Interface_Code_Gen/main.cpp | 1 + .../codegen/Interface_Code_Gen/makefile | 2 +- .../sim_services/MemoryManager/test/Makefile | 10 +- 19 files changed, 1320 insertions(+), 336 deletions(-) create mode 100755 libexec/trick/ICG_lib_deps_helper create mode 100755 libexec/trick/make_makefile_src create mode 100755 libexec/trick/make_makefile_swig create mode 100644 libexec/trick/pm/get_lib_deps.pm diff --git a/bin/trick-CP b/bin/trick-CP index 4ec948df..efdcce0b 100755 --- a/bin/trick-CP +++ b/bin/trick-CP @@ -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 $/; } ; $makefile_text =~ s/SUB_TRICK_HOME/$trick_home/ ; $makefile_text =~ s/SUB_TRICK_BIN/$trick_bin/ ; diff --git a/libexec/trick/ICG_lib_deps_helper b/libexec/trick/ICG_lib_deps_helper new file mode 100755 index 00000000..fc47170c --- /dev/null +++ b/libexec/trick/ICG_lib_deps_helper @@ -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 ( ) { + last if ( $_ =~ /END ICG PROCESSING/ ) ; + $header .= $_ ; +} + +(@resolved_files) = get_lib_deps($header, @ARGV[0]) ; + +print map { "$_\n" } @resolved_files ; diff --git a/libexec/trick/configuration_processor b/libexec/trick/configuration_processor index ec23ff57..09d6ee12 100755 --- a/libexec/trick/configuration_processor +++ b/libexec/trick/configuration_processor @@ -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 | B<--verbose>=I 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 diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src new file mode 100755 index 00000000..8a13eb2a --- /dev/null +++ b/libexec/trick/make_makefile_src @@ -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) = ; + 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) = ; +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 = ; + 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 ( ) { + 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,\${ \$@\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 ; + diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig new file mode 100755 index 00000000..d300b2ac --- /dev/null +++ b/libexec/trick/make_makefile_swig @@ -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 = ; + 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 = ; + 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() ; diff --git a/libexec/trick/pm/get_lib_deps.pm b/libexec/trick/pm/get_lib_deps.pm new file mode 100644 index 00000000..e23c7c69 --- /dev/null +++ b/libexec/trick/pm/get_lib_deps.pm @@ -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) = ; + 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 diff --git a/libexec/trick/pm/make_makefile.pm b/libexec/trick/pm/make_makefile.pm index bf902bfc..d14dfea6 100644 --- a/libexec/trick/pm/make_makefile.pm +++ b/libexec/trick/pm/make_makefile.pm @@ -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,\${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; diff --git a/libexec/trick/pm/mis_dep.pm b/libexec/trick/pm/mis_dep.pm index 7694ce4c..2d864f4f 100644 --- a/libexec/trick/pm/mis_dep.pm +++ b/libexec/trick/pm/mis_dep.pm @@ -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 ; } } diff --git a/libexec/trick/pm/s_source.pm b/libexec/trick/pm/s_source.pm index 7095c87b..982c2f7d 100644 --- a/libexec/trick/pm/s_source.pm +++ b/libexec/trick/pm/s_source.pm @@ -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 ; } #-------------------------------------------------------------- diff --git a/share/trick/makefiles/Makefile.sim b/share/trick/makefiles/Makefile.sim index ff47d9da..3a38ffd1 100644 --- a/share/trick/makefiles/Makefile.sim +++ b/share/trick/makefiles/Makefile.sim @@ -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 diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp index 3a2faddb..43a08ba1 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp @@ -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 +#include + +/* + 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 ; +} diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh b/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh index 1c45cb34..703f4072 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh @@ -4,6 +4,7 @@ #include #include +#include #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 ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index f79b08b5..cbf65b7e 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -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::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() { diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh index f5143362..12bcf452 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh @@ -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() ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 1a5da7e2..3557c94e 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -452,6 +452,7 @@ void PrintFileContents10::printClassMapHeader( std::ofstream & outfile , std::st "#include \n" "#include \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 \n" -"#include \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 ; } diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index ed95c3e0..8b6bedbc 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -191,6 +191,7 @@ int main( int argc , char * argv[] ) { if ( ! sim_services_flag ) { pa.printIOMakefile() ; + pa.printHeaderLibraryDependencies() ; } // Close the map files diff --git a/trick_source/codegen/Interface_Code_Gen/makefile b/trick_source/codegen/Interface_Code_Gen/makefile index 68d0ebc3..62c4c164 100644 --- a/trick_source/codegen/Interface_Code_Gen/makefile +++ b/trick_source/codegen/Interface_Code_Gen/makefile @@ -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 ) diff --git a/trick_source/sim_services/MemoryManager/test/Makefile b/trick_source/sim_services/MemoryManager/test/Makefile index 488b41e1..aa92b8ab 100644 --- a/trick_source/sim_services/MemoryManager/test/Makefile +++ b/trick_source/sim_services/MemoryManager/test/Makefile @@ -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 From dfa961808b2ccd1f6295758fc43cb3a58ea2e319 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Mon, 20 Jul 2015 16:22:34 -0500 Subject: [PATCH 2/5] Split CP up into components that can be called individually First tests are working. Changing a source file and header works as before. Adding library dependencies in either of these files causes the makefile pieces to be redone. Only tested in the ball sim so far. refs #86 --- libexec/trick/convert_swig | 217 ++++-------------- libexec/trick/make_makefile_src | 26 ++- libexec/trick/make_makefile_swig | 4 +- share/trick/makefiles/Makefile.sim | 52 +++-- .../Interface_Code_Gen/PrintAttributes.cpp | 14 +- 5 files changed, 100 insertions(+), 213 deletions(-) diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index 37ae5e96..b9a84854 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -10,7 +10,6 @@ use lib "$RealBin/pm" ; use File::Basename ; use Cwd 'abs_path' ; use gte ; -use get_headers ; use trick_version ; use Digest::MD5 qw(md5_hex) ; @@ -37,31 +36,25 @@ Options: display this help and exit -s, --stl Allow convert_swig to process STLs - -o, --outfile - provide a name for the generated SWIG interface file which - is usually denoted with a special .i or .swg suffix Usage: - convert_swig [-o ] + convert_swig Examples: - % convert_swig -o swig/Ball.i include/Ball.hh - % convert_swig -o swig_src/S_source.i S_source.hh + % convert_swig include/Ball.hh + % convert_swig S_source.hh " ; -my ($in_file , $out_file ) ; my $help = ''; # option variable with default value (false) my $stls = 0; # option variable with default value (false) -my ( @include_paths, @include_dirs , @defines) ; +my ( @include_dirs , @defines) ; my ( @swig_exclude_dirs) ; my ( @exclude_dirs) ; my %sim ; my %out_of_date ; my ($version, $thread, $year) ; -my %icg_no ; -my %skipped_files ; my %processed_templates ; my $typedef_def = qr/typedef\s+ # the word typedef @@ -112,8 +105,7 @@ my %stl_names = qw(deque 1 set 1 multiset 1 multimap 1 hash_set 1 std::bitset 1 std::auto_ptr 1 pair 1 std::pair 1 std::tr1::shared_ptr 1) ; Getopt::Long::Configure ("bundling"); -GetOptions ( "outfile|o=s" => \$out_file , - "stl|s" => sub { $stls = 1 } , +GetOptions ( "stl|s" => sub { $stls = 1 } , 'help|h' => \$help ) or usage() ; if ( $help ) { @@ -123,188 +115,65 @@ if ( $help ) { ($version, $thread) = get_trick_version() ; ($year) = $version =~ /^(\d+)/ ; -@include_paths = $ENV{"TRICK_CFLAGS"} =~ /(-I\s*\S+)/g ; # get include paths from TRICK_CFLAGS @include_dirs = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS + @swig_exclude_dirs = split /:/ , $ENV{"TRICK_SWIG_EXCLUDE"} ; if ( scalar @swig_exclude_dirs == 0 ) { @swig_exclude_dirs = split /:/ , $ENV{"TRICK_ICG_EXCLUDE"} ; } @exclude_dirs = split /:/ , $ENV{"TRICK_EXCLUDE"} ; -push @include_paths , ("-I".$ENV{"TRICK_HOME"}."/trick_source" , "-I../include") ; @defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS if ( $ENV{"TRICK_CFLAGS"} !~ /DTRICK_VER=/ ) { push @defines , "-DTRICK_VER=$year" ; } -#(my $cc = gte("TRICK_CC")) =~ s/\n// ; -# Use the c preporcessor directly -my $cc ; -my $system_type = `uname -s` ; -chomp $system_type ; -if ( $system_type eq "Darwin" ) { - $cc = "/usr/bin/llvm-gcc -E" ; -} else { - $cc = "/usr/bin/cpp" ; -} -($in_file) = (grep !/^-/ , @ARGV) ; - -## The list of header files to be processed is usually produced by the script -## make_swig_makefile.pm, as it's creating Makefile_swig. This list is stored in -## the file ".S_library_swig". So, if .S_library_swig exists, we can just open and read it. -## - -my ($s_library_swig) = "build/S_library_swig" ; - -if ( -e $s_library_swig ) { - open FILE_LIST, $s_library_swig ; +if ( scalar @ARGV == 0 ) { + my ($s_library_swig) = "build/S_library_swig" ; + open FILE_LIST, $s_library_swig or die "Could not open $s_library_swig" ; while ( ) { chomp ; - $sim{final_all_includes}{$_} = 1 ; + + my ($f) = $_ ; + my ($swig_dir , $base_file , $swig_file ) ; + + $base_file = basename($f) ; + $base_file =~ s/\.[^\.]+$// ; + + $swig_dir = dirname($f) ; + $swig_dir = "build/$swig_dir" ; + $swig_file = "$swig_dir/${base_file}.i" ; + + #print "$swig_file\n" ; + if ( -e $swig_file ) { + if ( !exists $sim{mod_date}{$f} ) { + $sim{mod_date}{$f} = (stat $f)[9] ; + } + $sim{swig_mod_date}{$f} = (stat $swig_file)[9] ; + if ( $sim{mod_date}{$f} > $sim{swig_mod_date}{$f} ) { + $out_of_date{$f} = 1 ; + } + } else { + $out_of_date{$f} = 1 ; + $sim{swig_mod_date}{$f} = 0 ; + } } } else { - -## Otherwise we need to process S_source.hh to produce the list of header files. -## -## Specifically, we want to generate SWIG interfaces for those header files that are: -## 1) actual dependencies of S_source.hh, GIVEN THE CURRENT environment and -## 2) not excluded from ICG processing ( by ICG_NO or ICG_EXCLUDE). -## -## The header files that are actually included are the dependencies we care -## about. Keep in mind that the pre-processor and the current ENVIRONMENT -## may cause some headers to be conditionally included or excluded. We only -## want to generate SWIG interfaces for headers that are ACTUALLY included. -## -## Whereas the pre-processor can (using the gcc -MM option) generate a list -## of dependencies that satisfy 1) (above), it can't handle that ICG exclusions. -## And, whereas the function get_headers() can generate a list of dependences -## which are flagged if they contain ICG_NO, it doesn't handle conditional includes. -## -## So, the strategy that we employ is to generate and then find the -## intersection of both lists. Then we eliminate those that are in 1) -## $TRICK_HOME/trick_source, or 2) flagged as containing ICG_NO or 3) are -## in ICG_EXCLUDE'd directories. -## -## First, create a list headers using the GCC with the -MM option. GCC will -## handle conditional inclusion. -## - - # list of files to process does not exist. Process S_source.hh to create one. - my ($s_source_full_path) = abs_path("S_source.hh") ; - open FILE_LIST, "$cc -MM -DSWIG @include_paths @defines $in_file |" ; - my $dir ; - $dir = dirname($s_source_full_path) ; - while ( ) { - next if ( /^#/ or /^\s+\\/ ) ; - my $word ; - foreach $word ( split ) { - next if ( $word eq "\\" or $word =~ /o:/ ) ; - if ( $word !~ /^\// and $dir ne "\/" ) { - $word = "$dir/$word" ; - } - $word = abs_path(dirname($word)) . "/" . basename($word) ; - # filter out system headers that are missed by the compiler -MM flag - next if ( $word =~ /^\/usr\/include/) ; - next if ( $word =~ /$ENV{TRICK_HOME}\/trick_source\//) ; - - #print "gcc found $word\n" ; - $sim{gcc_all_includes}{$word} = 1 ; - #$sim{mod_date}{$word} = (stat $word)[9] ; - } - } - -## Second, create a list where the files are flagged if they contain ICG_NO. -## - - get_headers(\%sim, $s_source_full_path) ; - if ( open ICGNOFOUND , ("build/icg_no_found") ) { - while ( ) { - chomp ; - $icg_no{$_} = 1 ; - } - } - -## Then we generate the intersection of the two lists and then eliminate the dependencies that: -## 1) are in $TRICK_HOME/trick_source. -## 2) contain ICG_NO. -## 3) are in ICG_EXCLUDE'd directories. -## to create the final list of header dependencies that we need to convert into SWIG interfaces. -## - - foreach my $k ( keys %{$sim{gcc_all_includes}} ) { - $sim{final_all_includes}{$k} = 1 if exists $sim{all_includes}{$s_source_full_path} ; - } - - foreach my $f ( keys %{$sim{final_all_includes}} ) { - if ( $f =~ /$ENV{TRICK_HOME}\/trick_source/ ) { - delete $sim{final_all_includes}{$f} ; - } elsif ( exists $icg_no{$f} ) { - $skipped_files{$f} = "ICG No found" ; - delete $sim{final_all_includes}{$f} ; - } else { - foreach my $ie ( @swig_exclude_dirs ) { - # if file location begins with $ie (an IGC exclude dir) - if ( $f =~ /^\Q$ie/ ) { - $skipped_files{$f} = "ICG exclude dir $ie" ; - delete $sim{final_all_includes}{$f} ; - last ; # break out of loop - } - } - foreach my $ie ( @exclude_dirs ) { - # if file location begins with $ie (an IGC exclude dir) - if ( $f =~ /^\Q$ie/ ) { - $skipped_files{$f} = "Exclude dir $ie" ; - delete $sim{final_all_includes}{$f} ; - last ; # break out of loop - } - } - } - } + #print "HERE I AM @ARGV\n" ; + map { $out_of_date{$_} = 1 } @ARGV ; } -## Next we need to determine which of the files do not have up-to-date SWIG files. -## For each header file in final dependency list, if the corresponding SWIG (.i) file -## doesn't exist or the header file is newer than the existing SWIG file, then record -## that a new SWIG file needs needs to be created. The global hash %out_of_date -## represents a list of header files whose corresponding .i files need to be regenerated. +## The global hash %out_of_date represents a list of header files whose +## corresponding .i files need to be regenerated. ## -foreach my $f ( keys %{$sim{final_all_includes}} ) { - my ($swig_dir , $base_file , $swig_file ) ; - - $base_file = basename($f) ; - $base_file =~ s/\.[^\.]+$// ; - - $swig_dir = dirname($f) ; - $swig_dir = "build/$swig_dir" ; - $swig_file = "$swig_dir/${base_file}.i" ; - - #print "$swig_file\n" ; - if ( -e $swig_file ) { - if ( !exists $sim{mod_date}{$f} ) { - $sim{mod_date}{$f} = (stat $f)[9] ; - } - $sim{swig_mod_date}{$f} = (stat $swig_file)[9] ; - if ( $sim{mod_date}{$f} > $sim{swig_mod_date}{$f} ) { - $out_of_date{$f} = 1 ; - } - } else { - $out_of_date{$f} = 1 ; - $sim{swig_mod_date}{$f} = 0 ; - } -} - if ( scalar keys %out_of_date == 0 ) { exit ; } -foreach ( sort keys %skipped_files ) { - print "convert_swig skipping $_ ($skipped_files{$_})\n" ; -} - ## Finally, call process_file() to create SWIG interface files for each of the out_of_date headers. ## -process_file(\%sim , abs_path($in_file)) ; +process_file() ; ## ## ================================================================================ @@ -319,16 +188,10 @@ process_file(\%sim , abs_path($in_file)) ; ## ## sim_ref ## -## Is this parameter ever used? -## -## in_file -## ## The name of input file, invariably "S_source.hh". ## -sub process_file($$) { - - my ($sim_ref , $in_file) = @_ ; +sub process_file() { ## Foreach out_of_date header file, generate a SWIG interface file. @@ -425,6 +288,7 @@ sub process_file($$) { my ($out_dir) = dirname($f) ; $out_dir = "build$out_dir" ; + my $out_file ; $out_file = basename($f) ; $out_file =~ s/\.h.*$/\.i/ ; @@ -447,7 +311,6 @@ sub process_file($$) { open OUT, ">$out_file" ; print OUT "\%module m$md5_sum\n\n" ; - print OUT "/* $in_file */\n" ; print OUT "#include \"trick/swig/trick_swig.i\"\n\n" ; diff --git a/libexec/trick/make_makefile_src b/libexec/trick/make_makefile_src index 8a13eb2a..318ee7ef 100755 --- a/libexec/trick/make_makefile_src +++ b/libexec/trick/make_makefile_src @@ -43,8 +43,10 @@ sub read_lib_deps(@) { } for my $f ( @ARGV ) { - print "Updating Dependencies for $f\n" ; - write_lib_deps($f) ; + if ( $f !~ /Makefile_io_src/ ) { + 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' ; @@ -258,7 +260,8 @@ foreach $k ( sort keys %files_by_dir ) { 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 "\$(CURDIR)/build/lib/o${num_inc_objs}.o : \$(MODEL_${print_ext}_OBJ_$files_by_dir{$k}{dir_num})\n" ; + print MAKEFILE "\$(CURDIR)/build/lib/o_${print_ext}_$files_by_dir{$k}{dir_num}.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 \${build/Makefile_src_deps" or die "Could not open build/Makefile_src_deps" ; -print MAKEFILEDEPS "build/Makefile_src :" ; +print MAKEFILEDEPS "\$(CURDIR)/build/Makefile_src :" ; print MAKEFILEDEPS map {"\\\n $_"} (sort keys %non_lib_processed_files) ; +print MAKEFILEDEPS "\n" ; close MAKEFILEDEPS ; # write out all of the files we used to S_library_list diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index d300b2ac..4bbaa9f5 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -294,7 +294,6 @@ OBJECTS += \$(SWIG_MODULE_OBJECTS) } close SWIGLIB ; - open S_INSTANCE , "build/S_instances" or return ; my @instances = ; close S_INSTANCE ; @@ -336,6 +335,9 @@ OBJECTS += \$(SWIG_MODULE_OBJECTS) print INITSWIGFILE " return ;\n}\n\n}\n" ; close INITSWIGFILE ; + if ( ! -e "trick") { + mkdir "trick" ; + } open INITFILE , ">trick/__init__.py" or return ; print INITFILE "import sys\n" ; diff --git a/share/trick/makefiles/Makefile.sim b/share/trick/makefiles/Makefile.sim index 3a38ffd1..6fac3c4d 100644 --- a/share/trick/makefiles/Makefile.sim +++ b/share/trick/makefiles/Makefile.sim @@ -12,8 +12,8 @@ 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" +PRINT_MAKEFILE_SRC = @echo "Creating/updating source Makefile" +PRINT_MAKEFILE_SWIG = @echo "Creating/updating swig Makefile" ECHO_CMD = @ endif @@ -24,7 +24,11 @@ export TRICK_ICG_EXCLUDE # Use /bin/bash as the shell so we can use PIPESTATUS SHELL = /bin/bash -all : ${TRICK_LIB_DIR}/libtrick.a S_source.hh build/Makefile_io_src build/Makefile_src build/Makefile_swig +all : ${TRICK_LIB_DIR}/libtrick.a S_source.hh \ + $(CURDIR)/build/Makefile_io_src \ + $(CURDIR)/build/Makefile_src \ + $(CURDIR)/build/Makefile_swig \ + $(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_src all 2>&1 | tee -a build/MAKE_out ; exit $${PIPESTATUS[0]} @@ -42,17 +46,13 @@ ${TRICK_LIB_DIR}/libtrick.a: @echo "Cannot find $@. Please build Trick for this platfrom" @exit -1 +# CP creates S_source.hh required for ICG and SWIG processing S_source.hh : S_define | build $(PRINT_CP) $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/configuration_processor $(TRICK_CPFLAGS) -# Create makefile for source code -build/Makefile_src: | build/Makefile_io_src - $(PRINT_MAKEFILE_SRC) - $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $? - -# ICG rules -build/Makefile_io_src : | S_source.hh +# Automatic and manual ICG rules +$(CURDIR)/build/Makefile_io_src : | S_source.hh $(PRINT_ICG) $(ECHO_CMD)${TRICK_HOME}/bin/trick-ICG -m ${TRICK_CXXFLAGS} S_source.hh @@ -64,24 +64,33 @@ 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 +# Create makefile for source code +$(CURDIR)/build/Makefile_src: $(CURDIR)/build/Makefile_io_src + $(PRINT_MAKEFILE_SRC) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/make_makefile_src $? + +# Create makefile for SWIG code +$(CURDIR)/build/Makefile_swig : | $(CURDIR)/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 $@ +# Automatic and manual convert_swig rules +$(CURDIR)/build/convert_swig_last_run : | $(CURDIR)/build/Makefile_swig + $(PRINT_CONVERT_SWIG) + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} + @ touch $@ convert_swig: $(PRINT_CONVERT_SWIG) - $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} S_source.hh + $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} @ 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 +S_define_exp: + $(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} S_define > $@ + +# Pass these options +sie: + @if [ -f build/Makefile_src ] ; then $(MAKE) --no-print-directory -f build/Makefile_src $@ ; else echo "No build/Makefile_src found" ; fi help: @ echo -e "\ @@ -111,7 +120,8 @@ apocalypse: clean @echo "I love the smell of napalm in the morning" -# Dependencies to other files that may cause a re-CP +# Dependencies for the above rules generated by configuration_process, ICG, make_makefile and make_makefile_swig +-include S_overrides.mk -include build/S_define.deps -include build/Makefile_ICG -include build/Makefile_convert_swig diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index cbf65b7e..ef00e2ce 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -428,7 +428,7 @@ void PrintAttributes::printIOMakefile() { makefile_io_src.close() ; /* - Makefile_ICG lists all headers as dependencies of class_map.cpp + Makefile_ICG lists all headers as dependencies of Makefile_io_src causing ICG to run if any header file changes. link_io_objs lists all io_src object files to be partially @@ -439,7 +439,7 @@ void PrintAttributes::printIOMakefile() { makefile_ICG.open("build/Makefile_ICG") ; link_io_objs.open("build/link_io_objs") ; ICG_processed.open("build/ICG_processed") ; - makefile_ICG << "$(CURDIR)/build/class_map.cpp :" ; + makefile_ICG << "$(CURDIR)/build/Makefile_io_src :" ; for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) { makefile_ICG << "\\\n " << (*mit).first ; size_t found ; @@ -461,13 +461,11 @@ void PrintAttributes::printHeaderLibraryDependencies() { 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++ ) { + size_t found ; + 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 ; if ( out_of_date_io_files.find((*mit).first) != out_of_date_io_files.end()) { - size_t found ; - 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) ; From d7b386227a193565bc942f0f6186d9a5c286aa4c Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 21 Jul 2015 08:52:00 -0500 Subject: [PATCH 3/5] Split CP up into components that can be called individually Fixed some library dependency bugs. JEOD test sims compile now. refs #86 --- libexec/trick/make_makefile_swig | 2 +- libexec/trick/pm/get_lib_deps.pm | 14 ++++---- libexec/trick/pm/s_source.pm | 4 +-- share/trick/makefiles/Makefile.sim | 7 ++-- .../Interface_Code_Gen/PrintAttributes.cpp | 36 +++++++++++++++++++ .../Interface_Code_Gen/PrintAttributes.hh | 6 ++++ 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 4bbaa9f5..56860b99 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -300,7 +300,7 @@ OBJECTS += \$(SWIG_MODULE_OBJECTS) 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 @instances ; print TOPFILE "\n\%}\n\n" ; print TOPFILE "\%import \"build$wd/S_source.i\"\n\n" ; print TOPFILE @instances ; diff --git a/libexec/trick/pm/get_lib_deps.pm b/libexec/trick/pm/get_lib_deps.pm index e23c7c69..8b0ea416 100644 --- a/libexec/trick/pm/get_lib_deps.pm +++ b/libexec/trick/pm/get_lib_deps.pm @@ -15,7 +15,7 @@ sub get_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_deps) = $contents =~ /LIBRARY[ _]DEPENDENC(?:Y|IES):[^(]*(.*?)\)([A-Z _\t\n\r]+:|\s*\*)/si ; @lib_list = split /\)[ \t\n\r\*]*\(/ , $lib_deps ; @inc_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS @@ -59,18 +59,20 @@ sub get_lib_deps ($$) { } } else { $l =~ s/o$// ; + my ($rel_dir) = dirname($l) ; + my ($base) = basename($l) ; foreach my $inc ( $file_path_dir , @inc_paths) { foreach my $ext ( "cpp" , "cc" , "c" , "c++" , "cxx" , "C" ) { - if ( -e "$inc/$l$ext" ) { + if ( -e "$inc/$rel_dir/$base$ext" ) { #print "found $inc/$l$ext\n" ; - my $f = abs_path(dirname("$inc/$l$ext")) . "/" . basename("$inc/$l$ext") ; + my $f = abs_path("$inc/$rel_dir") . "/$base$ext" ; push @resolved_files, $f ; $found = 1 ; last ; } - elsif ( -e "$inc/src/$l$ext" ) { + elsif ( -e "$inc/$rel_dir/src/$base$ext" ) { #print "found $inc/src/$l$ext\n" ; - my $f = abs_path(dirname("$inc/src/$l$ext")) . "/" . basename("$inc/src/$l$ext") ; + my $f = abs_path("$inc/$rel_dir/src") . "/$base$ext" ; push @resolved_files, $f ; $found = 1 ; last ; @@ -81,7 +83,7 @@ sub get_lib_deps ($$) { } if ( $found == 0 ) { - print STDERR "@ARGV[0]: Warning: Could not find dependency $l\n" ; + print STDERR "Warning: Could not find dependency $l\n" ; } } return @resolved_files ; diff --git a/libexec/trick/pm/s_source.pm b/libexec/trick/pm/s_source.pm index 982c2f7d..59c2d940 100644 --- a/libexec/trick/pm/s_source.pm +++ b/libexec/trick/pm/s_source.pm @@ -319,9 +319,9 @@ PURPOSE: open S_INSTANCE, ">build/S_instances" or die "Couldn't open build/S_instances!\n"; - print S_INSTANCE $$sim_ref{instance_declarations} ; + print S_INSTANCE $$sim_ref{extern_instance_declarations} ; foreach my $integ_loop ( @{$$sim_ref{integ_loop}} ) { - print S_INSTANCE "IntegLoopSimObject $$integ_loop{name} ;\n" ; + print S_INSTANCE "extern IntegLoopSimObject $$integ_loop{name} ;\n" ; } close S_INSTANCE ; } diff --git a/share/trick/makefiles/Makefile.sim b/share/trick/makefiles/Makefile.sim index 6fac3c4d..1337e1be 100644 --- a/share/trick/makefiles/Makefile.sim +++ b/share/trick/makefiles/Makefile.sim @@ -85,11 +85,8 @@ convert_swig: $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} @ touch $(CURDIR)/build/convert_swig_last_run -S_define_exp: - $(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} S_define > $@ - # Pass these options -sie: +sie S_define_exp: @if [ -f build/Makefile_src ] ; then $(MAKE) --no-print-directory -f build/Makefile_src $@ ; else echo "No build/Makefile_src found" ; fi help: @@ -121,7 +118,7 @@ apocalypse: clean # Dependencies for the above rules generated by configuration_process, ICG, make_makefile and make_makefile_swig --include S_overrides.mk +#-include S_overrides.mk -include build/S_define.deps -include build/Makefile_ICG -include build/Makefile_convert_swig diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index ef00e2ce..d5bb2447 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -357,6 +357,36 @@ void PrintAttributes::closeMapFiles() { } } +void PrintAttributes::addEmptyFiles() { + // Make a list of the empty files we processed. + // This list is written to the ICG_processed file and used by other processors. + clang::SourceManager::fileinfo_iterator fi ; + for ( fi = ci.getSourceManager().fileinfo_begin() ; fi != ci.getSourceManager().fileinfo_end() ; fi++ ) { + const clang::FileEntry * fe = (*fi).first ; + std::string header_file_name = fe->getName() ; + if ( visited_files.find(header_file_name) == visited_files.end() ) { + visited_files.insert(header_file_name) ; + // several tests require the real path of the header file. + char * rp = almostRealPath(header_file_name.c_str()) ; + if ( rp != NULL ) { + // Only include user directories (not system dirs like /usr/include) + if ( hsd.isPathInUserDir(rp) ) { + // Don't process files in excluded directories + if ( hsd.isPathInICGExclude(rp) == false ) { + // Only include files that do not have ICG: (No) + // hasICGNo uses original header name, not the real path + if ( ! cs.hasICGNo(header_file_name) ) { + std::string io_file_name = createIOFileName(std::string(rp)) ; + empty_header_files.insert(rp) ; + } + } + } + free(rp) ; + } + } + } +} + //TODO: Move this into PrintFileContents10. void PrintAttributes::printIOMakefile() { std::ofstream makefile_io_src ; @@ -447,6 +477,12 @@ void PrintAttributes::printIOMakefile() { link_io_objs << (*mit).second.substr(0,found) << ".o" << std::endl ; ICG_processed << (*mit).first << std::endl ; } + // Create the list of empty (of classes/enums) header files to be written to ICG_processed. + addEmptyFiles() ; + std::set< std::string >::iterator sit ; + for ( sit = empty_header_files.begin() ; sit != empty_header_files.end() ; sit++ ) { + ICG_processed << (*sit) << std::endl ; + } makefile_ICG << std::endl << std::endl ; makefile_ICG.close() ; link_io_objs << "build/class_map.o" << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh index 12bcf452..9a00fbb7 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh @@ -98,6 +98,9 @@ class PrintAttributes { bool isIOFileOutOfDate(std::string header_file_name, std::string io_file_name ) ; bool doesIODirectoryExist(std::string io_file_name ) ; + /** Adds empty header files to list of processed files. */ + void addEmptyFiles() ; + /** Determines the io_file_name based on the given header file name @param header_file_name = full path to header file @return string of full path to io_src file name. @@ -110,6 +113,9 @@ class PrintAttributes { /** map of all io_files we processed */ std::map< std::string , std::string > all_io_files ; + /** map of all io_files we processed */ + std::set< std::string > empty_header_files ; + /** map of open files to the out of date io_src file */ std::map< std::string , std::string > out_of_date_io_files ; From 9b7a933a06993df05a769e14e8e89617255adac5 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 21 Jul 2015 09:09:09 -0500 Subject: [PATCH 4/5] Split CP up into components that can be called individually Removed dead code. refs #86 --- libexec/trick/ICG_10 | 232 --------------- libexec/trick/MIS | 217 -------------- libexec/trick/depend_objs | 50 ---- libexec/trick/mis_dep | 57 ---- libexec/trick/pm/ICG.pm | 456 ----------------------------- libexec/trick/pm/MIS.pm | 290 ------------------ libexec/trick/pm/auto_doc.pm | 412 -------------------------- libexec/trick/pm/get_headers.pm | 110 ------- libexec/trick/pm/mis_dep.pm | 304 ------------------- libexec/trick/pm/parse_s_define.pm | 1 - libexec/trick/pm/trick_units.pm | 410 -------------------------- 11 files changed, 2539 deletions(-) delete mode 100755 libexec/trick/ICG_10 delete mode 100755 libexec/trick/MIS delete mode 100755 libexec/trick/depend_objs delete mode 100755 libexec/trick/mis_dep delete mode 100644 libexec/trick/pm/ICG.pm delete mode 100644 libexec/trick/pm/MIS.pm delete mode 100644 libexec/trick/pm/auto_doc.pm delete mode 100644 libexec/trick/pm/get_headers.pm delete mode 100644 libexec/trick/pm/mis_dep.pm delete mode 100644 libexec/trick/pm/trick_units.pm diff --git a/libexec/trick/ICG_10 b/libexec/trick/ICG_10 deleted file mode 100755 index ddd1bf65..00000000 --- a/libexec/trick/ICG_10 +++ /dev/null @@ -1,232 +0,0 @@ -#!/usr/bin/perl - -use FindBin qw($RealBin); -use strict ; -use Getopt::Long; -use Pod::Usage; -use Pod::Text; -use lib "$RealBin/pm" ; -use ICG ; -use trick_print ; -use trick_version ; -use get_headers ; -use Cwd 'abs_path'; - -############################################################################## -# Main program -############################################################################## - -my $icg_operation ; -my @icg_h_files ; -my %sim ; -my $ret ; -my $help ; -my @defs ; -my ($valid_types_ref,$icg_depends_ref, $mis_entries_ref,$mis_depends_ref) ; -my ($head_depends_ref,$rcs_tags_ref) ; - -# 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 the default verbose level to 2 -$sim{args}{v} = 2 ; -$sim{args}{force} = 0 ; - -# default operation -$icg_operation = "full" ; -$ICG::arg_lang = 0 ; - -Getopt::Long::Configure ("bundling"); -GetOptions ( "D=s" => sub { my $temp = join "" , @_ ; push @defs , "-$temp" ; } , - "U=s" => sub { my $temp = join "" , @_ ; push @defs , "-$temp" ; } , - "cpp|p" => sub { $ICG::arg_lang = "CPP" } , - "debug|d|g" => sub { $sim{args}{v} = 3 } , - "help|h|?" => \$help , - "force|f" => sub { $sim{args}{force} = 1} , - "outfile|o=s" => \$sim{args}{o} , - "sim_services|s" => sub { $icg_operation = "sim_services" } , - "single" => sub { $icg_operation = "single" } , - "s_source" => sub { $icg_operation = "s_source" } , - "tree|t" => sub { $icg_operation = "tree" } , - "unit_summary|u" => \&unit_summary , - "verbose|v=i" => \$sim{args}{v} - ) or pod2usage(1) ; - -pod2usage(1) if $help ; - -#if ( -e "S_overrides.mk" ) { -# -# open CFLAGS, "make -p -n -f S_overrides.mk fake_target 2>&1 |" ; -# -# while ( ) { -# -# if ( /^TRICK_CFLAGS\s*\:?=\s*(.*)/ ) { -# $ENV{TRICK_CFLAGS} = $1 ; -# } -# elsif ( /^TRICK_ICG_EXCLUDE\s*\:?=\s*(.*)/ ) { -# $ENV{TRICK_ICG_EXCLUDE} = $1 ; -# $ENV{TRICK_ICG_EXCLUDE} =~ s/\$[{(]([^})]+)[})]/$ENV{$1}/ge ; -# } -# } -# close CFLAGS ; -#} - -$ENV{TRICK_CFLAGS} =~ s/\$[{(](\w+)[})]/$ENV{$1}/g ; -$ENV{TRICK_CFLAGS} =~ s/\"//g ; - -# set and open the output file -if ( $sim{args}{o} ne "" ) { - my ($version, $thread) = get_trick_version() ; - $thread =~ s/\d+\.// ; - local *OUTFILE ; - open OUTFILE , ">$sim{args}{o}" - or warn "ICG cannot open $sim{args}{o} for writing\n" ; - $sim{fh} = *OUTFILE ; - print OUTFILE "Output for $0 version $version-$thread at " . localtime() . "\n\n" ; -} - -push @icg_h_files , (grep !/(^-|(\.d|\.dd)$)/ , @ARGV) ; - -#-------------------------------------------------------------- -# Get all headers used by the sim and their modification dates -#if ( $icg_operation eq "s_source" ) { -# get_headers(\%sim, abs_path("S_source.hh")) ; -#} - -$ret = ICG(@icg_h_files, $icg_operation, \@defs, \%sim) ; - -if ($ret eq -1) { - trick_print($sim{fh}, - "\nICG No files specified or found\n" , - "normal_yellow" , $sim{args}{v}) ; -} - -sub unit_summary() { - print " - Trick Measurement Units Summary ---------------------------------------------------------------------------------------------------- -Standard Units |Description ---------------------------------------------------------------------------------------------------- - Time: s min hr day |second, minute, hour, day -Angular Displacement: r d as am rev |radian, degree, arc-second, arc-minute, revolution - Voltage: v |volt - Amperage: amp |ampere - Resistance: ohm |ohm - Sound: dB |decibel - Unitless: -- cnt one mol |no unit, count, one, mole - | ---------------------------------------------------------------------------------------------------- -English System Units |Description ---------------------------------------------------------------------------------------------------- - Linear Displacement: ft kft in yd mi n.m. |foot, kilofoot, inch, yard, mile, nautical mile - Mass: sl lbm |slug, pound(mass) - Force: oz lbf |ounce, pound(force) - Temperature: R F |Rankine, Fahrenheit - Energy: BTU |British Thermal Unit - Power: hp |horsepower - Pressure: psi |pound per square inch - Volume: gal floz |gallon, fluid ounce - | ---------------------------------------------------------------------------------------------------- -Metric System Units |Description ---------------------------------------------------------------------------------------------------- - Linear Displacement: m |meter - Mass: g mt |gram, metric ton - Force: N |Newton - Temperature: C K |Celsius, Kelvin - Energy: J TNT |Joule, ton of TNT - Power: W |Watt - Pressure: Pa atm mHg |Pascal, atmosphere, meter of mercury - Frequency: Hz |Herz - Volume: l |liter - ---------------------------------------------------------------------------------------------------- - ---------------------------------------------------------- -You can use these prefixes for Multiples and Submultiples -(Only valid for units: r v amp ohm m g N J W Pa mHg Hz) ---------------------------------------------------------- -10**-1 d 10 da -10**-2 c 10**2 h -10**-3 m 10**3 k -10**-6 u 10**6 M -10**-9 n 10**9 G -10**-12 p 10**12 T ---------------------------------------------------------- -\n\n" ; - - exit() ; -} - -__END__ - -=head1 NAME - -ICG - Trick Interface Code Generator - -=head1 SYNOPSIS - -ICG [-D B