Changeset 1416 for trunk


Ignore:
Timestamp:
08/18/11 04:27:19 (9 months ago)
Author:
stefanct
Message:

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.

Signed-off-by: Stefan Tauner <stefan.tauner@…>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r1400 r1416  
    3939 
    4040# Determine the destination processor architecture 
    41 override ARCH = $(strip $(shell LC_ALL=C $(CC) -E arch.h|grep -v '^\#')) 
     41override ARCH := $(strip $(shell LC_ALL=C $(CC) -E arch.h|grep -v '^\#')) 
    4242 
    4343# FIXME We have to differentiate between host and target OS architecture. 
     
    532532        $(STRIP) $(STRIP_ARGS) $(PROGRAM)$(EXEC_SUFFIX) 
    533533 
     534# to define test programs we use verbatim variables, which get exported 
     535# to environment variables and are referenced with $$<varname> later 
     536 
     537define COMPILER_TEST 
     538int main(int argc, char **argv) 
     539{ 
     540        (void) argc; 
     541        (void) argv; 
     542        return 0; 
     543} 
     544endef 
     545export COMPILER_TEST 
     546 
    534547compiler: featuresavailable 
    535548        @printf "Checking for a C compiler... " 
    536         @$(shell ( echo "int main(int argc, char **argv)"; \ 
    537                    echo "{ (void) argc; (void) argv; return 0; }"; ) > .test.c ) 
    538         @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null &&    \ 
     549        @echo "$$COMPILER_TEST" > .test.c 
     550        @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null 2>&1 &&       \ 
    539551                echo "found." || ( echo "not found."; \ 
    540552                rm -f .test.c .test$(EXEC_SUFFIX); exit 1) 
     
    546558        @printf "%s\n" '$(ARCH)' 
    547559 
     560define LIBPCI_TEST 
     561/* Avoid a failing test due to libpci header symbol shadowing breakage */ 
     562#define index shadow_workaround_index 
     563#include <pci/pci.h> 
     564struct pci_access *pacc; 
     565int main(int argc, char **argv) 
     566{ 
     567        (void) argc; 
     568        (void) argv; 
     569        pacc = pci_alloc(); 
     570        return 0; 
     571} 
     572endef 
     573export LIBPCI_TEST 
     574 
    548575ifeq ($(CHECK_LIBPCI), yes) 
    549576pciutils: compiler 
    550577        @printf "Checking for libpci headers... " 
    551         @# Avoid a failing test due to libpci header symbol shadowing breakage 
    552         @$(shell ( echo "#define index shadow_workaround_index"; \ 
    553                    echo "#include <pci/pci.h>";            \ 
    554                    echo "struct pci_access *pacc;";        \ 
    555                    echo "int main(int argc, char **argv)"; \ 
    556                    echo "{ (void) argc; (void) argv; pacc = pci_alloc(); return 0; }"; ) > .test.c ) 
     578        @echo "$$LIBPCI_TEST" > .test.c 
    557579        @$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null 2>&1 &&           \ 
    558580                echo "found." || ( echo "not found."; echo;                     \ 
     
    589611endif 
    590612 
    591 ifeq ($(CONFIG_FT2232_SPI), yes) 
     613define FTDI_TEST 
     614#include <ftdi.h> 
     615struct ftdi_context *ftdic = NULL; 
     616int main(int argc, char **argv) 
     617{ 
     618        (void) argc; 
     619        (void) argv; 
     620        return ftdi_init(ftdic); 
     621} 
     622endef 
     623export FTDI_TEST 
     624 
     625define UTSNAME_TEST 
     626#include <sys/utsname.h> 
     627struct utsname osinfo; 
     628int main(int argc, char **argv) 
     629{ 
     630        (void) argc; 
     631        (void) argv; 
     632        uname (&osinfo); 
     633        return 0; 
     634} 
     635endef 
     636export UTSNAME_TEST 
     637 
    592638features: compiler 
    593639        @echo "FEATURES := yes" > .features.tmp 
     640ifeq ($(CONFIG_FT2232_SPI), yes) 
    594641        @printf "Checking for FTDI support... " 
    595         @$(shell ( echo "#include <ftdi.h>";               \ 
    596                    echo "struct ftdi_context *ftdic = NULL;";      \ 
    597                    echo "int main(int argc, char **argv)"; \ 
    598                    echo "{ (void) argc; (void) argv; return ftdi_init(ftdic); }"; ) > .featuretest.c ) 
     642        @echo "$$FTDI_TEST" > .featuretest.c 
    599643        @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(FTDILIBS) $(LIBS) >/dev/null 2>&1 &&     \ 
    600644                ( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) ||        \ 
    601645                ( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp ) 
     646endif 
    602647        @printf "Checking for utsname support... " 
    603         @$(shell ( echo "#include <sys/utsname.h>";                \ 
    604                    echo "struct utsname osinfo;";          \ 
    605                    echo "int main(int argc, char **argv)"; \ 
    606                    echo "{ (void) argc; (void) argv; uname (&osinfo); return 0; }"; ) > .featuretest.c ) 
     648        @echo "$$UTSNAME_TEST" > .featuretest.c 
    607649        @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \ 
    608650                ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) ||    \ 
     
    610652        @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features 
    611653        @rm -f .featuretest.c .featuretest$(EXEC_SUFFIX) 
    612 else 
    613 features: compiler 
    614         @echo "FEATURES := yes" > .features.tmp 
    615         @printf "Checking for utsname support... " 
    616         @$(shell ( echo "#include <sys/utsname.h>";                \ 
    617                    echo "struct utsname osinfo;";          \ 
    618                    echo "int main(int argc, char **argv)"; \ 
    619                    echo "{ (void) argc; (void) argv; uname (&osinfo); return 0; }"; ) > .featuretest.c ) 
    620         @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \ 
    621                 ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) ||    \ 
    622                 ( echo "not found."; echo "UTSNAME := no" >> .features.tmp ) 
    623         @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features 
    624         @rm -f .featuretest.c .featuretest$(EXEC_SUFFIX) 
    625 endif 
    626654 
    627655install: $(PROGRAM)$(EXEC_SUFFIX) 
Note: See TracChangeset for help on using the changeset viewer.