dragonos.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. install_musl_cross() {
  2. # Install musl-cross-make
  3. echo "Installing musl-cross-make..."
  4. mkdir -p $HOME/opt/cross/x86_64-linux-musl-cross || exit 1
  5. cp ./dragonos-config-stage1.mak ./config.mak || exit 1
  6. make clean || exit 1
  7. make -j $(nproc) || exit 1
  8. make install || exit 1
  9. mv ./output/* $HOME/opt/cross/x86_64-linux-musl-cross || exit 1
  10. # Add musl-cross-make to PATH
  11. echo "export PATH=\"\$PATH:$HOME/opt/cross/x86_64-linux-musl-cross/bin\"" >> $HOME/.bashrc || exit 1
  12. echo "export PATH=\"\$PATH:$HOME/opt/cross/x86_64-linux-musl-cross/bin\"" >> $HOME/.zshrc || exit 1
  13. source $HOME/.bashrc || exit 1
  14. source $HOME/.zshrc || exit 1
  15. }
  16. build_stage2(){
  17. echo "Building stage 2..."
  18. cp ./dragonos-config-stage2.mak ./config.mak || exit 1
  19. make clean || exit 1
  20. make -j $(nproc) || exit 1
  21. make install || exit 1
  22. }
  23. # Check if the toolchain is installed
  24. __TOOLCHAIN_INSTALLED=1
  25. # Check if x86_64-linux-musl-gcc and x86_64-linux-musl-g++ are installed
  26. if ! command -v x86_64-linux-musl-gcc &> /dev/null
  27. then
  28. echo "x86_64-linux-musl-gcc could not be found."
  29. __TOOLCHAIN_INSTALLED=0
  30. fi
  31. if ! command -v x86_64-linux-musl-g++ &> /dev/null
  32. then
  33. echo "x86_64-linux-musl-g++ could not be found"
  34. __TOOLCHAIN_INSTALLED=0
  35. fi
  36. # Check if the toolchain is installed
  37. if [ $__TOOLCHAIN_INSTALLED -eq 0 ]
  38. then
  39. install_musl_cross || exit 1
  40. fi
  41. build_stage2 || exit 1