+ -e 's/mips-.*/mips/' \
+ -e 's/mipsel-.*/mipsel/' \
+ -e 's/cris.*/cris/' \
+ )
+endif
+
+# A nifty macro to make testing gcc features easier, but note that everything
+# that uses this _must_ use := or it will be re-evaluated everytime it is
+# referenced.
+ifeq ($(strip $(BUILD_VERBOSE)),2)
+VERBOSE_CHECK_CC=echo CC=\"$(1)\" check_cc $(2) >&2;
+endif
+check_cc=$(shell \
+ $(VERBOSE_CHECK_CC) \
+ if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
+ echo "int i;" > ./conftest.c; \
+ if $(1) $(2) -c -o conftest.o conftest.c > /dev/null 2>&1; \
+ then echo "$(2)"; else echo "$(3)"; fi ; \
+ rm -f conftest.c conftest.o; \
+ fi)
+
+ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
+check_cc:=
+endif
+
+# A not very robust macro to check for available ld flags
+ifeq ($(strip $(BUILD_VERBOSE)),2)
+VERBOSE_CHECK_LD=echo LD=\"$(1)\" check_ld $(2) >&2;
+endif
+check_ld=$(shell \
+ $(VERBOSE_CHECK_LD) \
+ if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
+ $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && \
+ echo "-Wl,$(2)" ; \
+ fi)
+
+ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
+check_ld:=
+endif
+
+# A not very robust macro to check for available strip flags
+ifeq ($(strip $(BUILD_VERBOSE)),2)
+VERBOSE_CHECK_STRIP=echo STRIPCMD=\"$(1)\" check_strip $(2) >&2;
+endif
+check_strip=$(shell \
+ $(VERBOSE_CHECK_STRIP) \
+ if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
+ echo "int i;" > ./conftest.c ; \
+ $(CC) -c -o conftest.o conftest.c > /dev/null 2>&1 ; \
+ $(1) $(2) conftest.o > /dev/null 2>&1 && \
+ echo "$(1) $(2)" || echo "$(3)"; \
+ rm -f conftest.c conftest.o > /dev/null 2>&1 ; \
+ fi)
+
+ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
+check_strip:=
+endif
+
+
+# Select the compiler needed to build binaries for your development system
+HOSTCC = gcc
+HOSTCFLAGS:=$(call check_cc,$(HOSTCC),-Wall,)
+HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-Wstrict-prototypes,)
+HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-O2,)
+HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-fomit-frame-pointer,)
+
+LD_WHOLE_ARCHIVE:=$(shell echo "int i;" > conftest.c ; \
+ $(CC) -c -o conftest.o conftest.c ; \
+ echo "int main(void){return 0;}" > conftest_main.c ; \
+ $(CC) -c -o conftest_main.o conftest_main.c ; \
+ $(AR) $(ARFLAGS) conftest.a conftest.o ; \
+ $(CC) -Wl,--whole-archive conftest.a -Wl,--no-whole-archive \
+ conftest_main.o -o conftest > /dev/null 2>&1 \
+ && echo "-Wl,--whole-archive" ; \
+ rm conftest_main.o conftest_main.c conftest.o conftest.c \
+ conftest.a conftest > /dev/null 2>&1 ; )
+ifneq ($(findstring whole-archive,$(LD_WHOLE_ARCHIVE)),)
+LD_NO_WHOLE_ARCHIVE:= -Wl,--no-whole-archive
+endif
+
+LD_START_GROUP:=$(shell echo "int bar(void){return 0;}" > conftest.c ; \
+ $(CC) -c -o conftest.o conftest.c ; \
+ echo "int main(void){return bar();}" > conftest_main.c ; \
+ $(CC) -c -o conftest_main.o conftest_main.c ; \
+ $(AR) $(ARFLAGS) conftest.a conftest.o ; \
+ $(CC) -Wl,--start-group conftest.a conftest_main.o -Wl,--end-group \
+ -o conftest > /dev/null 2>&1 && echo "-Wl,--start-group" ; \
+ rm conftest_main.o conftest_main.c conftest.o conftest.c \
+ conftest.a conftest > /dev/null 2>&1 ; )
+ifneq ($(findstring start-group,$(LD_START_GROUP)),)
+LD_END_GROUP:= -Wl,--end-group
+endif
+
+CHECKED_LDFLAGS := $(call check_ld,$(LD),--warn-common,)
+#CHECKED_LDFLAGS := $(call check_ld,$(LD),-static-libgcc,)
+
+# Pin CHECKED_CFLAGS with := so it's only evaluated once.
+CHECKED_CFLAGS:=$(call check_cc,$(CC),-Wall,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-funsigned-char,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-mmax-stack-frame=256,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-fno-builtin-strlen,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-finline-limit=0,)
+CHECKED_CFLAGS+=$(call check_cc,$(CC),-static-libgcc,)
+
+# Preemptively pin this too.
+PROG_CFLAGS:=
+