-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxgcc
More file actions
executable file
·174 lines (151 loc) · 3.68 KB
/
xgcc
File metadata and controls
executable file
·174 lines (151 loc) · 3.68 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
PREFIX=${HOME}/.local
TARGET=x86_64-pc-elf
LANGUAGES=c
BINUTILS_VERSION=2.32
GCC_VERSION=8.3.0
TMPDIR=${PREFIX}/tmp
SRCDIR=${PREFIX}/src
BUILDROOTDIR=${TMPDIR}/.crosstools
BINUTILSBUILDDIR=${BUILDROOTDIR}/binutils-${BINUTILS_VERSION}/${TARGET}
GCCBUILDDIR=${BUILDROOTDIR}/gcc-${GCC_VERSION}/${TARGET}
GCCTAG=gcc-${GCC_VERSION}
GCCARCHIVE=${GCCTAG}.tar.gz
BINUTILSTAG=binutils-${BINUTILS_VERSION}
BINUTILSARCHIVE=${BINUTILSTAG}.tar.gz
GCCURL=ftp://ftp.gnu.org/gnu/gcc/${GCCTAG}/${GCCARCHIVE}
BINUTILSURL=ftp://ftp.gnu.org/gnu/binutils/${BINUTILSARCHIVE}
JOBS=$(nproc)
function _ {
echo "$@"
$@
}
function do_exit {
if [ -z "$1" ]
then
exit 0
else
exit $1
fi
}
function do_usage {
echo ""
echo "$0 - GCC cross-compiler builder"
echo ""
echo "$0 COMMAND [options]"
echo ""
echo "commands :"
echo " build build GCC cross compiler"
echo " clean reset build environment"
echo ""
echo "options :"
echo " --target=TARGET GCC cross compiler target"
echo " --enable-languages=LANGUAGES GCC enabled languages"
echo ""
do_exit $@
}
function parse_command_line {
for opt in $@
do
case $opt in
--target=*)
TARGET=$(echo $opt | sed 's/--target=//g')
;;
--enable-languages=*)
LANGUAGES=$(echo $opt | sed 's/--enable-languages=//g')
;;
esac
done
}
function do_build {
mkdir -p ${SRCDIR} ${BINUTILSBUILDDIR} ${GCCBUILDDIR}
(cd ${SRCDIR} && {
if ! [ -f ${BINUTILSARCHIVE} ]
then
wget ${BINUTILSURL}
fi
if ! [ -d ${BINUTILSTAG} ]
then
tar xfz ${BINUTILSARCHIVE}
fi
if ! [ -f ${GCCARCHIVE} ]
then
wget ${GCCURL}
fi
if ! [ -d ${GCCTAG} ]
then
tar xfz ${GCCARCHIVE}
fi
(cd ${GCCTAG} && ./contrib/download_prerequisites >/dev/null 2>&1)
})
if [ -z "`which ${TARGET}-as`" ]
then
(cd ${BINUTILSBUILDDIR} && {
${SRCDIR}/${BINUTILSTAG}/configure --target=${TARGET} --prefix="${PREFIX}" --with-sysroot --disable-nls
make -j ${JOBS}
make install
})
fi
if [ -z "`which ${TARGET}-gcc`" ]
then
case $TARGET in
x86_64-*-elf*)
MULTILIB_CONFIG_FILE=${SRCDIR}/${GCCTAG}/gcc/config/i386/t-kernel-amd64
CONFIG_FILE=${SRCDIR}/${GCCTAG}/gcc/config.gcc
if ! [ -f ${MULTILIB_CONFIG_FILE} ]
then
echo "MULTILIB_OPTIONS += mno-red-zone" > ${MULTILIB_CONFIG_FILE}
echo "MULTILIB_DIRNAMES += kernel" >> ${MULTILIB_CONFIG_FILE}
fi
if [ -z "`cat ${CONFIG_FILE} | grep t-kernel-amd64`" ]
then
sed -i 's,x86_64-\*-elf\*),x86_64-\*-elf\*)\n\ttmake_file="${tmake_file} i386/t-kernel-amd64",g' ${CONFIG_FILE}
fi
;;
*)
;;
esac
(cd ${GCCBUILDDIR} && {
${SRCDIR}/${GCCTAG}/configure --target=${TARGET} --prefix="${PREFIX}" --disable-nls --enable-languages=${LANGUAGES} --without-headers
make -j ${JOBS} all-gcc all-target-libgcc
make install-gcc install-target-libgcc
})
fi
}
function do_clean {
_ rm -rf ${BUILDROOTDIR}/*
_ rm -f ${PREFIX}/bin/${TARGET}-*
_ rm -rf ${PREFIX}/${TARGET}
_ rm -rf ${PREFIX}/lib/gcc/${TARGET}
_ rm -rf ${PREFIX}/libexec/gcc/${TARGET}
_ rm -rf ${PREFIX}/src/gcc*
_ rm -rf ${PREFIX}/src/binutils*
}
# do we have to fix the path ?
if [ -z "`echo $PATH | grep $PREFIX`" ]
then
export PATH="${PREFIX}/bin:$PATH"
fi
# command parser
COMMAND=$1
if [ -z "$COMMAND" ]
then
do_usage 1
else
shift
parse_command_line $@
case $COMMAND in
build)
do_build $@
;;
clean)
do_clean $@
;;
help)
do_usage
;;
*)
do_usage 1
;;
esac
fi