Subject: pkg/26143: Darwin bootstrap: interference from /usr/local/include
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <jbernard@mines.edu>
List: pkgsrc-bugs
Date: 07/02/2004 14:05:02
>Number:         26143
>Category:       pkg
>Synopsis:       Darwin bootstrap: interference from /usr/local/include
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 02 20:06:01 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jim Bernard
>Release:        pkgsrc as of Fri Jul  2 09:21:20 UTC 2004
>Organization:
>Environment:
Mac OS X 10.3.4
System: Mac OS X 10.3.4
Architecture: ppc
Machine: ppc
>Description:
	Apple's cpp checks for include files in /usr/local/include before
	checking "real" system directories (curiously, there doesn't seem
	to be an analogous issue with the linker).  I ran into a situation
	where someone had installed a copy of db4 in /usr/local, so that
	/usr/local/include/db.h overrode /usr/include/db.h, causing the
	pkgsrc bootstrap to fail (some symbols were not defined in the db4
	version).

	I believe this will also bite us in package builds.

>How-To-Repeat:
	On a Mac OS X 10.3 system:

	  mkdir -p /usr/local/include
	  touch /usr/local/include/db.h
	  try to bootstrap pkgsrc---it fails when compiling pkgdb.c.

	(Note: this isn't what I did, but I assume it will exhibit
	a similar failure.)

	One can discover the final include path used by the compiler
	with "-v" (in gcc 3.3).  So, repeating the failed compilation by
	hand like:

	  env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin \
	    gcc -v -E -H -DHAVE_CONFIG_H -DDEF_LOG_DIR=\"/usr/pkg/pkgdb\" \
	    -DTAR_CMD=\"/usr/pkg/bin/tar\" -DFTP_CMD=\"/usr/pkg/bin/ftp\" \
	    -I../libnbcompat -I../../libnbcompat -I. -I. -g -O2 -c pkgdb.c

	we find the final include path (after elimination of nonexistent
	directories) to be:

	  ../../libnbcompat
	  .
	  /usr/local/include
	  /usr/include/gcc/darwin/3.3
	  /usr/include

	the last 3 being the system default directories (these are what
	you find when executing "gcc -v -E" on an empty source file).

	  Also the "-H" gives a list of header files used, which in my case
	included the interfering /usr/local/include/db.h, instead of
	/usr/include/db.h.

>Fix:
	We can reconfigure the system include path sans /usr/local/include
	via the compiler flags:
	  -nostdinc -isystem /usr/include/gcc/darwin/default -isystem /usr/include

	In the bootstrap patch below, I did this by introducing
	BSTRAP_CPPFLAGS into CPPFLAGS wherever it is explicitly specified
	in the script, with the former defined as above for Darwin.  I
	also added CPPFLAGS (with BSTRAP_CPPFLAGS incorporated) to the
	configure command for bmake, so the flags show up in CFLAGS in
	work/bmake/makefile.boot.  I think this should work on OS X 10.2
	(because of the use of "default" in the path name, instead of
	"3.3"---default is a link to the default compiler version on the
	system), but I haven't tested it.

	Given that this is a fairly general problem, it's probably best
	to add these flags to CPPFLAGS generally, so I've also included
	a patch for mods/mk/Darwin.sys.mk that adds them.  This wasn't
	necessary to fix my specific problem, but I believe it will be
	necessary for package builds.

	Note that because of the change to Darwin.sys.mk, once bmake
	is built and the .mk files constructed, it should only be
	necessary to add BSTRAP_CPPFLAGS wherever CPPFLAGS is explicitly
	specified in the bootstrap script, since the necessary flags
	should be picked up from the conditional assignment in sys.mk,
	unless an explicit specification overrides that in the script
	(well, really in the makefiles generated by the configure
	runs executed by the script).  The bootstrap script patch is
	constructed with that in mind.

--- bootstrap-dist	Mon May 10 21:05:37 2004
+++ bootstrap	Fri Jul  2 13:20:54 2004
@@ -199,6 +199,7 @@
 	set_opsys=no
 	check_prog mtreeprog mtree
 	machine_arch=`uname -p`
+	BSTRAP_CPPFLAGS="-nostdinc -isystem /usr/include/gcc/darwin/default -isystem /usr/include ${BSTRAP_CPPFLAGS}"
 	;;
 FreeBSD)
 	root_group=wheel
@@ -538,7 +539,7 @@
 fi
 
 echo_msg "Installing bmake"
-run_cmd "(cd $wrkdir/bmake; $shprog ./configure --prefix=$prefix --with-default-sys-path=$prefix/share/mk $configargs && make -f makefile.boot bootstrap && env BINDIR=$prefix/bin MANDIR=$prefix/man $BSTRAP_ENV ./bmake -f Makefile install)"
+run_cmd "(cd $wrkdir/bmake; CPPFLAGS="\'${BSTRAP_CPPFLAGS}\'" $shprog ./configure --prefix=$prefix --with-default-sys-path=$prefix/share/mk $configargs && make -f makefile.boot bootstrap && env BINDIR=$prefix/bin MANDIR=$prefix/man $BSTRAP_ENV ./bmake -f Makefile install)"
 
 # build libnbcompat
 echo_msg "Building libnbcompat"
@@ -577,7 +578,7 @@
 case "$need_pax" in
 yes)	echo_msg "Installing pax"
 	copy_src ../archivers/pax/files pax
-	run_cmd "(cd $wrkdir/pax; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat' LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
+	run_cmd "(cd $wrkdir/pax; env $BSTRAP_ENV CPPFLAGS="\'-I../libnbcompat ${BSTRAP_CPPFLAGS}\'" LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
 	echo "PAX=$prefix/bin/pax" >> ${MKCONF_EXAMPLE}
 	pkg_install_args="$pkg_install_args --with-pax=$prefix/bin/pax --with-tar=$prefix/bin/tar"
 	;;
@@ -590,7 +591,7 @@
 case "$need_mtree" in
 yes)	echo_msg "Installing mtree"
 	copy_src ../pkgtools/mtree/files mtree
-	run_cmd "(cd $wrkdir/mtree; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat' LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
+	run_cmd "(cd $wrkdir/mtree; env $BSTRAP_ENV CPPFLAGS="\'-I../libnbcompat ${BSTRAP_CPPFLAGS}\'" LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
 	pkg_install_args="$pkg_install_args --with-mtree=$prefix/sbin/mtree"
 	;;
 *)	pkg_install_args="$pkg_install_args --with-mtree=$mtreeprog"
@@ -613,7 +614,7 @@
 if [ "$prefix" = "/usr" ]; then
 	pkg_install_mandir="$prefix/share/man"
 fi
-run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat -I../../libnbcompat' LDFLAGS='-L../libnbcompat -L../../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir --with-pkgdbdir=$pkgdbdir --mandir=$pkg_install_mandir $pkg_install_args && $prefix/bin/bmake && $prefix/bin/bmake install)"
+run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV CPPFLAGS="\'-I../libnbcompat -I../../libnbcompat ${BSTRAP_CPPFLAGS}\'" LDFLAGS='-L../libnbcompat -L../../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir --with-pkgdbdir=$pkgdbdir --mandir=$pkg_install_mandir $pkg_install_args && $prefix/bin/bmake && $prefix/bin/bmake install)"
 
 # all's ready, install the man page
 echo_msg "Installing packages(7) man page"


--- mods/mk/Darwin.sys.mk-dist	Thu Mar 11 06:03:59 2004
+++ mods/mk/Darwin.sys.mk	Fri Jul  2 12:59:13 2004
@@ -46,7 +46,7 @@
 
 CPP?=		cpp
 NOLINT=		1
-CPPFLAGS?=
+CPPFLAGS?=	-nostdinc -isystem /usr/include/gcc/darwin/default -isystem /usr/include
 
 MK_DEP?=	mkdeps.sh -N
 
>Release-Note:
>Audit-Trail:
>Unformatted: