-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc-link
executable file
·100 lines (87 loc) · 1.84 KB
/
cc-link
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
98
99
100
#!/bin/sh
fatal()
{
echo "cc-link: fatal: $1" 1>&2
exit 1
}
if [ $# -lt 2 ]
then
echo "cc-link: usage: [@dir] basename objects ..." 1>&2
exit 1
fi
#
# check if base directory was specified
#
BASE_DIR="."
echo "$1" | grep '^@' 2>&1 >/dev/null
if [ $? -eq 0 ]
then
BASE_DIR=`echo $1 | sed 's/^@//g'`
shift
fi
#
# Assume source is being cross linked if there is a cross-linker
# defined.
#
if [ -f "${BASE_DIR}/conf-x-ld" ]
then
LD=`head -n 1 "${BASE_DIR}/conf-x-ld"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-ld"
fi
SYSTYPE=`head -n 1 "${BASE_DIR}/conf-x-systype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-systype"
fi
LDTYPE=`head -n 1 "${BASE_DIR}/conf-x-ldtype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-ldtype"
fi
LDFLAGS="${LDFLAGS} `head -n 1 ${BASE_DIR}/conf-x-ldflags 2>/dev/null`"
else
LD=`head -n 1 "${BASE_DIR}/conf-ld"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-ld"
fi
SYSTYPE=`head -n 1 "${BASE_DIR}/conf-systype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-systype"
fi
LDTYPE=`head -n 1 "${BASE_DIR}/conf-ldtype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-ldtype"
fi
fi
LDFLAGS="${LDFLAGS} `head -n 1 ${BASE_DIR}/conf-ldflags 2>/dev/null`"
#
# Read global flag file list, if present.
#
if [ -f "${BASE_DIR}/conf-ldfflist" ]
then
for f in `cat "${BASE_DIR}/conf-ldfflist"`
do
FLAGS=`cat $f 2>/dev/null`
LDFLAGS="${LDFLAGS} ${FLAGS}"
done
fi
out="$1"
shift
#
# Read local flag file list, if present.
#
if [ -f "${out}.lff" ]
then
for f in `cat "${out}.lff"`
do
targ="`dirname $out`/`dirname $f`/`basename $f`"
FLAGS="`cat $targ 2>/dev/null`"
LDFLAGS="${LDFLAGS} ${FLAGS}"
done
fi
exec ${LD} -o ${out} ${1+"$@"} ${LDFLAGS}