From d30b8f52983fb27ba26aa80e487a981215e17abf Mon Sep 17 00:00:00 2001 From: Lucio Andrés Illanes Albornoz (arab, vxp) Date: Feb 07 2016 00:37:32 +0000 Subject: - Replaced non-portable cp -a command lines w/ tar (1) invocations. - Provide CFLAGS for each build level and script consistently. - Create compressed distribution tarball at the end of a finished build. - Fix bug that prevented gzip and libz from being installed. - Followup to c497546f591a3cc128abda42d0026c46ffdd6c36. --- diff --git a/101.gmp.build b/101.gmp.build index 61e874d..91559e9 100644 --- a/101.gmp.build +++ b/101.gmp.build @@ -1,6 +1,4 @@ parse_with_pkg_name ${2} gmp mpfr mpc libelf binutils; -[ -n "${_pkg_CC}" ] && export CC="${_pkg_CC}"; -[ -n "${_pkg_CFLAGS}" ] && export CFLAGS="${_pkg_CFLAGS}"; if is_build_script_done finished; then exit 212; else @@ -16,7 +14,7 @@ if ! is_build_script_done patched; then patch -d ${_pkg_subdir} -p1 \ < portage/${_pkg_subdir}.midipix.patch; if [ ${_pkg_no_libtool_midipix:-0} -eq 0 ]; then - cp -a portage/libtool.midipix ${_pkg_subdir}/; + cp portage/libtool.midipix ${_pkg_subdir}/; fi; set_build_script_done patched -configured; fi; diff --git a/200.coreutils.build b/200.coreutils.build index 89f0317..cf445fb 100644 --- a/200.coreutils.build +++ b/200.coreutils.build @@ -1,4 +1,3 @@ -export CFLAGS="${CFLAGS_PACKAGES}"; parse_with_pkg_name ${2} \ coreutils diffutils findutils patch \ gawk bash make grep sed binutils; @@ -30,7 +29,7 @@ fi; if ! is_build_script_done configured; then rm_if_exists -m -c ${_build_dir}; [ ${_no_config_cache:-0} -eq 0 ] &&\ - cp -a ../portage/config.cache .; + cp ../portage/config.cache .; ../${_pkg_subdir}/configure \ ${_configure_args} --target=${TARGET}; set_build_script_done configured -built; diff --git a/207.libz.build b/207.libz.build index 4afb479..507018d 100644 --- a/207.libz.build +++ b/207.libz.build @@ -1,27 +1,18 @@ +parse_with_pkg_name ${2} libz gzip; if is_build_script_done finished; then exit 212; -elif [ "x${2}" = "xlibz" ]; then - _pkg_url=https://sortix.org/libz/release/libz-${PKG_LIBZ_VERSION}.tar.gz; - _pkg_fname=${_pkg_url##*/}; - _pkg_sha256sum=${PKG_LIBZ_SHA256SUM}; - _pkg_subdir=${2}-${PKG_LIBZ_VERSION}; -elif [ "x${2}" = "xgzip" ]; then - _pkg_url=https://ftp.gnu.org/gnu/gzip/gzip-${PKG_GZIP_VERSION}.tar.gz; - _pkg_fname=${_pkg_url##*/}; - _pkg_sha256sum=${PKG_GZIP_SHA256SUM}; - _pkg_subdir=${2}-${PKG_GZIP_VERSION}; +else + fetch ${_pkg_url} ${_pkg_sha256sum}; fi; -fetch ${_pkg_url} ${_pkg_sha256sum}; if ! is_build_script_done extracted; then rm_if_exists ${_pkg_fname%%.tar*}; tar -axf ${_pkg_fname}; - set_build_script_done extracted -patched; + set_build_script_done extracted -configured; fi; if ! is_build_script_done configured; then set_build_dir ${_pkg_fname%%-*} native; rm_if_exists -c -m ${_build_dir}; - cp -a ../portage/config.cache .; - CFLAGS="${CFLAGS_PACKAGES}" \ + cp ../portage/config.cache .; ../${_pkg_subdir}/configure \ --host=${HOST_NATIVE} \ --prefix= \ @@ -31,19 +22,19 @@ else cd ${_build_dir}; fi; if ! is_build_script_done built; then - if [ "x${3}" = "xlibz" ]; then + if [ "x${2}" = "xlibz" ]; then make -j18; - elif [ "x${3}" = "xgzip" ]; then + elif [ "x${2}" = "xgzip" ]; then make clean; - make CFLAGS="-g3 -O0 -I${PREFIX_NATIVE}/include" LDFLAGS=--sysroot=${PREFIX_NATIVE}; + make; fi; set_build_script_done built -installed; fi; if ! is_build_script_done installed; then - if [ "x${3}" = "xlibz" ]; then + if [ "x${2}" = "xlibz" ]; then make -j18 DESTDIR=${PREFIX_NATIVE} install; - elif [ "x${3}" = "xgzip" ]; then - cp -a gunzip gzip zcat ${PREFIX_NATIVE}/bin; + elif [ "x${2}" = "xgzip" ]; then + cp gunzip gzip zcat ${PREFIX_NATIVE}/bin; fi; set_build_script_done installed finished; fi; diff --git a/build.sh b/build.sh index 736222d..bfbbd1c 100755 --- a/build.sh +++ b/build.sh @@ -3,8 +3,9 @@ { unset AR ARFLAGS CC CFLAGS CXX CXXFLAGS LD LDFLAGS; . ./build.vars; . ./build.subr; +check_path_vars PREFIX PREFIX_NATIVE WORKDIR; check_prereqs git make openssl sed tar tr wget; -log_msg info "Build started by ${USER}@$(hostname)."; +log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE:=$(date %Y-%m-%d-%H-%M-%S)}."; #trap (set -o errexit; mkdir -p ${PREFIX} ${WORKDIR}); BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${_nbuild:=0}}}; @@ -20,6 +21,7 @@ for BUILD_LVL in 0 1 2; do log_msg info "Invoking build script \`${BUILD_SCRIPT_FNAME}'"; (set -o errexit -- $(split . ${BUILD_SCRIPT_FNAME%.build}); \ SCRIPT_FNAME=${BUILD_SCRIPT_FNAME}; _pwd=$(pwd); \ + export CFLAGS="$(eval echo \${CFLAGS_LVL${BUILD_LVL}})"; \ cd ${WORKDIR}; . ${_pwd}/build.subr; \ . ${_pwd}/${BUILD_SCRIPT_FNAME}); case ${BUILD_SCRIPT_RC:=${?}} in @@ -37,6 +39,28 @@ for BUILD_LVL in 0 1 2; do fi; done; log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL} failed builds in ${_nbuild} build script(s)."; +if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\ +&& [ ${BUILD_NFAIL} -eq 0 ]; then + log_msg info "Building distribution tarball."; + (cd ${PREFIX}; + DISTRIB_FNAME=midipix.${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE}.tar.bz2; + rm_if_exists -m ${PREFIX_NATIVE##*/}/lib.bak; rm_if_exists ${DISTRIB_FNAME}; + tar -C ${PREFIX_NATIVE##*/}/lib -cpf - . |\ + tar -C ${PREFIX_NATIVE##*/}/lib.bak -xpf -; + (cd native/lib && + find . -maxdepth 1 -type l \ + -exec sh -c 'dest=$(readlink -- "$0") && rm -- "$0" && ln -- "$dest" "$0"' {} \;); + wait; + find . -maxdepth 2 -type d \ + -not -path . \ + -not -path ./${WORKDIR##*/} \ + -not -path ./${WORKDIR##*/}/\* \ + -not -path ./${PREFIX_NATIVE##*/} \ + -not -path ./${PREFIX_NATIVE##*/}/lib.bak |\ + tar -T - -cpf - | bzip2 -9c - > ${DISTRIB_FNAME} + rm -rf ${PREFIX_NATIVE##*/}/lib; + mv ${PREFIX_NATIVE##*/}/lib.bak ${PREFIX_NATIVE##*/}/lib); +fi; exit ${BUILD_SCRIPT_RC}; } 2>&1 | tee build.log; diff --git a/build.subr b/build.subr index b497c1c..26b62b7 100644 --- a/build.subr +++ b/build.subr @@ -4,17 +4,31 @@ TIMESTAMP_FMT="${TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}"; +check_path_vars() { + while [ $# -gt 0 ]; do + if [ -z "${_val:=$(eval echo \${${1}})}" ]; then + log_msg fail "Error: variable \`${1}' is empty or unset."; + exit 1; + elif [ "x${_val#* }" != "x${_val}" ]; then + log_msg fail "Error: variable \`${1}' contains one or more whitespace characters."; + exit 1; + else + shift; + fi; + done; unset _val; +}; + check_prereqs() { for _cmd in "$@"; do if ! command -v ${_cmd} >/dev/null; then - log_msg fail "Error: missing prerequisite command \`${_cmd}"; + log_msg fail "Error: missing prerequisite command \`${_cmd}."; exit 1; fi; done; unset _cmd; }; date() { - command date +"${TIMESTAMP_FMT}"; + command date +"${1:-${TIMESTAMP_FMT}}"; }; fetch() { @@ -71,9 +85,9 @@ log_msg() { succ) printf "\033[${LOG_MSG_SUCC_COLOUR}m"; ;; esac; if [ $# -gt 1 ]; then - printf "==> %s %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}" "$*"; + printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*"; else - printf "==> %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}"; + printf "==> %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}"; fi; unset _lvl; }; @@ -83,16 +97,18 @@ parse_with_pkg_name() { while [ $# -ge 0 ]; do if [ "x${_pkg_name}" = "x${1}" ]; then _pkg_NAME=$(echo "${_pkg_name}" | tr a-z A-Z); - eval _pkg_configure_extra_args=\"\${PKG_${_pkg_NAME}_CONFIGURE_EXTRA_ARGS}\"\ - _pkg_no_libtool_midipix=\${PKG_${_pkg_NAME}_NO_LIBTOOL_MIDIPIX}\ - _pkg_prefix=\${PKG_${_pkg_NAME}_PREFIX}\ - _pkg_prefix_extra=\${PKG_${_pkg_NAME}_PREFIX_EXTRA}\ - _pkg_sha256sum=\${PKG_${_pkg_NAME}_SHA256SUM}\ - _pkg_url=\${PKG_${_pkg_NAME}_URL}\ - _pkg_version=\${PKG_${_pkg_NAME}_VERSION}\ - _pkg_CC=\${PKG_${_pkg_NAME}_CC}\ - _pkg_CFLAGS=\${PKG_${_pkg_NAME}_CFLAGS}\ - _pkg_DESTDIR=\${PKG_${_pkg_NAME}_DESTDIR}; + for _vname in \ + configure_extra_args no_libtool_midipix \ + prefix prefix_extra sha256sum url version \ + CC CFLAGS LDFLAGS DESTDIR; do + _vNAME=$(echo "${_vname}" | tr a-z A-Z); + if [ -n "${_vval:=$(eval echo \${PKG_${_pkg_NAME}_${_vNAME}})}" ]; then + export _pkg_${_vname}="${_vval}"; + if [ "x${_vname#[A-Z]}" != "x${_vname}" ]; then + export ${_vname}="${_vval}"; + fi; + fi; unset _vval; + done; unset _pkg_NAME _vname _vNAME; _pkg_fname=${_pkg_url##*/}; _pkg_subdir=${_pkg_fname%%.tar*}; return 0; diff --git a/build.vars b/build.vars index 5f48797..e573944 100644 --- a/build.vars +++ b/build.vars @@ -3,9 +3,15 @@ # characters in any of the variables below save for MAKEFLAGS, # PATH, and TIMESTAMP_FMT. # +# $PREFIX_{NATIVE,TARGET} and $WORKDIR must be immediately +# beneath $PREFIX. $PREFIX must be o+rwx. The variables mentioned +# should not be forward slash-terminated. +# : ${ARCH:=nt64}; -: ${CFLAGS_PACKAGES:=-g3 -O0}; +: ${CFLAGS_LVL0:=-O0}; +: ${CFLAGS_LVL1:=-g3 -O0}; +: ${CFLAGS_LVL2:=-g3 -O0}; : ${GITROOT:=git://midipix.org}; : ${HOST_NATIVE:=x86_64-nt64-midipix}; : ${LOG_MSG_FAIL_COLOUR:=91}; @@ -24,18 +30,17 @@ TIMESTAMP_FMT="%Y/%m/%d %H:%M:%S"; : ${PKG_BASH_SHA256SUM:=afc687a28e0e24dc21b988fa159ff9dbcf6b7caa92ade8645cc6d5605cd024d4}; : ${PKG_BASH_VERSION:=4.3}; : ${PKG_BASH_URL:=https://ftp.gnu.org/gnu/bash/bash-${PKG_BASH_VERSION}.tar.gz}; +: ${PKG_BINUTILS_CONFIGURE_EXTRA_ARGS:=--with-libelf=${PREFIX_NATIVE} --with-gmp=${PREFIX_NATIVE} --with-mpc=${PREFIX_NATIVE} --with-mpfr=${PREFIX_NATIVE} --with-sysroot=/}; : ${PKG_BINUTILS_SHA256SUM:=250d3b2925c6b211fb16173b0b25bc091c58829fbcad3eb849645e0af52cf7fa}; : ${PKG_BINUTILS_VERSION:=2.24.51}; : ${PKG_BINUTILS_URL:=ftp://sourceware.org/pub/binutils/snapshots/binutils-${PKG_BINUTILS_VERSION}.tar.bz2}; -: ${PKG_CBB_CONFIGURE_EXTRA_ARGS:=--with-libelf=${PREFIX_NATIVE} --with-gmp=${PREFIX_NATIVE} --with-mpc=${PREFIX_NATIVE} --with-mpfr=${PREFIX_NATIVE} --with-sysroot=/}; -: ${PKG_CBB_VERSION:=cbb-gcc-4.6.4}; : ${PKG_COREUTILS_SHA256SUM:=ec43ca5bcfc62242accb46b7f121f6b684ee21ecd7d075059bf650ff9e37b82d}; : ${PKG_COREUTILS_VERSION:=8.23}; : ${PKG_COREUTILS_URL:=https://ftp.gnu.org/gnu/coreutils/coreutils-${PKG_COREUTILS_VERSION}.tar.xz}; : ${PKG_DIFFUTILS_SHA256SUM:=a25e89a8ab65fded1731e4186be1bb25cda967834b6df973599cdcd5abdfc19c}; : ${PKG_DIFFUTILS_VERSION:=3.3}; : ${PKG_DIFFUTILS_URL:=https://ftp.gnu.org/gnu/diffutils/diffutils-${PKG_DIFFUTILS_VERSION}.tar.xz}; -: ${PKG_FINDUTILS_CFLAGS:="${CFLAGS:+${CFLAGS} }-Dendpwent=setpwent"}; +: ${PKG_FINDUTILS_CFLAGS:=-Dendpwent=setpwent}; : ${PKG_FINDUTILS_SHA256SUM:=0de3cf625a5c9f154eee3171e072515ffdde405244dd00502af617ac57b73ae2}; : ${PKG_FINDUTILS_VERSION:=4.5.14}; : ${PKG_FINDUTILS_URL:=http://alpha.gnu.org/gnu/findutils/findutils-${PKG_FINDUTILS_VERSION}.tar.gz}; @@ -51,6 +56,9 @@ TIMESTAMP_FMT="%Y/%m/%d %H:%M:%S"; : ${PKG_GREP_SHA256SUM:=ca91d22f017bfcb503d4bc3b44295491c89a33a3df0c3d8b8614f2d3831836eb}; : ${PKG_GREP_VERSION:=2.22}; : ${PKG_GREP_URL:=https://ftp.gnu.org/gnu/grep/grep-${PKG_GREP_VERSION}.tar.xz}; +: ${PKG_GZIP_CC:=${HOST_NATIVE}-gcc}; +: ${PKG_GZIP_CFLAGS:="-g3 -O0 -I${PREFIX_NATIVE}/include"}; +: ${PKG_GZIP_LDFLAGS:=--sysroot=${PREFIX_NATIVE}}; : ${PKG_GZIP_SHA256SUM:=1ca41818a23c9c59ef1d5e1d00c0d5eaa2285d931c0fb059637d7c0cc02ad967}; : ${PKG_GZIP_VERSION:=1.2.4}; : ${PKG_GZIP_URL:=https://ftp.gnu.org/gnu/gzip/gzip-${PKG_GZIP_VERSION}.tar.gz};