mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
Makefile: fix and simplify test program compilations
This was totally broken due to the make's shell function's temporal behavior. quote from the gnu make documentation (http://www.gnu.org/s/hello/manual/make/Shell-Function.html): "The commands run by calls to the shell function are run when the function calls are expanded" we have used the shell function to echo the test programs to a file. the file name used was equal for all tests and was overwritten for each test. the result was that all tests (in a single target?) used the last test program because the echoing of the test programs was done before all test compilations(!) see my mail for details: http://lists.gnu.org/archive/html/bug-make/2011-08/msg00010.html also the branching for testing ifeq ($(CONFIG_FT2232_SPI), yes) was unnecessarily complicated. in my approach here i am using verbatim variables (allows to define even complex test programs in the makefile without jumping through hoops) that get exported to environment variables (via "export", reference afterwards with "$$<varname>"). i have also added the missing redirection of stderr to the compiler test and changed the definition of ARCH to use simple expansion (:=). the latter is still wrong, because it uses $(CC) before we check if a compiler is installed... makes the compiler check pretty much useless. The simple expansion just reduces the number of errors printed to 1. Corresponding to flashrom svn r1416. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
33670ba5c4
commit
56787086e3
104
Makefile
104
Makefile
@ -38,7 +38,7 @@ CFLAGS += -Werror
|
||||
endif
|
||||
|
||||
# Determine the destination processor architecture
|
||||
override ARCH = $(strip $(shell LC_ALL=C $(CC) -E arch.h|grep -v '^\#'))
|
||||
override ARCH := $(strip $(shell LC_ALL=C $(CC) -E arch.h|grep -v '^\#'))
|
||||
|
||||
# FIXME We have to differentiate between host and target OS architecture.
|
||||
OS_ARCH ?= $(shell uname)
|
||||
@ -531,11 +531,23 @@ distclean: clean
|
||||
strip: $(PROGRAM)$(EXEC_SUFFIX)
|
||||
$(STRIP) $(STRIP_ARGS) $(PROGRAM)$(EXEC_SUFFIX)
|
||||
|
||||
# to define test programs we use verbatim variables, which get exported
|
||||
# to environment variables and are referenced with $$<varname> later
|
||||
|
||||
define COMPILER_TEST
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
return 0;
|
||||
}
|
||||
endef
|
||||
export COMPILER_TEST
|
||||
|
||||
compiler: featuresavailable
|
||||
@printf "Checking for a C compiler... "
|
||||
@$(shell ( echo "int main(int argc, char **argv)"; \
|
||||
echo "{ (void) argc; (void) argv; return 0; }"; ) > .test.c )
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null && \
|
||||
@echo "$$COMPILER_TEST" > .test.c
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null 2>&1 && \
|
||||
echo "found." || ( echo "not found."; \
|
||||
rm -f .test.c .test$(EXEC_SUFFIX); exit 1)
|
||||
@rm -f .test.c .test$(EXEC_SUFFIX)
|
||||
@ -545,15 +557,25 @@ compiler: featuresavailable
|
||||
( echo "unknown. Aborting."; exit 1)
|
||||
@printf "%s\n" '$(ARCH)'
|
||||
|
||||
define LIBPCI_TEST
|
||||
/* Avoid a failing test due to libpci header symbol shadowing breakage */
|
||||
#define index shadow_workaround_index
|
||||
#include <pci/pci.h>
|
||||
struct pci_access *pacc;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
pacc = pci_alloc();
|
||||
return 0;
|
||||
}
|
||||
endef
|
||||
export LIBPCI_TEST
|
||||
|
||||
ifeq ($(CHECK_LIBPCI), yes)
|
||||
pciutils: compiler
|
||||
@printf "Checking for libpci headers... "
|
||||
@# Avoid a failing test due to libpci header symbol shadowing breakage
|
||||
@$(shell ( echo "#define index shadow_workaround_index"; \
|
||||
echo "#include <pci/pci.h>"; \
|
||||
echo "struct pci_access *pacc;"; \
|
||||
echo "int main(int argc, char **argv)"; \
|
||||
echo "{ (void) argc; (void) argv; pacc = pci_alloc(); return 0; }"; ) > .test.c )
|
||||
@echo "$$LIBPCI_TEST" > .test.c
|
||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null 2>&1 && \
|
||||
echo "found." || ( echo "not found."; echo; \
|
||||
echo "Please install libpci headers (package pciutils-devel)."; \
|
||||
@ -588,41 +610,47 @@ featuresavailable:
|
||||
@false
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FT2232_SPI), yes)
|
||||
define FTDI_TEST
|
||||
#include <ftdi.h>
|
||||
struct ftdi_context *ftdic = NULL;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
return ftdi_init(ftdic);
|
||||
}
|
||||
endef
|
||||
export FTDI_TEST
|
||||
|
||||
define UTSNAME_TEST
|
||||
#include <sys/utsname.h>
|
||||
struct utsname osinfo;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
uname (&osinfo);
|
||||
return 0;
|
||||
}
|
||||
endef
|
||||
export UTSNAME_TEST
|
||||
|
||||
features: compiler
|
||||
@echo "FEATURES := yes" > .features.tmp
|
||||
ifeq ($(CONFIG_FT2232_SPI), yes)
|
||||
@printf "Checking for FTDI support... "
|
||||
@$(shell ( echo "#include <ftdi.h>"; \
|
||||
echo "struct ftdi_context *ftdic = NULL;"; \
|
||||
echo "int main(int argc, char **argv)"; \
|
||||
echo "{ (void) argc; (void) argv; return ftdi_init(ftdic); }"; ) > .featuretest.c )
|
||||
@echo "$$FTDI_TEST" > .featuretest.c
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(FTDILIBS) $(LIBS) >/dev/null 2>&1 && \
|
||||
( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) || \
|
||||
( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp )
|
||||
@printf "Checking for utsname support... "
|
||||
@$(shell ( echo "#include <sys/utsname.h>"; \
|
||||
echo "struct utsname osinfo;"; \
|
||||
echo "int main(int argc, char **argv)"; \
|
||||
echo "{ (void) argc; (void) argv; uname (&osinfo); return 0; }"; ) > .featuretest.c )
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
|
||||
( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \
|
||||
( echo "not found."; echo "UTSNAME := no" >> .features.tmp )
|
||||
@$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features
|
||||
@rm -f .featuretest.c .featuretest$(EXEC_SUFFIX)
|
||||
else
|
||||
features: compiler
|
||||
@echo "FEATURES := yes" > .features.tmp
|
||||
@printf "Checking for utsname support... "
|
||||
@$(shell ( echo "#include <sys/utsname.h>"; \
|
||||
echo "struct utsname osinfo;"; \
|
||||
echo "int main(int argc, char **argv)"; \
|
||||
echo "{ (void) argc; (void) argv; uname (&osinfo); return 0; }"; ) > .featuretest.c )
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
|
||||
( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \
|
||||
( echo "not found."; echo "UTSNAME := no" >> .features.tmp )
|
||||
@$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features
|
||||
@rm -f .featuretest.c .featuretest$(EXEC_SUFFIX)
|
||||
endif
|
||||
@printf "Checking for utsname support... "
|
||||
@echo "$$UTSNAME_TEST" > .featuretest.c
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
|
||||
( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \
|
||||
( echo "not found."; echo "UTSNAME := no" >> .features.tmp )
|
||||
@$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features
|
||||
@rm -f .featuretest.c .featuretest$(EXEC_SUFFIX)
|
||||
|
||||
install: $(PROGRAM)$(EXEC_SUFFIX)
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/sbin
|
||||
|
Loading…
x
Reference in New Issue
Block a user