summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz (arab, vxp) <l.illanes@gmx.de>2017-02-01 03:20:19 +0100
committerLucio Andrés Illanes Albornoz (arab, vxp) <l.illanes@gmx.de>2017-02-01 03:20:19 +0100
commitce047ee9f0c206ef68dca70ff156fbcd29ea2ba5 (patch)
tree868cd222d91744e06db3aa9d011d1f2fd5a14fdc /subr
parent1548659e9cc2eeffbbd300791f228ae61524c280 (diff)
downloadmidipix_build-ce047ee9f0c206ef68dca70ff156fbcd29ea2ba5.tar.bz2
midipix_build-ce047ee9f0c206ef68dca70ff156fbcd29ea2ba5.tar.xz
subr/build.subr, build.sh: merged into build.sh.
subr/{pkg,rtl}.subr: merged into subr/rtl.subr.
Diffstat (limited to 'subr')
-rw-r--r--subr/build.subr143
-rw-r--r--subr/pkg.subr124
-rw-r--r--subr/rtl.subr119
3 files changed, 119 insertions, 267 deletions
diff --git a/subr/build.subr b/subr/build.subr
deleted file mode 100644
index 41cb4d80..00000000
--- a/subr/build.subr
+++ /dev/null
@@ -1,143 +0,0 @@
-#
-# . ./build.vars and set -o errexit -o noglob are assumed.
-# See warning at the top of build.vars.
-#
-
-check_cpuinfo() {
- if [ -z "${BUILD_CPUS}" ] \
- && [ -e /proc/cpuinfo ]; then
- BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
- fi;
-};
-
-clear_env() {
- for __ in $(export | sed -e 's/^export //' -e 's/=.*$//'); do
- if ! match_list "${CLEAR_ENV_VARS_EXCEPT}" " " "${__}"; then
- unset "${__}";
- fi;
- done;
-};
-
-check_paths() {
- for __ in ${CHECK_PATH_VARS}; do
- if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
- log_msg failexit "Error: variable \`${__}' is empty or unset.";
- elif [ "${___#* *}" != "${___}" ]; then
- log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
- fi;
- done;
- for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
- if [ "${__#/}" != "${__}" ]; then
- if [ ! -e "${__}" ]; then
- log_msg fail "Error: missing prerequisite file \`${__}'.";
- __exit=1;
- fi;
- else
- if ! test_cmd "${__}"; then
- log_msg fail "Error: missing prerequisite command \`${__}'.";
- __exit=1;
- fi;
- fi;
- done;
- for __ in ${CHECK_PREREQ_PERL_MODULES}; do
- if ! perl -M"${__}" -e "" 2>/dev/null; then
- log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
- __exit=1;
- fi;
- done;
- if [ ${__exit:-0} = 1 ]; then
- exit 1;
- elif [ -n "${__exit}" ]; then
- unset __exit;
- fi;
-};
-
-clean_prefix() {
- if [ ${ARG_CLEAN:-0} -eq 1 ]; then
- log_msg info "-c specified, cleaning prefix...";
- for __ in ${CLEAR_PREFIX_DIRS}; do
- if [ -e ${PREFIX}/${__} ]; then
- secure_rm ${PREFIX}/${__};
- fi;
- done;
- fi;
-};
-
-create_dirs() {
- insecure_mkdir ${PREFIX} ${PREFIX}/x86_64-w64-mingw32 ${PREFIX_NATIVE} ${PREFIX_CROSS} ${PREFIX_TARGET}/lib ${DLCACHEDIR} ${WORKDIR};
- for __ in ${PREFIX}/usr ${PREFIX_NATIVE}/usr; do
- if [ ! -L "${__}" ]; then
- secure_rm "${__}"; ln -sf -- . "${__}";
- fi;
- done;
- if [ ! -L ${PREFIX}/x86_64-w64-mingw32/mingw ]; then
- secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw;
- ln -sf . ${PREFIX}/x86_64-w64-mingw32/mingw;
- fi;
- if [ ! -d ${PREFIX}/x86_64-w64-mingw32/mingw/include ]; then
- secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw/include;
- insecure_mkdir ${PREFIX}/x86_64-w64-mingw32/mingw/include;
- fi;
- if [ ! -L ${PREFIX}/man ]; then
- secure_rm ${PREFIX}/man;
- ln -sf share/man ${PREFIX}/man;
- fi;
- if [ ! -L ${PREFIX_NATIVE}/man ]; then
- secure_rm ${PREFIX_NATIVE}/man;
- ln -sf share/man ${PREFIX_NATIVE}/man;
- fi;
- insecure_mkdir ${PREFIX_MINIPIX}/bin;
- for __ in lib libexec share; do
- if [ ! -e ${PREFIX_MINIPIX}/${__} ]; then
- ln -sf bin ${PREFIX_MINIPIX}/${__};
- fi;
- done;
-};
-
-fini_build_progress_file() {
- if [ -f "${BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
- secure_rm ${BUILD_STATUS_IN_PROGRESS_FNAME};
- fi;
-};
-
-fini_build_vars() {
- : $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
- : $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
- : $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
- : $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
-};
-
-init_build_log() {
- if [ -e ${BUILD_LOG_FNAME} ]; then
- mv -- ${BUILD_LOG_FNAME} ${BUILD_LOG_LAST_FNAME};
- fi;
-};
-
-init_build_progress_file() {
- touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
-};
-
-init_build_vars() {
- BUILD_DATE_START="$(date %Y-%m-%d-%H-%M-%S)";
- BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
- BUILD_TIMES_SECS=$(command date +%s);
-};
-
-source_vars() {
- for __ in ${HOME}/midipix_build.vars ../midipix_build.vars ./vars/build.vars; do
- [ -e ${__} ] && . ${__};
- done;
-};
-
-subst_tgts() {
- while [ ${#} -ge 1 ]; do
- case "${1}" in
- devroot)
- echo ${DEVROOT_PACKAGES}; ;;
- world) echo ${WORLD_PACKAGES}; ;;
- *) echo ${1}; ;;
- esac; shift;
- done;
-};
-
-# vim:filetype=sh
diff --git a/subr/pkg.subr b/subr/pkg.subr
deleted file mode 100644
index 2130feb5..00000000
--- a/subr/pkg.subr
+++ /dev/null
@@ -1,124 +0,0 @@
-#
-# . ./build.vars and set -o errexit -o noglob are assumed.
-# See warning at the top of build.vars.
-#
-
-is_build_script_done() {
- if [ "${1}" = "clean" ]; then
- if match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC} \
- && [ -n "${ARG_RESTART_AT}" ] \
- && match_list "${ARG_RESTART_AT}" , "${1}"; then
- return 1; # Build
- else
- return 0; # Skip
- fi;
- elif [ "${ARG_RESTART}" = "ALL" ]; then
- return 1; # Build
- elif match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC}; then
- if [ -n "${ARG_RESTART_AT}" ]; then
- if [ "${ARG_RESTART_AT}" = "ALL" ]; then
- return 1; # Build
- elif match_list "${ARG_RESTART_AT}" , "${1}"; then
- return 1; # Build
- else
- return 0; # Skip
- fi;
- else
- return 1; # Build
- fi;
- elif [ -f ${WORKDIR}/.${2:-${BUILD_PACKAGE_LC}}.${1} ]; then
- return 0; # Skip
- else
- return 1; # Build
- fi;
-};
-
-log_env_vars() {
- log_msg info "Variables for this ${1:-build}:"; shift;
- while [ ${_lev_nvar:=0} -lt ${#} ]; do
- _lev_arg="$(eval echo \${${_lev_nvar}})";
- _lev_arg="${_lev_arg%%=*}";
- if [ ${#_lev_arg} -gt ${_lev_arg_len_max:=0} ]; then
- _lev_arg_len_max=${#_lev_arg};
- fi; : $((_lev_nvar+=1));
- done; unset _lev_nvar _lev_arg;
- while [ ${#} -gt 0 ]; do
- log_msg info "$(printf \
- "%${_lev_arg_len_max}.${_lev_arg_len_max}s=%s" \
- "${1%%=*}" "$(get_var_unsafe ${1#*=})")";
- shift;
- done; unset _lev_arg_len_max;
-};
-
-parse_with_pkg_name() {
- PKG_NAME=${1}; shift;
- _pwpn_pkg_name_uc=$(echo ${PKG_NAME} | tr a-z A-Z);
- if [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URL)" ]\
- && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URLS_GIT)" ]\
- && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_VERSION)" ]; then
- unset _pwpn_pkg_name_uc;
- log_msg failexit "Error: package \`${PKG_NAME}' missing in build.vars.";
- else
- for _pwpn_vname in ${PKG_BUILD_VARS}; do
- if [ -n "$(get_var_unsafe DEFAULT_${_pwpn_vname})" ]; then
- set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe DEFAULT_${_pwpn_vname})";
- fi;
- if [ -n "$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})" ]; then
- set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})";
- fi;
- if [ "${BUILD}" = "debug" ] \
- && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)" ]; then
- set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)";
- elif [ "${BUILD}" = "release" ] \
- && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)" ]; then
- set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)";
- elif [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})" ]; then
- set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})";
- fi;
- done; unset _pwpn_vname;
- fi;
- [ -z "${PKG_FNAME}" ] && PKG_FNAME=${PKG_URL##*/};
- [ -z "${PKG_SUBDIR}" ] && PKG_SUBDIR=${PKG_FNAME%%.tar*};
- [ -n "${PKG_ENV_VARS_EXTRA}" ] && set_env_vars_with_sep : "${PKG_ENV_VARS_EXTRA}";
- for _pwpn_env_var in $(set); do
- if [ "${_pwpn_env_var#PKG_${_pwpn_pkg_name_uc}}" != "${_pwpn_env_var}" ]; then
- _pwpn_env_vars="${_pwpn_env_vars:+${_pwpn_env_vars} }${_pwpn_env_var%%=*}";
- fi;
- done;
- if [ -n "${_pwpn_env_vars}" ]; then
- log_env_vars "build" ${_pwpn_env_vars};
- fi; unset _pwpn_pkg_name_uc _pwpn_env_var _pwpn_env_vars;
-};
-
-run_cmd_unsplit() {
- _rcu_cmd=${1}; shift;
- while [ ${#} -gt 0 ]; do
- [ -n "${1}" ] &&\
- _rcu_cmdline="${_rcu_cmdline:+${_rcu_cmdline}:}${1}";
- shift;
- done;
- push_IFS :; ${_rcu_cmd} ${_rcu_cmdline}; _rcu_rc=$?; pop_IFS;
- unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc};
-};
-
-set_build_script_done() {
- _sbsd_script_fname=${BUILD_PACKAGE_LC};
- _sbsd_done_fname=${WORKDIR}/.${_sbsd_script_fname};
- while [ $# -ge 1 ]; do
- if [ "${1#-}" != "${1}" ]; then
- secure_rm ${_sbsd_done_fname}.${1#-};
- else
- touch ${_sbsd_done_fname}.${1};
- log_msg info "Finished build step ${1} of \`${_sbsd_script_fname}'.";
- fi; shift;
- done; unset _sbsd_script_fname _sbsd_done_fname;
-};
-
-set_env_vars_with_sep() {
- _sevws_sep=${1}; shift; push_IFS ${_sevws_sep}; set -- ${1};
- while [ ${#} -gt 0 ]; do
- export "${1}"; shift;
- done; unset _sevws_sep; pop_IFS;
-};
-
-# vim:filetype=sh
diff --git a/subr/rtl.subr b/subr/rtl.subr
index 6f15a432..70fcbe32 100644
--- a/subr/rtl.subr
+++ b/subr/rtl.subr
@@ -102,4 +102,123 @@ secure_rm() {
done;
};
+
+is_build_script_done() {
+ if [ "${1}" = "clean" ]; then
+ if match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC} \
+ && [ -n "${ARG_RESTART_AT}" ] \
+ && match_list "${ARG_RESTART_AT}" , "${1}"; then
+ return 1; # Build
+ else
+ return 0; # Skip
+ fi;
+ elif [ "${ARG_RESTART}" = "ALL" ]; then
+ return 1; # Build
+ elif match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC}; then
+ if [ -n "${ARG_RESTART_AT}" ]; then
+ if [ "${ARG_RESTART_AT}" = "ALL" ]; then
+ return 1; # Build
+ elif match_list "${ARG_RESTART_AT}" , "${1}"; then
+ return 1; # Build
+ else
+ return 0; # Skip
+ fi;
+ else
+ return 1; # Build
+ fi;
+ elif [ -f ${WORKDIR}/.${2:-${BUILD_PACKAGE_LC}}.${1} ]; then
+ return 0; # Skip
+ else
+ return 1; # Build
+ fi;
+};
+
+log_env_vars() {
+ log_msg info "Variables for this ${1:-build}:"; shift;
+ while [ ${_lev_nvar:=0} -lt ${#} ]; do
+ _lev_arg="$(eval echo \${${_lev_nvar}})";
+ _lev_arg="${_lev_arg%%=*}";
+ if [ ${#_lev_arg} -gt ${_lev_arg_len_max:=0} ]; then
+ _lev_arg_len_max=${#_lev_arg};
+ fi; : $((_lev_nvar+=1));
+ done; unset _lev_nvar _lev_arg;
+ while [ ${#} -gt 0 ]; do
+ log_msg info "$(printf \
+ "%${_lev_arg_len_max}.${_lev_arg_len_max}s=%s" \
+ "${1%%=*}" "$(get_var_unsafe ${1#*=})")";
+ shift;
+ done; unset _lev_arg_len_max;
+};
+
+parse_with_pkg_name() {
+ PKG_NAME=${1}; shift;
+ _pwpn_pkg_name_uc=$(echo ${PKG_NAME} | tr a-z A-Z);
+ if [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URL)" ]\
+ && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URLS_GIT)" ]\
+ && [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_VERSION)" ]; then
+ unset _pwpn_pkg_name_uc;
+ log_msg failexit "Error: package \`${PKG_NAME}' missing in build.vars.";
+ else
+ for _pwpn_vname in ${PKG_BUILD_VARS}; do
+ if [ -n "$(get_var_unsafe DEFAULT_${_pwpn_vname})" ]; then
+ set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe DEFAULT_${_pwpn_vname})";
+ fi;
+ if [ -n "$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})" ]; then
+ set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})";
+ fi;
+ if [ "${BUILD}" = "debug" ] \
+ && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)" ]; then
+ set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)";
+ elif [ "${BUILD}" = "release" ] \
+ && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)" ]; then
+ set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)";
+ elif [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})" ]; then
+ set_var_unsafe PKG_${_pwpn_vname} "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})";
+ fi;
+ done; unset _pwpn_vname;
+ fi;
+ [ -z "${PKG_FNAME}" ] && PKG_FNAME=${PKG_URL##*/};
+ [ -z "${PKG_SUBDIR}" ] && PKG_SUBDIR=${PKG_FNAME%%.tar*};
+ [ -n "${PKG_ENV_VARS_EXTRA}" ] && set_env_vars_with_sep : "${PKG_ENV_VARS_EXTRA}";
+ for _pwpn_env_var in $(set); do
+ if [ "${_pwpn_env_var#PKG_${_pwpn_pkg_name_uc}}" != "${_pwpn_env_var}" ]; then
+ _pwpn_env_vars="${_pwpn_env_vars:+${_pwpn_env_vars} }${_pwpn_env_var%%=*}";
+ fi;
+ done;
+ if [ -n "${_pwpn_env_vars}" ]; then
+ log_env_vars "build" ${_pwpn_env_vars};
+ fi; unset _pwpn_pkg_name_uc _pwpn_env_var _pwpn_env_vars;
+};
+
+run_cmd_unsplit() {
+ _rcu_cmd=${1}; shift;
+ while [ ${#} -gt 0 ]; do
+ [ -n "${1}" ] &&\
+ _rcu_cmdline="${_rcu_cmdline:+${_rcu_cmdline}:}${1}";
+ shift;
+ done;
+ push_IFS :; ${_rcu_cmd} ${_rcu_cmdline}; _rcu_rc=$?; pop_IFS;
+ unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc};
+};
+
+set_build_script_done() {
+ _sbsd_script_fname=${BUILD_PACKAGE_LC};
+ _sbsd_done_fname=${WORKDIR}/.${_sbsd_script_fname};
+ while [ $# -ge 1 ]; do
+ if [ "${1#-}" != "${1}" ]; then
+ secure_rm ${_sbsd_done_fname}.${1#-};
+ else
+ touch ${_sbsd_done_fname}.${1};
+ log_msg info "Finished build step ${1} of \`${_sbsd_script_fname}'.";
+ fi; shift;
+ done; unset _sbsd_script_fname _sbsd_done_fname;
+};
+
+set_env_vars_with_sep() {
+ _sevws_sep=${1}; shift; push_IFS ${_sevws_sep}; set -- ${1};
+ while [ ${#} -gt 0 ]; do
+ export "${1}"; shift;
+ done; unset _sevws_sep; pop_IFS;
+};
+
# vim:filetype=sh