summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/makefile.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-02-25 18:29:04 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-02-25 18:29:04 +0100
commit6c3ff9acd104dd0d55db41c3e049f3fe329c2e5d (patch)
tree124932cdc396551121d3978576744e2aa613e332 /source4/build/smb_build/makefile.pm
parentab88018a6e16c7b8d7f77913ad8c80e68ed6ccea (diff)
downloadsamba-6c3ff9acd104dd0d55db41c3e049f3fe329c2e5d.tar.gz
samba-6c3ff9acd104dd0d55db41c3e049f3fe329c2e5d.tar.bz2
samba-6c3ff9acd104dd0d55db41c3e049f3fe329c2e5d.zip
Include CFLAGS overrides in make file.
(This used to be commit f05d5f839e18e078a59ccd262fbffaa2eb4e3672)
Diffstat (limited to 'source4/build/smb_build/makefile.pm')
-rw-r--r--source4/build/smb_build/makefile.pm53
1 files changed, 53 insertions, 0 deletions
diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm
index bed98bb2c6..8b5856648f 100644
--- a/source4/build/smb_build/makefile.pm
+++ b/source4/build/smb_build/makefile.pm
@@ -360,4 +360,57 @@ sub write($$)
print __FILE__.": creating $file\n";
}
+my $sort_available = eval "use sort 'stable'; return 1;";
+$sort_available = 0 unless defined($sort_available);
+
+sub by_path {
+ return 1 if($a =~ m#^\-I/#);
+ return -1 if($b =~ m#^\-I/#);
+ return 0;
+}
+
+sub CFlags($$)
+{
+ my ($self, $key) = @_;
+
+ my $srcdir = $self->{config}->{srcdir};
+ my $builddir = $self->{config}->{builddir};
+
+ my $src_ne_build = ($srcdir ne $builddir) ? 1 : 0;
+
+ return unless defined ($key->{OBJ_LIST});
+ return unless defined ($key->{FINAL_CFLAGS});
+ return unless (@{$key->{FINAL_CFLAGS}} > 0);
+
+ my @sorted_cflags = @{$key->{FINAL_CFLAGS}};
+ if ($sort_available) {
+ @sorted_cflags = sort by_path @{$key->{FINAL_CFLAGS}};
+ }
+
+ # Rewrite CFLAGS so that both the source and the build
+ # directories are in the path.
+ my @cflags = ();
+ foreach my $flag (@sorted_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 = $_;
+ my $dfile = $_;
+ $dfile =~ s/\.o$/.d/;
+ $dfile =~ s/\.ho$/.d/;
+ $self->output("$ofile $dfile: CFLAGS+= $cflags\n");
+ }
+}
+
1;