Skip to content

Instantly share code, notes, and snippets.

@wangjiezhe
Forked from thesamesam/gentoo-crossdev.md
Created March 13, 2025 12:58
Show Gist options
  • Select an option

  • Save wangjiezhe/5d13485cd5bee5df85a9a4382099eee4 to your computer and use it in GitHub Desktop.

Select an option

Save wangjiezhe/5d13485cd5bee5df85a9a4382099eee4 to your computer and use it in GitHub Desktop.
Gentoo cross compilation instructions (crossdev -> stage3)

Cross instructions

Set up the toolchain

$ crossdev riscv64-unknown-linux-gnu

Avoid dependency hell and populate the ROOT

Emerge sys-libs/glibc (no, @system / @world won't make it realise it can/should do this, don't ask why, I don't know):

$ riscv64-unknown-linux-gnu-emerge -v1 sys-libs/glibc
$ riscv64-unknown-linux-gnu-emerge -v1 @system

Profile setup

Choosing profile

Run: PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile list

Pick a nice looking one, like default/linux/riscv/20.0/rv64gc/lp64.

$ PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile set default/linux/riscv/20.0/rv64gc/lp64

Remove -pam nonsense

Edit /usr/riscv64-unknown-linux-gnu/etc/portage/make.conf to remove USE=-pam because it'll conflict with sys-apps/util-linux being the default su provider:

$ sed -i -e "s:-pam::" /usr/riscv64-unknown-linux-gnu/etc/portage/make.conf

Avoid circular deps

$ USE="-filecaps" riscv64-unknown-linux-gnu-emerge -v1 @system
@wangjiezhe
Copy link
Author

对于 binfmt,还要参考 https://wiki.gentoo.org/wiki/Crossdev/Testing_packages_via_qemu 设置 LD_PREFIX 和 LD_LIBRARY_PATH。

@wangjiezhe
Copy link
Author

crossdev 建立的文件夹默认使用 split-usr 结构,要转换成 merge-usr 结构:

mkdir /usr/mips64el-unknown-linux-gnuabi64/bin
merge-usr --root /usr/mips64el-unknown-linux-gnuabi64

@wangjiezhe
Copy link
Author

要交叉编译 mesa,需要补充软链接:

ln -s /usr/mips64el-unknown-linux-gnuabi64/usr/lib/llvm/19/bin/mips64el-unknown-linux-gnuabi64-llvm-config \
  /usr/lib/llvm/19/bin/mips64el-unknown-linux-gnuabi64-llvm-config

并使用 binfmt。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment