usb: tools: fix a regression issue that gcc can't link to pthread
authorHuang Rui <ray.huang@amd.com>
Wed, 4 Dec 2013 07:56:10 +0000 (15:56 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Dec 2013 23:10:54 +0000 (15:10 -0800)
Reproduce:
ray@hr-bak:~/usb$ make -C tools/usb/
make: Entering directory `/home/ray/usb/tools/usb'
gcc -Wall -Wextra -g -lpthread -I../include -o testusb testusb.c
/tmp/cc0EMxfy.o: In function `main':
/home/ray/usb/tools/usb/testusb.c:508: undefined reference to `pthread_create'
/home/ray/usb/tools/usb/testusb.c:531: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make: *** [testusb] Error 1
make: Leaving directory `/home/ray/usb/tools/usb'

Comments:
In the latest version (4.7.3) of gcc compiler, it requres that
libraries must follow the object or source files like below:

"gcc hello.c -lpthread" instead of "gcc -lpthread hello.c"

And it isn't encountered at gcc version 4.7.2.
So this patch fix to move the pthread option after testusb.c.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/Makefile

index 396d6c44e9d738d8cf85a0ce20317b001c573212..acf2165c04e64f8b15e844b787de9f59c324b199 100644 (file)
@@ -3,11 +3,12 @@
 CC = $(CROSS_COMPILE)gcc
 PTHREAD_LIBS = -lpthread
 WARNINGS = -Wall -Wextra
-CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include
+CFLAGS = $(WARNINGS) -g -I../include
+LDFLAGS = $(PTHREAD_LIBS)
 
 all: testusb ffs-test
 %: %.c
-       $(CC) $(CFLAGS) -o $@ $^
+       $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 clean:
        $(RM) testusb ffs-test