diff options
Diffstat (limited to 'build.subr')
-rw-r--r-- | build.subr | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/build.subr b/build.subr new file mode 100644 index 00000000..e8a9fca1 --- /dev/null +++ b/build.subr @@ -0,0 +1,101 @@ +TIMESTAMP_FMT="${TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}"; + +date() { + command date +"${TIMESTAMP_FMT}"; +}; + +fetch() { + wget --no-check-certificate -N "${@}"; +}; + +fetch_git() { + local _subdir="${1}" _repo="${2}"; + if [ -d "${_subdir}" ]; then + (cd "${_subdir}" && git pull origin main); + else + git clone "${_repo}" "${_subdir}"; + fi; +}; + +is_build_script_done() { + local _op="${1}" _script_fname="${SCRIPT_FNAME##*/}"; + [ -f "${WORKDIR}/.${_script_fname%.build}.${_op}" ]; +}; +set_build_script_done() { + local _script_fname="${SCRIPT_FNAME##*/}" _done_fname; + _done_fname="${WORKDIR}/.${_script_fname%.build}"; + while [ $# -ge 1 ]; do + if [ "x${1#-}" != "x${1}" ]; then + rm -f "${_done_fname}.${1#-}"; + else + printf "" >| "${_done_fname}.${1}"; + log_msg info "Finished build step ${1} of build script \`${_script_fname}'."; + fi; shift; + done; +}; + +log_msg() { + local _lvl="${1}"; shift; + case "${_lvl}" in + fail) printf "\033[91m"; ;; + info) printf "\033[97m"; ;; + succ) printf "\033[92m"; ;; + esac; + if [ $# -gt 1 ]; then + printf "==> %s %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}" "$*"; + else + printf "==> %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}"; + fi; +}; + +parse_with_pkg_name() { + _pkg_name="${1}"; local _envvs _envv; shift; + while [ $# -ge 0 ]; do + _pkg_url="${1}"; _envvs="${2}"; _pkg_fname="${_pkg_url##*/}"; + if [ "x${_pkg_fname%%-*}" = "x${_pkg_name}" ]; then + IFS=:; for _envv in ${_envvs}; do + export ${_envv}; + done; + _pkg_subdir="${_pkg_fname%%.tar*}"; + return; + fi; shift 2; + done; exit 1; +}; + +rm_if_exists() { + while [ $# -gt 1 ]; do [ "x${1%[a-z]}" = "x-" ] &&\ + eval local _${1#-}flag=1; shift; done; + local _dir="${1}"; + if [ -d "${_dir}" ]; then + rm -rf "${_dir}" || return 1; + fi; + if [ ${_mflag:-0} -eq 1 ]; then + mkdir "${_dir}" || return 2; + fi; + if [ ${_cflag:-0} -eq 1 ]; then + cd "${_dir}" || return 3; + fi; +}; + +run_configure_with_extra_args() { + local IFS="," _script="${1}" _extra_args="${2}"; + shift 2; "${_script}" "${@}" ${_extra_args}; +}; + +set_build_dir() { + export _build_dir="${1}-build-${2}"; +}; + +set_env_vars() { + local _val="${1}"; shift; + while [ $# -ge 1 ]; do + export "${1}=${_val}"; shift; + done; +}; + +split() { + local _IFS="${IFS}" IFS="${1}" _txt="${2}"; + set -- ${_txt}; IFS="${_IFS}"; echo "${*}"; +}; + +# vim:filetype=sh |