Skip to content

Instantly share code, notes, and snippets.

@andy5995
Created February 4, 2023 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy5995/89a53cde95a50b93ffce3cd1f57fc357 to your computer and use it in GitHub Desktop.
Save andy5995/89a53cde95a50b93ffce3cd1f57fc357 to your computer and use it in GitHub Desktop.
Check for supported compiler flags in a Makefile
Minor adaptation of example at https://stackoverflow.com/a/61634784/6838037
CHECK_CC_FLAGS := -Wall -Wextra -I. --std=gnu89 -fPIC -flto=auto
define check_cc_flag
$(shell echo 'int main() { return 0; }' | $(CC) $(1) -xc - 2>/dev/null && echo $(1))
endef
HAVE_FLAGS += $(foreach flag,$(CHECK_CC_FLAGS),$(call check_cc_flag,$(flag)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment