This commit is contained in:
parent
a5e339a358
commit
7bf624589f
@ -91,48 +91,55 @@ fi
|
||||
INSTALL_DIR="$USER_HOME/.musl-cross"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
|
||||
MUSL_CC_URL="https://musl.cc"
|
||||
TMPDIR=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
|
||||
# x86_64
|
||||
if [ ! -d "$INSTALL_DIR/x86_64-linux-musl-cross" ]; then
|
||||
echo "Downloading x86_64 musl cross toolchain..."
|
||||
wget -nc -O "$TMPDIR/x86_64-linux-musl-cross.tgz" $MUSL_CC_URL/x86_64-linux-musl-cross.tgz
|
||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/x86_64-linux-musl-cross.tgz"
|
||||
function install_musl_cross() {
|
||||
local TOOLCHAIN="$1"
|
||||
local MUSL_CC_URL="https://musl.cc"
|
||||
if [ ! -d "$INSTALL_DIR/$TOOLCHAIN" ]; then
|
||||
echo "Downloading $TOOLCHAIN musl cross toolchain..."
|
||||
wget -nc -O "$TMPDIR/$TOOLCHAIN.tgz" $MUSL_CC_URL/$TOOLCHAIN.tgz
|
||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/$TOOLCHAIN.tgz"
|
||||
fi
|
||||
}
|
||||
|
||||
# x86_64 native
|
||||
if [ ! -d "$INSTALL_DIR/x86_64-linux-musl-native" ]; then
|
||||
echo "Downloading x86_64 musl native toolchain..."
|
||||
wget -nc -O "$TMPDIR/x86_64-linux-musl-native.tgz" $MUSL_CC_URL/x86_64-linux-musl-native.tgz
|
||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/x86_64-linux-musl-native.tgz"
|
||||
function check_path() {
|
||||
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
||||
local BASHRC="$USER_HOME/.bashrc"
|
||||
local TOOLCHAIN="$1"
|
||||
local MUSL_PATH="$INSTALL_DIR/$TOOLCHAIN/bin"
|
||||
if ! echo "$PATH" | grep -q "$MUSL_PATH"; then
|
||||
echo "Adding $MUSL_PATH to PATH in $BASHRC"
|
||||
PATH_LINE="export PATH=\"$MUSL_PATH:\$PATH\""
|
||||
if ! grep -Fxq "$PATH_LINE" "$BASHRC"; then
|
||||
echo "" >> "$BASHRC"
|
||||
echo "# Add musl cross compilers to PATH for dropshell" >> "$BASHRC"
|
||||
echo "$PATH_LINE" >> "$BASHRC"
|
||||
echo "Added musl cross compilers to $BASHRC"
|
||||
echo "You should run 'source ~/.bashrc' to update your PATH"
|
||||
else
|
||||
echo "You should run 'source ~/.bashrc' to update your PATH"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# aarch64
|
||||
if [ ! -d "$INSTALL_DIR/aarch64-linux-musl-cross" ]; then
|
||||
echo "Downloading aarch64 musl cross toolchain..."
|
||||
wget -nc -O "$TMPDIR/aarch64-linux-musl-cross.tgz" $MUSL_CC_URL/aarch64-linux-musl-cross.tgz
|
||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/aarch64-linux-musl-cross.tgz"
|
||||
fi
|
||||
|
||||
TOOLCHAIN_LIST=(
|
||||
"aarch64-linux-musl-cross"
|
||||
"x86_64-linux-musl-cross"
|
||||
"x86_64-linux-musl-native"
|
||||
)
|
||||
|
||||
for TOOLCHAIN in "${TOOLCHAIN_LIST[@]}"; do
|
||||
install_musl_cross "$TOOLCHAIN"
|
||||
check_path "$TOOLCHAIN"
|
||||
done
|
||||
|
||||
# Clean up
|
||||
rm -rf "$TMPDIR"
|
||||
|
||||
# If run with sudo, add to invoking user's ~/.bashrc
|
||||
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
||||
BASHRC="$USER_HOME/.bashrc"
|
||||
EXPORT_LINE="export PATH=\"$INSTALL_DIR/x86_64-linux-musl-cross/bin:$INSTALL_DIR/aarch64-linux-musl-cross/bin:\$PATH\""
|
||||
if ! grep -Fxq "$EXPORT_LINE" "$BASHRC"; then
|
||||
echo "" >> "$BASHRC"
|
||||
echo "# Add musl cross compilers to PATH for bb64" >> "$BASHRC"
|
||||
echo "$EXPORT_LINE" >> "$BASHRC"
|
||||
echo "Added musl cross compilers to $BASHRC"
|
||||
else
|
||||
echo "musl cross compiler PATH already present in $BASHRC"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
# COMPLETE
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user