Enhance makefile to autodetect if AVOIDCOMBINE is needed.

This commit is contained in:
Kevin O'Connor 2009-01-25 16:11:27 -05:00
parent d99908e511
commit 231f710715
2 changed files with 28 additions and 1 deletions

View File

@ -54,10 +54,14 @@ vpath %.S src
################ Build rules
ifndef AVOIDCOMBINE
AVOIDCOMBINE=$(shell CC=$(CC) tools/test-combine.sh)
endif
# Do a whole file compile - two methods are supported. The first
# involves including all the content textually via #include
# directives. The second method uses gcc's "-combine" option.
ifdef AVOIDCOMBINE
ifeq "$(AVOIDCOMBINE)" "1"
define whole-compile
@echo " Compiling whole program $3"
$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c

23
tools/test-combine.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
# Script to test if gcc's -combine option works properly.
TMPFILE1=out/tmp_testcompile1.c
TMPFILE2=out/tmp_testcompile.o
mkdir -p out
cat - > $TMPFILE1 <<EOF
struct ts { union { int u1; struct { int u2; }; }; };
void t1(struct ts *r);
EOF
$CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE2 > /dev/null 2>&1
if [ $? -eq 0 ]; then
#echo " Setting AVOIDCOMBINE=0" > /dev/fd/2
echo 0
else
echo " Enabling AVOIDCOMBINE=1" > /dev/fd/2
echo 1
fi
rm -f $TMPFILE1 $TMPFILE2