Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active February 8, 2021 23:50
Show Gist options
  • Save CMCDragonkai/75157d37e6907b6fbaa02b8f04598d87 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/75157d37e6907b6fbaa02b8f04598d87 to your computer and use it in GitHub Desktop.
Runtime Conditionals in Makefiles
# this phony target shows how to use a conditional within a recipe
# this conditional is executed at "run-time"
# rather than at "build-time" which is when the Makefile `ifeq` are evaluated
# notice how everything in the conditional must be joined up as one line
test_conditional:
@echo 'NESTED CONDITIONAL'
[ "$$(echo 1)" -lt 2 ] && { \
echo 'oh no'; \
exit 1; \
} || { \
[ -f issomefilethere ] && { \
echo 'true'; \
} || { \
echo 'false'; \
} \
}
.PHONY test_conditional
@geovra
Copy link

geovra commented May 21, 2020

thank you for sharing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment