[SOLVED] How to garnish the toolchain required for a build via a script?

I created a script a while back to make it easier to setup a build environment in Ubuntu through automating as much of the process as possible.

  • However, the one thing I couldn't figure out was how to garnish the correct toolchain required for a user's build in order to utilize sed to add it to their .bashrc's PATH.

Seems I forgot to ask the actual question...

  • Is there a way to determine what toolchain a user's device will require via cli?

Solution:

  • Must be ran after menuconfig, but before make

  • Solution 1:

    • Assumes the following:
      • STAGING_DIR=/home/user/openwrt/source/staging_dir/toolchain pre-added to ~/.bashrc:

      • buildroot is at $HOME/openwrt/source
    # Paramaters #
    #----------------------------------------------------------------
    
    # User Name:
      user="$(echo $USER)"
    
    # Directories:
      OWrt="/home/$user/openwrt"
        SOURCE="$OWrt/source"
          STAGING=$SOURCE/staging_dir
            TOOLCHAIN="$(find $STAGING -maxdepth 1 -name "toolchain-*")"
    
    # Build #
    #----------------------------------------------------------------
    
      # Modify ~/.bashrc
    
        # Add STAGING_DIR variable
          sed -i "s|STAGING_DIR=/home/user/openwrt/source/staging_dir/toolchain|STAGING_DIR=$TOOLCHAIN|g" ~/.bashrc
    
        # Add Toolchain and Staging directories to PATH
          export PATH="$PATH:$TOOLCHAIN/bin:$STAGING/host/bin" && source ~/.bashrc
    
    • Since Solution 1 is meant to be utilized in my lede-build.sh script, if not using a script, Solution 2 would be sufficient.

  • Solution 2:

    • Assumes the following:
      • buildroot is at $HOME/openwrt/source
      # Modify ~/.bashrc
    
        # Add STAGING_DIR variable
          TOOLCHAIN="$(find $HOME/openwrt/source/staging_dir -maxdepth 1 -name "toolchain-*")" && echo "STAGING_DIR=$TOOLCHAIN" >> ~/.bashrc
    
        # Add Toolchain and Staging directories to PATH
          export PATH="$PATH:$TOOLCHAIN/bin:$HOME/openwrt/source/staging_dir/host/bin" && source ~/.bashrc