summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-04-26 02:59:08 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-04-26 10:49:40 (EDT)
commit18d7422d8787e3de08b7df1cb712d2613a70ba9b (patch)
tree0148d1996fae10a97096849df6c9d5f100bba1c7
parent751cb7a5ec4c6cdc6342265fc7a37578192536f4 (diff)
Support cross-building with kbuild.
-rw-r--r--src/opkbuild.sh46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/opkbuild.sh b/src/opkbuild.sh
index bc32915..a167716 100644
--- a/src/opkbuild.sh
+++ b/src/opkbuild.sh
@@ -197,25 +197,44 @@ if [ ! -f "@@DATADIR@@/opkhelper/archtab" ]; then
exit 1
fi
-# Look up build GNU architecture name.
-export OH_BUILD_ARCH_GNU="$(sed -n \
- "s/^${OH_BUILD_ARCH_DIST}[ \\t][ \\t]*\\(.*\\)$/\\1/p" \
+archtab_bre='[ \t][ \t]*\([^ \t][^ \t]*[ \t][ \t]*[^ \t][^ \t]*\)'
+
+# TODO: kbuild doesn't have standardized architecture names. For example, IA-32
+# is known as "x86" in Linux and "i386" in BusyBox. So we should support a
+# comma-separated list of possible values and try to find one in src/arch once
+# the software source code is copied into the work area.
+
+# TODO: Ideally, we should have a tool like debhelper's dh_auto_configure that
+# detects the build system in use and configures the build automatically,
+# including cross building options.
+
+# Look up build GNU and kbuild architecture names.
+archtab_row_build="$(sed -n \
+ "s/^${OH_BUILD_ARCH_DIST}${archtab_bre}\$/\\1/p" \
"@@DATADIR@@/opkhelper/archtab")"
-if [ -z "${OH_BUILD_ARCH_GNU}" ]; then
+if [ -z "${archtab_row_build}" ]; then
printf 'opkbuild: Error: "%s" not found in architecture table.\n' \
"${OH_BUILD_ARCH_DIST}" >&2
exit 1
fi
+read OH_BUILD_ARCH_GNU OH_BUILD_ARCH_KBUILD <<EOF
+${archtab_row_build}
+EOF
+export OH_BUILD_ARCH_GNU OH_BUILD_ARCH_KBUILD
-# Look up host GNU architecture name.
-export OH_HOST_ARCH_GNU="$(sed -n \
- "s/^${OH_HOST_ARCH_DIST}[ \\t][ \\t]*\\(.*\\)$/\\1/p" \
+# Look up host GNU and kbuild architecture names.
+archtab_row_host="$(sed -n \
+ "s/^${OH_HOST_ARCH_DIST}${archtab_bre}\$/\\1/p" \
"@@DATADIR@@/opkhelper/archtab")"
-if [ -z "${OH_HOST_ARCH_GNU}" ]; then
+if [ -z "${archtab_row_host}" ]; then
printf 'opkbuild: Error: "%s" not found in architecture table.\n' \
"${OH_HOST_ARCH_DIST}" >&2
exit 1
fi
+read OH_HOST_ARCH_GNU OH_HOST_ARCH_KBUILD <<EOF
+${archtab_row_host}
+EOF
+export OH_HOST_ARCH_GNU OH_HOST_ARCH_KBUILD
# Detect cross building.
if [ "${OH_BUILD_ARCH_GNU}" != "${OH_HOST_ARCH_GNU}" ]; then
@@ -240,6 +259,9 @@ export READELF="${toolchain_prefix}readelf"
export SIZE="${toolchain_prefix}size"
export STRINGS="${toolchain_prefix}strings"
export STRIP="${toolchain_prefix}strip"
+# These are used by kbuild (the build system of Linux, BusyBox, and others).
+export ARCH="${OH_HOST_ARCH_KBUILD}"
+export CROSS_COMPILE="${toolchain_prefix}"
# Set build flags.
if [ -f "@@DATADIR@@/opkhelper/buildflags/${OH_HOST_ARCH_CPU}" ]; then
@@ -248,12 +270,12 @@ fi
# Print build and host architecture and platform information.
printf 'opkbuild: Build system:\n'
-printf 'opkbuild: Architecture: %s (%s)\n' \
- "${OH_BUILD_ARCH_DIST}" "${OH_BUILD_ARCH_GNU}"
+printf 'opkbuild: Architecture: %s (%s, %s)\n' \
+ "${OH_BUILD_ARCH_DIST}" "${OH_BUILD_ARCH_GNU}" "${OH_BUILD_ARCH_KBUILD}"
printf 'opkbuild: Platform: %s\n' "${OH_BUILD_PLATFORM}"
printf 'opkbuild: Host system:\n'
-printf 'opkbuild: Architecture: %s (%s)\n' \
- "${OH_HOST_ARCH_DIST}" "${OH_HOST_ARCH_GNU}"
+printf 'opkbuild: Architecture: %s (%s, %s)\n' \
+ "${OH_HOST_ARCH_DIST}" "${OH_HOST_ARCH_GNU}" "${OH_HOST_ARCH_KBUILD}"
printf 'opkbuild: Platform: %s\n' "${OH_HOST_PLATFORM:-<none>}"
# Check build dependencies.