summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/opkbuild.sh35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/opkbuild.sh b/src/opkbuild.sh
index 6881546..a184501 100644
--- a/src/opkbuild.sh
+++ b/src/opkbuild.sh
@@ -220,22 +220,29 @@ if [ -z "${OH_HOST_ARCH_GNU}" ]; then
exit 1
fi
+# Detect cross building.
+if [ "${OH_BUILD_ARCH_GNU}" != "${OH_HOST_ARCH_GNU}" ]; then
+ toolchain_prefix="${OH_HOST_ARCH_GNU}-"
+else
+ toolchain_prefix=
+fi
+
# Set toolchain environment variables.
# NB: This is written for GNU Binutils and GCC and won't work for, e.g., LLVM.
-export AR="${OH_HOST_ARCH_GNU}-ar"
-export AS="${OH_HOST_ARCH_GNU}-as"
-export CC="${OH_HOST_ARCH_GNU}-gcc"
-export CPP="${OH_HOST_ARCH_GNU}-cpp"
-export CXX="${OH_HOST_ARCH_GNU}-g++"
-export LD="${OH_HOST_ARCH_GNU}-ld"
-export NM="${OH_HOST_ARCH_GNU}-nm"
-export OBJCOPY="${OH_HOST_ARCH_GNU}-objcopy"
-export OBJDUMP="${OH_HOST_ARCH_GNU}-objdump"
-export RANLIB="${OH_HOST_ARCH_GNU}-ranlib"
-export READELF="${OH_HOST_ARCH_GNU}-readelf"
-export SIZE="${OH_HOST_ARCH_GNU}-size"
-export STRINGS="${OH_HOST_ARCH_GNU}-strings"
-export STRIP="${OH_HOST_ARCH_GNU}-strip"
+export AR="${toolchain_prefix}ar"
+export AS="${toolchain_prefix}as"
+export CC="${toolchain_prefix}gcc"
+export CPP="${toolchain_prefix}cpp"
+export CXX="${toolchain_prefix}g++"
+export LD="${toolchain_prefix}ld"
+export NM="${toolchain_prefix}nm"
+export OBJCOPY="${toolchain_prefix}objcopy"
+export OBJDUMP="${toolchain_prefix}objdump"
+export RANLIB="${toolchain_prefix}ranlib"
+export READELF="${toolchain_prefix}readelf"
+export SIZE="${toolchain_prefix}size"
+export STRINGS="${toolchain_prefix}strings"
+export STRIP="${toolchain_prefix}strip"
# Set build flags.
if [ -f "@@DATADIR@@/opkhelper/buildflags/${OH_HOST_ARCH_CPU}" ]; then