forked from top-sekret/psptoolchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepends.sh
97 lines (83 loc) · 1.31 KB
/
depends.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
fail ()
{
exit 1
}
check_program ()
{
if ! command -v "$1" >/dev/null 2>&1
then
cat >&2 <<_EOF_
Error: program $1 is missing.
It is a part of $2.
It can be downloaded from <$3>.
_EOF_
fail
fi
}
find_header_file ()
{
if [ -z "$HEADER_LOC_LIST" ]
then
HEADER_LOC_LIST="$(cc -v -E - </dev/null 2>&1 | sed -n -e '/^#include "\.\.\." search starts here:$/,/^End of search list\.$/p' | grep '^ ' | sed -e 's|^ ||')"
fi
IFS_backup="$IFS"
IFS='
'
for DIR in $HEADER_LOC_LIST
do
if [ -f "$DIR/$1" ]
then
return 0
fi
done
IFS="$IFS_backup"
unset IFS_backup
return 1
}
check_header ()
{
printf "Checking for header %s... " "$1"
cat >tmp.$$.c <<_EOF_
#include <stdio.h>
#include <stdlib.h>
#include <$1>
int
main (void)
{
return 0;
}
_EOF_
if gcc -c -o tmp.$$.o tmp.$$.c >/dev/null 2>&1
then
rm -f tmp.$$.c tmp.$$.o
echo "yes"
return 0
elif find_header_file "$1"
then
rm -f tmp.$$.c tmp.$$.o
echo "present but cannot be compiled"
return 99
else
rm -f tmp.$$.c tmp.$$.o
echo "no"
return 1
fi
}
check_headers ()
{
LIBRARY="$1"
shift
echo "Checking headers of $LIBRARY:"
for HEADER
do
if ! check_header "$HEADER"
then
cat >&2 <<_EOF_
Error: missing header: $HEADER
This usually means that $LIBRARY is not installed or is misconfigured.
_EOF_
fail
fi
done
}