mk/compile.mk: add cc-option macro

Adds a macro to test the availability of a compiler option. For example:

 $(call cc-option,-opt1,-opt2)

...will evaluate to '-opt1' if the C compiler supports option -opt1, or
'-opt2' otherwise. The second argument (-opt2) is optional.

Signed-off-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/mk/compile.mk b/mk/compile.mk
index d270502..ddeb408 100644
--- a/mk/compile.mk
+++ b/mk/compile.mk
@@ -17,6 +17,15 @@
 # Disable all builtin rules
 .SUFFIXES:
 
+__cc-option = $(if $(shell $(CC$(sm)) $(1) -c -x c /dev/null -o /dev/null 2>&1 >/dev/null),$(2),$(1))
+_cc-opt-cached-var-name = cached-cc-option$(subst =,~,$(strip $(1)))$(subst $(empty) $(empty),,$(CC$(sm)))
+define _cc-option
+$(eval _cached := $(call _cc-opt-cached-var-name,$1))
+$(eval $(_cached) := $(if $(filter $(origin $(_cached)),undefined),$(call __cc-option,$(1),$(2)),$($(_cached))))
+$($(_cached))
+endef
+cc-option = $(strip $(call _cc-option,$(1),$(2)))
+
 comp-cflags$(sm) = -std=gnu99
 comp-aflags$(sm) =
 comp-cppflags$(sm) =