summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/oh-applypatches.sh55
-rw-r--r--src/oh-buildopk.sh106
-rw-r--r--src/oh-checkbuilddeps.sh32
-rw-r--r--src/oh-copyconfig.sh81
-rw-r--r--src/oh-gencontrol.sh105
-rw-r--r--src/oh-installdocs.sh58
-rw-r--r--src/oh-parsechangelog.sh64
-rw-r--r--src/oh-unpacksource.sh123
-rw-r--r--src/opkbuild.sh471
9 files changed, 0 insertions, 1095 deletions
diff --git a/src/oh-applypatches.sh b/src/oh-applypatches.sh
deleted file mode 100644
index 621e882..0000000
--- a/src/oh-applypatches.sh
+++ /dev/null
@@ -1,55 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-applypatches
-# Apply patches to source code.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-
-main()
-{
- oh_locale_set
- oh_set_source_dir ..
-
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- apply_patches
-}
-
-apply_patches()
-{
- applied=false
-
- if [ -d ../patches ]; then
- # Iterate over patches ordered alphabetically by name.
- for patch in $(ls -1 ../patches | sort); do
- oh_info "${oh_str_applying_patch}" "${patch}"
- patch -N -p 1 -u -d src -i "../../patches/${patch}" || \
- oh_error "${oh_str_cant_apply_patch}" "${patch}"
- applied=true
- done
- fi
-
- ${applied} || oh_info "${oh_str_no_patches}"
-}
-
-main "${@}"
diff --git a/src/oh-buildopk.sh b/src/oh-buildopk.sh
deleted file mode 100644
index 5fcec68..0000000
--- a/src/oh-buildopk.sh
+++ /dev/null
@@ -1,106 +0,0 @@
-#!@@SHELL@@
-#
-# opkhelper
-# src/oh-buildopk
-# Pack binary package files into an opk file.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/opkhelper/controlfields
-. @@LIBDIR@@/opkhelper/architecture
-. @@LIBDIR@@/opkhelper/messages
-
-print_usage()
-{
- printf 'Usage: %s -s | pkgname...\n' "${1}"
-}
-
-opts=$(getopt -n "${0}" -o 's' -- "${@}")
-if [ ${?} -ne 0 ]; then
- print_usage "${0}" >&2
- exit 1;
-fi
-eval set -- "${opts}"
-while true; do
- case "${1}" in
- -s)
- is_srcpkg=true
- shift
- ;;
- --)
- shift
- break
- ;;
- *)
- print_usage "${0}" >&2
- exit 1
- ;;
- esac
-done
-
-if [ -n "${is_srcpkg}" ]; then
- pkg="${OH_SRCPKG}-src"
-
- # Write debian-binary.
- echo '2.0' > debian-binary || exit 2
-
- # Pack data.tar.gz.
- cd ${pkg}.data
- tar -czf ../data.tar.gz . || exit 2
- cd ..
-
- # Pack control.tar.gz.
- cd ${pkg}.control
- tar -czf ../control.tar.gz . || exit 2
- cd ..
-
- # Pack opk file.
- tar -czf ../../${pkg}_${OH_PKGVER}_all.opk \
- debian-binary data.tar.gz control.tar.gz || exit 2
- rm -Rf debian-binary control data.tar.gz control.tar.gz || exit 2
-else
- if [ ${#} -eq 0 ]; then
- print_usage ${0} >&2
- exit 1
- fi
-
- # Iterate over packages.
- while [ ${#} -gt 0 ]; do
- oh_info 'Packing package "%s"...' "${1}"
-
- arch="$(oh_get_package_architecture ${1})"
-
- # Write debian-binary.
- echo '2.0' > debian-binary || exit 2
-
- # Pack data.tar.gz.
- cd ${1}.data
- tar -czf ../data.tar.gz . || exit 2
- cd ..
-
- # Pack control.tar.gz.
- cd ${1}.control
- tar -czf ../control.tar.gz . || exit 2
- cd ..
-
- # Pack opk file.
- tar -czf ../../${1}_${OH_PKGVER}_${arch}.opk \
- debian-binary data.tar.gz control.tar.gz || exit 2
- rm -Rf debian-binary control data.tar.gz control.tar.gz || exit 2
-
- shift
- done
-fi
diff --git a/src/oh-checkbuilddeps.sh b/src/oh-checkbuilddeps.sh
deleted file mode 100644
index 80ab9f4..0000000
--- a/src/oh-checkbuilddeps.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-checkbuilddeps
-# Make sure that package build dependencies are installed.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-
-main()
-{
- oh_locale_set
-
- oh_info "${oh_str_checking_build_deps}"
-}
-
-main "${@}"
diff --git a/src/oh-copyconfig.sh b/src/oh-copyconfig.sh
deleted file mode 100644
index d6621d4..0000000
--- a/src/oh-copyconfig.sh
+++ /dev/null
@@ -1,81 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-copyconfig
-# Copy build-time or run-time platform configuration files.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-
-main()
-{
- oh_locale_set
- oh_set_source_dir ..
-
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- copied=false
-
- if [ -f ../config ]; then
- copy_config config '.'
- copied=true
- fi
-
- for bin_config in ../*.pkg/config; do
- copy_config "${bin_config#../}" 'dest'
- copied=true
- done
-
- "${copied}" || oh_info "${oh_str_no_plat_config}"
-}
-
-copy_config()
-{
- list="${1}"
- dest_base="${2}"
-
- while read -r src dest; do
- if [ -z "${src}" -o -z "${dest}" ]; then
- oh_error "${oh_str_bad_config_syntax}" "${list}"
- fi
- # Make sure the destination directory exists.
- mkdir -p "${dest_base}/${dest%/*}" || \
- oh_error "${oh_str_cant_make_config_dest_dir}" "${dest%/*}"
- # Find the config package files.
- # TODO: Don't hardcode path.
- config_dir_base="/usr/share/config/${OH_HOST_PLATFORM}/${OH_SOURCE}"
- if [ -d "${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" ]; then
- src_base="${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}"
- elif [ -d "${config_dir_base}" ]; then
- src_base="${config_dir_base}"
- else
- # This shouldn't happen unless the package maintainer neglected to
- # add the config package to the package's Build-Depends field.
- oh_error "${oh_str_no_config_dir}"
- fi
- # Copy the config file(s).
- oh_info "${oh_str_copying_config_file}" "${src}" "${dest}"
- cp -p "${src_base}/${src}" "${dest_base}/${dest}" || \
- oh_error "${oh_str_cant_copy_config_file}"
- done <"../${list}"
-}
-
-main "${@}"
diff --git a/src/oh-gencontrol.sh b/src/oh-gencontrol.sh
deleted file mode 100644
index 9b2718e..0000000
--- a/src/oh-gencontrol.sh
+++ /dev/null
@@ -1,105 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-gencontrol
-# Generates a control directory with a control file and scripts.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/locale
-. @@LIBDIR@@/control
-. @@LIBDIR@@/util
-
-main()
-{
- oh_locale_set
- oh_set_source_dir ..
-
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- for pkg in "${OH_SOURCE_DIR}/"*.pkg/; do
-
- pkg="${pkg#../}"
- pkg="${pkg%/}"
-
- # Load field values from cache properties.
- for name in ${OH_CONTROL_BINARY_FIELDS_REQUIRED} \
- ${OH_CONTROL_BINARY_FIELDS_OPTIONAL}; do
- value="$(oh_cache "bin.${pkg}.control.${name}")"
- param="OH_CONTROL_BINARY_FIELD_$(echo "${name}" | \
- LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
- # Escape the value.
- value="$(echo "${value}" | sed "s/'/'\\\\''/g")"
- eval "${param}='${value}'"
- done
- oh_control_gen_binary "${pkg}"
-
- install_maintainer_scripts "${pkg}"
- gen_conffiles "${pkg}"
- gen_md5sums "${pkg}"
-
- done
-}
-
-install_maintainer_scripts()
-{
- pkg="${1}"
-
- for script in preinst postinst prerm postrm; do
- if [ -L "${OH_SOURCE_DIR}/${pkg}.pkg/${script}" ]; then
- target="$(ls -l "${OH_SOURCE_DIR}/${pkg}.pkg/${script}")"
- target="${target#* -> }"
- ln -s "${target}" "${OH_SOURCE_DIR}/tmp/${pkg}.control/${script}"
- else
- cp "${OH_SOURCE_DIR}/${pkg}.pkg/${script}" \
- "${OH_SOURCE_DIR}/tmp/${pkg}.control/${script}"
- chmod 755 "${OH_SOURCE_DIR}/tmp/${pkg}.control/${script}"
- fi
- done
-}
-
-gen_conffiles()
-{
- if [ -d "${OH_SOURCE_DIR}/tmp/${pkg}.data/etc" ]; then
- find "${OH_SOURCE_DIR}/tmp/${pkg}.data/etc" -type f | \
- sed "^@"${OH_SOURCE_DIR}/tmp/${pkg}.data"@@" \
- >"${OH_SOURCE_DIR}/tmp/${pkg}.control/conffiles"
- if [ -z "$(head -n 1 \
- "${OH_SOURCE_DIR}/tmp/${pkg}.control/conffiles")" ]; then
- rm -f "${OH_SOURCE_DIR}/tmp/${pkg}.control/conffiles"
- else
- chmod 644 "${OH_SOURCE_DIR}/tmp/${pkg}.control/conffiles"
- fi
- fi
-}
-
-gen_md5sums()
-{
- find "${OH_SOURCE_DIR}/tmp/${pkg}.data" -type f | sort | xargs md5sum | \
- sed "^@"${OH_SOURCE_DIR}/tmp/${pkg}.data"@@" \
- >"${OH_SOURCE_DIR}/tmp/${pkg}.control/md5sums"
- if [ -z "$(head -n 1 \
- "${OH_SOURCE_DIR}/tmp/${pkg}.control/md5sums")" ]; then
- rm -f "${OH_SOURCE_DIR}/tmp/${pkg}.control/md5sums"
- else
- chmod 644 "${OH_SOURCE_DIR}/tmp/${pkg}.control/md5sums"
- fi
-}
-
-main "${@}"
diff --git a/src/oh-installdocs.sh b/src/oh-installdocs.sh
deleted file mode 100644
index ae0f5d4..0000000
--- a/src/oh-installdocs.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!@@SHELL@@
-#
-# opkhelper
-# src/oh-installdocs
-# Install package documentation into a binary package staging area.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/opkhelper/messages
-
-print_usage()
-{
- printf 'Usage: %s providing_pkg\n' "${1}"
-}
-
-if [ ${#} -ne 1 ]; then
- print_usage ${0} >&2
- exit 1
-fi
-
-# Iterate through packages that have been installed.
-for pkgdir in *.data/; do
- pkg=${pkgdir%'.data/'}
- docdir=${pkgdir}usr/share/doc
- mkdir -p ${docdir}
- if [ ${pkg} = ${1} ]; then
- # Make the providing package provide the documentation files.
- oh_info 'Installing package documentation into package "%s"...' "${pkg}"
- mkdir -p ${docdir}/${pkg}
- cp ../copyright ${docdir}/${pkg}/copyright || \
- oh_error 'Cannot copy "copyright"'
- cp ../changelog ${docdir}/${pkg}/changelog.dist || \
- oh_error 'Cannot copy "changelog"'
- if [ -f ../README ]; then
- cp ../README ${docdir}/${pkg}/README.dist || \
- oh_error 'Cannot copy package "README"'
- fi
- else
- # Make dependent packages link to the providing package's documentation
- # directory.
- oh_info 'Making link to documentation in package "%s"...' "${pkg}"
- ln -s /usr/share/doc/${1} ${docdir}/${pkg} || \
- oh_error 'Cannot make link to documentation files'
- fi
-done
diff --git a/src/oh-parsechangelog.sh b/src/oh-parsechangelog.sh
deleted file mode 100644
index 141c5de..0000000
--- a/src/oh-parsechangelog.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-parsechangelog
-# Parse a changelog.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-. @@LIBDIR@@/changelog
-
-main()
-{
- oh_locale_set
- oh_set_source_dir ..
-
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- oh_changelog_parse output
-}
-
-output()
-{
- # These strings are machine-readable output and should not be localized or
- # printed with oh_info().
-
- printf 'Source: %s\nVersion: %s\nDistribution: %s\n' \
- "${OH_CHANGELOG_SOURCE}" "${OH_CHANGELOG_VERSION}" \
- "${OH_CHANGELOG_DISTRIBUTION}"
- printf 'Maintainer: %s\nDate: %s\n' \
- "${OH_CHANGELOG_MAINTAINER}" "${OH_CHANGELOG_DATE}"
-
- printf 'Changes:\n'
- while IFS= read -r line; do
- if [ -z "${line}" ]; then
- printf ' .\n'
- else
- printf ' %s\n' "${line}"
- fi
- done <<EOF
-${OH_CHANGELOG_CHANGES}
-EOF
-
- return 1
-}
-
-main "${@}"
diff --git a/src/oh-unpacksource.sh b/src/oh-unpacksource.sh
deleted file mode 100644
index 2e5fc7a..0000000
--- a/src/oh-unpacksource.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/oh-unpacksource
-# Unpack native or upstream source.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-
-# Global parameters:
-UPSTREAM_ARCHIVE_BASE=
-UPSTREAM_ARCHIVE=
-UPSTREAM_ARCHIVE_Z=
-UPSTREAM_ARCHIVE_DIR=
-
-main()
-{
- oh_locale_set
- oh_set_source_dir ..
-
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- if [ -d ../src ]; then
- unpack_native
- else
- unpack_upstream
- fi
-}
-
-unpack_native()
-{
- oh_info "${oh_str_unpacking_native}"
- cp -Rp ../src src || oh_error "${oh_str_cant_unpack_native}"
-}
-
-unpack_upstream()
-{
- get_upstream_archive
- get_upstream_compression
- get_upstream_dir
- extract_upstream
-}
-
-get_upstream_archive()
-{
- UPSTREAM_ARCHIVE_BASE="${OH_SOURCE}-${OH_SOURCE_VERSION_UPSTREAM}.orig.tar."
- UPSTREAM_ARCHIVE=$(find .. -name "${UPSTREAM_ARCHIVE_BASE}*")
- case "$(echo "${UPSTREAM_ARCHIVE}" | grep -v '^$' | wc -l)" in
- 0)
- oh_error "${oh_str_no_sources}"
- ;;
- 1)
- ;;
- *)
- oh_error "${oh_str_multiple_upstream_sources}"
- ;;
- esac
-}
-
-get_upstream_compression()
-{
- z_ext="${UPSTREAM_ARCHIVE#../${UPSTREAM_ARCHIVE_BASE}}"
- case "${z_ext}" in
- gz)
- UPSTREAM_ARCHIVE_Z=z
- ;;
- bz2)
- UPSTREAM_ARCHIVE_Z=j
- ;;
- lz)
- UPSTREAM_ARCHIVE_Z=a
- ;;
- Z)
- UPSTREAM_ARCHIVE_Z=Z
- ;;
- *)
- oh_error "${oh_str_unsupported_archive_compression}" "${z_ext}"
- ;;
- esac
-}
-
-get_upstream_dir()
-{
- UPSTREAM_ARCHIVE_DIR=$(tar "-t${UPSTREAM_ARCHIVE_Z}f" \
- "${UPSTREAM_ARCHIVE}" | sed -n 's@^\./\([^/]*\)$@\1@p')
- case "$(echo "${UPSTREAM_ARCHIVE_DIR}" | grep -v '^$' | wc -l)" in
- 0)
- oh_error "${oh_str_no_upstream_dirs}"
- ;;
- 1)
- ;;
- *)
- oh_error "${oh_str_multiple_top_upstream_dirs}"
- esac
-}
-
-extract_upstream()
-{
- oh_info "${oh_str_unpacking_upstream}"
- tar "-x${UPSTREAM_ARCHIVE_Z}f" "${UPSTREAM_ARCHIVE}" || \
- oh_error "${oh_str_cant_unpack_upstream}"
- mv "${UPSTREAM_ARCHIVE_DIR}" src || oh_error "${oh_str_cant_move_native}"
-}
-
-main "${@}"
diff --git a/src/opkbuild.sh b/src/opkbuild.sh
deleted file mode 100644
index e1da8e4..0000000
--- a/src/opkbuild.sh
+++ /dev/null
@@ -1,471 +0,0 @@
-#!@@SH@@
-#
-# opkhelper
-# src/opkbuild
-# Build opkg packages.
-#
-# Copyright (C) 2012 Patrick "P. J." McDermott
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-. @@LIBDIR@@/changelog
-. @@LIBDIR@@/control
-. @@LIBDIR@@/cache
-
-# Environment variables:
-export OH_SOURCE=
-export OH_SOURCE_VERSION=
-export OH_SOURCE_VERSION_UPSTREAM=
-export OH_BINARY_VERSION=
-export OH_BUILD_ARCH=
-export OH_BUILD_ARCH_CPU=
-export OH_BUILD_ARCH_KERNEL=
-export OH_BUILD_ARCH_LIBS=
-export OH_BUILD_PLATFORM=
-export OH_BUILD_ARCH_GNU=
-export OH_HOST_ARCH=
-export OH_HOST_ARCH_CPU=
-export OH_HOST_ARCH_KERNEL=
-export OH_HOST_ARCH_LIBS=
-export OH_HOST_PLATFORM=
-export OH_HOST_ARCH_GNU=
-export OH_TOOL_PREFIX=
-export AR=
-export AS=
-export CC=
-export CPP=
-export CXXLD=
-export NM=
-export OBJCOPY=
-export OBJDUMP=
-export RANLIB=
-export READELF=
-export SIZE=
-export STRINGS=
-export STRIP=
-
-# Global parameters:
-OPT_BUILD=
-OPT_TARGET=
-OPT_HOST_ARCH=
-OPT_HOST_PLAT=
-OPT_CHECK_BUILD_DEPS=
-OPT_CLEAN=
-OPT_UID0_CMD=
-
-main()
-{
- oh_locale_set
- oh_set_source_dir .
-
- get_options "${@}"
- shift $(($OPTIND - 1))
- if [ "${#}" -ne 0 ]; then
- oh_usage
- exit 1
- fi
-
- test_uid0_cmd
-
- find_sanity
- oh_changelog_parse setup_package
- setup_source_control
-
- make_work_area
-
- if [ "${OPT_BUILD}" = 'source' -o "${OPT_BUILD}" = 'full' ]; then
- build_source
- fi
-
- if [ "${OPT_BUILD}" != 'source' ]; then
- "${OPT_CHECK_BUILD_DEPS}" && oh-checkbuilddeps
- setup_build
- print_arch_stats
- cp_step=$(oh_cache 'opkbuild.step')
- if [ -n "${cp_step}" ]; then
- "step_${cp_step}"
- else
- step_unpack
- fi
- fi
-}
-
-get_options()
-{
- # Parse and handle command-line options.
- while getopts 'bBASFT:a:P:DdCcr:hV' opt; do
- case "${opt}" in
- b)
- if [ -n "${OPT_BUILD}" ]; then
- oh_error "${oh_str_bbasf_mutex}"
- fi
- OPT_BUILD=binary
- ;;
- B)
- if [ -n "${OPT_BUILD}" ]; then
- oh_error "${oh_str_bbasf_mutex}"
- fi
- OPT_BUILD=binary-arch
- ;;
- A)
- if [ -n "${OPT_BUILD}" ]; then
- oh_error "${oh_str_bbasf_mutex}"
- fi
- OPT_BUILD=binary-indep
- ;;
- S)
- if [ -n "${OPT_BUILD}" ]; then
- oh_error "${oh_str_bbasf_mutex}"
- fi
- OPT_BUILD=source
- ;;
- F)
- if [ -n "${OPT_BUILD}" ]; then
- oh_error "${oh_str_bbasf_mutex}"
- fi
- OPT_BUILD=full
- ;;
- T)
- OPT_TARGET="${OPTARG}"
- ;;
- a)
- OPT_HOST_ARCH="${OPTARG}"
- ;;
- P)
- OPT_HOST_PLAT="${OPTARG}"
- ;;
- D)
- OPT_CHECK_BUILD_DEPS=true
- ;;
- d)
- OPT_CHECK_BUILD_DEPS=false
- ;;
- C)
- OPT_CLEAN=true
- ;;
- c)
- OPT_CLEAN=false
- ;;
- r)
- OPT_UID0_CMD="${OPTARG}"
- ;;
- h)
- oh_help
- exit 0
- ;;
- V)
- oh_version
- exit 0
- ;;
- ?)
- oh_error "${oh_str_bad_opt}" "${opt}"
- exit 1
- ;;
- esac
- done
-
- # Set default option values.
- [ -z "${OPT_BUILD}" ] && OPT_BUILD=full
- [ -z "${OPT_CHECK_BUILD_DEPS}" ] && OPT_CHECK_BUILD_DEPS=true
- [ -z "${OPT_UID0_CMD}" ] && OPT_UID0_CMD=fakeroot
-
- # Set default target and cleaning behavior.
- if [ -n "${OPT_TARGET}" ]; then
- [ -z "${OPT_CLEAN}" ] && OPT_CLEAN=false
- else
- if [ "${OPT_BUILD}" = 'full' ]; then
- OPT_TARGET=binary
- else
- OPT_TARGET="${OPT_BUILD}"
- fi
- [ -z "${OPT_CLEAN}" ] && OPT_CLEAN=true
- fi
-}
-
-test_uid0_cmd()
-{
- # Verify that the UID 0 command works.
- test_uid=$("${OPT_UID0_CMD}" id -u)
- if [ "${?}" -ne 0 ]; then
- oh_error "${oh_str_uid0_cmd_not_found}" "${OPT_UID0_CMD}"
- fi
- if [ "${test_uid}" -ne 0 ]; then
- oh_error "${oh_str_uid0_cmd_bad_uid}" "${OPT_UID0_CMD}"
- fi
-}
-
-find_sanity()
-{
- oh_info "${oh_str_find_sanity}"
-
- format="$(cat format 2>/dev/null)"
- if [ "${?}" -ne 0 ]; then
- oh_error "${oh_str_no_format}"
- fi
- if [ "${format}" != '2.0' ]; then
- oh_error "${oh_str_unsupported_format}" "${format}"
- fi
-
- # Check for all files immediately required by SPF 2.0.
- [ ! -f 'control' ] && oh_error "${oh_str_no_control}"
- [ ! -x 'config' ] && oh_error "${oh_str_no_config}"
- [ ! -f 'copyright' ] && oh_error "${oh_str_no_copyright}"
- [ ! -f 'changelog' ] && oh_error "${oh_str_no_changelog}"
-}
-
-setup_package()
-{
- OH_SOURCE="${OH_CHANGELOG_SOURCE}"
- OH_SOURCE_VERSION="${OH_CHANGELOG_VERSION}"
- OH_SOURCE_VERSION_UPSTREAM="${OH_SOURCE_VERSION%%-*}"
- OH_BINARY_VERSION="${OH_SOURCE_VERSION}"
-
- return 1
-}
-
-setup_source_control()
-{
- oh_control_parse_source
- for field in ${OH_CONTROL_SOURCE_FIELDS_REQUIRED} \
- ${OH_CONTROL_SOURCE_FIELDS_OPTIONAL}; do
- field_tr=$(echo "${field}" | \
- LC_CTYPE=POSIX tr '[:lower:]-' '[:upper:]_')
- param="OH_CONTROL_SOURCE_FIELD_${field_tr}"
- oh_cache "src.control.${field}" \
- "$(eval echo \$\{"${param}"\})"
- done
-}
-
-make_work_area()
-{
- if [ ! -d tmp ]; then
- mkdir tmp || oh_error "${oh_str_cant_make_work_area}"
- fi
- cd tmp || oh_error "${oh_str_cant_enter_work_area}"
-
- oh_set_source_dir ..
-}
-
-build_source()
-{
- oh_info "${oh_str_installing_src_pkg_files}"
-
- src_pkg_data_base="src:${OH_SOURCE}.data/usr/src"
- src_pkg_data_base="${src_pkg_data_base}/${OH_SOURCE}_${OH_SOURCE_VERSION}"
-
- "${OPT_UID0_CMD}" mkdir -p \
- "${src_pkg_data_base}" || \
- oh_error "${oh_str_cant_make_src_pkg_dir}"
-
- for file in ../*; do
- case "${file}" in
- ../tmp)
- ;;
- ../*)
- "${OPT_UID0_CMD}" cp -R "${file}" "${src_pkg_data_base}" || \
- oh_error "${oh_str_cant_install_src_pkg_file}"
- ;;
- esac
- done
-
- oh_control_gen_source
- # TODO: oh-buildopk
-
- return 0
- rm -Rf "src:${OH_SOURCE}.data" || oh_error "${oh_str_cant_rm_src_pkg_data}"
-}
-
-setup_build()
-{
- setup_build_arch
- setup_build_flags
- setup_build_platform
- setup_host_arch
- setup_host_platform
- setup_toolchain
-}
-
-setup_build_arch()
-{
- # TODO: Get build arch from opkg.
- # TODO: Get GNU system type from table.
-
- IFS=- read OH_BUILD_ARCH_CPU OH_BUILD_ARCH_KERNEL OH_BUILD_ARCH_LIBS <<EOF
-${OH_BUILD_ARCH}
-EOF
-}
-
-setup_build_flags()
-{
- # TODO: Don't hardcode path.
- if [ -f "/usr/local/share/opkhelper/buildflags/${OH_HOST_ARCH_CPU}" ]; then
- . /usr/local/share/opkhelper/buildflags/${OH_HOST_ARCH_CPU}
- fi
-}
-
-setup_build_platform()
-{
- # TODO: Get build platform from opkg.
- :
-}
-
-setup_host_arch()
-{
- if [ -n "${OPT_HOST_ARCH}" ]; then
- OH_HOST_ARCH="${OPT_HOST_ARCH}"
- else
- OH_HOST_ARCH="${OH_BUILD_ARCH}"
- fi
-
- IFS=- read OH_HOST_ARCH_CPU OH_HOST_ARCH_KERNEL OH_HOST_ARCH_LIBS <<EOF
-${OH_HOST_ARCH}
-EOF
-}
-
-setup_host_platform()
-{
- if [ -n "${OPT_HOST_PLAT}" ]; then
- OH_HOST_PLATFORM="${OPT_HOST_PLAT}"
- else
- OH_HOST_PLATFORM="${OH_BUILD_PLATFORM}"
- fi
-}
-
-setup_toolchain()
-{
- OH_TOOL_PREFIX="${OH_HOST_ARCH}-"
-
- # Set toolchain environment variables.
- # NB: This is written for GNU Binutils and GCC and won't work for, e.g., LLVM.
- AR="${OH_TOOL_PREFIX}ar"
- AS="${OH_TOOL_PREFIX}as"
- CC="${OH_TOOL_PREFIX}gcc"
- CPP="${OH_TOOL_PREFIX}cpp"
- CXX="${OH_TOOL_PREFIX}g++"
- LD="${OH_TOOL_PREFIX}ld"
- NM="${OH_TOOL_PREFIX}nm"
- OBJCOPY="${OH_TOOL_PREFIX}objcopy"
- OBJDUMP="${OH_TOOL_PREFIX}objdump"
- RANLIB="${OH_TOOL_PREFIX}ranlib"
- READELF="${OH_TOOL_PREFIX}readelf"
- SIZE="${OH_TOOL_PREFIX}size"
- STRINGS="${OH_TOOL_PREFIX}strings"
- STRIP="${OH_TOOL_PREFIX}strip"
-}
-
-print_arch_stats()
-{
- oh_info "${oh_str_build_arch_stat_header}"
- oh_info "${oh_str_arch_stat_arch}" "${OH_BUILD_ARCH}"
- oh_info "${oh_str_arch_stat_plat}" "${OH_BUILD_PLATFORM}"
- oh_info "${oh_str_host_arch_stat_header}"
- oh_info "${oh_str_arch_stat_arch}" "${OH_HOST_ARCH}"
- oh_info "${oh_str_arch_stat_plat}" "${OH_HOST_PLATFORM}"
-}
-
-step_unpack()
-{
- oh_cache 'opkbuild.step' 'unpack'
-
- oh-unpacksource
-
- step_patch
-}
-
-step_patch()
-{
- oh_cache 'opkbuild.step' 'patch'
-
- oh-applypatches
-
- step_config
-}
-
-step_config()
-{
- oh_cache 'opkbuild.step' config
-
- ./config
-
- step_bincontrol
-}
-
-step_bincontrol()
-{
- oh_cache 'opkbuild.step' bincontrol
-
- for pkg in ../*.pkg/; do
- pkg="${pkg#../}"
- pkg="${pkg%.pkg/}"
- if [ "${pkg}" = '*' ]; then
- if [ -d '../*.pkg' ]; then
- oh_error "${oh_str_asterisk_binary_package}"
- else
- oh_error "${oh_str_no_binary_packages}"
- fi
- fi
- echo "${pkg}" | grep -E "${OH_SOURCE_RE}" >/dev/null 2>&1
- if [ "${?}" -ne 0 ]; then
- oh_error "${oh_str_bad_binary_package_name}" "${pkg}"
- fi
- oh_control_parse_binary "${pkg}"
- for field in ${OH_CONTROL_BINARY_FIELDS_REQUIRED} \
- ${OH_CONTROL_BINARY_FIELDS_OPTIONAL}; do
- field_tr=$(echo "${field}" | \
- LC_CTYPE=POSIX tr '[:lower:]-' '[:upper:]_')
- param="OH_CONTROL_BINARY_FIELD_${field_tr}"
- oh_cache "bin.${pkg}.control.${field}" \
- "$(eval echo \$\{"${param}"\})"
- done
- done
-
- step_platconf
-}
-
-step_platconf()
-{
- oh_cache 'opkbuild.step' platconf
-
- oh-copyconfig
-
- step_build
-}
-
-step_build()
-{
- oh_cache 'opkbuild.step' build
-
- ./build "${OPT_TARGET}"
-
- "${OPT_CLEAN}" && step_clean
-}
-
-step_clean()
-{
- oh_cache 'opkbuild.step' clean
-
- ./config clean
-
- step_cleanwork
-}
-
-step_cleanwork()
-{
- cd ..
- rm -Rf tmp
-}
-
-main "${@}"