From a33d97341f2e2afa2e7e6994eb7f14e848408fb7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 10 Oct 2007 23:58:29 +0200 Subject: r25617: Make sure system include paths come after samba include paths. Patch from Timur Bakeyev. (This used to be commit 7565c4a0dd304312898839df6789f7338cc1ea63) --- source4/build/smb_build/cflags.pm | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/source4/build/smb_build/cflags.pm b/source4/build/smb_build/cflags.pm index e6cdff02cd..95f9cac7db 100755 --- a/source4/build/smb_build/cflags.pm +++ b/source4/build/smb_build/cflags.pm @@ -6,8 +6,15 @@ package cflags; use strict; -sub create_cflags($$$$) -{ +use sort 'stable'; + +sub by_path { + return 1 if($a =~ m#^\-I/#); + return -1 if($b =~ m#^\-I/#); + return 0; +} + +sub create_cflags($$$$) { my $CTX = shift; my $srcdir = shift; my $builddir = shift; @@ -15,27 +22,29 @@ sub create_cflags($$$$) open(CFLAGS_TXT,">$file") || die ("Can't open `$file'\n"); - my $src_ne_build = 0; - $src_ne_build = 1 unless ($srcdir eq $builddir); + my $src_ne_build = ($srcdir ne $builddir) ? 1 : 0; foreach my $key (values %{$CTX}) { next unless defined ($key->{OBJ_LIST}); - next unless defined ($key->{FINAL_CFLAGS}); - next unless ($#{$key->{FINAL_CFLAGS}} >= 0); + next unless (@{$key->{FINAL_CFLAGS}} > 0); # Rewrite CFLAGS so that both the source and the build # directories are in the path. - my $cflags = ""; - foreach my $flag (@{$key->{FINAL_CFLAGS}}) { - my $dir; - if ($src_ne_build and ($dir) = ($flag =~ /^-I([^\/].*)$/)) { - $cflags .= " -I$builddir/$dir"; - $cflags .= " -I$srcdir/$dir"; - } else { - $cflags .= " $flag"; + my @cflags = (); + foreach my $flag (sort by_path @{$key->{FINAL_CFLAGS}}) { + if($src_ne_build) { + if($flag =~ m#^-I([^/].*$)#) { + my $dir = $1; + $dir =~ s#^\$\((?:src|build)dir\)/?##; + push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir"); + next; + } } + push(@cflags, $flag); } + + my $cflags = join(' ', @cflags); foreach (@{$key->{OBJ_LIST}}) { my $ofile = $_; -- cgit