When processing configure time checks, there is a Samba-specific hook activated for each check being made. This hooks looks into CPPPATH and LIBPATH, and, if the default path supplied by configure option does not present there, adds those to respective lists in those variables. I do not know, why, but new paths are prepended to this list instead of being appended to it. As a result, the results of previous configure checks are not reliable anymore, because they were made in a different environment, not looking at the directories added later. This could (and break) some setups, especially on *BSD, when base system and additional packages install headers and/or libraries with the same name.
The patch below reverses the order of paths being appended. I suspect this could be wrong, because this seems an obvious decision for initial implementation, but there are no comments in the code describing the reasons to do this either way.
Created attachment 8892 [details]
Patch to fix issue
Created attachment 8901 [details]
Patch to fix issue via git format-patch