1#!/bin/sh -ex
2
3if [ -z "$OBJROOT" ]
4then
5	OBJROOT=.
6fi
7
8ARCH_CACHE="$OBJROOT/.test_arch_cache"
9
10# Always test locally built products.
11if [ -z "$TEST_NO_SOURCE_DYLD" ]
12then
13	export DYLD_LIBRARY_PATH="$BUILT_PRODUCTS_DIR"
14	#export DYLD_PRINT_LIBRARIES=1
15	export OPENSSL_X509_TEA_DISABLE=1
16fi
17
18make_arch_cache()
19{
20	if [ ! -f $ARCH_CACHE ]
21	then
22		for arch in $ARCHS
23		do
24			# Cannot do ppc since there is no /bin/sh for ppc
25			if [ "$arch" != "`echo $arch | sed "s@ppc@@g"`" ]
26			then
27				continue
28			fi
29
30			valid="`lipo -detailed_info /usr/lib/dyld | grep -o $arch 2>/dev/null`"
31			if [ "$valid" == "$arch" ]
32			then
33				echo " $arch" >> "$ARCH_CACHE"
34			fi
35		done
36	fi
37}
38
39remove_arch_cache()
40{
41	rm -f "$ARCH_CACHE"
42}
43
44get_exec_arches()
45{
46
47	if [ -n "$1" ] && [ "$1" == "squash" ]
48	then
49		remove_arch_cache
50	fi
51
52	make_arch_cache
53	cat $ARCH_CACHE
54}
55
56test_binary()
57{
58	if [ -n "$1" ]
59	then
60		for aa in `get_exec_arches`
61		do
62			arch -${aa} $@
63		done
64	fi
65}
66
67test_binary_in_dir()
68{
69	cd "$1"
70	shift
71
72	test_binary $@
73}
74
75
76