1#!/usr/bin/perl -w 2 3# 4# Courtesy of Trilinos v9 5# 6# This perl script removes duplicate include paths left to the right 7use strict; 8my @all_incl_paths = @ARGV; 9my @cleaned_up_incl_paths; 10foreach( @all_incl_paths ) { 11 $_ = remove_rel_paths($_); 12 if( !($_=~/-I/) ) { 13 push @cleaned_up_incl_paths, $_; 14 } 15 elsif( !entry_exists($_,\@cleaned_up_incl_paths) ) { 16 push @cleaned_up_incl_paths, $_; 17 } 18} 19print join( " ", @cleaned_up_incl_paths ); 20# 21# Subroutines 22# 23sub entry_exists { 24 my $entry = shift; # String 25 my $list = shift; # Reference to an array 26 foreach( @$list ) { 27 if( $entry eq $_ ) { return 1; } 28 } 29 return 0; 30} 31# 32sub remove_rel_paths { 33 my $entry_in = shift; 34 if ($entry_in=~/-I\.\./) { 35 return $entry_in; 36 } 37 my @paths = split("/",$entry_in); 38 my @new_paths; 39 foreach( @paths ) { 40 if( !($_=~/\.\./) ) { 41 push @new_paths, $_; 42 } 43 else { 44 pop @new_paths 45 } 46 } 47 return join("/",@new_paths); 48} 49