#!@@SH@@
#
# opkbuild
# 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 .
. '@@LIBOPKBUILD@@/load.sm'
ob_use locale
ob_use output
ob_use package
ob_use metadata
export OB_SOURCE=
export OB_SOURCE_VERSION=
export OB_SOURCE_VERSION_UPSTREAM=
export OB_BINARY_VERSION=
export OB_BUILD_ARCH=
export OB_BUILD_ARCH_CPU=
export OB_BUILD_ARCH_KERNEL=
export OB_BUILD_ARCH_LIBS=
export OB_BUILD_PLATFORM=
export OB_BUILD_ARCH_GNU=
export OB_HOST_ARCH=
export OB_HOST_ARCH_CPU=
export OB_HOST_ARCH_KERNEL=
export OB_HOST_ARCH_LIBS=
export OB_HOST_PLATFORM=
export OB_HOST_ARCH_GNU=
opt_build=
opt_target=
opt_host_arch=
opt_host_plat=
opt_check_build_deps=
opt_clean=
opt_uid0_cmd=
main()
{
ob_set_text_domain 'opkbuild'
get_options "${@}"
shift $(($OPTIND - 1))
if [ ${#} -ne 0 ]; then
usage
exit 1
fi
test_uid0_cmd
ob_info "$(ob_get_msg 'setup_arch_plat')"
setup_arch_plat
ob_info "$(ob_get_msg 'make_work_area')"
mkdir -p 'tmp'
cd 'tmp'
ob_info "$(ob_get_msg 'parse_package_metadata')"
ob_init_package '..'
ob_parse_package_metadata -c '.opkbuild.cache'
OB_SOURCE="$(ob_get_source_parameter 'Source')"
OB_SOURCE_VERSION="$(ob_get_source_parameter 'Version')"
ob_parse_version -u 'OB_SOURCE_VERSION_UPSTREAM' "${OB_SOURCE_VERSION}"
OB_BINARY_VERSION="$(ob_get_source_parameter 'Version')"
ob_info "$(ob_get_msg 'build_source')"
build_source
ob-checkbuilddeps
pkgs="$(ob_get_binary_packages -a "${OB_HOST_ARCH}")"
eval "$(ob-buildenv | sed 's/^/export /')"
ob-unpacksource
ob-applypatches
ob-installplatconf
../build build
${opt_uid0_cmd} ../build install
ob-installdocs
ob-gencontrol
ob-buildopk
ob-genchanges
if "${opt_clean}"; then
cd ..
rm -Rf 'tmp'
fi
}
usage()
{
printf "$(ob_get_msg 'usage')\n" 'opkbuild'
}
help()
{
usage
printf '%s\n' "$(ob_get_msg 'help')"
}
version()
{
printf "$(ob_get_msg 'version')\n" \
'opkbuild' '@@PACKAGE_NAME@@' '@@PACKAGE_VERSION@@'
}
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)
help
exit 0
;;
V)
version
exit 0
;;
?)
ob_error "$(ob_get_msg '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
ob_error "$(ob_get_msg 'uid0_cmd_not_found')" "${opt_uid0_cmd}"
fi
if [ ${test_uid} -ne 0 ]; then
ob_error "$(ob_get_msg 'uid0_cmd_bad_uid')" "${opt_uid0_cmd}"
fi
}
setup_arch_plat()
{
OB_BUILD_ARCH="$(ob_get_system_arch)"
OB_BUILD_PLATFORM="$(ob_get_system_plat)"
if [ -n "${opt_host_arch}" ]; then
OB_HOST_ARCH="${opt_host_arch}"
else
OB_HOST_ARCH="${OB_BUILD_ARCH}"
fi
if [ -n "${opt_host_plat}" ]; then
OB_HOST_PLATFORM="${opt_host_plat}"
else
OB_HOST_PLATFORM="${OB_BUILD_PLATFORM}"
fi
IFS=- read OB_BUILD_ARCH_CPU OB_BUILD_ARCH_KERNEL OB_BUILD_ARCH_LIBS <