summaryrefslogtreecommitdiffstats
path: root/src/opkbuild
diff options
context:
space:
mode:
Diffstat (limited to 'src/opkbuild')
-rw-r--r--src/opkbuild38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/opkbuild b/src/opkbuild
index e9b1f3f..7c3c953 100644
--- a/src/opkbuild
+++ b/src/opkbuild
@@ -34,7 +34,7 @@ error()
exit 1
}
-opts=$(getopt -n "${0}" -o 'r:' -- "${@}")
+opts=$(getopt -n "${0}" -o 'r:p:' -- "${@}")
if [ ${?} -ne 0 ]; then
print_usage "${0}" >&2
exit 1;
@@ -46,6 +46,10 @@ while true; do
uid0_cmd=${2}
shift 2
;;
+ -p)
+ platform=${2}
+ shift 2
+ ;;
--)
shift
break
@@ -77,6 +81,29 @@ if [ "$(cat format)" != '1.0' ]; then
exit 1
fi
+# Attempt to detect the target platform.
+# If there no config files to copy, build platform-independent packages.
+if [ ! -f config ]; then
+ platform=''
+# If a target platform was not specified ...
+elif [ -z "${platform}" ]; then
+ platform=$(opkg print-architecture | \
+ grep '^arch [^-] [0-9][0-9]*')
+ # ... and there are config files and zero installable platforms, fail.
+ if [ -z "${platform}" ]; then
+ printf 'opkbuild: Error: %s\n' \
+ 'Building platform-dependent package and no platforms detected' >&2
+ exit 1
+ # ... and there are config files and multiple installable platforms, request
+ # explicit selection.
+ elif [ $(echo "${platform}" | wc -l) -gt 1 ]; then
+ printf 'opkbuild: Error: %s\n' \
+ 'Multiple platforms found while detecting target' >&2
+ exit 1
+ fi
+ # ... and there are config files and one installable platform, build for it.
+fi
+
# Make work area.
printf 'opkbuild: Making work area...\n'
mkdir tmp
@@ -87,6 +114,12 @@ printf 'opkbuild: Reading source package control fields...\n'
srcpkg=$(oh_get_field Source)
version=$(oh_get_field Version)
+# Set environment variables for the build configuration.
+export OH_PLATFORM="${platform}"
+export OH_SRCPKG="${srcpkg}"
+export OH_PKGVER="${version%'-'*}"
+export OH_PKGREV="${version#*'-'}"
+
# Check build dependencies.
oh-checkbuilddeps || error "${srcpkg}-src"
@@ -117,6 +150,7 @@ printf 'opkbuild: Package "%s" complete!\n\n' "${srcpkg}-src"
for binpkgdir in ../*.pkg/; do
binpkg=${binpkgdir#'../'}
binpkg=${binpkg%'.pkg/'}
+ export OH_BINPKG="${binpkg}"
# TODO: Check architecture.
if true; then
printf 'opkbuild: Attempting to build package "%s"...\n' "${binpkg}"
@@ -132,6 +166,8 @@ for binpkgdir in ../*.pkg/; do
# TODO: Other compression formats, putting things in src/, ...
# Apply patches.
oh-applypatches
+ # Copy platform config files.
+ oh-copyconfig || error "${binpkg}"
# Build the package.
${uid0_cmd} ../build ${binpkg} || error "${binpkg}"
printf 'opkbuild: Package "%s" complete!\n\n' "${binpkg}"