2
votes

I have found an unusual C makefile setup that relies upon a deprecated feature of GCC that appears to have no modern replacement.

This system needs to preprocess or 'cook' the local header files before including them. The makefiles take care of this and put the cooked versions in local './prepared/' directories. The header files are included as normal in the c using their normal names eg #include "name.h". The system simply needs './prepared/' to occur in the GCC header file search path before '.'.

Gcc used to offer the -I- option to remove the default '.' and allow the addition of header search path entries before it, but this option is deprecated.

From the gcc docs:

GCC looks for headers requested with #include "file" first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.h contains #include "types.h", GCC looks for types.h first in /usr/include/sys, then in its usual search path.

Is there no way to control the C header search path properly in gcc any more? Or is there another sensible way forward? I don't want to use a deprecated feature that may disappear. Right now I am sadly filtering the gcc deprecated feature warning messages to hide them. I didn't create the build environment, and it would be unpopular to solve the problem in a way that breaks the 'cookery'.

1
This Makefile sounds awful.Jonathon Reinhart
Well I think break the cookery and say it had to be broken if you want the program to still work or just leave out it will eventually disappear and leave it for the poor programmer that comes after you :)jgr208
What exactly were they doing to the system header files? That sounds completely unnecessary.Jonathon Reinhart
What exactly were they doing to the system header files? -nothing. They are cooking the programs own header files; not system ones. I.e. #include "name.h" and not #include <name.h>. Mostly they are adding markup that is not possible with the c preprocessor.greg20

1 Answers

0
votes

As far as I can tell, GCC provides no other means than the one you've described to avoid having each source file's directory first in the include search path used when compiling that file.

The best solution is probably to fix the headers and build system to get rid of header cooking. Such a scheme is very unusual -- pretty much everybody else gets by without.

If you must continue to rely on header cooking, then you probably should move the original headers to a directory that is not in the include search path. For example, create an "include" subdirectory of the main source directory, and put them there.

Edited to add: Another alternative is to switch from the quoted include style to the angle-bracketed include style, and rely on -I options to set up the needed internal include directories however you want.