[Samba4] [FreeBSD] include headers order patch [1/1]

Timur I. Bakeyev timur at com.bat.ru
Mon Oct 8 02:33:59 GMT 2007


Hi!

Currently, it's not possible to build Samba4 if you have installed
version of Heimdal Kerberos due the conflict of type definitions when
certain Kerberos headers are included.

Here is the problem:

Compiling auth/credentials/credentials.c
In file included from heimdal/lib/gssapi/gssapi/gssapi_spnego.h:39,
                 from heimdal/lib/gssapi/gssapi/gssapi.h:807,
                 from ./auth/credentials/credentials_krb5.h:23,
                 from auth/credentials/credentials.c:27:
/usr/local/include/gssapi.h:50: error: redefinition of typedef 'OM_uint32'
heimdal/lib/gssapi/gssapi/gssapi.h:50: error: previous declaration of 'OM_uint32
' was here
/usr/local/include/gssapi.h:52: error: redefinition of typedef 'gss_uint32'
heimdal/lib/gssapi/gssapi/gssapi.h:53: error: previous declaration of 'gss_uint3
2' was here

A lot of warnings skipped...

/usr/local/include/gssapi.h:711: error: conflicting types for 'gss_duplicate_nam
e'
heimdal/lib/gssapi/gssapi/gssapi.h:652: error: previous declaration of 'gss_dupl
icate_name' was here
The following command failed:
cc   -Iheimdal_build -Iheimdal/lib/krb5 -Iheimdal/lib/roken -Iheimdal/lib/asn1 -
Iheimdal/lib/com_err -Iheimdal/lib/hx509 -Iheimdal/lib/hcrypto -Iheimdal/lib -Il
ib/talloc -I/usr/local/include -Ilib/replace -Iheimdal/lib/gssapi -Iheimdal/lib/
gssapi/gssapi -Iheimdal/lib/gssapi/spnego -Iheimdal/lib/gssapi/krb5 -Iheimdal/li
b/gssapi/mech -Ilib/socket_wrapper  -pipe -g -g -DDEBUG_PASSWORD -DDEVELOPER -Wa
ll -Wshadow -Werror-implicit-function-declaration -Wstrict-prototypes -Wpointer-
arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-format-attribute -Wform
at=2 -Wdeclaration-after-statement -Wunused-macros -Wno-format-y2k -Wno-unused-p
arameter -I./include -I. -I./lib -I./lib/replace -I./lib/talloc -D_SAMBA_BUILD_=
4 -DHAVE_CONFIG_H  -I/usr/local/include -fPIC -DPIC -c auth/credentials/credenti
als.c -o auth/credentials/credentials.o
gmake: *** [auth/credentials/credentials.o] Error 1
*** Error code 2

And it dies. The reason for this is the headers inclusion order. From
extra_cflags.txt:

auth/credentials/credentials.o auth/credentials/credentials.d: CFLAGS+=  -Iheimd
al_build -Iheimdal/lib/krb5 -Iheimdal/lib/roken -Iheimdal/lib/asn1 -Iheimdal/lib
/com_err -Iheimdal/lib/hx509 -Iheimdal/lib/hcrypto -Iheimdal/lib -Ilib/talloc -I
/usr/local/include -Ilib/replace -Iheimdal/lib/gssapi -Iheimdal/lib/gssapi/gssap
i -Iheimdal/lib/gssapi/spnego -Iheimdal/lib/gssapi/krb5 -Iheimdal/lib/gssapi/mec
h -Ilib/socket_wrapper

We can see -I/usr/local/include in the middle, which is injected to
correclty use libiconv. Unfortunately, System wide Kerberos headers are
also stored there, so they come before the headers of the included
Heimdal Kerberos.

Ok, here is the fix or workaround - to move all absolute search paths for 
includes at the end of the list. I think, it's a correct approach, as we
always want our(Samba4) headers to take precedence. This patch also tries
to take care about situations when srcdir != buildir, but that's too moving
target.

With regards,
Timur.
-------------- next part --------------
--- build/smb_build/cflags.pm.orig	Tue Sep 11 01:14:24 2007
+++ build/smb_build/cflags.pm	Tue Sep 11 03:46:55 2007
@@ -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 @@
 
 	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 = $_;
@@ -49,4 +58,5 @@
 
 	print __FILE__.": creating $file\n";
 }
+
 1;


More information about the samba-technical mailing list