From 9f3175d01b6da697dff7ebb45994ead9a7a31cc2 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Tue, 18 Jun 2019 10:52:37 -0500 Subject: [PATCH] Use TRICK_CXXFLAGS for include paths & defines Fixes #819 --- libexec/trick/convert_swig | 17 ++++++----------- libexec/trick/make_makefile_swig | 25 ++++++------------------- libexec/trick/pm/default_data.pm | 3 ++- libexec/trick/pm/get_lib_deps.pm | 5 +++-- libexec/trick/pm/get_paths.pm | 10 +++++++++- libexec/trick/pm/parse_s_define.pm | 7 ++----- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index d3ebf3d3..f3e7d7a3 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -53,10 +53,6 @@ Examples: my $help = ''; # option variable with default value (false) my $stls = 0; # option variable with default value (false) -my ( @include_dirs , @defines) ; -my @exclude_paths ; -my @swig_exclude_paths ; -my @ext_lib_paths ; my %sim ; my %out_of_date ; my ($version, $thread, $year) ; @@ -128,14 +124,13 @@ if ( $help ) { ($version, $thread) = get_trick_version() ; ($year) = $version =~ /^(\d+)/ ; -@include_dirs = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS +my @include_dirs = get_include_paths() ; +my @defines = get_defines() ; +my @exclude_paths = get_paths("TRICK_EXCLUDE") ; +my @swig_exclude_paths = get_paths("TRICK_SWIG_EXCLUDE") ; +my @ext_lib_paths = get_paths("TRICK_EXT_LIB_DIRS") ; -@exclude_paths = get_paths( "TRICK_EXCLUDE") ; -@swig_exclude_paths = get_paths( "TRICK_SWIG_EXCLUDE") ; -@ext_lib_paths = get_paths( "TRICK_EXT_LIB_DIRS") ; - -@defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS -if ( $ENV{"TRICK_CFLAGS"} !~ /DTRICK_VER=/ ) { +if ( "$ENV{'TRICK_CFLAGS'} $ENV{'TRICK_CXXFLAGS'}" !~ /DTRICK_VER=/ ) { push @defines , "-DTRICK_VER=$year" ; } diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 40a90adc..4dc736ab 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -26,26 +26,13 @@ my %python_modules ; my %python_module_dirs ; sub read_files_to_process() { - my @include_paths ; - my $cc ; - my @defines ; - my ($version, $thread, $year) ; + my $version, my $thread = get_trick_version() ; + my $year = $version =~ /^(\d+)/ ; + (my $cc = gte("TRICK_CC")) =~ s/\n// ; - ($version, $thread) = get_trick_version() ; - ($year) = $version =~ /^(\d+)/ ; - ($cc = gte("TRICK_CC")) =~ s/\n// ; - - # add -I paths and #defines - foreach my $value ( "TRICK_CFLAGS", "TRICK_CXXFLAGS" ) { - push @include_paths, $ENV{$value} =~ /(-I\s*\S+)/g ; - push @defines, $ENV{$value} =~ /(-D\S+)/g ; - } - push @include_paths , ("-I".$ENV{"TRICK_HOME"}."/include") ; - push @include_paths , ("-I".$ENV{"TRICK_HOME"}."/include/trick/compat") ; - push @include_paths , ("-I".$ENV{"TRICK_HOME"}."/trick_source" , "-I../include") ; - push @defines , "-DTRICK_VER=$year" ; - push @defines , "-DSWIG" ; - push @defines , "-std=c++11" ; + # Prepend -I to each include path before we pass them to the compiler + my @include_paths = map("-I$_", (get_include_paths(), "$ENV{TRICK_HOME}/include", "$ENV{TRICK_HOME}/include/trick/compat", "$ENV{TRICK_HOME}/trick_source", "../include")) ; + my @defines = (get_defines(), "-DTRICK_VER=$year", "-DSWIG", "-std=c++11") ; # get the list of header files from the compiler open FILE_LIST, "$cc -MM @include_paths @defines S_source.hh |" ; diff --git a/libexec/trick/pm/default_data.pm b/libexec/trick/pm/default_data.pm index 63857700..4a69c67e 100644 --- a/libexec/trick/pm/default_data.pm +++ b/libexec/trick/pm/default_data.pm @@ -9,6 +9,7 @@ use strict ; use lib $ENV{"TRICK_HOME"} . "/bin/pm" ; use gte ; use trick_print ; +use get_paths ; #-------------------------------------------------------------- # Make Default Data @@ -53,7 +54,7 @@ sub make_default_data($) { // USER: $user\n\n" ; my @default_data_list ; - @include_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS + @include_paths = get_include_paths() ; foreach my $dd_comment ( @{$$sim_ref{default_data}} ) { $dd_comment =~ s/\(\s*\(/\(/sg ; diff --git a/libexec/trick/pm/get_lib_deps.pm b/libexec/trick/pm/get_lib_deps.pm index a9384513..89142bda 100644 --- a/libexec/trick/pm/get_lib_deps.pm +++ b/libexec/trick/pm/get_lib_deps.pm @@ -5,6 +5,7 @@ use Cwd 'abs_path'; use File::Path qw(make_path) ; use Exporter (); use gte ; +use get_paths ; @ISA = qw(Exporter); @EXPORT = qw(get_lib_deps write_lib_deps); @@ -29,7 +30,7 @@ sub get_lib_deps ($$) { # if there is preprocessor directive in the library dependencies, run the text through cpp. if ( $r =~ /#/ ) { (my $cc = gte("TRICK_CC")) =~ s/\n// ; - my @defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; + my @defines = get_defines() ; my $temp ; open FILE, "echo \"$r\" | cpp -P @defines |" ; while ( ) { @@ -40,7 +41,7 @@ sub get_lib_deps ($$) { push @lib_list , (split /\)[ \t\n\r\*]*\(/ , $r) ; } - @inc_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS + @inc_paths = get_include_paths() ; # Get only the include paths that exist my @valid_inc_paths ; foreach (@inc_paths) { diff --git a/libexec/trick/pm/get_paths.pm b/libexec/trick/pm/get_paths.pm index 50f7b034..413d08f0 100644 --- a/libexec/trick/pm/get_paths.pm +++ b/libexec/trick/pm/get_paths.pm @@ -3,7 +3,7 @@ package get_paths ; use Exporter (); use Cwd 'abs_path' ; @ISA = qw(Exporter); -@EXPORT = qw(get_paths); +@EXPORT = qw(get_paths get_include_paths get_defines); use strict ; @@ -12,4 +12,12 @@ sub get_paths { return grep { $_ ne ''} map abs_path($_), grep { $_ ne '' } map { s/(^\s+|\s+$)//g ; $_ } split /:/, $ENV{$_[0]} ; } +sub get_include_paths { + return "$ENV{TRICK_CFLAGS} $ENV{TRICK_CXXFLAGS}" =~ /-I(\S+)/g +} + +sub get_defines { + return "$ENV{TRICK_CFLAGS} $ENV{TRICK_CXXFLAGS}" =~ /-D\S+/g +} + 1; diff --git a/libexec/trick/pm/parse_s_define.pm b/libexec/trick/pm/parse_s_define.pm index 214179d8..4c609891 100644 --- a/libexec/trick/pm/parse_s_define.pm +++ b/libexec/trick/pm/parse_s_define.pm @@ -11,7 +11,6 @@ use strict ; use Cwd 'abs_path'; use IPC::Open3 ; -use lib $ENV{"TRICK_HOME"} . "/bin/pm" ; use edit ; use find_module ; use gte ; @@ -19,6 +18,7 @@ use trick_print ; use trick_version ; use Text::Balanced qw(extract_bracketed); use html ; +use get_paths ; my ($integ_loop_def , $collect_def , $vcollect_def); my ($job_class_order_def ) ; @@ -172,15 +172,12 @@ sub parse_s_define ($) { my ($CC, $contents) ; my (@prescan_job_class_order) ; my ($version, $thread, $year) ; - my @defines ; my @comments ; my @preprocess_output; - # Get Include Paths From $TRICK_CFLAGS - @{$$sim_ref{inc_paths}} = "$ENV{TRICK_CFLAGS} $ENV{TRICK_SYSTEM_CFLAGS}" =~ /-I\s*(\S+)/g ; + @{$$sim_ref{inc_paths}} = (get_include_paths(), $ENV{TRICK_SYSTEM_CFLAGS} =~ /-I(\S+)/g, "$ENV{TRICK_HOME}/trick_source" , "../include") ; - push @{$$sim_ref{inc_paths}} , ("$ENV{TRICK_HOME}/trick_source" , "../include") ; my @valid_inc_paths ; foreach (@{$$sim_ref{inc_paths}}) {