diff options
-rw-r--r-- | src/opkbuild.sh | 467 |
1 files changed, 115 insertions, 352 deletions
diff --git a/src/opkbuild.sh b/src/opkbuild.sh index e1da8e4..bb2521b 100644 --- a/src/opkbuild.sh +++ b/src/opkbuild.sh @@ -1,6 +1,6 @@ #!@@SH@@ # -# opkhelper +# opkbuild # src/opkbuild # Build opkg packages. # @@ -19,453 +19,216 @@ # 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= +. '@@LIBOPKBUILD@@/load.sm' + +ob_use locale +ob_use output +ob_use package +ob_use metadata + +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 . + ob_set_text_domain 'opkbuild' get_options "${@}" shift $(($OPTIND - 1)) - if [ "${#}" -ne 0 ]; then - oh_usage + if [ ${#} -ne 0 ]; then + usage exit 1 fi test_uid0_cmd - find_sanity - oh_changelog_parse setup_package - setup_source_control + setup_arch_plat - make_work_area + ob_init_package '.' - if [ "${OPT_BUILD}" = 'source' -o "${OPT_BUILD}" = 'full' ]; then - build_source - fi + mkdir -p 'tmp' + cd 'tmp' - 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 + ob_parse_package_metadata -c '.opkbuild.cache' + + build_source + + ob-checkbuilddeps + + pkgs="$(ob_get_binary_packages -a "${OB_HOST_ARCH}")" + + eval "$(ob-buildenv)" + + 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 + if [ -n "${opt_build}" ]; then oh_error "${oh_str_bbasf_mutex}" fi - OPT_BUILD=binary + opt_build='binary' ;; B) - if [ -n "${OPT_BUILD}" ]; then + if [ -n "${opt_build}" ]; then oh_error "${oh_str_bbasf_mutex}" fi - OPT_BUILD=binary-arch + opt_build='binary-arch' ;; A) - if [ -n "${OPT_BUILD}" ]; then + if [ -n "${opt_build}" ]; then oh_error "${oh_str_bbasf_mutex}" fi - OPT_BUILD=binary-indep + opt_build='binary-indep' ;; S) - if [ -n "${OPT_BUILD}" ]; then + if [ -n "${opt_build}" ]; then oh_error "${oh_str_bbasf_mutex}" fi - OPT_BUILD=source + opt_build='source' ;; F) - if [ -n "${OPT_BUILD}" ]; then + if [ -n "${opt_build}" ]; then oh_error "${oh_str_bbasf_mutex}" fi - OPT_BUILD=full + opt_build='full' ;; T) - OPT_TARGET="${OPTARG}" + opt_target="${OPTARG}" ;; a) - OPT_HOST_ARCH="${OPTARG}" + opt_host_arch="${OPTARG}" ;; P) - OPT_HOST_PLAT="${OPTARG}" + opt_host_plat="${OPTARG}" ;; D) - OPT_CHECK_BUILD_DEPS=true + opt_check_build_deps='true' ;; d) - OPT_CHECK_BUILD_DEPS=false + opt_check_build_deps='false' ;; C) - OPT_CLEAN=true + opt_clean='true' ;; c) - OPT_CLEAN=false + opt_clean='false' ;; r) - OPT_UID0_CMD="${OPTARG}" + opt_uid0_cmd="${OPTARG}" ;; h) - oh_help + help exit 0 ;; V) - oh_version + version exit 0 ;; ?) - oh_error "${oh_str_bad_opt}" "${opt}" + 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 + [ -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 + if [ -n "${opt_target}" ]; then + [ -z "${opt_clean}" ] && opt_clean='false' else - if [ "${OPT_BUILD}" = 'full' ]; then - OPT_TARGET=binary + if [ "${opt_build}" = 'full' ]; then + opt_target='binary' else - OPT_TARGET="${OPT_BUILD}" + opt_target="${opt_build}" fi - [ -z "${OPT_CLEAN}" ] && OPT_CLEAN=true + [ -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 -} + test_uid=$("${opt_uid0_cmd}" id -u) -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}" + if [ ${?} -ne 0 ]; then + ob_error "$(ob_get_msg 'uid0_cmd_not_found')" "${opt_uid0_cmd}" 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} + if [ ${test_uid} -ne 0 ]; then + ob_error "$(ob_get_msg 'uid0_cmd_bad_uid')" "${opt_uid0_cmd}" fi } -setup_build_platform() +setup_arch_plat() { - # TODO: Get build platform from opkg. - : -} + OB_BUILD_ARCH="$(ob_get_system_arch)" + OB_BUILD_PLATFORM="$(ob_get_system_plat)" -setup_host_arch() -{ - if [ -n "${OPT_HOST_ARCH}" ]; then - OH_HOST_ARCH="${OPT_HOST_ARCH}" + if [ -n "${opt_host_arch}" ]; then + OB_HOST_ARCH="${opt_host_arch}" else - OH_HOST_ARCH="${OH_BUILD_ARCH}" + OB_HOST_ARCH="${OB_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}" + if [ -n "${opt_host_plat}" ]; then + OB_HOST_PLATFORM="${opt_host_plat}" else - OH_HOST_PLATFORM="${OH_BUILD_PLATFORM}" + OB_HOST_PLATFORM="${OB_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 + IFS=- read OB_BUILD_ARCH_CPU OB_BUILD_ARCH_KERNEL OB_BUILD_ARCH_LIBS <<EOF +${OB_BUILD_ARCH} +EOF + IFS=- read OB_HOST_ARCH_CPU OB_HOST_ARCH_KERNEL OB_HOST_ARCH_LIBS <<EOF +${OB_HOST_ARCH} +EOF } main "${@}" |