Ensure HTSlib prefers its own headers when being compiled #1078
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The full preprocessor search path for #include "..." is typically:
It's easy to oversimplify (1) as “the current directory” but that's misleading when the compiler's PWD is always the top-level htslib source directory but the “current directory of the
#includedirective” might be one of the subdirectories.When a top-level *.[ch] file does
#include "htslib/foo.h", the nearby header file within the source tree is found due to (1). When a file in a subdirectory (htslib/*.h, cram/*.[ch], or test/*.c) does the same#include, the nearby header file is intended to be found due to (3) via the Makefile's hard-coded-I.—.here being the compiler process's $PWD, i.e., the top-level HTSlib source directory.However the latter can be subverted if there is an "htslib" directory containing foo.h in $CPATH, $C_INCLUDE_PATH, or on the command line prior to the hard-coded$CPATH/etc or by adding a -I option to $ (CFLAGS) (rather than $(CPPFLAGS)). One reason we have found this hard to reproduce in the past is that we have naturally added dummy
-I.. This will be the case if users have made a previous HTSlib installation accessible via-Ioptions to CPPFLAGS, but that comes later in the search path than-I.. Naive users OTOH are likely to add their dummy-Ioptions to CFLAGS.Avoid this and fix #347 by adding
../to #includes in subdirectories (and always using""rather than<>), so that includes within HTSlib (even from the source subdirectories) are found due to (1).This PR is split into three commits: for htslib/*.h, for cram/*.h, and for all other *.h files. The question is whether to apply 1, 2, or all 3 commits.
The first commit covers the public headers, which is the likely scenario of “oops I added my previous HTSlib installation to
$C_INCLUDE_PATH”.Adding the second commit extends this to the private cram/*.h headers. See the commit messages for details; note that for a (long) time Debian packaged and shipped these headers alongside htslib/*.h.
Adding the third commit as well extends this to all intra-HTSlib inclusions, so they're all similarly somewhat uglified. With this, the only
#includes in HTSlib still depending on (3)'s hard-coded-I.are each *.c file's#include <config.h>.Probably the answer is either to apply 1 (for the minimal change) or all 3 commits (for consistency).