xref: /DragonOS/user/port/gcc/11.3.0/build-hosted.sh (revision fd91905f022b3ceaa59e666d1ff42d91fb8d40ef)
12224c93eSguanjinquan##############################################
22224c93eSguanjinquan# DragonOS hosted gcc build script
32224c93eSguanjinquan#
42224c93eSguanjinquan# This script is used to build userland gcc for DragonOS(Running on Linux)
52224c93eSguanjinquan##############################################
62224c93eSguanjinquan
72224c93eSguanjinquan# 编译前请先设置参数
82224c93eSguanjinquansys_root=$DRAGONOS_SYSROOT
92224c93eSguanjinquangcc_path=请填写gcc的路径
102224c93eSguanjinquan
112224c93eSguanjinquan# 要安装到的目录
122224c93eSguanjinquanPREFIX=$HOME/opt/dragonos-host-userspace
132224c93eSguanjinquan
142224c93eSguanjinquan
152224c93eSguanjinquanif [ ! -d ${gcc_path} ]; then
162224c93eSguanjinquan    echo "Error: ${gcc_path} not found"
172224c93eSguanjinquan    exit 1
182224c93eSguanjinquanfi
192224c93eSguanjinquan
20*fd91905fSloginif [ ! -d ${sys_root} ]; then
21*fd91905fSlogin    echo "Error: ${sys_root} not found"
222224c93eSguanjinquan    exit 1
232224c93eSguanjinquanfi
242224c93eSguanjinquan
252224c93eSguanjinquan# 安装依赖
262224c93eSguanjinquan# 注意texinfo和binutils的版本是否匹配
272224c93eSguanjinquan# 注意gmp/mpc/mpfr和gcc/g++的版本是否匹配
282224c93eSguanjinquansudo apt-get install -y \
292224c93eSguanjinquan    g++ \
302224c93eSguanjinquan    gcc \
312224c93eSguanjinquan    make \
322224c93eSguanjinquan    texinfo \
332224c93eSguanjinquan    libgmp3-dev \
342224c93eSguanjinquan    libmpc-dev \
352224c93eSguanjinquan    libmpfr-dev \
362224c93eSguanjinquan    flex \
372224c93eSguanjinquan    wget
382224c93eSguanjinquan
392224c93eSguanjinquanmkdir -p build-gcc || exit 1
402224c93eSguanjinquanmkdir -p ${PREFIX} || exit 1
412224c93eSguanjinquan
422224c93eSguanjinquancd build-gcc
43*fd91905fSlogin${gcc_path}/configure --prefix=${PREFIX} --target=x86_64-dragonos --with-sysroot=${sys_root} --disable-werror --disable-shared --disable-bootstrap --enable-languages=c,c++ || exit 1
442224c93eSguanjinquanmake all-gcc all-target-libgcc -j $(nproc) || exit 1
452224c93eSguanjinquanmake install-gcc install-target-libgcc -j $(nproc)  || exit 1
462224c93eSguanjinquan# 这里会报错,暂时不知道为什么
472224c93eSguanjinquan# make all-target-libstdc++-v3 -j $(nproc) || exit 1
482224c93eSguanjinquan# make install-target-libstdc++-v3 -j $(nproc) || exit 1
492224c93eSguanjinquanmake clean
502224c93eSguanjinquancd ..
512224c93eSguanjinquanrm -rf build-gcc
52