Created
March 31, 2022 17:18
-
-
Save mjy9088/0a9cde6e79b72591afb55b0edbf291b0 to your computer and use it in GitHub Desktop.
config.mk generator
This file contains hidden or 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
Q := $(if $(filter 1,$(V) $(VERBOSE)),,@) | |
NAME := config.mk | |
$(NAME): variable_cc.mk variable_diagnostics.mk | |
$Qrm -f tmp_$@ | |
$Qcat variable_*.mk > tmp_$@ | |
$Qmv tmp_$@ $@ | |
$Qecho "Configure OK!" | |
$Qmake --no-print-directory clean | |
all: $(NAME) | |
clean: | |
$Qrm -f tmp_* | |
fclean: clean | |
$Qrm -rf $(NAME) variable_*.mk | |
re: fclean all | |
.PHONY: all clean fclean re | |
SUPPORTED_CC := $(foreach V,14 13 12 11 10 9 8 7,clang-$V) clang $(foreach V,11 10 9 8 7,gcc-$V) gcc | |
variable_cc.mk: | |
$Qrm -f $@ | |
$Qecho "int main() {}" > [email protected] | |
$Q$Q${foreach CC,$(SUPPORTED_CC),($(CC) -c [email protected] -o [email protected] && echo "CC := $(CC)" >> $@) || }(echo "Failed to find any supported C compiler." && false) | |
$Qrm -f [email protected] [email protected] | |
.PHONY: variable_diagnostics | |
# TODO: add diagnostics https://clang.llvm.org/docs/DiagnosticsReference.html#w-pragma-messages | |
DIAGNOSTICS_TO_USE := all extra extra-tokens ambiguous-member-template bind-to-temporary-copy | |
variable_diagnostics.mk: variable_cc.mk | |
$Qrm -f tmp_$@ | |
$Qecho "int main() {}" > [email protected] | |
$Qecho "DIAGNOSTICS :=" > tmp_$@ | |
$Q$Q(sh -c "\$$(cut -c 7- < variable_cc.mk) -Werror -Wunknown-warning-option -Wthis-should-not-be-done-because-this-is-an-unknown-option -c [email protected] -o [email protected]" && echo "-Wunknown-warning-option not supported, skip detecting supported diagnostics") || (${foreach DIAGNOSTICS,$(DIAGNOSTICS_TO_USE),sh -c "\$$(cut -c 7- < variable_cc.mk) -Werror -Wunknown-warning-option -W$(DIAGNOSTICS) -c [email protected] -o [email protected]" && echo "DIAGNOSTICS += $(DIAGNOSTICS)" >> tmp_$@ ; }) | |
$Qmv tmp_$@ $@ | |
$Qrm -f [email protected] [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment