@@ -374,10 +374,25 @@ if test "$PHP_MONGODB" != "no"; then
374374 PHP_MONGODB_ADD_SOURCES([ src/libmongoc/src/libbson/src/jsonsl/] , $PHP_MONGODB_JSONSL_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS)
375375 PHP_MONGODB_ADD_SOURCES([ src/libmongoc/src/libmongoc/src/mongoc/] , $PHP_MONGODB_MONGOC_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS)
376376
377- dnl Add the build directories as include paths to some generated files
378- PHP_ADD_INCLUDE([ $PWD/src/libmongoc/src/common/src] )
379- PHP_ADD_INCLUDE([ $PWD/src/libmongoc/src/libbson/src] )
380- PHP_ADD_INCLUDE([ $PWD/src/libmongoc/src/libmongoc/src] )
377+ dnl TODO: Use $ext_builddir/$ext_srcdir once this block can move after PHP_NEW_EXTENSION.
378+ dnl $ext_builddir and $ext_srcdir are set by PHP_NEW_EXTENSION, but PHP_ADD_INCLUDE
379+ dnl and PHP_MONGODB_ADD_SOURCES calls must precede PHP_NEW_EXTENSION, so the whole
380+ dnl block cannot be deferred. PHP_EXT_BUILDDIR/PHP_EXT_SRCDIR are M4 macros that
381+ dnl are always available and provide equivalent values without that constraint.
382+ dnl
383+ dnl PHP_EXT_BUILDDIR expands to the extension's directory relative to the build
384+ dnl root: "ext/mongodb" for PHP in-tree builds, "." for phpize builds. Pairing
385+ dnl it with $abs_builddir (the absolute path to wherever configure was invoked)
386+ dnl produces the correct absolute path to the generated config headers regardless
387+ dnl of build layout. Using $PWD here breaks PHP in-tree builds because $PWD is
388+ dnl the PHP source/build root, not the extension's subdirectory within it.
389+ php_mongodb_ext_builddir=PHP_EXT_BUILDDIR(mongodb)
390+
391+ dnl Add the build directories as include paths so the compiler finds generated
392+ dnl config headers (common-config.h, bson/config.h, mongoc-config.h, etc.).
393+ PHP_ADD_INCLUDE([ $abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/common/src] )
394+ PHP_ADD_INCLUDE([ $abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/libbson/src] )
395+ PHP_ADD_INCLUDE([ $abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/libmongoc/src] )
381396
382397 PHP_MONGODB_ADD_INCLUDE([ src/libmongoc/src/common/src/] )
383398 PHP_MONGODB_ADD_INCLUDE([ src/libmongoc/src/uthash/] )
@@ -399,16 +414,17 @@ if test "$PHP_MONGODB" != "no"; then
399414 PHP_MONGODB_ADD_BUILD_DIR([ src/libmongoc/src/kms-message/src/] )
400415 fi
401416
402- dnl TODO: Use $ext_srcdir if we can move this after PHP_NEW_EXTENSION
403- ac_config_dir=PHP_EXT_SRCDIR(mongodb)
404-
417+ dnl Write generated config headers into the extension's build directory
418+ dnl (${php_mongodb_ext_builddir}/... relative to the configure invocation directory).
419+ dnl For standalone out-of-source builds this stays in the build tree; for
420+ dnl PHP in-tree builds it lands under ext/mongodb/ rather than the PHP root.
405421 AC_CONFIG_FILES ( [
406- src/libmongoc/src/common/src/common-config.h
407- src/libmongoc/src/libbson/src/bson/config.h
408- src/libmongoc/src/libbson/src/bson/version.h
409- src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
410- src/libmongoc/src/libmongoc/src/mongoc/mongoc-config-private.h
411- src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
422+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/common/src/common-config.h
423+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/libbson/src/bson/config.h
424+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/libbson/src/bson/version.h
425+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
426+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/libmongoc/src/mongoc/mongoc-config-private.h
427+ ${php_mongodb_ext_builddir}/ src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
412428 ] )
413429
414430 if test "x$bundled_utf8proc" = "xyes"; then
@@ -423,7 +439,7 @@ if test "$PHP_MONGODB" != "no"; then
423439 PHP_MONGODB_ADD_SOURCES([ src/libmongoc/src/zlib-1.3.1/] , $PHP_MONGODB_ZLIB_SOURCES, $PHP_MONGODB_ZLIB_CFLAGS)
424440 PHP_MONGODB_ADD_INCLUDE([ src/libmongoc/src/zlib-1.3.1/] )
425441 PHP_MONGODB_ADD_BUILD_DIR([ src/libmongoc/src/zlib-1.3.1/] )
426- AC_CONFIG_FILES ( [ ${ac_config_dir }/src/libmongoc/src/zlib-1.3.1/zconf.h] )
442+ AC_CONFIG_FILES ( [ ${php_mongodb_ext_builddir }/src/libmongoc/src/zlib-1.3.1/zconf.h] )
427443 fi
428444
429445 if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
@@ -462,7 +478,7 @@ if test "$PHP_MONGODB" != "no"; then
462478 PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/kms-message/src/] )
463479
464480 AC_CONFIG_FILES ( [
465- ${ac_config_dir }/src/libmongocrypt/src/mongocrypt-config.h
481+ ${php_mongodb_ext_builddir }/src/libmongocrypt/src/mongocrypt-config.h
466482 ] )
467483 fi
468484 fi
0 commit comments