OSDN Git Service

- tighten up output
[uclinux-h8/uclibc-ng.git] / test / Test.mak
1 # Common makefile rules for tests
2 #
3 # Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org>
4 #
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Library General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option) any
8 # later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Library General Public License
16 # along with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 include ../Rules.mak
20
21 U_TARGETS := $(TESTS)
22 G_TARGETS := $(patsubst %,%_glibc,$(U_TARGETS))
23 U_TARGETS += $(U_TESTS)
24 G_TARGETS += $(G_TESTS)
25
26 TARGETS    = 
27 ifeq ($(GLIBC_ONLY),)
28 TARGETS   += $(U_TARGETS)
29 endif
30 ifeq ($(UCLIBC_ONLY),)
31 TARGETS   += $(G_TARGETS)
32 endif
33
34 test check all: $(TARGETS)
35 # dummy rule to prevent the "Nothing to be done for `all'." message
36 ifeq ($(Q),@)
37         @true
38 endif
39
40 $(TARGETS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
41 $(U_TARGETS): $(patsubst %,%.c,$(U_TARGETS))
42 $(G_TARGETS): $(patsubst %_glibc,%.c,$(G_TARGETS))
43
44 define diff_test
45         $(Q)\
46         for x in "$@.out" "$(patsubst %_glibc,%,$@).out" ; do \
47                 test -e "$$x.good" && $(do_showdiff) "$@.out" "$$x.good" && exec diff -u "$@.out" "$$x.good" ; \
48         done ; \
49         true
50 endef
51 define uclibc_glibc_diff_test
52         $(Q)\
53         test -z "$(DODIFF_$(patsubst %_glibc,%,$@))" && exec true ; \
54         uclibc_out="$@.out" ; \
55         glibc_out="$(patsubst %_glibc,%,$@).out" ; \
56         $(do_showdiff) $$uclibc_out $$glibc_out ; \
57         exec diff -u "$$uclibc_out" "$$glibc_out"
58 endef
59 define exec_test
60         $(Q)\
61         $(WRAPPER) $(WRAPPER_$(patsubst %_glibc,%,$@)) \
62         ./$@ $(OPTS) $(OPTS_$(patsubst %_glibc,%,$@)) &> "$@.out" ; \
63                 ret=$$? ; \
64                 expected_ret="$(RET_$(patsubst %_glibc,%,$@))" ; \
65                 test -z "$$expected_ret" && export expected_ret=0 ; \
66         if ! test $$ret -eq $$expected_ret ; then \
67                 $(RM) $@ ; \
68                 cat "$@.out" ; \
69                 exec false ; \
70         fi
71         $(SCAT) "$@.out"
72 endef
73
74 $(U_TARGETS):
75         $(showtest)
76         $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
77         $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
78 ifeq ($(COMPILE_ONLY),)
79         $(exec_test)
80         $(diff_test)
81 endif
82
83 $(G_TARGETS):
84         $(showtest)
85         $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
86         $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
87 ifeq ($(COMPILE_ONLY),)
88         $(exec_test)
89         $(diff_test)
90         $(uclibc_glibc_diff_test)
91 endif
92
93 %.so: %.c
94         $(showlink)
95         $(Q)$(CC) \
96                 $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
97                 -fPIC -shared $< -o $@ -Wl,-soname,$@ \
98                 $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
99
100 clean:
101         $(showclean)
102         $(Q)$(RM) *.a *.o *.so *~ core *.out $(TARGETS)