Test.mak 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. include ../Rules.mak
  19. U_TARGETS := $(TESTS)
  20. G_TARGETS := $(patsubst %,%_glibc,$(U_TARGETS))
  21. U_TARGETS += $(U_TESTS)
  22. G_TARGETS += $(G_TESTS)
  23. TARGETS =
  24. ifeq ($(GLIBC_ONLY),)
  25. TARGETS += $(U_TARGETS)
  26. endif
  27. ifeq ($(UCLIBC_ONLY),)
  28. TARGETS += $(G_TARGETS)
  29. endif
  30. test check all: $(TARGETS)
  31. # dummy rule to prevent the "Nothing to be done for `all'." message
  32. ifeq ($(Q),@)
  33. @true
  34. endif
  35. $(TARGETS): Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak
  36. $(U_TARGETS): $(patsubst %,%.c,$(U_TARGETS))
  37. $(G_TARGETS): $(patsubst %_glibc,%.c,$(G_TARGETS))
  38. define diff_test
  39. $(Q)\
  40. for x in "$@.out" "$(patsubst %_glibc,%,$@).out" ; do \
  41. test -e "$$x.good" && $(do_showdiff) "$@.out" "$$x.good" && exec diff -u "$@.out" "$$x.good" ; \
  42. done ; \
  43. true
  44. endef
  45. define uclibc_glibc_diff_test
  46. $(Q)\
  47. test -z "$(DODIFF_$(patsubst %_glibc,%,$@))" && exec true ; \
  48. uclibc_out="$@.out" ; \
  49. glibc_out="$(patsubst %_glibc,%,$@).out" ; \
  50. $(do_showdiff) $$uclibc_out $$glibc_out ; \
  51. exec diff -u "$$uclibc_out" "$$glibc_out"
  52. endef
  53. define exec_test
  54. $(Q)\
  55. $(WRAPPER) $(WRAPPER_$(patsubst %_glibc,%,$@)) \
  56. ./$@ $(OPTS) $(OPTS_$(patsubst %_glibc,%,$@)) &> "$@.out" ; \
  57. ret=$$? ; \
  58. expected_ret="$(RET_$(patsubst %_glibc,%,$@))" ; \
  59. test -z "$$expected_ret" && export expected_ret=0 ; \
  60. if ! test $$ret -eq $$expected_ret ; then \
  61. $(RM) $@ ; \
  62. cat "$@.out" ; \
  63. exec false ; \
  64. fi
  65. $(SCAT) "$@.out"
  66. endef
  67. $(U_TARGETS):
  68. $(showtest)
  69. $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c $@.c -o $@.o
  70. $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
  71. ifeq ($(COMPILE_ONLY),)
  72. $(exec_test)
  73. $(diff_test)
  74. endif
  75. $(G_TARGETS):
  76. $(showtest)
  77. $(Q)$(HOSTCC) $(HOST_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) -c $(patsubst %_glibc,%,$@).c -o $@.o
  78. $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  79. ifeq ($(COMPILE_ONLY),)
  80. $(exec_test)
  81. $(diff_test)
  82. $(uclibc_glibc_diff_test)
  83. endif
  84. %.so: %.c
  85. $(showlink)
  86. $(Q)$(CC) \
  87. $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(patsubst %_glibc,%,$@)) \
  88. -fPIC -shared $< -o $@ -Wl,-soname,$@ \
  89. $(LDFLAGS) $(EXTRA_LIBS) $(LDFLAGS_$(patsubst %_glibc,%,$@))
  90. clean:
  91. $(showclean)
  92. $(Q)$(RM) *.a *.o *.so *~ core *.out $(TARGETS) $(EXTRA_CLEAN)