xref: /DragonOS/user/port/gcc/11.3.0/build-hosted.sh (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1##############################################
2# DragonOS hosted gcc build script
3#
4# This script is used to build userland gcc for DragonOS(Running on Linux)
5##############################################
6
7# 编译前请先设置参数
8sys_root=$DRAGONOS_SYSROOT
9gcc_path=请填写gcc的路径
10
11# 要安装到的目录
12PREFIX=$HOME/opt/dragonos-host-userspace
13
14
15if [ ! -d ${gcc_path} ]; then
16    echo "Error: ${gcc_path} not found"
17    exit 1
18fi
19
20if [ ! -d ${sys_root} ]; then
21    echo "Error: ${sys_root} not found"
22    exit 1
23fi
24
25# 安装依赖
26# 注意texinfo和binutils的版本是否匹配
27# 注意gmp/mpc/mpfr和gcc/g++的版本是否匹配
28sudo apt-get install -y \
29    g++ \
30    gcc \
31    make \
32    texinfo \
33    libgmp3-dev \
34    libmpc-dev \
35    libmpfr-dev \
36    flex \
37    wget
38
39mkdir -p build-gcc || exit 1
40mkdir -p ${PREFIX} || exit 1
41
42cd build-gcc
43${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
44make all-gcc all-target-libgcc -j $(nproc) || exit 1
45make install-gcc install-target-libgcc -j $(nproc)  || exit 1
46# 这里会报错,暂时不知道为什么
47# make all-target-libstdc++-v3 -j $(nproc) || exit 1
48# make install-target-libstdc++-v3 -j $(nproc) || exit 1
49make clean
50cd ..
51rm -rf build-gcc
52