xref: /minix3/sys/external/bsd/compiler_rt/dist/test/builtins/Unit/test (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#!/usr/bin/env bash
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel SambucARCHS='<host>'
4*0a6a1f1dSLionel SambucREMOTE=0
5*0a6a1f1dSLionel Sambucif test `uname` = "Darwin"; then
6*0a6a1f1dSLionel Sambuc  if test "$1" = "armv6"; then
7*0a6a1f1dSLionel Sambuc    ARCHS="armv6"
8*0a6a1f1dSLionel Sambuc    LIBS="-lSystem"
9*0a6a1f1dSLionel Sambuc    REMOTE=1
10*0a6a1f1dSLionel Sambuc    mkdir -p remote
11*0a6a1f1dSLionel Sambuc  else
12*0a6a1f1dSLionel Sambuc    ARCHS="i386 x86_64 ppc"
13*0a6a1f1dSLionel Sambuc    LIBS="-lSystem"
14*0a6a1f1dSLionel Sambuc  fi
15*0a6a1f1dSLionel Sambucelse
16*0a6a1f1dSLionel Sambuc  LIBS="-lc -lm"
17*0a6a1f1dSLionel Sambucfi
18*0a6a1f1dSLionel Sambuc
19*0a6a1f1dSLionel Sambucfor ARCH in $ARCHS; do
20*0a6a1f1dSLionel Sambuc  CFLAGS="-Os -nodefaultlibs -I../../lib"
21*0a6a1f1dSLionel Sambuc  if test "$ARCH" != '<host>'; then
22*0a6a1f1dSLionel Sambuc    CFLAGS="-arch $ARCH $CFLAGS"
23*0a6a1f1dSLionel Sambuc  fi
24*0a6a1f1dSLionel Sambuc  for FILE in $(ls *.c); do
25*0a6a1f1dSLionel Sambuc    # Use -nodefaultlibs to avoid using libgcc.a
26*0a6a1f1dSLionel Sambuc    # Use -lSystem to link with libSystem.dylb.
27*0a6a1f1dSLionel Sambuc    # Note -lSystem is *after* libcompiler_rt.Optimized.a so that linker will
28*0a6a1f1dSLionel Sambuc    # prefer our implementation over the ones in libSystem.dylib
29*0a6a1f1dSLionel Sambuc    EXTRA=
30*0a6a1f1dSLionel Sambuc    if test $FILE = gcc_personality_test.c
31*0a6a1f1dSLionel Sambuc    then
32*0a6a1f1dSLionel Sambuc      # the gcc_personality_test.c requires a helper C++ program
33*0a6a1f1dSLionel Sambuc      EXTRA="-fexceptions gcc_personality_test_helper.cxx -lstdc++ /usr/lib/libgcc_s.1.dylib"
34*0a6a1f1dSLionel Sambuc      # the libgcc_s.1.dylib use at the end is a hack until libSystem contains _Unwind_Resume
35*0a6a1f1dSLionel Sambuc    fi
36*0a6a1f1dSLionel Sambuc    if test $FILE = trampoline_setup_test.c
37*0a6a1f1dSLionel Sambuc    then
38*0a6a1f1dSLionel Sambuc      # this test requires an extra compiler option
39*0a6a1f1dSLionel Sambuc      EXTRA="-fnested-functions"
40*0a6a1f1dSLionel Sambuc    fi
41*0a6a1f1dSLionel Sambuc    if test "$REMOTE" = "1"
42*0a6a1f1dSLionel Sambuc    then
43*0a6a1f1dSLionel Sambuc      if gcc $CFLAGS $FILE ../../darwin_fat/Release/libcompiler_rt.a $LIBS $EXTRA -o ./remote/$FILE.exe
44*0a6a1f1dSLionel Sambuc      then
45*0a6a1f1dSLionel Sambuc        echo "Built $FILE.exe for $ARCH"
46*0a6a1f1dSLionel Sambuc      else
47*0a6a1f1dSLionel Sambuc        echo "$FILE failed to compile"
48*0a6a1f1dSLionel Sambuc      fi
49*0a6a1f1dSLionel Sambuc    else
50*0a6a1f1dSLionel Sambuc      if gcc $CFLAGS $FILE ../../darwin_fat/Release/libcompiler_rt.a $LIBS $EXTRA
51*0a6a1f1dSLionel Sambuc      then
52*0a6a1f1dSLionel Sambuc        echo "Testing $FILE for $ARCH"
53*0a6a1f1dSLionel Sambuc        if ./a.out
54*0a6a1f1dSLionel Sambuc        then
55*0a6a1f1dSLionel Sambuc          rm ./a.out
56*0a6a1f1dSLionel Sambuc        else
57*0a6a1f1dSLionel Sambuc          echo "fail"
58*0a6a1f1dSLionel Sambuc          exit 1
59*0a6a1f1dSLionel Sambuc        fi
60*0a6a1f1dSLionel Sambuc      else
61*0a6a1f1dSLionel Sambuc        echo "$FILE failed to compile"
62*0a6a1f1dSLionel Sambuc        exit 1
63*0a6a1f1dSLionel Sambuc      fi
64*0a6a1f1dSLionel Sambuc    fi
65*0a6a1f1dSLionel Sambuc  done
66*0a6a1f1dSLionel Sambucdone
67*0a6a1f1dSLionel Sambucecho "pass"
68*0a6a1f1dSLionel Sambucexit
69