Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright 2018, Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. top_srcdir ?= ..
  29. DEF_FLAGS = -g -pipe
  30. DEF_WFLAGS = -Wall
  31. CFLAGS ?= $(DEF_FLAGS)
  32. CXXFLAGS ?= $(DEF_FLAGS)
  33. CFLAGS += $(DEF_WFLAGS) -Wstrict-prototypes
  34. CXXFLAGS += $(DEF_WFLAGS)
  35. CPPFLAGS += -I$(top_srcdir)
  36. # We use static linking here so that if people run through qemu/etc... by hand,
  37. # it's a lot easier to run/debug. Same for strace output.
  38. LDFLAGS += -static
  39. TESTS = \
  40. unlink \
  41. all: check
  42. %_test: %.c test_skel.h $(top_srcdir)/linux_syscall_support.h
  43. $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
  44. %_test: %.cc test_skel.h $(top_srcdir)/linux_syscall_support.h
  45. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
  46. %_run: %_test
  47. @t=$(@:_run=_test); \
  48. echo "./$$t"; \
  49. if ! env -i ./$$t; then \
  50. env -i strace -f -v ./$$t; \
  51. echo "TRY: gdb -q -ex r -ex bt ./$$t"; \
  52. exit 1; \
  53. fi
  54. ALL_TEST_TARGETS = $(TESTS:=_test)
  55. compile_tests: $(ALL_TEST_TARGETS)
  56. ALL_RUN_TARGETS = $(TESTS:=_run)
  57. check: $(ALL_RUN_TARGETS)
  58. # The "tempfile" targets are the names we use with temp files.
  59. # Clean them out in case some tests crashed in the middle.
  60. clean:
  61. rm -f *~ *.o tempfile.* a.out core $(ALL_TEST_TARGETS)
  62. .SUFFIXES:
  63. .PHONY: all check clean compile_tests
  64. .SECONDARY: $(ALL_TEST_TARGETS)
  65. # Try to cross-compile the tests for all our supported arches. We test with
  66. # both gcc and clang. We don't support execution (yet?), but just compiling
  67. # & linking helps catch common bugs.
  68. .PHONY: cross compile_cross
  69. cross_compile:
  70. @echo "Running: $(MAKE) $@ CC='$(CC)' CXX='$(CXX)'"; \
  71. if (echo '#include <stdio.h>' | $(CC) -x c -c -o /dev/null -) 2>/dev/null; then \
  72. $(MAKE) -s clean; \
  73. $(MAKE) -k --no-print-directory compile_tests; \
  74. else \
  75. echo "Skipping $(CC) test: not installed"; \
  76. fi; \
  77. echo
  78. # The names here are a best effort. Not easy to probe for.
  79. cross:
  80. @for cc in \
  81. "x86_64-pc-linux-gnu-gcc" \
  82. "i686-pc-linux-gnu-gcc" \
  83. "x86_64-pc-linux-gnu-gcc -mx32" \
  84. "armv7a-unknown-linux-gnueabi-gcc -marm -mhard-float" \
  85. "armv7a-unknown-linux-gnueabi-gcc -mthumb -mhard-float" \
  86. "powerpc-unknown-linux-gnu-gcc" \
  87. "aarch64-unknown-linux-gnu-gcc" \
  88. "mips64-unknown-linux-gnu-gcc -mabi=64" \
  89. "mips64-unknown-linux-gnu-gcc -mabi=32" \
  90. "mips64-unknown-linux-gnu-gcc -mabi=n32" \
  91. "s390-ibm-linux-gnu-gcc" \
  92. "s390x-ibm-linux-gnu-gcc" \
  93. ; do \
  94. cxx=`echo "$$cc" | sed 's:-gcc:-g++:'`; \
  95. $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \
  96. \
  97. sysroot=`$$cc --print-sysroot 2>/dev/null`; \
  98. gccdir=`$$cc -print-file-name=libgcc.a 2>/dev/null`; \
  99. gccdir=`dirname "$$gccdir"`; \
  100. : Skip building for clang for mips/o32 and s390/31-bit until it works.; \
  101. case $$cc in \
  102. mips64*-mabi=32) continue;; \
  103. s390-*) continue;; \
  104. esac; \
  105. set -- $$cc; \
  106. tuple=$${1%-gcc}; \
  107. shift; \
  108. cc="clang -target $$tuple $$*"; \
  109. : Assume the build system is x86_64 based, so ignore the sysroot.; \
  110. case $$tuple in \
  111. x86_64*) ;; \
  112. *) cc="$$cc --sysroot $$sysroot -B$$gccdir -L$$gccdir";; \
  113. esac; \
  114. cxx=`echo "$$cc" | sed 's:^clang:clang++:'`; \
  115. $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \
  116. done