From b6a9a1a3c8b98077cce47d579069c42080d17da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 15 Mar 2020 09:14:23 +0000 Subject: General cleanup. --- build.sh | 116 +++++---- dist/dist_zipdist.dist | 2 +- etc/README.md | 33 ++- etc/build.usage | 4 +- pkgtool.sh | 238 ++++++++++-------- subr/build_init.subr | 274 +++++++++------------ subr/ex_pkg.subr | 132 +++++++--- subr/ex_pkg_dispatch.subr | 101 ++++---- subr/ex_pkg_env.subr | 6 +- subr/ex_pkg_exec.subr | 8 +- subr/pkg_configure_autotools.subr | 2 +- subr/pkg_fetch_extract.subr | 4 +- subr/pkg_install.subr | 4 +- subr/pkg_install_files.subr | 2 +- subr/pkgtool_init.subr | 169 +++---------- subr/rtl.subr | 9 +- subr/rtl_complex.subr | 21 +- subr/rtl_fetch.subr | 3 +- subr/rtl_fileop.subr | 98 ++++---- subr/rtl_list.subr | 24 +- subr/rtl_log.subr | 115 +++++---- subr/rtl_string.subr | 15 +- vars/clang_host.vars | 4 +- vars/gcc.vars | 493 ++++++++++++++++++++------------------ vars/git.vars | 2 +- vars/libxml2.vars | 4 +- vars/llvm_host.vars | 4 +- vars/rpm_host.vars | 2 +- 28 files changed, 973 insertions(+), 916 deletions(-) diff --git a/build.sh b/build.sh index 4c812f62..c36eae05 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ buildp_ast() { local _param="${1}" _pids="" _pids_niter=0 _pkg_name="" RTL_KILL_TREE_PIDS=""; if [ "${_param}" = "abort" ]; then - rtl_log_msg failexit "Build aborted."; + rtl_log_msg fatalexit "Build aborted."; fi; if [ -n "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then rtl_fileop rm "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; @@ -20,34 +20,34 @@ buildp_ast() { fi; done; if [ -n "${_pids}" ]; then - rtl_log_msg vnfo "Killed PIDs $(rtl_uniq ${_pids})"; + rtl_log_msg notice "Killed PID(s): %s" "$(rtl_uniq ${_pids})"; fi; if [ -n "${EX_PKG_DISPATCH_WAIT}" ]; then for _pkg_name in ${EX_PKG_DISPATCH_WAIT}; do rtl_state_clear "${BUILD_WORKDIR}" "${_pkg_name}"; done; - rtl_log_msg vnfo "Reset package state for: ${EX_PKG_DISPATCH_WAIT}"; + rtl_log_msg notice "Reset package state for: %s" "${EX_PKG_DISPATCH_WAIT}"; fi; }; buildp_dispatch_fail_pkg() { local _group_name="${1}" _pkg_name="${2}"; : $((BUILD_NFAIL+=1)); BUILD_PKGS_FAILED="$(rtl_lconcat "${BUILD_PKGS_FAILED}" "${_pkg_name}")"; - if [ "${ARG_RELAXED:-0}" -eq 1 ]; then - rtl_log_msg fail "$(printf "Build failed in \`%s', check \`%s' for details." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log")"; - if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then - rtl_log_msg info "Logged environment dump for failed package \`${_pkg_name}' to \`${BUILD_WORKDIR}/${_pkg_name}.dump'."; - fi; - else rtl_log_msg fail "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log:"; + if [ "${ARG_RELAXED:-0}" -eq 0 ]; then + rtl_log_msg fatal "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log:"; cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then printf "%s" "${_pkg_name}" > "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; fi; - rtl_log_msg fail "$(printf "Build failed in \`%s', check \`%s' for details." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log")"; - if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then - rtl_log_msg info "Logged environment dump for failed package \`${_pkg_name}' to \`${BUILD_WORKDIR}/${_pkg_name}.dump'."; - rtl_log_msg info "Enter an interactive package build shell w/ the command line: ./pkgtool.sh -a ${ARCH} -b ${BUILD} ${_pkg_name} PREFIX=\"${PREFIX}\""; - fi; + rtl_log_msg fatal "Build failed in \`%s', check \`%s' for details." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; + else rtl_log_msg warning "Build failed in \`%s', check \`%s' for details." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; + fi; + if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then + rtl_log_msg info "Logged environment dump for failed package \`%s' to \`%s'." "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}.dump"; + rtl_log_msg info "Enter an interactive package build shell w/ the command line: ./pkgtool.sh -a %s -b %s \"%s\" PREFIX=\"%s\""\ + "${ARCH}" "${BUILD}" "${_pkg_name}" "${PREFIX}"; + fi; + if [ "${ARG_RELAXED:-0}" -eq 0 ]; then exit 1; fi; }; @@ -55,29 +55,29 @@ buildp_dispatch_fail_pkg() { buildp_dispatch_group_state() { local _msg="${1}" _group_name="${2}"; case "${_msg}" in - finish_group) rtl_log_msg suc2 "Finished \`${_group_name}' build group."; ;; - start_group) rtl_log_msg inf2 "Starting \`${_group_name}' build group..."; ;; + finish_group) rtl_log_msg success_end "Finished \`%s' build group." "${_group_name}"; ;; + start_group) rtl_log_msg success "Starting \`%s' build group..." "${_group_name}"; ;; esac; }; buildp_dispatch_pkg_state() { local _msg="${1}" _group_name="${2}" _pkg_name="${3}"; case "${_msg}" in - disabled_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg vnfo "$(printf "Skipping disabled package \`%s'." "${_pkg_name}")"; ;; - missing_pkg) rtl_log_msg failexit "Error: unknown package \`${_pkg_name}'."; ;; - msg_pkg) shift 3; rtl_log_msg vucc "$(printf "%s/%s: %s" "${_group_name}" "${_pkg_name}" "${*}")"; ;; - skipped_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg vnfo "$(printf "Skipping finished package \`%s'." "${_pkg_name}")"; ;; - start_pkg) rtl_log_msg info "$(printf "[%03d/%03d] Starting \`%s' build..." "${4}" "${5}" "${_pkg_name}")"; ;; - step_pkg) rtl_log_msg vucc "$(printf "Finished build step %s of package \`%s'." "${4}" "${_pkg_name}")"; ;; + disabled_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg verbose "Skipping disabled package \`%s'." "${_pkg_name}"; ;; + missing_pkg) rtl_log_msg fatalexit "Error: unknown package \`%s'." "${_pkg_name}"; ;; + msg_pkg) shift 3; rtl_log_msg verbose "%s/%s: %s" "${_group_name}" "${_pkg_name}" "${*}"; ;; + skipped_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg verbose "Skipping finished package \`%s'." "${_pkg_name}"; ;; + start_pkg) rtl_log_msg info "[%03d/%03d] Starting \`%s' build..." "${4}" "${5}" "${_pkg_name}"; ;; + step_pkg) rtl_log_msg verbose "Finished build step %s of package \`%s'." "${4}" "${_pkg_name}"; ;; finish_pkg) : $((BUILD_NFINI+=1)); if [ "${ARG_VERBOSE:-0}" -ge 2 ]; then cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; fi; - rtl_log_msg succ "$(printf "Finished \`%s' build." "${_pkg_name}")"; ;; + rtl_log_msg info_end "Finished \`%s' build." "${_pkg_name}"; ;; start_pkg_child) if [ "${PKG_NO_LOG_VARS:-0}" -eq 0 ]; then - rtl_log_env_vars "build" $(set | awk -F= '/^PKG_/{print $1}' | sort); + rtl_log_env_vars "build" $(rtl_get_vars_fast "^PKG_"); fi; if [ "${ARG_VERBOSE:-0}" -ge 3 ]; then set -o xtrace; @@ -98,36 +98,52 @@ buildp_dispatch() { esac; }; +buildp_time_init() { + BUILD_DATE_START="$(rtl_date %Y-%m-%d-%H-%M-%S)"; + _build_time_secs="$(rtl_date %s)"; +}; + +buildp_time_update() { + : $((_build_time_secs=$(rtl_date %s)-${_build_time_secs})); + : $((_build_time_hours=${_build_time_secs}/3600)); + : $((_build_time_minutes=(${_build_time_secs}%3600)/60)); + : $((_build_time_secs=(${_build_time_secs}%3600)%60)); +}; + build() { - local _build_time_hours=0 _build_time_mins=0 _build_time_secs=0 _pkg_name="" \ - BUILD_DATE_START="" BUILD_NFAIL=0 BUILD_NFINI=0 BUILD_NSKIP=0 \ - BUILD_PKGS_FAILED="" EX_PKG_DISPATCH_UNKNOWN=""; - if ! cd "$(dirname "${0}")"; then - printf "Error: failed to setup environment.\n"; exit 1; - elif . ./subr/build_init.subr && build_init "${@}"\ - && trap "buildp_ast abort" HUP INT TERM USR1 USR2\ - && trap "buildp_ast exit" EXIT; then - BUILD_DATE_START="$(rtl_date %Y-%m-%d-%H-%M-%S)"; _build_time_secs="$(rtl_date %s)"; - rtl_log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}."; + local _build_time_hours=0 _build_time_mins=0 _build_time_secs=0 _pkg_name="" _rc=0 _status="" \ + BUILD_DATE_START="" BUILD_GROUPS="" BUILD_GROUPS_INHIBIT_DEPS=0 BUILD_HNAME="" BUILD_IS_PARENT=1 \ + BUILD_NFAIL=0 BUILD_NFINI=0 BUILD_NSKIP=0 BUILD_PKGS_FAILED="" BUILD_TARGET="" BUILD_USER="" \ + DEFAULT_BUILD_CPUS=1 DEFAULT_BUILD_LAST_FAILED_PKG_FNAME="" DEFAULT_BUILD_LOG_FNAME="" \ + DEFAULT_BUILD_STEPS="" DEFAULT_BUILD_VARS="" DEFAULT_CLEAR_PREFIX_PATHS="" DEFAULT_GIT_ARGS="" \ + DEFAULT_GITROOT_HEAD="" DEFAULT_LOG_ENV_VARS="" DEFAULT_TARGET="" DEFAULT_WGET_ARGS="" \ + MIDIPIX_BUILD_PWD=""; DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; + if ! . "${0%/*}/subr/build_init.subr"; then + _rc=1; printf "Error: failed to source \`${0%/*}/subr/build_init.subr'." >&2; + elif ! build_init "${@}"; then + _rc=1; _status="${_status}"; + elif [ -n "${_status}" ]; then + _rc=0; _status="${_status}"; + else trap "buildp_ast exit" EXIT; trap "buildp_ast abort" HUP INT TERM USR1 USR2; + buildp_time_init; + rtl_log_msg info "Build started by %s@%s at %s." "${BUILD_USER}" "${BUILD_HNAME}" "${BUILD_DATE_START}"; rtl_log_env_vars "build (global)" ${DEFAULT_LOG_ENV_VARS}; - if ! ex_pkg_dispatch "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ - buildp_dispatch "${BUILD_GROUPS}" "${BUILD_GROUPS_INHIBIT_DEPS:-0}" \ - "${ARG_PARALLEL:-1}" "${BUILD_WORKDIR}/build.fifo" "${ARG_RESTART}" \ - "${ARG_RESTART_AT}" "${ARG_RESTART_RECURSIVE}" "${BUILD_WORKDIR}"; then - for _pkg_name in ${EX_PKG_DISPATCH_UNKNOWN}; do - rtl_log_msg fail "Error: package \`${_pkg_name}' unknown."; - done; exit 1; - else : $((_build_time_secs=$(rtl_date %s)-${_build_time_secs})); - : $((_build_time_hours=${_build_time_secs}/3600)); - : $((_build_time_minutes=(${_build_time_secs}%3600)/60)); - : $((_build_time_secs=(${_build_time_secs}%3600)%60)); - rtl_log_msg info "${BUILD_NFINI:-0} finished, ${BUILD_NSKIP:-0} skipped, and ${BUILD_NFAIL:-0} failed package(s)."; - rtl_log_msg info "Build time: ${_build_time_hours:-0} hour(s), ${_build_time_minutes:-0} minute(s), and ${_build_time_secs:-0} second(s)."; - if [ -n "${BUILD_PKGS_FAILED}" ]; then - rtl_log_msg failexit "Build script failure(s) in: ${BUILD_PKGS_FAILED}."; - fi; + ex_pkg_dispatch "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ + buildp_dispatch "${BUILD_GROUPS}" "${BUILD_GROUPS_INHIBIT_DEPS}" \ + "${ARG_PARALLEL}" "${BUILD_WORKDIR}/build.fifo" "${ARG_RESTART}" \ + "${ARG_RESTART_AT}" "${ARG_RESTART_RECURSIVE}" "${BUILD_WORKDIR}"; + buildp_time_update; + rtl_log_msg info "%s finished, %s skipped, and %s failed package(s)." "${BUILD_NFINI:-0}" "${BUILD_NSKIP:-0}" "${BUILD_NFAIL:-0}"; + rtl_log_msg info "Build time: %s hour(s), %s minute(s), and %s second(s)." "${_build_time_hours:-0}" "${_build_time_minutes:-0}" "${_build_time_secs:-0}"; + if [ -n "${BUILD_PKGS_FAILED}" ]; then + _rc=1; _status="Build script failure(s) in: ${BUILD_PKGS_FAILED}."; fi; fi; + if [ "${_rc}" -ne 0 ]; then + rtl_log_msg fatalexit "${_status}"; + elif [ -n "${_status}" ]; then + rtl_log_msg info "${_status}"; + fi; }; set +o errexit -o noglob; build "${@}"; diff --git a/dist/dist_zipdist.dist b/dist/dist_zipdist.dist index eda7997c..27d68ac7 100644 --- a/dist/dist_zipdist.dist +++ b/dist/dist_zipdist.dist @@ -9,7 +9,7 @@ pkg_dist_zipdist_all() { rtl_log_msg info "Finished building deployable distribution ZIP archive."; for _pkg_name in $(cat "${_pkglist_fname}"); do if [ ! -e "${BUILD_WORKDIR}/${_pkg_name}-native-${DEFAULT_TARGET}" ]; then - rtl_log_msg failexit "Error: missing package build directory for package \`${_pkg_name}'."; + rtl_log_msg fatalexit "Error: missing package build directory for package \`%s'." "${_pkg_name}"; fi; done; _dist_fname="${DEFAULT_ZIPDIST_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.zip"; diff --git a/etc/README.md b/etc/README.md index 290a6dd3..b51a447a 100644 --- a/etc/README.md +++ b/etc/README.md @@ -157,24 +157,33 @@ Package archive files and/or Git repositories additionally consume at least [//]: # "{{{ 3. Common tasks" ## 3. Common tasks -Rebuild set of packages in isolation, along w/ their dependencies, if any, as -needed, or forcibly, respectively: +Rebuild set of packages in isolation: ```shell ./build.sh [ ... ] -r mc,zsh +``` + +Rebuild set of packages along w/ their dependencies, if any, as needed, or forcibly, +respectively: +```shell ./build.sh [ ... ] -r \*mc,zsh ./build.sh [ ... ] -r \*\*mc,zsh ``` - + +Forcibly rebuild all reverse dependencies of a set of packages: +```shell +./build.sh [ ... ] -r \*\*\*glib,libflac +``` + Restart the ``configure``, ``build``, and ``install`` steps of the ``coreutils`` package: ```shell ./build.sh -r coreutils:configure,build,install ``` - + Rebuild entire build groups including or excluding group dependencies, respectively: ```shell ./build.sh [ ... ] -r ALL native_runtime -./build.sh [ ... ] -r ALL \*native_runtime +./build.sh [ ... ] -r ALL =native_runtime ``` [Back to top](#table-of-contents) @@ -188,7 +197,7 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-d] [-D kind[ [-F ipv4|ipv6|offline] [-h] [-p jobs] [-P] [-r ALL|LAST] [-r [*[*[*]]]name[,..][:step,..]] [-R] [-v[v[v[v]]]] [--as-needed] [--debug-minipix] [--dump-on-abort] - [[*]|=[ ..]] + [[=]|=[ ..]] -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. -b debug|release Selects debug or release build; defaults to debug. @@ -239,7 +248,7 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-d] [-D kind[ host_toolchain, host_tools, minipix, native_packages, native_runtime, native_toolchain, native_tools. - Prepend w/ `*' to inhibit group-group dependency expansion. + Prepend w/ `=' to inhibit group-group dependency expansion. =[ ..] Override build or package variable. @@ -253,11 +262,11 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-d] [-D kind[ Packages are grouped into *build groups* according to sets of common package variable defaults, such as ``${PKG_CFLAGS_CONFIGURE}, ${PKG_LDFLAGS_CONFIGURE}`` -and ``${PKG_CONFIGURE_ARGS}``, and semantic associativity, such as the ``native_runtime`` -build group comprising the Midipix runtime components. Packages may belong to -more than one build group such as when subsumed by a shorthand build group e.g. -the ``dev_packages`` build group, as long as the default set of build groups or -as overriden on the command line does not entail group membership conflicts. +and ``${PKG_CONFIGURE_ARGS}``, and semantic interrelatedness, such as the +``native_runtime`` build group comprising the Midipix runtime components. +Packages may belong to more than one build group such as when subsumed by a shorthand +build group e.g. the ``dev_packages`` build group, as long as the default set of build +groups or as overriden on the command line does not entail group membership conflicts. Build groups files beneath ``groups/`` named ``[0-9][0-9][0-9]..group`` contain package variable defaults, the alphabetically sorted list of contained diff --git a/etc/build.usage b/etc/build.usage index f287b98c..2c272a7c 100644 --- a/etc/build.usage +++ b/etc/build.usage @@ -2,7 +2,7 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-d] [-D kind[ [-F ipv4|ipv6|offline] [-h] [-p jobs] [-P] [-r ALL|LAST] [-r [*[*[*]]]name[,..][:step,..]] [-R] [-v[v[v[v]]]] [--as-needed] [--debug-minipix] [--dump-on-abort] - [[*]|=[ ..]] + [[=]|=[ ..]] -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. -b debug|release Selects debug or release build; defaults to debug. @@ -53,7 +53,7 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-d] [-D kind[ host_toolchain, host_tools, minipix, native_packages, native_runtime, native_toolchain, native_tools. - Prepend w/ `*' to inhibit group-group dependency expansion. + Prepend w/ `=' to inhibit group-group dependency expansion. =[ ..] Override build or package variable. diff --git a/pkgtool.sh b/pkgtool.sh index e6768e85..c8dd2bb6 100755 --- a/pkgtool.sh +++ b/pkgtool.sh @@ -3,154 +3,186 @@ # pkgtoolp_info() { - local _group_name="" _pkg_name_uc="$(rtl_toupper "${PKG_NAME}")" _pkg_names="" \ - EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; - if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then - rtl_log_msg failexit "Error: unknown package \`${PKG_NAME}'."; + local _pkg_name="${1}" _group_name="" _pkg_name_uc="$(rtl_toupper "${1}")" _pkg_names="" _rc=0\ + EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status=""; + if ! ex_pkg_load_groups; then + _rc=1; _status="Error: failed to load build groups."; + elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then + _rc=1; _status="Error: unknown package \`${_pkg_name}'."; elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then - rtl_log_msg failexit "Error: failed to expand package list of build group \`${_group_name}'."; - elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ - "${_group_name}" 1 "${PKG_NAME}" "" "${BUILD_WORKDIR}"; then - rtl_log_msg failexit "Error: failed to set package environment for \`${PKG_NAME}'."; - else rtl_log_env_vars "package" $(set | awk -F= '/^PKG_'"${_pkg_name_uc}"'_/{print $1}' | sort); + _rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'."; + elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\ + "${_group_name}" 1 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then + _rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'."; + else rtl_log_env_vars "package" $(rtl_get_vars_fast "^PKG_${_pkg_name_uc}"); if [ -z "${PKG_DEPENDS}" ]; then - rtl_log_msg info "Package \`${PKG_NAME}' has no dependencies."; - else rtl_log_msg info "Direct dependencies of \`${PKG_NAME}': ${PKG_DEPENDS}"; - if ! ex_pkg_unfold_depends "${_group_name}" "${_pkg_names}" "${PKG_NAME}" 2 0; then - rtl_log_msg warn "Warning: failed to unfold dependency-expanded package name list for \`${PKG_NAME}'."; - else EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${PKG_NAME}")"; + rtl_log_msg info "Package \`%s' has no dependencies." "${_pkg_name}"; + else rtl_log_msg info "Direct dependencies of \`%s': %s" "${_pkg_name}" "${PKG_DEPENDS}"; + if ! ex_pkg_unfold_depends 1 1 "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then + rtl_log_msg warning "Warning: failed to unfold dependency-expanded package name list for \`%s'." "${_pkg_name}"; + else EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")"; if [ -n "${EX_PKG_NAMES}" ]; then - rtl_log_msg info "Full dependencies of \`${PKG_NAME}': $(rtl_lsort "${EX_PKG_NAMES}")"; + rtl_log_msg info "Full dependencies of \`%s': %s"\ + "${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")"; fi; if [ -n "${EX_PKG_DISABLED}" ]; then - rtl_log_msg info "Full dependencies of \`${PKG_NAME}' (disabled packages:) $(rtl_lsort "${EX_PKG_DISABLED}")"; + rtl_log_msg info "Full dependencies of \`%s' (disabled packages:) %s"\ + "${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")"; fi; fi; fi; - fi; + fi; return "${_rc}"; }; pkgtoolp_restart_at() { - case "${ARG_RESTART_AT}" in - ALL) "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${PKG_NAME}" -v; ;; - *) "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${PKG_NAME}:${ARG_RESTART_AT}" -v; ;; - esac; + local _pkg_name="${1}" _rc=0; _status=""; + if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then + _rc=1; _status="${_status}"; + else case "${ARG_RESTART_AT}" in + ALL) if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}" -v; then + _rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name} -v"; + fi; ;; + *) if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}:${ARG_RESTART_AT}" -v; then + _rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name}:${ARG_RESTART_AT} -v"; + fi; ;; + esac; + fi; return "${_rc}"; }; pkgtoolp_rdepends() { - local _group_name="" _pkg_names="" EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; - if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then - rtl_log_msg failexit "Error: unknown package \`${PKG_NAME}'."; + local _pkg_name="${1}" _group_name="" _pkg_names="" _rc=0\ + EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status=""; + if ! ex_pkg_load_groups; then + _rc=1; _status="Error: failed to load build groups."; + elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then + _rc=1; _status="Error: unknown package \`${_pkg_name}'."; elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then - rtl_log_msg failexit "Error: failed to expand package list of build group \`${_group_name}'."; - elif ! ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${PKG_NAME}" 0; then - rtl_log_msg failexit "Error: failed to unfold reverse dependency-expanded package name list for \`${PKG_NAME}'."; + _rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'."; + elif ! ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then + _rc=1; _status="Error: failed to unfold reverse dependency-expanded package name list for \`${_pkg_name}'."; elif [ -z "${EX_PKG_NAMES}" ] && [ -z "${EX_PKG_DISABLED}" ]; then - rtl_log_msg info "Package \`${PKG_NAME}' has no reverse dependencies."; + rtl_log_msg info "Package \`%s' has no reverse dependencies." "${_pkg_name}"; else if [ -n "${EX_PKG_NAMES}" ]; then - rtl_log_msg info "Reverse dependencies of \`${PKG_NAME}': $(rtl_lsort "${EX_PKG_NAMES}")"; + rtl_log_msg info "Reverse dependencies of \`%s': %s"\ + "${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")"; fi; if [ -n "${EX_PKG_DISABLED}" ]; then - rtl_log_msg info "Reverse dependencies of \`${PKG_NAME}' (disabled packages:) $(rtl_lsort "${EX_PKG_DISABLED}")"; + rtl_log_msg info "Reverse dependencies of \`%s' (disabled packages:) %s"\ + "${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")"; fi; - fi; + fi; return "${_rc}"; }; pkgtoolp_shell() { - rtl_log_env_vars "build" $(set | awk -F= '/^PKG_/{print $1}' | sort); - rtl_log_msg info "Launching shell \`${SHELL}' within package environment and \`${PKG_BUILD_DIR}'."; - rtl_log_msg info "Run \$R to rebuild \`${PKG_NAME}'."; - rtl_log_msg info "Run \$RS to restart the specified build step of \`${PKG_NAME}'"; - rtl_log_msg info "Run \$D to automatically regenerate the patch for \`${PKG_NAME}'."; - export ARCH BUILD \ - BUILD_DLCACHEDIR BUILD_WORKDIR \ - MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}" \ - MIDIPIX_BUILD_PWD \ - PKG_NAME \ - PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ - PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; - D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff" \ - R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL" \ - RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at " \ - "${SHELL}"; + local _pkg_name="${1}" _rc=0; _status=""; + if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then + _rc=1; _status="${_status}"; + else rtl_log_env_vars "package" $(rtl_get_vars_fast "^PKG_"); + rtl_log_msg info "Launching shell \`%s' within package environment and \`%s'." "${SHELL}" "${PKG_BUILD_DIR}"; + rtl_log_msg info "Run \$R to rebuild \`%s'." "${_pkg_name}"; + rtl_log_msg info "Run \$RS to restart the specified build step of \`%s'" "${_pkg_name}"; + rtl_log_msg info "Run \$D to automatically regenerate the patch for \`%s'." "${_pkg_name}"; + export ARCH BUILD \ + BUILD_DLCACHEDIR BUILD_WORKDIR \ + MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}" \ + MIDIPIX_BUILD_PWD \ + PKG_NAME \ + PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ + PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; + D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff" \ + R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL" \ + RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at " \ + "${SHELL}"; + fi; return "${_rc}"; }; pkgtoolp_tarball() { - local _date="" _group_name="" _hname="" _pkg_name_full="" _pkg_version="" _tarball_fname=""; - if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then - rtl_log_msg failexit "Error: unknown package \`${PKG_NAME}'."; + local _pkg_name="${1}" _date="" _group_name="" _hname="" _pkg_name_full=""\ + _pkg_version="" _rc=0 _tarball_fname="" EX_PKG_BUILD_GROUPS=""; _status=""; + if ! ex_pkg_load_groups; then + _rc=1; _status="Error: failed to load build groups."; + elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then + _rc=1; _status="Error: unknown package \`${_pkg_name}'."; elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ - "${_group_name}" "${PKG_NAME}" "" "${BUILD_WORKDIR}"; then - rtl_log_msg failexit "Error: failed to set package environment for \`${PKG_NAME}'."; + "${_group_name}" 0 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then + _rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'."; elif ! _date="$(date +%Y%m%d_%H%M%S)"; then - rtl_log_msg failexit "Error: failed to call date(1)."; + _rc=1; _status="Error: failed to call date(1)."; elif ! _hname="$(hostname -f)"; then - rtl_log_msg failexit "Error: failed to call hostname(1)."; + _rc=1; _status="Error: failed to call hostname(1)."; else if [ -n "${PKG_VERSION}" ]; then - _pkg_name_full="${PKG_NAME}-${PKG_VERSION}"; + _pkg_name_full="${_pkg_name}-${PKG_VERSION}"; else - _pkg_name_full="${PKG_NAME}"; + _pkg_name_full="${_pkg_name}"; fi; _tarball_fname="${_pkg_name_full}@${_hname}-${_date}.tbz2"; - rtl_log_msg info "Creating compressed tarball of \`${PKG_BASE_DIR}' and \`${PKG_NAME}_stderrout.log'..."; + rtl_log_msg info "Creating compressed tarball of \`%s' and \`%s_stderrout.log'..."\ + "${PKG_BASE_DIR}" "${_pkg_name}"; if ! tar -C "${BUILD_WORKDIR}" -cpf - \ "${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}" \ - "${PKG_NAME}_stderrout.log" |\ + "${_pkg_name}_stderrout.log" |\ bzip2 -c -9 - > "${_tarball_fname}"; then - rtl_log_msg failexit "Error: failed to create compressed tarball of \`${PKG_BASE_DIR}' and \`${PKG_NAME}_stderrout.log'."; + _rc=1; _status="Error: failed to create compressed tarball of \`${PKG_BASE_DIR}' and \`${_pkg_name}_stderrout.log'."; else - rtl_log_msg info "Created compressed tarball of \`${PKG_BASE_DIR}' and \`${PKG_NAME}_stderrout.log'."; + rtl_log_msg info "Created compressed tarball of \`%s' and \`%s_stderrout.log'."\ + "${PKG_BASE_DIR}" "${_pkg_name}"; fi; - fi; + fi; return "${_rc}"; }; pkgtoolp_update_diff() { - local _diff_fname_dst="" _diff_fname_src="" _fname="" _fname_base=""; - if [ -n "${PKG_VERSION}" ]; then - _diff_fname_dst="${PKG_NAME}-${PKG_VERSION}.local.patch"; - else - _diff_fname_dst="${PKG_NAME}.local.patch"; - fi; - if ! _diff_fname_src="$(mktemp)"; then - rtl_log_msg failexit "Error: failed to create temporary target diff(1) file."; - else trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2; - (cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}"; - for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do - _fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}"; - case "${_fname_base}" in - config.sub) - continue; ;; - *) diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;; - esac; - done); - if [ "${?}" -ne 0 ]; then - rtl_log_msg failexit "Error: failed to create diff(1)."; - elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then - rtl_log_msg failexit "Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'."; - else trap - EXIT HUP INT TERM USR1 USR2; - rtl_log_msg info "Updated \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'."; + local _pkg_name="${1}" _diff_fname_dst="" _diff_fname_src="" _fname=""\ + _fname_base="" _rc=0; _status=""; + if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then + _rc=1; _status="${_status}"; + else if [ -n "${PKG_VERSION}" ]; then + _diff_fname_dst="${_pkg_name}-${PKG_VERSION}.local.patch"; + else + _diff_fname_dst="${_pkg_name}.local.patch"; fi; - fi; + if ! _diff_fname_src="$(mktemp)"; then + _rc=1; _status="Error: failed to create temporary target diff(1) file."; + else trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2; + (cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}"; + for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do + _fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}"; + case "${_fname_base}" in + config.sub) + continue; ;; + *) diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;; + esac; + done); + if [ "${?}" -ne 0 ]; then + _rc=1; _status="Error: failed to create diff(1)."; + elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then + _rc=1; _status="Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'."; + else trap - EXIT HUP INT TERM USR1 USR2; + rtl_log_msg info "Updated \`%s/patches/%s'."\ + "${MIDIPIX_BUILD_PWD}" "${_diff_fname_dst}"; + fi; + fi; + fi; return "${_rc}"; }; pkgtool() { - local _status=""; - if ! cd "$(dirname "${0}")"\ - || ! . ./subr/pkgtool_init.subr\ - || ! pkgtool_init "${@}"; then - printf "Error: failed to setup environment.\n"; exit 1; - elif [ -n "${ARG_RESTART_AT}" ]; then - pkgtoolp_restart_at; - elif [ "${ARG_UPDATE_DIFF:-0}" -eq 1 ]; then - pkgtoolp_update_diff; - elif [ "${ARG_INFO:-0}" -eq 1 ]; then - pkgtoolp_info; - elif [ "${ARG_RDEPENDS:-0}" -eq 1 ]; then - pkgtoolp_rdepends; - elif [ "${ARG_SHELL:-0}" -eq 1 ]; then - pkgtoolp_shell; - elif [ "${ARG_TARBALL:-0}" -eq 1 ]; then - pkgtoolp_tarball; + local _rc=0 _status="" BUILD_GROUPS="" ARCH BUILD BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX; + if ! . "${0%/*}/subr/pkgtool_init.subr"; then + _rc=1; printf "Error: failed to source \`${0%/*}/subr/pkgtool_init.subr'." >&2; + elif ! pkgtool_init "${@}"; then + _rc=1; _status="${_status}"; + else case "1" in + "${ARG_INFO:-0}") pkgtoolp_info "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_RDEPENDS:-0}") pkgtoolp_rdepends "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_RESTART_AT:+1}") pkgtoolp_restart_at "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_SHELL:-0}") pkgtoolp_shell "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_TARBALL:-0}") pkgtoolp_tarball "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_UPDATE_DIFF:-0}") pkgtoolp_update_diff "${PKGTOOL_PKG_NAME}"; ;; + esac; _rc="${?}"; + fi; + if [ "${_rc}" -ne 0 ]; then + rtl_log_msg fatalexit "${_status}"; + elif [ -n "${_status}" ]; then + rtl_log_msg info "${_status}"; fi; }; diff --git a/subr/build_init.subr b/subr/build_init.subr index eeeaf60b..91784f83 100644 --- a/subr/build_init.subr +++ b/subr/build_init.subr @@ -3,87 +3,117 @@ # buildp_init_args() { - local _last_pkg=""; _status=""; - if [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ + local _group="" _last_pkg="" _pkg_names_unknown="" _rc=0; _status=""; + if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\ + && [ "${ARG_RELAXED:-0}" -eq 1 ]; then + _rc=1; _status="Error: --dump-on-abort excludes -R."; + elif [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ && [ -e "${PREFIX}/build.gitref" ]\ && [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then - _status="Git repository has not changed since last build and --as-needed was specified."; - fi; - if [ -n "${ARG_RESTART}" ]; then - if [ "${ARG_RESTART#\*\*\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*\*\*}"; ARG_RESTART_RECURSIVE=3; - elif [ "${ARG_RESTART#\*\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*\*}"; ARG_RESTART_RECURSIVE=2; - elif [ "${ARG_RESTART#\*}" != "${ARG_RESTART}" ]; then - ARG_RESTART="${ARG_RESTART#\*}"; ARG_RESTART_RECURSIVE=1; - fi; - fi; - case "${ARG_RESTART}" in - ALL) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;; - LAST) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; ;; - "") ;; - *:*) ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="$(rtl_llift "${ARG_RESTART%%:*}" "," " ")"; ;; - *) ARG_RESTART="$(rtl_llift "${ARG_RESTART}" "," " ")"; ARG_RESTART_AT=ALL; ;; - esac; - if [ "${ARG_RESTART}" = "LAST" ]; then - if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\ - && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then - _last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")"; - rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; - rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; - ARG_RESTART="${_last_pkg}"; + _rc=0; _status="Git repository has not changed since last build and --as-needed was specified."; + else case "${ARG_PARALLEL}" in + auto) if ! ARG_PARALLEL="$(rtl_get_cpu_count)"; then + _rc=1; _status="Error: failed to get CPU count."; + else + ARG_PARALLEL=$((${ARG_PARALLEL}/2)); + fi; ;; + "") ARG_PARALLEL=1; ;; + *) if ! rtl_isnumber "${ARG_PARALLEL}"; then + _rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; + fi; ;; + esac; + if [ "${_rc:-0}" -eq 0 ]; then + DEFAULT_BUILD_CPUS="${ARG_PARALLEL}"; + case "${ARG_FETCH_FORCE}" in + ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;; + ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;; + esac; + case "${ARG_RESTART}" in + \*\*\*[a-zA-Z]*) + ARG_RESTART="${ARG_RESTART#\*\*\*}"; ARG_RESTART_RECURSIVE=3; ;; + \*\*[a-zA-Z]*) ARG_RESTART="${ARG_RESTART#\*\*}"; ARG_RESTART_RECURSIVE=2; ;; + \*[a-zA-Z]*) ARG_RESTART="${ARG_RESTART#\*}"; ARG_RESTART_RECURSIVE=1; ;; + ALL) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;; + LAST) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; + if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\ + && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then + _last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")"; + rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; + rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; + ARG_RESTART="${_last_pkg}"; + else + _rc=1; _status="Error: cannot rebuild last failed package."; + fi; ;; + esac; + if [ "${_rc:-0}" -eq 0 ]; then + case "${ARG_RESTART}" in + *:*) ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="$(rtl_llift "${ARG_RESTART%%:*}" "," " ")"; ;; + *) ARG_RESTART="$(rtl_llift "${ARG_RESTART}" "," " ")"; ARG_RESTART_AT=ALL; ;; + esac; + if ! ex_pkg_load_groups; then + _rc=1; _status="Error: failed to load build groups."; + else if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then + EX_PKG_BUILD_GROUPS="$(rtl_lfilter "${EX_PKG_BUILD_GROUPS}" "host_deps_rpm")"; + fi; + if [ -z "${BUILD_GROUPS}" ]; then + BUILD_GROUPS="${EX_PKG_BUILD_GROUPS}"; + else for _group in ${BUILD_GROUPS}; do + if ! rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then + _rc=1; _status="Error: unknown build group \`${_group}'."; break; + fi; + done; + fi; + if [ "${_rc:-0}" -eq 0 ]; then + if [ -n "${ARG_DIST}" ]; then + BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")"; + fi; + if [ -n "${ARG_RESTART}" ]; then + for _pkg_name in ${ARG_RESTART}; do + if ! ex_pkg_find_package "${BUILD_GROUPS}" "${_pkg_name}" >/dev/null; then + _pkg_names_unknown="$(rtl_lconcat "${_pkg_names_unknown}" "${_pkg_name}")"; + fi; + done; + case "$(rtl_llength "${_pkg_names_unknown}")" in + 0) ;; + 1) _rc=1; _status="Error: unknown package \`${_pkg_names_unknown}'."; ;; + *) _rc=1; _status="Error: unknown packages: $(rtl_subst "${_pkg_names_unknown}" " " ", ")"; ;; + esac; + fi; + if [ "${_rc}" -eq 0 ]; then + case "${ARG_VERBOSE:-0}" in + 0) rtl_fileop_set_log 0; rtl_log_set_lvl 0; ;; + 1) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 2) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 3) rtl_fileop_set_log 0; rtl_log_set_lvl 2; ;; + 4) rtl_fileop_set_log 1; rtl_log_set_lvl 3; ;; + *) _rc=1; _status="Error: invalid verbosity level (max. -vvvv)"; ;; + esac; + fi; + fi; + fi; + fi; fi; - fi; - rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}"; - case "${ARG_FETCH_FORCE}" in - ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;; - ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;; - esac; - return 0; -}; - -buildp_init_defaults() { - local _rc=0; _status=""; - - # Command-line arguments - : ${ARCH:="nt64"}; : ${BUILD:="debug"}; - ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DUMP_IN=""; - ARG_DUMP_ON_ABORT=0; ARG_DIST=""; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; - ARG_RESTART=""; ARG_VERBOSE=0; - - # Build parameters & state - BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS=""; BUILD_GROUPS_INHIBIT_DEPS=0; - BUILD_TARGET=""; BUILD_USER=""; MIDIPIX_BUILD_PWD=""; - - # Global defaults - DEFAULT_BUILD_CPUS=1; - DEFAULT_BUILD_LAST_FAILED_PKG_FNAME="" - DEFAULT_BUILD_LOG_FNAME=""; - DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; - DEFAULT_BUILD_STEPS=""; - DEFAULT_BUILD_VARS=""; - DEFAULT_CLEAR_PREFIX_PATHS=""; - DEFAULT_GIT_ARGS=""; - DEFAULT_GITROOT_HEAD=""; - DEFAULT_LOG_ENV_VARS=""; - DEFAULT_TARGET=""; - DEFAULT_WGET_ARGS=""; - - return "${_rc}"; + fi; return "${_rc}"; }; buildp_init_env() { local _fname="" _rc=0; _status=""; - if ! umask 022; then - printf "Error: failed to setup environment.\n"; exit 1; + if ! cd "${0%/*}"; then + printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1; + elif ! umask 022; then + printf "Error: failed to set umask(2).\n" >&2; exit 1; + elif ! BUILD_HNAME="$(hostname)"; then + _rc=1; _status="Error: failed to obtain hostname."; + elif ! BUILD_USER="$(id -nu)"; then + _rc=1; _status="Error: failed to obtain username."; else for _fname in $(find subr -name *.subr); do if ! . "${_fname}"; then printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1; fi; - done; fi; - return "${_rc}"; + done; + fi; return "${_rc}"; }; buildp_init_files() { @@ -107,7 +137,7 @@ buildp_init_files() { rtl_fileop mv "${DEFAULT_BUILD_LOG_FNAME}" "${_log_last_fname}"; rtl_fileop ln_symbolic "${_log_last_fname}" "${DEFAULT_BUILD_LOG_LAST_FNAME}"; fi; - rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; + rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; rtl_log_set_fname "${DEFAULT_BUILD_LOG_FNAME}"; if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then rtl_log_msg info "-C prefix specified, cleaning prefix..."; for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do @@ -123,6 +153,10 @@ buildp_init_files() { buildp_init_getopts() { local _arg="" _opt="" _rc=0 _shiftfl=0 OPTIND=0; _status=""; + : ${ARCH:="nt64"}; : ${BUILD:="debug"}; + ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=1; ARG_DUMP_IN=""; + ARG_DUMP_ON_ABORT=0; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESTART=""; + ARG_VERBOSE=0; while [ "${#}" -gt 0 ]; do case "${1}" in --as-needed) ARG_AS_NEEDED=1; _shiftfl=1; ;; @@ -161,13 +195,10 @@ buildp_init_getopts() { break; fi; done; - if [ "${_rc}" -eq 0 ]; then - if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\ - && [ "${ARG_RELAXED:-0}" -eq 1 ]; then - _rc=1; _status="Error: --dump-on-abort excludes -R."; - else while [ ${#} -gt 0 ]; do - if [ "${1#\*}" != "${1}" ]; then - BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#\*}"; + if [ "${_rc:-0}" -eq 0 ]; then + while [ ${#} -gt 0 ]; do + if [ "${1#=}" != "${1}" ]; then + BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#=}"; else _arg="${1}"; fi; @@ -176,56 +207,17 @@ buildp_init_getopts() { [^a-zA-Z]*) _rc=1; _status="Error: build group names must start with [a-zA-Z] (in argument \`${_arg}'.)"; ;; *[^_a-zA-Z]*) _rc=1; _status="Error: build group names must not contain [^_a-zA-Z] (in argument \`${_arg}'.)"; ;; *) BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "${_arg}")"; ;; - esac; shift; done; - fi; + esac; shift; + done; fi; return "${_rc}"; }; -buildp_init_groups() { - local _default_build_groups="" _fname="" _group="" _groups="" _rc=0; _status=""; - for _fname in $(find ./groups -name *.group | sort); do - rtl_fileop source_opt "${_fname}"; - if [ -n "${GROUP_TARGET}" ]; then - _group="${GROUP_TARGET}"; unset GROUP_TARGET; - else - _group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}"; - fi; - if ! rtl_lmatch "${_groups}" "${_group}"; then - _groups="$(rtl_lconcat "${_groups}" "${_group}")"; - if [ -n "${GROUP_AUTO}" ]; then - if [ "${GROUP_AUTO:-0}" -ne 0 ]; then - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - unset GROUP_AUTO; - else - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - fi; - done; - _default_build_groups="$(rtl_uniq "${_default_build_groups}")"; - if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then - _default_build_groups="$(rtl_lfilter "${_default_build_groups}" "host_deps_rpm")"; - fi; - if [ -z "${BUILD_GROUPS}" ]; then - BUILD_GROUPS="${_default_build_groups}"; - fi; - if [ -n "${ARG_DIST}" ]; then - BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")"; - fi; - for _group in ${BUILD_GROUPS}; do - if ! rtl_lmatch "${_groups}" "${_group}"; then - _rc=1; _status="Error: unknown build group \`${_group}'."; break; - fi; - done; - return "${_rc}"; -}; - buildp_init_prereqs() { local _cmd="" _cmds_missing="" _rc=0; _status=""; for _cmd in \ awk bunzip2 bzip2 cat chmod cmake cp date find flock \ - g++ gcc git grep gunzip gzip hostname install kill \ + g++ gcc git grep gunzip gzip hostname id install kill \ ln lzip make mkdir mkfifo mktemp mv paste patch perl \ pgrep pkill printf readlink rm sed sha256sum sort \ tail tar test touch tr uniq wget xz zip; do @@ -242,50 +234,16 @@ buildp_init_prereqs() { return "${_rc}"; }; -buildp_init_vars() { - local _rc=0; _status=""; - if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then - _rc=1; _status="Error: invalid architecture \`${ARCH}'."; - elif ! rtl_lmatch "${BUILD}" "debug release"; then - _rc=1; _status="Error: unknown build type \`${BUILD}'."; - elif [ -n "${ARG_PARALLEL}" ] && [ "${ARG_PARALLEL}" != "auto" ]\ - && ! rtl_isnumber "${ARG_PARALLEL}"; then - _rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; - else case "${ARCH}" in - nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; - nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; - esac; - if DEFAULT_BUILD_CPUS="$(rtl_get_cpu_count)"; then - if [ "${ARG_PARALLEL}" = "auto" ]\ - && [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then - ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2)); - fi; - rtl_fileop source_opt \ - "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \ - ../midipix_build.vars ./midipix.env; - if [ -z "${PREFIX}" ]; then - _rc=1; _status="Error: \${PREFIX} empty or unset."; - fi; - fi; - fi; return "${_rc}"; -}; - build_init() { - local _fname="" _rc=0 _status=""; + local _rc=0; _status=""; if ! buildp_init_env \ - || ! buildp_init_defaults \ || ! buildp_init_getopts "${@}" \ || ! buildp_init_prereqs \ - || ! buildp_init_vars \ - || ! buildp_init_groups \ + || ! ex_pkg_load_vars \ || ! buildp_init_args \ || ! buildp_init_files; then - _rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}"; - elif [ -n "${_status}" ]; then - rtl_log_msg info "${_status}"; exit 0; - else - return "${_rc}"; - fi; + _rc=1; _status="${_status}"; + fi; return "${_rc}"; }; # vim:filetype=sh diff --git a/subr/ex_pkg.subr b/subr/ex_pkg.subr index 497e89ce..3dcfbc7e 100644 --- a/subr/ex_pkg.subr +++ b/subr/ex_pkg.subr @@ -4,31 +4,27 @@ # # ex_pkg_check_depends() - check single named package for unsatisfied dependencies +# @_checkfl: enable (1) or inhibit (0) dependency expansion # @_pkg_disabled: list of disabled packages # @_pkg_finished: list of finished packages # @_pkg_name: single package name # @_pkg_wait: list of in-progress packages -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # # Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise # ex_pkg_check_depends() { - local _pkg_disabled="${1}" _pkg_finished="${2}" _pkg_name="${3}" \ - _pkg_wait="${4}" _restart_recursive="${5}" \ - _pkg_depends="" _pkg_name_depend="" _dependfl=0; - if _pkg_depends="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS")))"\ - && [ -n "${_pkg_depends}" ]; then - if [ -z "${_restart}" ]\ - || [ "${_restart_recursive:-0}" -ge 1 ]; then - for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do - if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name_depend}"\ - && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name_depend}"; then - _dependfl=1; break; - elif rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then - _dependfl=1; break; - fi; - done; - fi; + local _checkfl="${1}" _pkg_disabled="${2}" _pkg_finished="${3}" _pkg_name="${4}" _pkg_wait="${5}"\ + _dependfl=0 _pkg_depends="" _pkg_name_depend=""; + if [ "${_checkfl:-0}" -eq 1 ]\ + && _pkg_depends="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS")))"; then + for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do + if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name_depend}"\ + && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name_depend}"; then + _dependfl=1; break; + elif rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then + _dependfl=1; break; + fi; + done; fi; return "${_dependfl}"; }; @@ -41,7 +37,7 @@ ex_pkg_check_depends() { # Return: zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found. # ex_pkg_find_package() { - local _group_names="${1}" _pkg_name="${2}" _group_name="" _pkg_names=""; + local _group_names="${1}" _pkg_name="${2}" _foundfl=0 _group_name="" _pkg_names=""; for _group_name in ${_group_names}; do if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ && [ -n "${_pkg_names}" ]\ @@ -51,7 +47,7 @@ ex_pkg_find_package() { done; case "${_foundfl:-0}" in 0) return 1; ;; - 1) echo "${_group_name}"; return 0; ;; + 1) printf "%s" "${_group_name}"; return 0; ;; esac; }; @@ -65,32 +61,113 @@ ex_pkg_get_packages() { local _group_name="${1}" _pkg_names=""; if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ && [ -n "${_pkg_names}" ]; then - echo "${_pkg_names}"; return 0; + printf "%s" "${_pkg_names}"; return 0; else return 1; fi; }; +# +# ex_pkg_load_dump() - load package dump +# @_pkg_name: package name +# +# Return: zero (0) on success, non-zero (>0) on failure, package dump post-return on success. +# +ex_pkg_load_dump() { + local _pkg_name="${1}" _workdir="${2}" _rc=0; _status=""; + if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then + rtl_log_msg warn "Warning: failed to locate environment dump for package \`%s' in \`%s'." "${_pkg_name}" "${_workdir}"; + rtl_log_msg info "Re_building package \`%s' w/ --dump-in _build..." "${_pkg_name}"; + (export ARCH BUILD BUILD_DLCACHEDIR BUILD_WORKDIR \ + PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ + PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; + ./build.sh --dump-in _build -P -r "${_pkg_name}" -v); + if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then + _rc=1; _status="Error: failed to locate environment dump for package \`${_pkg_name}' in \`${_workdir}'."; + fi; + else + _rc=0; + fi; + if [ "${_rc:-0}" -eq 0 ]\ + && ! . "${_workdir}/${_pkg_name}.dump"; then + _rc=1; _status="Error: failed to source environment dump for package \`${_pkg_name}' from \`${_workdir}'."; + elif [ "${_rc:-0}" -eq 0 ]\ + && ! rtl_fileop cd "${PKG_BUILD_DIR}"; then + _rc=1; _status="Error: failed to change working directory to \`${PKG_BUILD_DIR}'."; + fi; return "${_rc}"; +}; + +# +# ex_pkg_load_vars() - load build variables +# +# Return: zero (0) on success, non-zero (>0) on failure, build variables post-return on success. +# +ex_pkg_load_vars() { + local _rc=0; _status=""; + if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then + _rc=1; _status="Error: invalid architecture \`${ARCH}'."; + elif ! rtl_lmatch "${BUILD}" "debug release"; then + _rc=1; _status="Error: unknown build type \`${BUILD}'."; + else case "${ARCH}" in + nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; + nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; + esac; + rtl_fileop source_opt \ + "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \ + ../midipix_build.vars ./midipix.env; + if [ -z "${PREFIX}" ]; then + _rc=1; _status="Error: \${PREFIX} empty or unset."; + fi; + fi; return "${_rc}"; +}; + +# +# ex_pkg_load_groups() - load all available build groups +# +# Return: zero (0) on success, non-zero (>0) on failure, build groups loaded and ${EX_PKG_BUILD_GROUPS} set post-return. +# +ex_pkg_load_groups() { + local _build_groups="" _fname="" _group="" _groups=""; + for _fname in $(find ./groups -name *.group | sort); do + rtl_fileop source_opt "${_fname}"; + if [ -n "${GROUP_TARGET}" ]; then + _group="${GROUP_TARGET}"; unset GROUP_TARGET; + else + _group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}"; + fi; + if ! rtl_lmatch "${_groups}" "${_group}"; then + _groups="$(rtl_lconcat "${_groups}" "${_group}")"; + if [ -n "${GROUP_AUTO}" ]; then + if [ "${GROUP_AUTO:-0}" -ne 0 ]; then + _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; + fi; + unset GROUP_AUTO; + else + _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; + fi; + fi; + done; + EX_PKG_BUILD_GROUPS="$(rtl_uniq "${_build_groups}")"; +}; + # # ex_pkg_unfold_depends() - unfold list of package names into dependency-expanded set of complete, disabled, finished, and outstanding package names +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages # @_group_name: build group name # @_pkg_names: list of package names # @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} # # Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. # ex_pkg_unfold_depends() { - local _group_name="${1}" _pkg_names="${2}" _restart="${3}" \ - _restart_recursive="${4}" _test_finished="${5}" \ + local _checkfl="${1}" _forcefl="${2}" _group_name="${3}" _pkg_names="${4}" _restart="${5}" _test_finished="${6}"\ _pkg_name="" _restartfl=0; if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then _pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")"; fi; - if [ -n "${_restart}" ]\ - && [ "${_restart_recursive:-0}" -ge 1 ]\ - && [ "${_restart_recursive:-0}" -le 2 ]; then + if [ -n "${_restart}" ] && [ "${_checkfl:-0}" -eq 1 ]; then _pkg_names="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))"; fi; for _pkg_name in ${_pkg_names}; do @@ -106,7 +183,7 @@ ex_pkg_unfold_depends() { elif [ "${_test_finished:-1}" -eq 1 ]\ && ex_pkg_state_test "${_pkg_name}" finish\ && [ "${_restartfl:-0}" -eq 0 ]\ - && [ "${_restart_recursive:-0}" -ne 2 ]\ + && [ "${_forcefl:-0}" -ne 1 ]\ && [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; @@ -122,7 +199,6 @@ ex_pkg_unfold_depends() { # @_group_name: build group name # @_pkg_names: list of package names # @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} # # Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr index 5426b8d7..44ed8d43 100644 --- a/subr/ex_pkg_dispatch.subr +++ b/subr/ex_pkg_dispatch.subr @@ -23,19 +23,21 @@ exp_pkg_dispatch_complete() { # # exp_pkg_dispatch_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages # @_group_name: build group name # @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) +# @_reversefl: unfold reverse dependencies (1) or dependencies (0) # # Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. # exp_pkg_dispatch_expand_packages() { - local _group_name="${1}" _restart="${2}" _restart_recursive="${3}" _pkg_names=""; - EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; + local _checkfl="${1}" _forcefl="${2}" _group_name="${3}" _restart="${4}" _reversefl="${5}"\ + _pkg_names=""; EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ && [ -n "${_pkg_names}" ]; then - if [ "${_restart_recursive:-0}" -ne 3 ]; then - ex_pkg_unfold_depends "${_group_name}" "${_pkg_names}" "${_restart}" "${_restart_recursive}" 1; + if [ "${_reversefl:-0}" -eq 0 ]; then + ex_pkg_unfold_depends "${_checkfl}" "${_forcefl}" "${_group_name}" "${_pkg_names}" "${_restart}" 1; else ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${_restart}" 1; fi; fi; @@ -46,20 +48,20 @@ exp_pkg_dispatch_expand_packages() { # exp_pkg_dispatch_group() - dispatch a single build group # @_build_steps_default: list of default build steps # @_build_vars_default: list of default build variables +# @_checkfl: enable (1) or inhibit (0) dependency expansion # @_dispatch_fn: top-level dispatch function name # @_group_name: build group name # @_njobs_max: maximum count of simultaneous jobs # @_pipe_path: pathname to build FIFO # @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_workdir: pathname to build-specific temporary directory # # Return: zero (0) on success, non-zero (>0) on failure. # exp_pkg_dispatch_group() { - local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ - _group_name="${4}" _njobs_max="${5}" _pipe_path="${6}" _restart_at="${7}" \ - _restart_recursive="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0; + local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}" \ + _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}" \ + _restart_at="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0; rtl_fileop mkfifo "${_pipe_path}"; while true; do while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -gt 0 ] && read _pipe_msg; do @@ -72,11 +74,11 @@ exp_pkg_dispatch_group() { if [ -n "${EX_PKG_NAMES}" ] && [ "${_rc}" -eq 0 ]; then if [ "${EXP_PKG_DISPATCH_NJOBS}" -ne "${_njobs_max}" ]; then exp_pkg_dispatch_packages "${_build_steps_default}" \ - "${_build_vars_default}" "${_dispatch_fn}" \ - "${_group_name}" "${_njobs_max}" \ - "${_pipe_path}" "${EX_PKG_DISABLED}" \ - "${EX_PKG_FINISHED}" "${_restart_at}" \ - "${_restart_recursive}" "${_workdir}"; + "${_build_vars_default}" "${_checkfl}" \ + "${_dispatch_fn}" "${_group_name}" \ + "${_njobs_max}" "${_pipe_path}" \ + "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}" \ + "${_restart_at}" "${_workdir}"; fi; elif [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -eq 0 ]; then break; @@ -90,11 +92,11 @@ exp_pkg_dispatch_group() { if [ -n "${EX_PKG_NAMES}" ] && [ "${_rc}" -eq 0 ]; then if [ "${EXP_PKG_DISPATCH_NJOBS}" -ne "${_njobs_max}" ]; then exp_pkg_dispatch_packages "${_build_steps_default}" \ - "${_build_vars_default}" "${_dispatch_fn}" \ - "${_group_name}" "${_njobs_max}" "${_pipe_path}" \ + "${_build_vars_default}" "${_checkfl}" \ + "${_dispatch_fn}" "${_group_name}" \ + "${_njobs_max}" "${_pipe_path}" \ "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}" \ - "${_restart_at}" "${_restart_recursive}" \ - "${_workdir}"; + "${_restart_at}" "${_workdir}"; fi; elif [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -eq 0 ]; then break; @@ -121,7 +123,13 @@ exp_pkg_dispatch_package() { _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"; if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}"; then : $((EXP_PKG_DISPATCH_NJOBS+=1)); : $((EXP_PKG_DISPATCH_COUNT+=1)); EX_PKG_DISPATCH_WAIT="$(rtl_lconcat "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; - (set +o errexit -o noglob; BUILD_IS_PARENT=0; + (trap "if [ \${?} -eq 0 ]; then \ + printf \"done %s %s\n\" \"${_group_name}\" \"${_pkg_name}\" >&3; \ + else \ + printf \"fail %s %s\n\" \"${_group_name}\" \"${_pkg_name}\" >&3; \ + pkill -U "${$}"; \ + fi;" EXIT HUP INT TERM USR1 USR2; + set +o errexit -o noglob; BUILD_IS_PARENT=0; rtl_log_set_fname ""; rtl_log_set_no_attr 1; if ex_pkg_env "${_build_steps_default}" "${_build_vars_default}" \ "${_group_name}" 0 "${_pkg_name}" "${_restart_at}" "${_workdir}"; then ex_pkg_exec "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; @@ -137,6 +145,7 @@ exp_pkg_dispatch_package() { # exp_pkg_dispatch_packages() - dispatch set of packages # @_build_steps_default: list of default build steps # @_build_vars_default: list of default build variables +# @_checkfl: enable (1) or inhibit (0) dependency expansion # @_dispatch_fn: top-level dispatch function name # @_group_name: build group name # @_njobs_max: maximum count of simultaneous jobs @@ -144,15 +153,14 @@ exp_pkg_dispatch_package() { # @_pkg_disabled: list of disabled packages # @_pkg_finished: list of finished packages # @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_workdir: pathname to build-specific temporary directory # # Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_DISPATCH_NJOBS}, ${EXP_PKG_DISPATCH_COUNT}, ${EX_PKG_NAMES}, and ${EX_PKG_DISPATCH_WAIT} may be mutated post-return. # exp_pkg_dispatch_packages() { - local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ - _group_name="${4}" _njobs_max="${5}" _pipe_path="${6}" _pkg_disabled="${7}" \ - _pkg_finished="${8}" _restart_at="${9}" _restart_recursive="${10}" _workdir="${11}" \ + local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}" \ + _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}" \ + _pkg_disabled="${8}" _pkg_finished="${9}" _restart_at="${10}" _workdir="${11}" \ _foundfl=0 _njob=0 _pkg_depends="" _pkg_name=""; while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -lt "${_njobs_max}" ]; do _foundfl=0; @@ -160,8 +168,8 @@ exp_pkg_dispatch_packages() { if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name}"\ && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name}"\ && ! rtl_lmatch "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}"\ - && ex_pkg_check_depends "${_pkg_disabled}" "${_pkg_finished}" "${_pkg_name}" \ - "${EX_PKG_DISPATCH_WAIT}" "${_restart_recursive}"; then + && ex_pkg_check_depends "${_checkfl}" "${_pkg_disabled}" "${_pkg_finished}" \ + "${_pkg_name}" "${EX_PKG_DISPATCH_WAIT}"; then exp_pkg_dispatch_package "${_build_steps_default}" \ "${_build_vars_default}" "${_dispatch_fn}" \ "${_group_name}" "${_pkg_name}" "${_restart_at}" \ @@ -185,55 +193,52 @@ exp_pkg_dispatch_packages() { # @_pipe_path: pathname to build FIFO # @_restart: optional whitespace-separated list of package names to rebuild # @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) # @_workdir: pathname to build-specific temporary directory # -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISPATCH_UNKNOWN} and ${EX_PKG_DISPATCH_WAIT} mutated post-return. +# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISPATCH_WAIT} mutated post-return. # ex_pkg_dispatch() { local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ _group_names="${4}" _groups_inhibit_deps="${5}" _njobs_max="${6}" _pipe_path="${7}" \ _restart="${8}" _restart_at="${9}" _restart_recursive="${10}" _workdir="${11}" \ - _pkg_name="" _pkg_names="" _rc=0 \ + _checkfl=1 _forcefl=0 _pkg_name="" _pkg_names="" _rc=0 _reversefl=0 \ EX_PKG_DISABLED EX_PKG_FINISHED EX_PKG_NAMES EXP_PKG_DISPATCH_COUNT \ EXP_PKG_DISPATCH_COUNT_MAX EXP_PKG_DISPATCH_NJOBS; EX_PKG_DISPATCH_WAIT=""; - if [ "${_groups_inhibit_deps:-0}" -eq 0 ]; then - _group_names="$(rtl_uniq $(rtl_lunfold_depends '${_name}_GROUP_DEPENDS' ${_group_names}))"; + case "${_groups_inhibit_deps:-0}" in + 0) _group_names="$(rtl_uniq $(rtl_lunfold_depends '${_name}_GROUP_DEPENDS' ${_group_names}))"; + esac; + if [ -n "${_restart}" ]; then + case "${_restart_recursive:-0}" in + 0) _checkfl=0; _forcefl=0; _reversefl=0; ;; + 1) _checkfl=1; _forcefl=0; _reversefl=0; ;; + 2) _checkfl=1; _forcefl=1; _reversefl=0; ;; + 3) _checkfl=1; _forcefl=1; _reversefl=1; ;; + esac; fi; for _group_name in ${_group_names}; do EX_PKG_DISABLED=""; EX_PKG_DISPATCH_WAIT=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; EXP_PKG_DISPATCH_COUNT=0; EXP_PKG_DISPATCH_COUNT_MAX=0; EXP_PKG_DISPATCH_NJOBS=0; if "${_dispatch_fn}" start_group "${_group_name}" ""; then if rtl_fileop mkdir "${_workdir}"\ - && rtl_log_msg vnfo "Resolving \`${_group_name}' dependencies..."\ - && exp_pkg_dispatch_expand_packages "${_group_name}" "${_restart}" "${_restart_recursive}"\ + && rtl_log_msg notice "Resolving \`%s' dependencies..." "${_group_name}"\ + && exp_pkg_dispatch_expand_packages "${_checkfl}" "${_forcefl}" "${_group_name}" "${_restart}" "${_reversefl}"\ && exp_pkg_dispatch_complete "${_dispatch_fn}" "${_group_name}" "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}"\ - && rtl_log_msg vnfo "Resolved \`${_group_name}' dependencies."\ + && rtl_log_msg notice "Resolved \`%s' dependencies." "${_group_name}"\ && EXP_PKG_DISPATCH_COUNT_MAX="$(rtl_llength "${EX_PKG_NAMES}")"\ && [ "${EXP_PKG_DISPATCH_COUNT_MAX}" -gt 0 ]; then _pkg_names="$(rtl_lconcat "${_pkg_names}" "${EX_PKG_NAMES}")"; exp_pkg_dispatch_group "${_build_steps_default}" \ - "${_build_vars_default}" "${_dispatch_fn}" "${_group_name}" \ - "${_njobs_max}" "${_pipe_path}" "${_restart_at}" \ - "${_restart_recursive}" "${_workdir}"; _rc="${?}"; + "${_build_vars_default}" "${_checkfl}" "${_dispatch_fn}" \ + "${_group_name}" "${_njobs_max}" "${_pipe_path}" \ + "${_restart_at}" "${_workdir}"; _rc="${?}"; fi; "${_dispatch_fn}" finish_group "${_group_name}" ""; if [ "${_rc}" -ne 0 ]; then break; fi; fi; - done; - if ! rtl_lmatch "${_restart}" "ALL LAST"; then - for _pkg_name in ${_restart}; do - if ! rtl_lmatch "${_pkg_names}" "${_pkg_name}"; then - EX_PKG_DISPATCH_UNKNOWN="$(rtl_lconcat "${EX_PKG_DISPATCH_UNKNOWN}" "${_pkg_name}")"; - fi; - done; - fi; - if [ -n "${EX_PKG_DISPATCH_UNKNOWN}" ]; then - _rc=1; - fi; - return "${_rc}"; + done; return "${_rc}"; }; # vim:filetype=sh textwidth=0 diff --git a/subr/ex_pkg_env.subr b/subr/ex_pkg_env.subr index edb5e8d1..48b57535 100644 --- a/subr/ex_pkg_env.subr +++ b/subr/ex_pkg_env.subr @@ -52,7 +52,7 @@ exp_pkg_env_defaults() { # exp_pkg_env_set() { local _build_vars_default="${1}" _group_name="${2}" _nounset="${3}" \ - _pkg_name="${4}" _var_prefixes="" _vars_set="" _vname=""; + _pkg_name="${4}" _var_prefixes="" _vars_set="" _vname="" IFS IFS0; rtl_set_vars _vars_set BUILD_TYPE "DEFAULT ${_group_name} PKG_${_pkg_name}"; rtl_set_vars _vars_set INHERIT_FROM "PKG_${_pkg_name}"; _var_prefixes="$(rtl_toupper "DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_group_name}")"; @@ -67,9 +67,9 @@ exp_pkg_env_set() { "$(rtl_toupper "PKG_${_pkg_name}")")"; fi; done; - rtl_push_IFS :; for _vname in ${PKG_ENV_VARS_EXTRA}; do + IFS0="${IFS}"; IFS=":"; for _vname in ${PKG_ENV_VARS_EXTRA}; do export "${_vname}"; - done; rtl_pop_IFS; + done; IFS="${IFS0}"; if [ "${_nounset:-0}" -eq 0 ]; then rtl_unset_vars $(rtl_lfilter \ "$(set | sed -ne '/^PKG_[^=]*=/s/=.*$//p')" \ diff --git a/subr/ex_pkg_exec.subr b/subr/ex_pkg_exec.subr index fb0cfa02..4519ce25 100644 --- a/subr/ex_pkg_exec.subr +++ b/subr/ex_pkg_exec.subr @@ -88,12 +88,6 @@ exp_pkg_exec_step() { ex_pkg_exec() { local _dispatch_fn="${1}" _group_name="${2}" _pkg_name="${3}" _restart_at="${4}" \ _rc=0 _step="" _step_next=""; - trap "if [ \${?} -eq 0 ]; then \ - echo \"done ${_group_name} ${_pkg_name}\" >&3; \ - else \ - echo \"fail ${_group_name} ${_pkg_name}\" >&3; \ - pkill -U "${$}"; \ - fi;" EXIT HUP INT TERM USR1 USR2; if exp_pkg_exec_pre "${_group_name}" "${_pkg_name}" "${_restart_at}"\ && "${_dispatch_fn}" start_pkg_child "${_group_name}" "${_pkg_name}"; then if rtl_test_cmd "pkg_${_pkg_name}_all"; then @@ -112,7 +106,7 @@ ex_pkg_exec() { elif ! exp_pkg_exec_step "${_group_name}" "${_pkg_name}" "${_restart_at}" "${_step}"; then _rc=1; break; else - echo "step ${_group_name} ${_pkg_name} ${_step}" >&3; + printf "step %s %s %s\n" "${_group_name}" "${_pkg_name}" "${_step}" >&3; ex_pkg_state_set "${_pkg_name}" "${_step}" "${_step_next:+-${_step_next}}"; fi; done; diff --git a/subr/pkg_configure_autotools.subr b/subr/pkg_configure_autotools.subr index d28cc8e1..32daedc1 100644 --- a/subr/pkg_configure_autotools.subr +++ b/subr/pkg_configure_autotools.subr @@ -53,7 +53,7 @@ pkg_configure_autotools() { "${PKG_CONFIG_CACHE}" \ "${PKG_CONFIG_CACHE_LOCAL}" \ "${PKG_CONFIG_CACHE_EXTRA}"; - do if ! echo "${_config_cache}" |\ + do if ! printf "%s" "${_config_cache}" |\ tr " " "\n" >> "${PKG_BUILD_DIR}/config.cache"; then return 1; fi; diff --git a/subr/pkg_fetch_extract.subr b/subr/pkg_fetch_extract.subr index eedd84ab..8a9d8319 100644 --- a/subr/pkg_fetch_extract.subr +++ b/subr/pkg_fetch_extract.subr @@ -5,9 +5,9 @@ pkgp_fetch_extract_type() { local _fname="${1}"; if [ "${1##*.tar.}" != "${1}" ]; then - echo "${1##*.tar.}"; + printf "%s" "${1##*.tar.}"; elif [ "${1##*.t}" != "${1}" ]; then - echo "${1##*.t}"; + printf "%s" "${1##*.t}"; fi; }; diff --git a/subr/pkg_install.subr b/subr/pkg_install.subr index d0b59486..4cefa2d1 100644 --- a/subr/pkg_install.subr +++ b/subr/pkg_install.subr @@ -23,7 +23,7 @@ pkg_install() { fi; done; IFS="${_ifs_old}"; (set +o errexit -o noglob; trap "rm -f \"${BUILD_WORKDIR}/install.lock\"" EXIT; - date; echo trying to grab lock + date; while true; do if flock -E 622 -w 600 4; then break; @@ -44,7 +44,7 @@ pkg_install() { return 1; else _pkglist_name="${PKG_BASE_DIR##*/}"; _pkglist_name="${_pkglist_name%%-*}"; - if ! echo "${_pkglist_name}" >> "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then + if ! printf "%s" "${_pkglist_name}" >> "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then return 1; fi; fi; diff --git a/subr/pkg_install_files.subr b/subr/pkg_install_files.subr index c555499b..2c6703fb 100644 --- a/subr/pkg_install_files.subr +++ b/subr/pkg_install_files.subr @@ -33,7 +33,7 @@ pkgp_install_files_strip() { fi; for _bin_path in $(find "${_tree_root}" -perm /a=x -type f); do if objdump -sj .debug_info "${_bin_path}" >/dev/null 2>&1; then - rtl_log_msg info "Stripping ${_bin_path}..."; + rtl_log_msg info "Stripping %s..." "${_bin_path}"; if ! "${PKG_TARGET}-strip" "${_bin_path}"; then return 1; fi; diff --git a/subr/pkgtool_init.subr b/subr/pkgtool_init.subr index ce3c6808..f92572fb 100644 --- a/subr/pkgtool_init.subr +++ b/subr/pkgtool_init.subr @@ -2,57 +2,35 @@ # set +o errexit -o noglob is assumed. # -pkgtoolp_init_defaults() { - : ${ARCH:="nt64"}; : ${BUILD:="debug"}; : ${PKG_NAME:=""}; - : ${BUILD_WORKDIR:=""}; : ${PREFIX=""}; - ARG_INFO=0; ARG_RESTART_AT=""; ARG_RDEPENDS=0; - ARG_UPDATE_DIFF=0; ARG_SHELL=0; ARG_TARBALL=0; - BUILD_GROUPS=""; -}; - -pkgtoolp_init_dump() { +pkgtoolp_init_args() { local _rc=0; _status=""; - if [ -n "${ARG_RESTART_AT}" ]\ - || [ "${ARG_UPDATE_DIFF:-0}" -eq 1 ]\ - || [ "${ARG_SHELL:-0}" -eq 1 ]; then - if [ ! -e "${BUILD_WORKDIR}/${PKG_NAME}.dump" ]; then - rtl_log_msg warn "Warning: failed to locate environment dump for package \`${PKG_NAME}' in \`${BUILD_WORKDIR}'."; - rtl_log_msg info "Rebuilding package \`${PKG_NAME}' w/ --dump-in build..."; - (export ARCH BUILD \ - BUILD_DLCACHEDIR BUILD_WORKDIR \ - PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ - PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; - ./build.sh -a "${ARCH}" -b "${BUILD}" --dump-in build -P -r "${PKG_NAME}" -v); - if [ ! -e "${BUILD_WORKDIR}/${PKG_NAME}.dump" ]; then - _rc=1; _status="Error: failed to locate environment dump for package \`${PKG_NAME}' in \`${BUILD_WORKDIR}'."; - fi; - else - _rc=0; - fi; - if [ "${_rc:-0}" -eq 0 ]\ - && ! . "${BUILD_WORKDIR}/${PKG_NAME}.dump"; then - _rc=1; _status="Error: failed to source environment dump for package \`${PKG_NAME}' from \`${BUILD_WORKDIR}'."; - elif [ "${_rc:-0}" -eq 0 ]\ - && ! rtl_fileop cd "${PKG_BUILD_DIR}"; then - _rc=1; _status="Error: failed to change working directory to \`${PKG_BUILD_DIR}'."; - fi; + if [ "$((${ARG_INFO:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -gt 1 ]; then + cat etc/pkgtool.usage; _rc=1; _status="Error: only one of -i, -r, -s, or -t must be specified."; + elif [ "$((${ARG_INFO:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -eq 0 ]\ + && [ -z "${ARG_RESTART_AT}" ]\ + && [ "${ARG_UPDATE_DIFF:-0}" -eq 0 ]; then + cat etc/pkgtool.usage; _rc=1; _status="Error: one of -i, -r, -s, or -t must be specified."; + else _rc=0; fi; return "${_rc}"; }; pkgtoolp_init_env() { local _fname="" _rc=0; _status=""; - if ! umask 022; then - printf "Error: failed to setup environment.\n"; exit 1; + if ! cd "${0%/*}"; then + printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1; + elif ! umask 022; then + printf "Error: failed to set umask(2).\n" >&2; exit 1; else for _fname in $(find subr -name *.subr); do if ! . "${_fname}"; then - printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1; + printf "Error: failed to source \`%s'.\n" "${_fname}" >&2; exit 1; fi; - done; fi; - return "${_rc}"; + done; + fi; return "${_rc}"; }; pkgtoolp_init_getopts() { - local _opt="" _shiftfl=0 _rc=0 OPTIND=0; _status=""; + local _opt="" _shiftfl=0 _rc=0 OPTIND=0; _status=""; : ${ARCH:="nt64"}; : ${BUILD:="debug"}; + ARG_INFO=0; ARG_RESTART_AT=""; ARG_RDEPENDS=0; ARG_UPDATE_DIFF=0; ARG_SHELL=0; ARG_TARBALL=0; while [ "${#}" -gt 0 ]; do case "${1}" in --update-diff) @@ -86,78 +64,22 @@ pkgtoolp_init_getopts() { fi; done; if [ "${_rc}" -eq 0 ]; then - if [ "$((${ARG_INFO:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -gt 1 ]; then - cat etc/pkgtool.usage; rtl_log_msg failexit "Error: only one of -i, -r, -s, or -t must be specified."; - elif [ "$((${ARG_INFO:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -eq 0 ]; then - if [ -z "${ARG_RESTART_AT}" ]\ - && [ "${ARG_UPDATE_DIFF:-0}" -eq 0 ]; then - cat etc/pkgtool.usage; rtl_log_msg failexit "Error: one of -i, -r, -s, or -t must be specified."; - fi; - fi; while [ "${#}" -gt 0 ]; do - case "${1}" in - *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; - *) if [ "${#}" -ne 1 ]; then - _rc=1; _status="Error: invalid argument \`${1}'."; - fi; break; ;; - esac; shift; done; + case "${1}" in + *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; + *) if [ "${#}" -ne 1 ]; then + _rc=1; _status="Error: invalid argument \`${1}'."; + fi; break; ;; + esac; shift; + done; if [ "${_rc:-0}" -eq 0 ]; then if [ "${#}" -ne 1 ]\ - && [ -z "${PKG_NAME}" ]; then + && [ -z "${PKGTOOL_PKG_NAME}" ]; then _rc=1; _status="Error: missing package name."; elif [ "${#}" -eq 1 ]; then - PKG_NAME="${1}"; + PKGTOOL_PKG_NAME="${1}"; export PKGTOOL_PKG_NAME; fi; fi; - fi; - return "${_rc}"; -}; - -pkgtoolp_init_groups() { - local _default_build_groups="" _fname="" _group="" _groups="" _rc=0; _status=""; - if [ "${ARG_INFO:-0}" -eq 1 ]\ - || [ "${ARG_RDEPENDS:-0}" -eq 1 ]\ - || [ "${ARG_TARBALL:-0}" -eq 1 ]; then - for _fname in $(find ./groups -name *.group | sort); do - rtl_fileop source_opt "${_fname}"; - if [ -n "${GROUP_TARGET}" ]; then - _group="${GROUP_TARGET}"; unset GROUP_TARGET; - else - _group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}"; - fi; - if ! rtl_lmatch "${_groups}" "${_group}"; then - _groups="$(rtl_lconcat "${_groups}" "${_group}")"; - if [ -n "${GROUP_AUTO}" ]; then - if [ "${GROUP_AUTO:-0}" -ne 0 ]; then - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - unset GROUP_AUTO; - else - _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")"; - fi; - fi; - done; - _default_build_groups="$(rtl_uniq "${_default_build_groups}")"; - BUILD_GROUPS="${_default_build_groups}"; - fi; return "${_rc}"; -}; - -pkgtoolp_init_package() { - local _foundfl=0 _group_name="" _pkg_names="" _rc=0; _status=""; - if [ "${ARG_INFO:-0}" -eq 1 ]\ - || [ "${ARG_RDEPENDS:-0}" -eq 1 ]\ - || [ "${ARG_TARBALL:-0}" -eq 1 ]; then - for _group_name in ${BUILD_GROUPS}; do - if ! _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ - || [ -z "${_pkg_names}" ]; then - rtl_log_msg warn "Warning: ignoring non-existent or invalid build group \`${_build_group}'."; - elif rtl_lmatch "${_pkg_names}" "${PKG_NAME}"; then - _foundfl=1; - fi; - done; - if [ "${_foundfl:-0}" -eq 0 ]; then - _rc=1; _status="Error: package \`${PKG_NAME}' unknown."; - fi; fi; return "${_rc}"; }; @@ -176,45 +98,18 @@ pkgtoolp_init_prereqs() { elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \ sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then _rc=1; _status="Error: sed(1) in \${PATH} does not support the \`-i' option."; - fi; - return "${_rc}"; -}; - -pkgtoolp_init_vars() { - local _rc=0; _status=""; - if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then - _rc=1; _status="Error: invalid architecture \`${ARCH}'."; - elif ! rtl_lmatch "${BUILD}" "debug release"; then - _rc=1; _status="Error: unknown build type \`${BUILD}'."; - else case "${ARCH}" in - nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; - nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; - esac; - rtl_fileop source_opt \ - "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \ - ../midipix_build.vars ./midipix.env; - if [ -z "${PREFIX}" ]; then - _rc=1; _status="Error: \${PREFIX} empty or unset."; - fi; fi; - return "${_rc}"; + fi; return "${_rc}"; }; pkgtool_init() { - local _fname="" _rc=0 _status=""; + local _fname="" _rc=0; _status=""; if ! pkgtoolp_init_env \ - || ! pkgtoolp_init_defaults \ || ! pkgtoolp_init_getopts "${@}" \ || ! pkgtoolp_init_prereqs \ - || ! pkgtoolp_init_vars \ - || ! pkgtoolp_init_dump \ - || ! pkgtoolp_init_groups \ - || ! pkgtoolp_init_package; then - _rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}"; - elif [ -n "${_status}" ]; then - rtl_log_msg info "${_status}"; exit 0; - else - return "${_rc}"; - fi; + || ! ex_pkg_load_vars \ + || ! pkgtoolp_init_args; then + _rc=1; _status="${_status}"; + fi; return "${_rc}"; }; # vim:filetype=sh diff --git a/subr/rtl.subr b/subr/rtl.subr index 18ddb8d6..f029a8e1 100644 --- a/subr/rtl.subr +++ b/subr/rtl.subr @@ -2,16 +2,11 @@ # set +o errexit -o noglob is assumed. # -EXP_RTL_IFS="${IFS}"; - -rtl_basename() { echo "${1##*/}"; }; +rtl_basename() { local _fname="${1##*/}"; printf "%s" "${_fname}"; }; rtl_date() { command date "+${1:-${DEFAULT_TIMESTAMP_FMT}}"; }; -rtl_dirname() { echo "${1%/*}"; }; -rtl_pop_IFS() { IFS="${EXP_RTL_IFS}"; }; -rtl_push_IFS() { EXP_RTL_IFS="${IFS}"; IFS="${1}"; }; rtl_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; }; rtl_test_cmd() { command -v "${1}" >/dev/null; }; -rtl_uniq() { echo "${@}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; }; +rtl_uniq() { if [ "${#}" -gt 0 ]; then printf "%s" "${*}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; fi; }; rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; }; # vim:filetype=sh diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr index 01e373ea..0e39178d 100644 --- a/subr/rtl_complex.subr +++ b/subr/rtl_complex.subr @@ -27,6 +27,13 @@ rtl_clean_env() { rtl_unset_vars $(rtl_lfilter "${_env_vars}" "${_env_vars_except}"); }; +rtl_dirname() { + local _dname="${1%/*}"; + while rtl_matchr "${_dname}" "*/"; do + _dname="${_dname%/}"; + done; printf "%s" "${_dname:-/}"; +}; + rtl_exists_any() { local _subdir="${1}"; shift; while [ "${#}" -gt 0 ]; do @@ -79,12 +86,13 @@ rtl_filter_vars() { esac; ;; esac; if "${_fn}" "${_vname}"; then - _vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")"; _fnfl=1; + _vars="${_vars:+${_vars} +}${_var_spec}"; _fnfl=1; else _fnfl=0; fi; done; - echo "${_vars}"; + printf "%s" "${_vars}"; }; rtl_get_cpu_count() { @@ -96,7 +104,7 @@ rtl_get_cpu_count() { if rtl_match "${_line}" "processor*:"; then : $((_ncpus+=1)); fi; - done < /proc/cpuinfo; echo "${_ncpus}"; + done < /proc/cpuinfo; printf "%s" "${_ncpus}"; fi; ;; *) _rc=1; _status="Error: unknown platform \`${_sname}'."; ;; esac; return "${_rc}"; @@ -112,6 +120,11 @@ rtl_get_var_unsafe() { eval echo \${${_vname}}; }; +rtl_get_vars_fast() { + local _pattern="${1}"; + set | awk -F= '/'"${_pattern}"'/{print $1}' | sort; +}; + rtl_head() { local _pattern="${1}" _s="${2}"; while true; do @@ -121,7 +134,7 @@ rtl_head() { _s="${_s%%${_pattern}}"; fi; done; - echo "${_s}"; + printf "%s" "${_s}"; }; rtl_is_newer() { diff --git a/subr/rtl_fetch.subr b/subr/rtl_fetch.subr index 3afd30dc..e93d69eb 100644 --- a/subr/rtl_fetch.subr +++ b/subr/rtl_fetch.subr @@ -82,7 +82,8 @@ rtl_fetch_url_wget() { if [ -n "${_sha256sum_src}" ]; then set -- $(sha256sum "${_url_dst}"); if [ "${_sha256sum_dst:=${1}}" != "${_sha256sum_src}" ]; then - rtl_log_msg failexit "Error: hash mismatch for URL \`${_url}' (downloaded file: ${_sha256sum_dst}, from build variables: ${_sha256sum_src}.)"; + rtl_log_msg fatalexit "Error: hash mismatch for URL \`%s' (downloaded file: %s, from build variables: %s.)"\ + "${_url}" "${_sha256sum_dst}" "${_sha256sum_src}"; fi; fi; rtl_fileop touch "${_url_dst}.fetched"; diff --git a/subr/rtl_fileop.subr b/subr/rtl_fileop.subr index c2b403fa..fd45f67f 100644 --- a/subr/rtl_fileop.subr +++ b/subr/rtl_fileop.subr @@ -2,123 +2,137 @@ # set +o errexit -o noglob is assumed. # -exp_rtl_fileop_check() { +# +# Private globals and subroutines +# +RTLP_FILEOP_LOG=0; +rtl_fileop_set_log() { RTLP_FILEOP_LOG="${1}"; }; + +rtlp_fileop_check() { local _prefix="${1}" _pname="" _rname=""; shift; while [ "${#}" -gt 0 ]; do return 0; shift; done; }; +rtlp_fileop_log() { + local _msg="${1}"; + if [ "${RTLP_FILEOP_LOG:-0}" -eq 1 ]; then + rtl_log_msg debug "${_msg}"; + fi; +}; + + rtl_fileop() { local _op="${1}" _dst="" _mode="" _install_args="" _owner="" _rc=0 _src=""; shift; case "${_op}" in cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then - rtl_log_msg failexit "Invalid or non-existent directory \`${1}'."; - elif exp_rtl_fileop_check "${PREFIX}" "${1}"; then - rtl_log_msg vvvv "Changing working directory to \`${1}'."; + rtl_log_msg fatalexit "Invalid or non-existent directory \`%s'." "${1}"; + elif rtlp_fileop_check "${PREFIX}" "${1}"; then + rtlp_fileop_log "Changing working directory to \`${1}'."; cd -- "${1}"; _rc="${?}"; fi; ;; chmod) if [ "${#}" -lt 2 ]; then - rtl_log_msg failexit "Missing parameters (in: chmod ${*}.)"; + rtl_log_msg fatalexit "Missing parameters (in: chmod %s.)" "${*}"; elif _mode="${1}" && shift\ - && exp_rtl_fileop_check "${PREFIX}" "${*}"; then - rtl_log_msg vvvv "Changing file mode bits of \`${*}' to \`${_mode}'."; + && rtlp_fileop_check "${PREFIX}" "${*}"; then + rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_mode}'."; chmod -- "${_mode}" "${@}"; _rc="${?}"; fi; ;; chown) if [ "${#}" -lt 2 ]; then - rtl_log_msg failexit "Missing parameters (in: chown ${*}.)"; + rtl_log_msg fatalexit "Missing parameters (in: chown %s.)" "${*}"; elif _owner="${1}" && shift\ - && exp_rtl_fileop_check "${PREFIX}" "${*}"; then - rtl_log_msg vvvv "Changing file owner of \`${*}' to \`${_owner}'."; + && rtlp_fileop_check "${PREFIX}" "${*}"; then + rtlp_fileop_log "Changing file owner of \`${*}' to \`${_owner}'."; chown -- "${_owner}" "${@}"; _rc="${?}"; fi; ;; cp_follow) if [ "${#}" -lt 2 ]; then - rtl_log_msg failexit "Missing parameters (in: cp_follow ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then + rtl_log_msg fatalexit "Missing parameters (in: cp_follow %s}.)" "${*}"; + elif rtlp_fileop_check "${PREFIX}" "${*}"; then _src="${*}"; _src="${_src% *}"; _dst="${*}"; _dst="${_dst##* }"; - rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pLR."; + rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pLR."; cp -pLR -- "${@}"; _rc="${?}"; fi; ;; cp) if [ "${#}" -lt 2 ]; then - rtl_log_msg failexit "Missing parameters (in: cp ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then + rtl_log_msg fatalexit "Missing parameters (in: cp %s.)" "${*}"; + elif rtlp_fileop_check "${PREFIX}" "${*}"; then _src="${*}"; _src="${_src% *}"; _dst="${*}"; _dst="${_dst##* }"; - rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pPR."; + rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pPR."; cp -pPR -- "${@}"; _rc="${?}"; fi; ;; install) if [ "${#}" -lt 2 ]; then - rtl_log_msg failexit "Missing parameters (in: install ${*}.)"; - else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${2}")"; - _install_args="$(while [ ""${#}"" -gt 2 ]; do echo "${1}"; shift; done)"; - _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${1}")"; - if exp_rtl_fileop_check "${PREFIX}" "${_dst}" "${_src}"; then - rtl_log_msg vvvv "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; + rtl_log_msg fatalexit "Missing parameters (in: install %s.)" "${*}"; + else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${2}")"; + _install_args="$(while [ ""${#}"" -gt 2 ]; do printf "%s" "${1}"; shift; done)"; + _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${1}")"; + if rtlp_fileop_check "${PREFIX}" "${_dst}" "${_src}"; then + rtlp_fileop_log "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; install "${@}"; _rc="${?}"; fi; fi; ;; ln_symbolic) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then - rtl_log_msg failexit "Missing parameters (in: ln_symbolic ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${2}"; then + rtl_log_msg fatalexit "Missing parameters (in: ln_symbolic %s.)" "${*}"; + elif rtlp_fileop_check "${PREFIX}" "${2}"; then if rtl_fileop test "${2}"; then rtl_fileop rm "${2}"; fi; if [ "${?}" -eq 0 ]; then - rtl_log_msg vvvv "Linking \`${1}' to \`${2}' w/ -fs"; + rtlp_fileop_log "Linking \`${1}' to \`${2}' w/ -fs"; ln -fs -- "${1}" "${2}"; _rc="${?}"; fi; fi; ;; mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then - rtl_log_msg failexit "Missing parameters (in: mv ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${1}" "${2}"; then - rtl_log_msg vvvv "Moving \`${1}' to \`${2}' w/ -fs"; + rtl_log_msg fatalexit "Missing parameters (in: mv %s.)" "${*}"; + elif rtlp_fileop_check "${PREFIX}" "${1}" "${2}"; then + rtlp_fileop_log "Moving \`${1}' to \`${2}' w/ -fs"; mv -f -- "${1}" "${2}"; _rc="${?}"; fi; ;; mkdir|mkfifo|rm|source_opt|test|touch) while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do if [ -z "${1}" ]; then - rtl_log_msg failexit "Missing parameters (in: ${_op} ${*}.)"; + rtl_log_msg fatalexit "Missing parameters (in: %s %s.)" "${_op}" "${*}"; elif [ "${_op}" = mkdir ]\ && [ ! -d "${1}" ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + && rtlp_fileop_check "${PREFIX}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; - rtl_log_msg vvvv "Making directory \`${1}'."; + rtlp_fileop_log "Making directory \`${1}'."; mkdir -p -- "${1}"; _rc="${?}"; elif [ "${_op}" = mkfifo ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + && rtlp_fileop_check "${PREFIX}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; - rtl_log_msg vvvv "Creating FIFO \`${1}'."; - exp_rtl_fileop_check "${PREFIX}" "${1}"; + rtlp_fileop_log "Creating FIFO \`${1}'."; + rtlp_fileop_check "${PREFIX}" "${1}"; mkfifo -- "${1}"; _rc="${?}"; elif [ "${_op}" = rm ]\ && rtl_fileop test "${1}"\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - rtl_log_msg vvvv "Removing directory or file \`${1}'."; + && rtlp_fileop_check "${PREFIX}" "${1}"; then + rtlp_fileop_log "Removing directory or file \`${1}'."; rm -rf -- "${1}"; _rc="${?}"; elif [ "${_op}" = source_opt ]\ && rtl_fileop test "${1}"\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - rtl_log_msg vvvv "Sourcing file \`${1}'."; + && rtlp_fileop_check "${PREFIX}" "${1}"; then + rtlp_fileop_log "Sourcing file \`${1}'."; . "${1}"; _rc="${?}"; elif [ "${_op}" = test ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"\ + && rtlp_fileop_check "${PREFIX}" "${1}"\ && ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then return 1; elif [ "${_op}" = touch ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - rtl_log_msg vvvv "Touching file \`${1}'."; + && rtlp_fileop_check "${PREFIX}" "${1}"; then + rtlp_fileop_log "Touching file \`${1}'."; touch -- "${1}"; _rc="${?}"; fi; shift; done; ;; - *) rtl_log_msg failexit "Error: rtl_fileop() called w/ invalid parameter(s): ${*}"; ;; + *) rtl_log_msg fatalexit "Error: rtl_fileop() called w/ invalid parameter(s): %s" "${*}"; ;; esac; return "${_rc}"; }; diff --git a/subr/rtl_list.subr b/subr/rtl_list.subr index f57a3ee9..b1105bab 100644 --- a/subr/rtl_list.subr +++ b/subr/rtl_list.subr @@ -15,7 +15,7 @@ rtl_lfilter() { local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ _filterfl="" _litem="" _litem_filter="" _lnew=""; if [ -z "${_filter}" ]; then - echo "${_list}"; return 0; + printf "%s" "${_list}"; return 0; else for _litem in ${_list}; do _filterfl=0; for _litem_filter in ${_filter}; do @@ -27,7 +27,7 @@ rtl_lfilter() { _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; fi; done; fi; - echo "${_lnew}"; + printf "%s" "${_lnew}"; }; rtl_llength() { @@ -35,13 +35,13 @@ rtl_llength() { for _litem in ${_list}; do : $((_llength+=1)); done; - echo "${_llength}"; + printf "%s" "${_llength}"; }; rtl_llift() { local _list="${1}" _sep="${2}" _sep_new="${3}" IFS; IFS="${_sep}"; set -- ${_list}; IFS="${_sep_new}"; - echo "${*}"; + printf "%s" "${*}"; }; rtl_lmatch() { @@ -49,11 +49,21 @@ rtl_lmatch() { [ -n "$(rtl_lsearch "${_list}" "${_item}" "${_sep}")" ]; }; +rtl_lmax() { + local _len=0 _len_max=0; + while [ "${#}" -gt 0 ]; do + _len="${#1}"; + if [ "${_len}" -gt "${_len_max}" ]; then + _len_max="${_len}"; + fi; shift; + done; printf "%s" "${_len_max}"; +}; + rtl_lsearch() { local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ _litem="" _litem_filter="" _lnew=""; if [ -z "${_filter}" ]; then - echo "${_list}"; return 0; + printf "%s" "${_list}"; return 0; else for _litem in ${_list}; do for _litem_filter in ${_filter}; do if [ "${_litem_filter}" = "${_litem}" ]; then @@ -62,7 +72,7 @@ rtl_lsearch() { fi; done; done; fi; - echo "${_lnew}"; + printf "%s" "${_lnew}"; }; rtl_lsort() { @@ -80,7 +90,7 @@ rtl_lunfold_depends() { fi; _names="$(rtl_lconcat "${_names}" "${_name}")"; done; - echo "${_names}"; + printf "%s" "${_names}"; }; # vim:filetype=sh diff --git a/subr/rtl_log.subr b/subr/rtl_log.subr index 51db687b..860ccf03 100644 --- a/subr/rtl_log.subr +++ b/subr/rtl_log.subr @@ -2,77 +2,76 @@ # set +o errexit -o noglob is assumed. # -: ${DEFAULT_LOG_MSG_FAIL_COLOUR:=91}; -: ${DEFAULT_LOG_MSG_INFO_COLOUR:=93}; -: ${DEFAULT_LOG_MSG_INF2_COLOUR:=33}; -: ${DEFAULT_LOG_MSG_SUCC_COLOUR:=92}; -: ${DEFAULT_LOG_MSG_SUC2_COLOUR:=32}; -: ${DEFAULT_LOG_MSG_VNFO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VUCC_COLOUR:=90}; -: ${DEFAULT_LOG_MSG_VVFO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VVVO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VVVV_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_WARN_COLOUR:=31}; +# +# Private globals and subroutines +# +RTLP_LOG_NO_ATTR=0; +RTLP_LOG_FNAME=""; +RTLP_LOG_LVL="0"; +rtl_log_set_fname() { RTLP_LOG_FNAME="${1}"; }; +rtl_log_set_lvl() { RTLP_LOG_LVL="${1}"; }; +rtl_log_set_no_attr() { RTLP_LOG_NO_ATTR="${1}"; }; -exp_rtl_log_printf() { - local _attrs="${1}" _msg=""; shift; _msg="$(printf "${@}")"; - if [ "${BUILD_IS_PARENT:-0}" -eq 1 ]\ - && [ -n "${DEFAULT_BUILD_LOG_FNAME}" ]\ - && [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then - printf "%s\n" "${_msg}" >> "${DEFAULT_BUILD_LOG_FNAME}"; +rtlp_log_printf() { + local _attr="${1}" _fmt="${2}"; shift 2; _msg="$(printf "${_fmt}" "${@}")"; + if [ -n "${RTLP_LOG_FNAME}" ]; then + printf "%s\n" "${_msg}" >> "${RTLP_LOG_FNAME}"; + fi; + if [ "${RTLP_LOG_NO_ATTR:-0}" -eq 0 ]; then + printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; + else + printf "%s\n" "${_msg}"; fi; - printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; }; +# +# Public globals +# +RTL_LOG_MSG_FATAL_COLOUR=91; # Bright red +RTL_LOG_MSG_WARNING_COLOUR=31; # Dark red +RTL_LOG_MSG_SUCCESS_COLOUR=33; # Dark yellow +RTL_LOG_MSG_SUCCESS_END_COLOUR=32; # Dark green +RTL_LOG_MSG_INFO_COLOUR=93; # Bright yellow +RTL_LOG_MSG_INFO_END_COLOUR=92; # Bright green +RTL_LOG_MSG_NOTICE_COLOUR=96; # Bright cyan +RTL_LOG_MSG_VERBOSE_COLOUR=90; # Dark grey +RTL_LOG_MSG_DEBUG_COLOUR=36; # Dark cyan + + rtl_log_env_vars() { - local _nvar=1 _arg="" _arg_len_max=0; + local _arg_len_max=0; rtl_log_msg info "Variables for this ${1:-build}:"; shift; - while [ ${_nvar} -le ${#} ]; do - _arg="$(eval echo \${${_nvar}})"; - _arg="${_arg%%=*}"; - if [ ${#_arg} -gt ${_arg_len_max} ]; then - _arg_len_max=${#_arg}; - fi; : $((_nvar+=1)); - done; - while [ ${#} -gt 0 ]; do - rtl_log_msg info "$(printf \ + _arg_len_max="$(rtl_lmax "${@}")"; + while [ "${#}" -gt 0 ]; do + rtl_log_msg info \ "%${_arg_len_max}.${_arg_len_max}s=%s" \ - "${1%%=*}" "$(rtl_get_var_unsafe ${1#*=})")"; + "${1%%=*}" "$(rtl_get_var_unsafe "${1#*=}")"; shift; done; }; -rtl_log_set_vnfo_lvl() { - EXP_RTL_LOG_VNFO_LVL="${1}"; -}; - rtl_log_msg() { - local _lvl="${1}" _lvl_uc="" _attr=""; shift; - if [ "${_lvl}" = vnfo ]\ - || [ "${_lvl}" = vucc ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 1 ]; then - return; - elif [ "${_lvl}" = vvfo ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 2 ]; then - return; - elif [ "${_lvl}" = vvvo ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 3 ]; then - return; - elif [ "${_lvl}" = vvvv ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 4 ]; then - return; - fi; - _lvl_uc="$(rtl_toupper "${_lvl%exit}")"; - _attr="$(rtl_get_var_unsafe "DEFAULT_LOG_MSG_${_lvl_uc}_COLOUR")"; - if [ ${#} -gt 1 ]; then - exp_rtl_log_printf "${_attrs}" "==> %s %s %s" "$(rtl_date)" "${1}" "$*"; - else - exp_rtl_log_printf "${_attrs}" "==> %s %s" "$(rtl_date)" "${1}"; - fi; - if [ ${_lvl} = failexit ]; then + local _lvl="${1}" _fmt="${2}" _attr=""; shift 2; + case "${RTLP_LOG_LVL:-0}" in + 0) rtl_lmatch "notice verbose debug" "${_lvl}" && return; ;; + 1) rtl_lmatch "verbose debug" "${_lvl}" && return; ;; + 2) rtl_lmatch "debug" "${_lvl}" && return; ;; + 3) ;; + esac; + case "${_lvl}" in + fatal|fatalexit) _attr="${RTL_LOG_MSG_FATAL_COLOUR}"; ;; + warning) _attr="${RTL_LOG_MSG_WARNING_COLOUR}"; ;; + success) _attr="${RTL_LOG_MSG_SUCCESS_COLOUR}"; ;; + success_end) _attr="${RTL_LOG_MSG_SUCCESS_END_COLOUR}"; ;; + info) _attr="${RTL_LOG_MSG_INFO_COLOUR}"; ;; + info_end) _attr="${RTL_LOG_MSG_INFO_END_COLOUR}"; ;; + notice) _attr="${RTL_LOG_MSG_NOTICE_COLOUR}"; ;; + verbose) _attr="${RTL_LOG_MSG_VERBOSE_COLOUR}"; ;; + debug) _attr="${RTL_LOG_MSG_DEBUG_COLOUR}"; ;; + esac; + rtlp_log_printf "${_attr}" "==> %s ${_fmt}" "$(rtl_date)" "${@}"; + if [ "x${_lvl}" = "xfatalexit" ]; then exit 1; - else - return 0; fi; }; diff --git a/subr/rtl_string.subr b/subr/rtl_string.subr index c30cfe8c..2dd9e27a 100644 --- a/subr/rtl_string.subr +++ b/subr/rtl_string.subr @@ -21,6 +21,15 @@ rtl_match() { fi; }; +rtl_matchr() { + local _s="${1}" _find="${2}"; + if [ "${_s%${_find}}" != "${_s}" ]; then + return 0; + else + return 1; + fi; +}; + rtl_subst() { local _s="${1}" _find="${2}" _replace="${3}" _prefix="" _s_new=""; while [ -n "${_s}" ]; do @@ -29,7 +38,7 @@ rtl_subst() { _s_new="${_s_new:+${_s_new}}${_prefix}${_replace}"; ;; *) _s_new="${_s_new:+${_s_new}}${_s}"; _s=""; ;; esac; done; - echo "${_s_new}"; + printf "%s" "${_s_new}"; }; rtl_tolower() { @@ -68,7 +77,7 @@ rtl_tolower() { _s="${_s#[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; done; ;; esac; done; - echo "${_s_new}"; + printf "%s" "${_s_new}"; }; rtl_toupper() { @@ -107,7 +116,7 @@ rtl_toupper() { _s="${_s#[^abcdefghijklmnopqrstuvwxyz]}"; done; ;; esac; done; - echo "${_s_new}"; + printf "%s" "${_s_new}"; }; # vim:filetype=sh diff --git a/vars/clang_host.vars b/vars/clang_host.vars index b7ec7e97..851564f1 100644 --- a/vars/clang_host.vars +++ b/vars/clang_host.vars @@ -6,7 +6,7 @@ pkg_clang_host_configure() { if ! rtl_fileop rm "../cfe-${PKG_VERSION}-host" \ || ! rtl_fileop mkdir "../cfe-${PKG_VERSION}-host" \ || ! rtl_fileop cd "../cfe-${PKG_VERSION}-host" \ - || ! rtl_log_msg info "Bootstrapping clang_host..." \ + || ! rtl_log_msg verbose "Bootstrapping clang_host..." \ || ! ("${PREFIX}/bin/cmake" \ "../cfe-${PKG_VERSION}.src" \ -DCLANG_BUILD_EXAMPLES:BOOL=OFF \ @@ -19,7 +19,7 @@ pkg_clang_host_configure() { -DLLVM_PREFIX="${PKG_PREFIX}" \ -G "Unix Makefiles" \ -Wno-dev) \ - || ! rtl_log_msg info "Finished bootstrapping clang_host."; then + || ! rtl_log_msg verbose "Finished bootstrapping clang_host."; then return 1; fi; }; diff --git a/vars/gcc.vars b/vars/gcc.vars index bf2ab44f..f2354ca1 100644 --- a/vars/gcc.vars +++ b/vars/gcc.vars @@ -4,157 +4,153 @@ # Order: stage1_mingw32, native_mingw32 # +# +# Private subroutines +# pkgp_gcc_build_dir() { PKG_BUILD_DIR="${1}-${2}-${PKG_TARGET}"; }; -pkgp_gcc_state_set() { echo "step unknown ${PKG_NAME} ${1}" >&3; ex_pkg_state_set "${PKG_NAME}" ${1} -${2}; }; +pkgp_gcc_state_set() { + printf "step unknown %s %s\n" "${PKG_NAME}" "${1}" >&3; + ex_pkg_state_set "${PKG_NAME}" ${1} -${2}; +}; + +pkgp_gcc_configure() { + if ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" \ + || ! rtl_fileop mkdir "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" \ + || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" \ + || ! "../cbb-gcc-${PKG_VERSION}/configure" "${@}" \ + --disable-bootstrap \ + --disable-libmudflap \ + --disable-multilib \ + --disable-nls \ + --disable-obsolete \ + --disable-symvers \ + --enable-canonical-system-headers \ + --enable-__cxa_atexit \ + --enable-debug \ + --enable-gnu-indirect-function \ + --enable-gnu-unique-object \ + --enable-initfini-array \ + --enable-languages=c,c++,fortran,objc,lto \ + --enable-libstdcxx-debug \ + --enable-lto \ + --enable-multiarch \ + --enable-secureplt \ + --enable-shared \ + --enable-threads=posix \ + --target="${PKG_TARGET}" \ + --with-fpmath=sse; then + return 1; + else + pkgp_gcc_state_set "configure" -"build"; + fi; +}; pkgp_gcc_setup_env() { - local __=""; - export MAKE="make LIBTOOL=slibtool"; - export cbb_target="${PKG_TARGET}"; - unwind_midipix_h=$(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${1}/gcc/unwind-midipix.h"); + local _vname=""; + for _vname in CFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD \ + CXXFLAGS CXXFLAGS_FOR_BUILD; do + export "${_vname}=${GCCFLAGS}"; + done; + for _vname in CFLAGS_FOR_TARGET CPPFLAGS_FOR_TARGET CXXFLAGS_FOR_TARGET \ + LIBCFLAGS_FOR_TARGET XGCC_FLAGS_FOR_TARGET; do + export "${_vname}=${GCCTARGET_FLAGS}"; + done; + for _vname in cbb_cflags_for_stage1 cbb_cflags_for_stage2 \ + cbb_cflags_for_stage3 cbb_cflags_for_stage4; do + export "${_vname}=${CFLAGS_FOR_BUILD}" ; + done; +}; + +pkgp_gcc_setup_vars() { + local _unwind_midipix_h=""; + export cbb_target="${PKG_TARGET}" MAKE="make LIBTOOL=slibtool"; + _unwind_midipix_h="$(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${PKG_VERSION}/gcc/unwind-midipix.h")"; case "${PKG_NAME}" in + gcc_full) + GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PKG_PREFIX}"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "--include=${_unwind_midipix_h}")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "${DEFAULT_CFLAGS_DEBUG_RUNTIME}")"; + export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ + cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ + cbb_xgcc_for_specs="${PKG_TARGET}-gcc" \ + sysroot_headers_suffix="${PKG_PREFIX}"; ;; + gcc_stage1_cross_mingw32) + GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_MINGW32} -midata"; + export cbb_ldflags_for_target=--sysroot="${PREFIX_MINGW32}" \ + cbb_neutral_libiberty=no \ + cbb_sysroot_for_libgcc="${PREFIX_MINGW32}" \ + cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc"; ;; gcc_stage1_host) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_CROSS}"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} --include=${unwind_midipix_h}"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} -DTARGET_PERSONALITY_FUNCTION"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} -DTARGET_PERSONALITY_FUNCTION_MIDIPIX"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} ${DEFAULT_CFLAGS_DEBUG_RUNTIME}"; - export cbb_neutral_libiberty=no \ - cbb_ldflags_for_target=--sysroot="${PREFIX_CROSS}" \ + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "--include=${_unwind_midipix_h}")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX")"; + GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "${DEFAULT_CFLAGS_DEBUG_RUNTIME}")"; + export cbb_ldflags_for_target="--sysroot=${PREFIX_CROSS}" \ + cbb_neutral_libiberty="no" \ cbb_sysroot_for_libgcc="${PREFIX_CROSS}" \ cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc" \ LDFLAGS="${PKG_LDFLAGS_CONFIGURE}"; ;; - gcc_stage1_cross_mingw32) - GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_MINGW32} -midata"; - export cbb_neutral_libiberty=no \ - cbb_ldflags_for_target=--sysroot="${PREFIX_MINGW32}" \ - cbb_sysroot_for_libgcc="${PREFIX_MINGW32}" \ - cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc"; ;; gcc_stage1_native_mingw32) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PKG_PREFIX} -midata"; - export cbb_neutral_libiberty=no \ - cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ + export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ + cbb_neutral_libiberty=no \ cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ cbb_xgcc_for_specs="${PKG_TARGET}-gcc"; ;; - gcc_full) - GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PKG_PREFIX}"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} --include=${unwind_midipix_h}"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} -DTARGET_PERSONALITY_FUNCTION"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} -DTARGET_PERSONALITY_FUNCTION_MIDIPIX"; - GCCTARGET_FLAGS="${GCCTARGET_FLAGS} ${DEFAULT_CFLAGS_DEBUG_RUNTIME}"; - export cbb_xgcc_for_specs="${PKG_TARGET}-gcc" \ - cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ - cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ - sysroot_headers_suffix="${PKG_PREFIX}"; ;; esac; - GCCFLAGS="${PKG_CFLAGS_CONFIGURE} --include $(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${1}/libc/cbb-musl-pe.h")"; - for __ in CFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD CXXFLAGS CXXFLAGS_FOR_BUILD; do - export "${__}=${GCCFLAGS}"; - done; - for __ in CFLAGS_FOR_TARGET CPPFLAGS_FOR_TARGET CXXFLAGS_FOR_TARGET LIBCFLAGS_FOR_TARGET XGCC_FLAGS_FOR_TARGET; do - export "${__}=${GCCTARGET_FLAGS}"; - done; - for __ in cbb_cflags_for_stage1 cbb_cflags_for_stage2 cbb_cflags_for_stage3 cbb_cflags_for_stage4; do - export "${__}=${CFLAGS_FOR_BUILD}" ; - done; - export CFLAGS CXXFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD CXXFLAGS_FOR_BUILD CFLAGS_FOR_TARGET XGCC_FLAGS_FOR_TARGET CPPFLAGS_FOR_TARGET CXXFLAGS_FOR_TARGET LIBCFLAGS_FOR_TARGET; -}; - -pkgp_gcc_configure() { - rtl_fileop rm "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - rtl_fileop mkdir "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - "../cbb-gcc-${PKG_VERSION}/configure" "${@}"\ - --disable-bootstrap \ - --disable-libmudflap \ - --disable-multilib \ - --disable-nls \ - --disable-obsolete \ - --disable-symvers \ - --enable-__cxa_atexit \ - --enable-canonical-system-headers \ - --enable-debug \ - --enable-gnu-indirect-function \ - --enable-gnu-unique-object \ - --enable-initfini-array \ - --enable-languages=c,c++,fortran,objc,lto \ - --enable-libstdcxx-debug \ - --enable-lto \ - --enable-multiarch \ - --enable-secureplt \ - --enable-shared \ - --enable-threads=posix \ - --target="${PKG_TARGET}" \ - --with-fpmath=sse; - pkgp_gcc_state_set configure build; -}; - -pkg_gcc_stage1_host_all() { - pkg_gcc_stage1_all "${@}"; + GCCFLAGS="$(rtl_lconcat "${PKG_CFLAGS_CONFIGURE}" \ + "--include $(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${PKG_VERSION}/libc/cbb-musl-pe.h")")"; }; -pkg_gcc_stage1_cross_mingw32_all() { - rtl_fileop ln_symbolic . "${PKG_PREFIX}/x86_64-w64-mingw32/mingw"; - rtl_fileop mkdir "${PKG_DESTDIR}/x86_64-w64-mingw32"; - rtl_fileop ln_symbolic . "${PKG_DESTDIR}/x86_64-w64-mingw32/mingw"; - rtl_fileop mkdir "${PKG_PREFIX}/x86_64-w64-mingw32/include"; - pkg_gcc_stage1_all "${@}"; -}; - -pkg_gcc_stage1_native_mingw32_all() { - rtl_fileop ln_symbolic . "${PKG_PREFIX}/x86_64-w64-mingw32/mingw"; - rtl_fileop mkdir "${PKG_DESTDIR}/x86_64-w64-mingw32"; - rtl_fileop ln_symbolic . "${PKG_DESTDIR}/x86_64-w64-mingw32/mingw"; - rtl_fileop mkdir "${PKG_PREFIX}/x86_64-w64-mingw32/include"; - pkg_gcc_stage1_all "${@}"; -}; - -pkg_gcc_stage1_all() { - local __="" _restart_at="${1}"; +pkgp_gcc_stage1_all() { + local _restart_at="${1}" _rc=0; case "${PKG_NAME}" in - gcc_stage1_host) - rtl_fileop ln_symbolic . "${PREFIX_CROSS}/usr"; - rtl_fileop mkdir "${PREFIX_CROSS}/usr/include"; - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; - ;; gcc_stage1_cross_mingw32) - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" mingw32; - ;; + pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" mingw32; ;; + gcc_stage1_host) + if ! rtl_fileop ln_symbolic . "${PREFIX_CROSS}/usr"\ + || ! rtl_fileop mkdir "${PREFIX_CROSS}/usr/include"\ + || ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; then + _rc=1; + fi; ;; gcc_stage1_native_mingw32) - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; - ;; + pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; ;; esac; - # GCC, stage1. + if [ "${_rc}" -ne 0 ]; then + return 1; + fi; if ! ex_pkg_state_test "${PKG_NAME}" fetch "${_restart_at}"; then - rtl_fetch_urls_git "${PKG_BASE_DIR}" "cbb-gcc-${PKG_VERSION}=${PKG_GITROOT}/cbb/cbb-gcc-${PKG_VERSION}"; - pkgp_gcc_state_set fetch patch; + rtl_fetch_urls_git "${PKG_BASE_DIR}" "cbb-gcc-${PKG_VERSION}=${PKG_GITROOT}/cbb/cbb-gcc-${PKG_VERSION}" || return 1; + pkgp_gcc_state_set "fetch" -"patch"; fi; if ! ex_pkg_state_test "${PKG_NAME}" patch "${_restart_at}"; then if [ -e "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" ]; then - patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch"; + patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" || return 1; fi; - pkgp_gcc_state_set patch configure; + pkgp_gcc_state_set "patch" -"configure"; fi; - pkgp_gcc_setup_env "${PKG_VERSION}"; + pkgp_gcc_setup_vars; pkgp_gcc_setup_env; if ! ex_pkg_state_test "${PKG_NAME}" configure "${_restart_at}"; then case "${PKG_NAME}" in - gcc_stage1_host) + gcc_stage1_cross_mingw32) pkgp_gcc_configure \ - --disable-sjlj-exceptions \ + --enable-sjlj-exceptions \ --prefix="${PREFIX}" \ --with-gmp="${PREFIX}" \ --with-mpc="${PREFIX}" \ --with-mpfr="${PREFIX}" \ - --with-sysroot="${PREFIX_CROSS}"; ;; - gcc_stage1_cross_mingw32) + --with-sysroot="${PREFIX_MINGW32}" \ + --without-headers; ;; + gcc_stage1_host) pkgp_gcc_configure \ - --enable-sjlj-exceptions \ + --disable-sjlj-exceptions \ --prefix="${PREFIX}" \ --with-gmp="${PREFIX}" \ --with-mpc="${PREFIX}" \ --with-mpfr="${PREFIX}" \ - --with-sysroot="${PREFIX_MINGW32}" \ - --without-headers; ;; + --with-sysroot="${PREFIX_CROSS}"; ;; gcc_stage1_native_mingw32) pkgp_gcc_configure \ --build=x86_64-unknown-linux-gnu \ @@ -168,139 +164,71 @@ pkg_gcc_stage1_all() { --with-sysroot= \ --without-headers; ;; esac; - else - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; + if [ "${?}" -ne 0 ]; then + return 1; + fi; + else rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; fi; if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} all-gcc; - pkgp_gcc_state_set build install; + make ${PKG_MAKEFLAGS_BUILD} "all-gcc" || return 1; + pkgp_gcc_state_set "build" -"install_subdirs"; fi; if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs; - pkgp_gcc_state_set install_subdirs install_make; + pkg_install_subdirs || return 1; + pkgp_gcc_state_set "install_subdirs" -"install_make"; fi; if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then case "${PKG_NAME}" in - gcc_stage1_host) - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install-gcc; ;; gcc_stage1_cross_mingw32) - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install-gcc; ;; + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; + gcc_stage1_host) + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; gcc_stage1_native_mingw32) - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install-gcc; ;; + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; esac; - __="$(uname -s)"; - if [ "${__#*CYGWIN*}" != "${__}" ]; then - rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.dll.a" \ - rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.so"; + if [ "${?}" -ne 0 ]; then + return 1; + else case "$(uname -s)" in + CYGWIN_*) + if ! rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.dll.a"\ + || ! rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.so"; then + return 1; + fi; ;; + esac; + pkgp_gcc_state_set "install_make" -"install"; fi; - pkgp_gcc_state_set install_make install; fi; if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install; - ex_pkg_state_set "${PKG_NAME}" install finish; + pkg_install || return 1; + pkgp_gcc_state_set "install" -"finish"; fi; }; -pkg_gcc_runtime_host_all() { - local _restart_at="${1}"; - local _vis_hide="vis_hide=-fvisibility=hidden"; - export MAKE="make LIBTOOL=slibtool ${_vis_hide}"; - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - # GCC, compiler runtime. - if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} all-target-libgcc ${_vis_hide}; - pkgp_gcc_state_set build install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs; - pkgp_gcc_state_set install_subdirs install_make; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install-target-libgcc; - pkgp_gcc_state_set install_make install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install; - ex_pkg_state_set "${PKG_NAME}" install finish; - fi; -}; - -pkg_gcc_libstdcpp_v3_host_all() { - local _restart_at="${1}"; - export MAKE="make LIBTOOL=slibtool"; - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - # GCC, libstdc++-v3. - if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} all-target-libstdc++-v3; - pkgp_gcc_state_set build install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs; - pkgp_gcc_state_set install_subdirs install_make; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install-target-libstdc++-v3; - pkgp_gcc_state_set install_make install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install; - ex_pkg_state_set "${PKG_NAME}" install finish; - fi; -}; - -pkg_gcc_full_host_all() { - local _restart_at="${1}"; - export MAKE="make LIBTOOL=slibtool"; - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - # GCC, everything else. - if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD}; - pkgp_gcc_state_set build install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs; - pkgp_gcc_state_set install_subdirs install_make; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install; - pkgp_gcc_state_set install_make install; - fi; - if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install; - ex_pkg_state_set "${PKG_NAME}" install finish; - fi; -}; pkg_gcc_full_all() { - local _restart_at="${1}" _configure_host=""; - local _vis_hide="vis_hide=-fvisibility=hidden"; + local _restart_at="${1}" _configure_host="" _vis_hide="vis_hide=-fvisibility=hidden"; export MAKE="make LIBTOOL=slibtool ${_vis_hide}"; - # GCC, native. pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; if ! ex_pkg_state_test "${PKG_NAME}" fetch "${_restart_at}"; then - rtl_fetch_urls_git "${PKG_BASE_DIR}" "cbb-gcc-${PKG_VERSION}=${PKG_GITROOT}/cbb/cbb-gcc-${PKG_VERSION}"; - pkgp_gcc_state_set fetch patch; + rtl_fetch_urls_git "${PKG_BASE_DIR}" "cbb-gcc-${PKG_VERSION}=${PKG_GITROOT}/cbb/cbb-gcc-${PKG_VERSION}" || return 1; + pkgp_gcc_state_set "fetch" -"patch"; fi; if ! ex_pkg_state_test "${PKG_NAME}" patch "${_restart_at}"; then if [ -e "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" ]; then - patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch"; + patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" || return 1; fi; - pkgp_gcc_state_set patch configure; + pkgp_gcc_state_set "patch" -"configure"; fi; pkgp_gcc_setup_env "${PKG_VERSION}"; if ! ex_pkg_state_test "${PKG_NAME}" configure "${_restart_at}"; then - rtl_fileop mkdir "${PKG_PREFIX}/${PKG_TARGET}"; + rtl_fileop mkdir "${PKG_PREFIX}/${PKG_TARGET}" || return 1; if [ \! -d "${PKG_PREFIX}/${PKG_TARGET}/usr" ]; then - rtl_fileop ln_symbolic . "${PKG_PREFIX}/${PKG_TARGET}/usr"; - fi; - if [ "${ARCH}" = nt32 ]; then - _configure_host="i686-nt32-midipix"; - else - _configure_host="x86_64-nt64-midipix"; + rtl_fileop ln_symbolic . "${PKG_PREFIX}/${PKG_TARGET}/usr" || return 1; fi; + case "${ARCH}" in + nt32) _configure_host="i686-nt32-midipix"; ;; + nt64) _configure_host="x86_64-nt64-midipix"; ;; + esac; pkgp_gcc_configure \ --disable-sjlj-exceptions \ --host="${_configure_host}" \ @@ -309,29 +237,132 @@ pkg_gcc_full_all() { --with-gmp="${PKG_PREFIX}" \ --with-mpc="${PKG_PREFIX}" \ --with-mpfr="${PKG_PREFIX}" \ - --with-sysroot=; - else - rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; + --with-sysroot="" || return 1; + else rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; fi; if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} all-gcc; - make ${PKG_MAKEFLAGS_BUILD} all-target-libgcc ${_vis_hide}; - make ${PKG_MAKEFLAGS_BUILD} all-target-libstdc++-v3; - make ${PKG_MAKEFLAGS_BUILD} all-target-libgfortran; - make ${PKG_MAKEFLAGS_BUILD} all; - pkgp_gcc_state_set build install; + if ! make ${PKG_MAKEFLAGS_BUILD} "all-gcc"\ + || ! make ${PKG_MAKEFLAGS_BUILD} "all-target-libgcc" ${_vis_hide}\ + || ! make ${PKG_MAKEFLAGS_BUILD} "all-target-libstdc++-v3"\ + || ! make ${PKG_MAKEFLAGS_BUILD} "all-target-libgfortran"\ + || ! make ${PKG_MAKEFLAGS_BUILD} "all"; then + return 1; + else pkgp_gcc_state_set "build" -"install_subdirs"; + fi; fi; if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs; - pkgp_gcc_state_set install_subdirs install_make; + pkg_install_subdirs || return 1; + pkgp_gcc_state_set "install_subdirs" -"install_make"; fi; if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then - make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" install; - pkgp_gcc_state_set install_make install; + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install" || return 1; + pkgp_gcc_state_set "install_make" -"install"; fi; if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install; - ex_pkg_state_set "${PKG_NAME}" install finish; + pkg_install || return 1; pkgp_gcc_state_set "install" "finish"; + fi; +}; + +pkg_gcc_full_host_all() { + local _restart_at="${1}"; + export MAKE="make LIBTOOL=slibtool"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ + || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then + return 1; + else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} || return 1; + pkgp_gcc_state_set "build" -"install_subdirs"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then + pkg_install_subdirs || return 1; + pkgp_gcc_state_set "install_subdirs" -"install_make"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install" || return 1; + pkgp_gcc_state_set "install_make" -"install"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then + pkg_install || return 1; + pkgp_gcc_state_set "install" "finish"; + fi; + fi; +}; + +pkg_gcc_libstdcpp_v3_host_all() { + local _restart_at="${1}"; + export MAKE="make LIBTOOL=slibtool"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ + || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then + return 1; + else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} "all-target-libstdc++-v3" || return 1; + pkgp_gcc_state_set "build" -"install_subdirs"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then + pkg_install_subdirs || return 1; + pkgp_gcc_state_set "install_subdirs" -"install_make"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-target-libstdc++-v3" || return 1; + pkgp_gcc_state_set "install_make" -"install"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then + pkg_install || return 1; + pkgp_gcc_state_set "install" "finish"; + fi; + fi; +}; + +pkg_gcc_runtime_host_all() { + local _restart_at="${1}" _vis_hide="vis_hide=-fvisibility=hidden"; + export MAKE="make LIBTOOL=slibtool ${_vis_hide}"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ + || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then + return 1; + else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} "all-target-libgcc" ${_vis_hide} || return 1; + pkgp_gcc_state_set "build" -"install_subdirs"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then + pkg_install_subdirs || return 1; + pkgp_gcc_state_set "install_subdirs" -"install_make"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then + make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-target-libgcc" || return 1; + pkgp_gcc_state_set "install_make" -"install"; + fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then + pkg_install || return 1; + pkgp_gcc_state_set "install" "finish"; + fi; + fi; +}; + +pkg_gcc_stage1_all() { + pkgp_gcc_stage1_all "${@}"; +}; + +pkg_gcc_stage1_cross_mingw32_all() { + if ! rtl_fileop ln_symbolic . "${PKG_PREFIX}/x86_64-w64-mingw32/mingw"\ + || ! rtl_fileop mkdir "${PKG_DESTDIR}/x86_64-w64-mingw32"\ + || ! rtl_fileop ln_symbolic . "${PKG_DESTDIR}/x86_64-w64-mingw32/mingw"\ + || ! rtl_fileop mkdir "${PKG_PREFIX}/x86_64-w64-mingw32/include"\ + || ! pkgp_gcc_stage1_all "${@}"; then + return 1; + fi; +}; + +pkg_gcc_stage1_host_all() { + pkgp_gcc_stage1_all "${@}"; +}; + +pkg_gcc_stage1_native_mingw32_all() { + if ! rtl_fileop ln_symbolic . "${PKG_PREFIX}/x86_64-w64-mingw32/mingw"\ + || ! rtl_fileop mkdir "${PKG_DESTDIR}/x86_64-w64-mingw32"\ + || ! rtl_fileop ln_symbolic . "${PKG_DESTDIR}/x86_64-w64-mingw32/mingw"\ + || ! rtl_fileop mkdir "${PKG_PREFIX}/x86_64-w64-mingw32/include"\ + || ! pkgp_gcc_stage1_all "${@}"; then + return 1; fi; }; diff --git a/vars/git.vars b/vars/git.vars index 89ef2121..80d24c8b 100644 --- a/vars/git.vars +++ b/vars/git.vars @@ -9,7 +9,7 @@ ac_cv_snprintf_returns_bogus=0"}; pkg_git_install_make_post() { local _fname="" _fname_new=""; for _fname in $(find "${PKG_DESTDIR}" -name "Git*::*" -type f); do - _fname_new="$(echo ${_fname} | sed "s/::/./g")"; + _fname_new="$(rtl_subst "${_fname}" "::" ".")"; if ! rtl_fileop mv "${_fname}" "${_fname_new}"; then return 1; fi; diff --git a/vars/libxml2.vars b/vars/libxml2.vars index a30c3c1a..42dbe42f 100644 --- a/vars/libxml2.vars +++ b/vars/libxml2.vars @@ -10,8 +10,8 @@ pkg_libxml2_install_make_post() { if ! cat > "${PKG_DESTDIR}/bin/${PKG_TARGET}-xml2-config" < "${PKG_DESTDIR}/lib/rpm/elfdeps"\ + if ! printf "%s" "#!/bin/true" > "${PKG_DESTDIR}/lib/rpm/elfdeps"\ || ! rtl_fileop chmod +x "${PKG_DESTDIR}/lib/rpm/elfdeps"\ || ! rtl_fileop rm "${PKG_DESTDIR}/var"; then return 1; -- cgit v1.2.3