This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc-compile
executable file
·126 lines (110 loc) · 2.18 KB
/
cc-compile
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
fatal()
{
echo "cc-compile: fatal: $1" 1>&2
exit 1
}
if [ $# -lt 1 ]
then
echo "cc-compile: usage: [@dir] source" 1>&2
exit 1
fi
#
# check if new base dir was specified
#
BASE_DIR="."
if [ $# -gt 1 ]
then
echo "$1" | grep '^@' >/dev/null
if [ $? -eq 0 ]
then
BASE_DIR=`echo "$1" | sed 's/^@//g'`
shift
fi
fi
#
# Extract base name of given source file.
#
out=`echo "$1" | awk -F. '{print $1}'`
src="$1"
shift
#
# Assume source is being cross compiled if there is a cross-compiler
# defined.
#
if [ -f "${BASE_DIR}/conf-x-cc" ]
then
CC=`head -n 1 "${BASE_DIR}/conf-x-cc"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-cc"
fi
SYSTYPE=`head -n 1 "${BASE_DIR}/conf-x-systype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-systype"
fi
CCTYPE=`head -n 1 "${BASE_DIR}/conf-x-cctype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-x-cctype"
fi
CFLAGS="${CFLAGS} `head -n 1 "${BASE_DIR}/conf-x-cflags" 2>/dev/null`"
else
CC=`head -n 1 "${BASE_DIR}/conf-cc"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-cc"
fi
SYSTYPE=`head -n 1 "${BASE_DIR}/conf-systype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-systype"
fi
CCTYPE=`head -n 1 "${BASE_DIR}/conf-cctype"`
if [ $? -ne 0 ]
then
fatal "could not read ${BASE_DIR}/conf-cctype"
fi
fi
CFLAGS="${CFLAGS} `head -n 1 ${BASE_DIR}/conf-cflags 2>/dev/null`"
#
# Read global flag file list, if present.
#
if [ -f "${BASE_DIR}/conf-ccfflist" ]
then
for f in `cat "${BASE_DIR}/conf-ccfflist"`
do
FLAGS=`cat $f 2>/dev/null`
CFLAGS="${CFLAGS} ${FLAGS}"
done
fi
#
# Read local flag file list, if present.
#
if [ -f "${out}.iff" ]
then
for f in `cat "${out}.iff"`
do
targ="`dirname $out`/`dirname $f`/`basename $f`"
FLAGS="`cat $targ 2>/dev/null`"
CFLAGS="${CFLAGS} ${FLAGS}"
done
fi
#
# compensate for any compiler bugs
#
case ${SYSTYPE} in
DARWIN)
case ${CCTYPE} in
GCC)
CFLAGS="${CFLAGS} -fno-common" # darwin linker bug workaround
;;
*)
;;
esac
;;
*)
;;
esac
exec ${CC} -o ${out}.o -c ${src} ${1+"$@"} ${CFLAGS}