Created
July 9, 2024 12:48
-
-
Save imaami/eb23ee79afb9f934dd13b1b48d6020a8 to your computer and use it in GitHub Desktop.
Experimenting with compiler introspection in GNU Make
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: default gnu23 gnu23.mk | |
default:| gnu23; $(info $(CC) -std=$(gnu23)) | |
gnu23:| gnu23.mk; $(eval include gnu23.mk) | |
gnu23.mk: gnu23.h; @$(CC) -E -xc -P $< >$@ | |
gnu23.h: $(lastword $(MAKEFILE_LIST)); $(call cstd,$@) @: | |
override cstd =$(file >$1,$(.cstd)) | |
override .cstd =$(call \ | |
P,#ifdef __clang_major__) $(call \ | |
L,#if __clang_major__ > 17) $(call \ | |
L,override gnu23 := gnu23) $(call \ | |
L,#elif __clang_major__ > 8) $(call \ | |
L,override gnu23 := gnu2x) $(call \ | |
L,#endif) $(call \ | |
L,#elif __GNUC__ > 13) $(call \ | |
L,override gnu23 := gnu23) $(call \ | |
L,#elif __GNUC__ > 8) $(call \ | |
L,override gnu23 := gnu2x) $(call \ | |
L,#endif) | |
override P = $(call .P,$(value 1)) | |
override .P = $(value 1) | |
override L = $(call .L,$(value 1)) | |
override .L = $n$(value 1) | |
override define n:= | |
endef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment