Makefile conditional include
Yes, there is a cleaner way. You can test for the existence of a file with the wildcard
function, and then use ifeq
/endif
to set up the appropriate CFLAGS
. If you stick the audio-related flags into something like AUDIO_CFLAGS
then you can automatically include the correct set of flags throughout the Makefile.
It'll look something like this:
OSS_CONF_FILE := $(strip $(wildcard /etc/oss.conf))
ifeq ($OSS_CONF_FILE,)
AUDIO_CFLAGS = "-I${ALSALIBDIR} -DUSE_ALSA"
else
AUDIO_CFLAGS = "-I${OSSLIBDIR} -DUSE_OSS"
endif
sample_build_rule:
$(CC) $(CFLAGS) $(AUDIO_CFLAGS) ...
One suggest: use -include
(then it won't warn + quit on failure). I don't know if I ever quite got this syntax to work myself, though.
Another hack could be something along the lines of: DUMMY_VAR := $(shell ... )
to execute arbitrary code. I think this is even less likely to work.
Other than that, I don' think this is possible. When I looked into a similar problem recently, I found that I can't get make to run arbitrary shell commands during the makefile creation process.