I want to add another option to the CFLAGS make variable, depending on the result of a shell command that i want to execute outside of a recipe in my "configuration" section of the makefile. This is what i have come up with:
GCC_VERSION := $(shell gcc -dumpversion); \
if [[ ${GCC_VERSION} > 5.0 ]] ; then \
CFLAGS += -D _POSIX_C_SOURCE=199309L; \
fi
At first i execute the command with the shell make function as you see above. If i execute the above it doesn't add this define flag. I intentionally do this on linux with GCC Version 5.4.0. I believe this is wrong because then i have to create a new shell to execute the conditional statement. In that new shell though the GCC_VERSION variable will not exist. I could be wrong though.
If i do like this then (all in one shell):
$(shell GCC_VERSION=$(gcc -dumpversion); \
if [[ ${GCC_VERSION} > 5.0 ]] ; then \
CFLAGS += -D _POSIX_C_SOURCE=199309L; \
fi)
i get error:
*** recipe commences before first target. Stop.
Yeah, very confusing.
If someone could help i would appreciate it. Thanks.
if
follows thebash
syntax, not themake
syntax. – xhienne Sep 20 '17 at 21:20