--- trunk/mage/usr/lib/mage/smage2.sh 2011/12/20 16:06:13 1543 +++ trunk/mage/usr/lib/mage/smage2.sh 2012/01/13 13:20:22 1631 @@ -1,50 +1,15 @@ #!/bin/bash +# $Id$ # compiles/installs .smage2 source install scripts # needs pkgbuild_dir (mage) -# SMAGE2 -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.62 2007-11-28 10:47:50 niro Exp $ +# TODO: record dynlib, gz | xz database -#01.10.2004 -# added ccache support -# added distcc support # set default user mage.rc : ${MAGERC="/etc/mage.rc"} -## setup ## -PKGSUFFIX="mpk" -SRCPKGSUFFIX="mpks" -SMAGENAME="$1" -SMAGESUFFIX="smage2" -MLIBDIR=/usr/lib/mage -SMAGEVERSION="$( < ${MLIBDIR}/version)" - -## only for tests -> normally in /etc/rc.d/init.d/functions -COLRED="\033[1;6m\033[31m" -COLGREEN="\033[1;6m\033[32m" -COLYELLOW="\033[1;6m\033[33m" -COLBLUE="\033[1;6m\033[34m" -COLMAGENTA="\033[1;6m\033[35m" -COLWHITE="\033[1;6m\033[37m" -COLGRAY="\033[0;6m\033[37m" -COLBOLD="\033[1m" -COLDEFAULT="\033[0m" - -if [[ ${NOCOLORS} = true ]] -then - COLRED="" - COLGREEN="" - COLYELLOW="" - COLBLUE="" - COLMAGENTA="" - COLWHITE="" - COLGRAY="" - COLBOLD="" - COLDEFAULT="" -fi - # export default C locale export LC_ALL=C @@ -52,6 +17,10 @@ source ${MAGERC} source ${MLIBDIR}/mage4.functions.sh +## setup ## +SMAGENAME="$1" +SMAGEVERSION="$(< ${MLIBDIR}/version)" + # set PKGDIR and BUILDDIR and BINDIR to MROOT if [[ -n ${MROOT} ]] then @@ -170,209 +139,93 @@ download_sources() { - [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 - local EOA=${#SRC_URI[*]} - local my_SRC_URI - local my_SRC_URI_DEST - local my_SRC_URI_MIRROR - local my_SOURCEDIR - local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" - local FETCHING - local i mirror - local wget_opts - - # filter wget command if busybox was found - wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" - - # install SRCDIR/PNAME if not exist - [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} + local count=${#SRC_URI[*]} + local uri + local subdir + local outputdir + local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" + local fetching + local i # check if FETCHING is needed - ( cd ${SOURCEDIR}/${PNAME}; md5sum -c ${DB_MD5_SUM_FILE} &> /dev/null ) - if [[ $? = 0 ]] + if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 then # md5's ok, no fetching needed - FETCHING=false + fetching=false else - FETCHING=true + fetching=true fi - for ((i=0; i < EOA; i++)) - do - # url to file - my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" - - # subdir in sources dir; the my_SRCI_URI file goes to there - my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" - - # if my_src_uri_dest is not equal my_src_uri; than an other dir is used - if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] - then - my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}" - else - my_SOURCEDIR="${SOURCEDIR}/${PNAME}" - fi - - # create the SOURCEDIR - install -d ${my_SOURCEDIR} - - # if an mirrored file than replace first the mirror uri - if [[ -n $(echo ${my_SRC_URI} | grep 'mirror://') ]] - then - for mirror in ${MIRRORS} - do - my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")" - - if [[ ${FETCHING} = true ]] - then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \ - "${my_SRC_URI_MIRROR}" - if [[ $? = 0 ]] - then - break - else - continue - fi - fi - done - elif [[ -n $(echo ${my_SRC_URI} | grep 'sourceforge://') ]] - then - for mirror in ${SOURCEFORGE_MIRRORS} - do - my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|sourceforge:/|${mirror}|g")" - - if [[ ${FETCHING} = true ]] - then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \ - "${my_SRC_URI_MIRROR}" - if [[ $? = 0 ]] - then - break - else - continue - fi - fi - done - elif [[ -n $(echo ${my_SRC_URI} | grep 'gnu://') ]] - then - for mirror in ${GNU_MIRRORS} - do - my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnu:/|${mirror}|g")" - - if [[ ${FETCHING} = true ]] - then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \ - "${my_SRC_URI_MIRROR}" - if [[ $? = 0 ]] - then - break - else - continue - fi - fi - done - elif [[ -n $(echo ${my_SRC_URI} | grep 'kde://') ]] - then - for mirror in ${KDE_MIRRORS} - do - my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|kde:/|${mirror}|g")" + if [[ ${fetching} = true ]] + then + for ((i=0; i < count; i++)) + do + # url to file + uri="${SRC_URI[${i}]%%' '*}" - if [[ ${FETCHING} = true ]] - then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \ - "${my_SRC_URI_MIRROR}" - if [[ $? = 0 ]] - then - break - else - continue - fi - fi - done - elif [[ -n $(echo ${my_SRC_URI} | grep 'gnome://') ]] - then - for mirror in ${GNOME_MIRRORS} - do - my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnome:/|${mirror}|g")" + # subdir in sources dir; the my_SRCI_URI file goes to there + subdir="${SRC_URI[${i}]##*' '}" - if [[ ${FETCHING} = true ]] - then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \ - "${my_SRC_URI_MIRROR}" - if [[ $? = 0 ]] - then - break - else - continue - fi - fi - done - else - if [[ ${FETCHING} = true ]] + # if $subdir is not equal with $uri then an other dir is used + if [[ ${uri} != ${subdir} ]] then - echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI}${COLDEFAULT}" - wget \ - ${wget_opts} \ - --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI})" \ - "${my_SRC_URI}" + outputdir="${SOURCEDIR}/${PNAME}/${subdir}" + else + outputdir="${SOURCEDIR}/${PNAME}" fi - fi - # unset them to be shure - unset my_SRC_URI - unset my_SRC_URI_DEST - unset my_SRC_URI_MIRROR - unset my_SOURCEDIR - done + echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}" + # always use verbose mode for source downloads + FVERBOSE=off msetfeature "verbose" + # do not die here, mchecksum catches download errors + mdownload --uri "${uri}" --dir "${outputdir}" + + # unset them to be sure + unset uri + unset subdir + unset outputdir + done - # recheck md5 sums - echo - echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}" - ( cd ${SOURCEDIR}/${PNAME}; md5sum -c ${DB_MD5_SUM_FILE} ) || die "md5 failed" - echo + # recheck md5 sums after download + echo + echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}" + mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed" + echo + else + echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}" + fi # not needed anymore unset SRC_URI } -# dummy function, used if that not exist in smage file +# dummy function, used if that does not exist in smage file src_prepare() { - echo "no src_prepare defined" - sleep 2 + echo "no src_prepare defined; doing nothing ..." return 0 } -# dummy function, used if that not exist in smage file +# dummy function, used if that does not exist in smage file src_compile() { - echo "no src_compile defined" - sleep 2 + echo "no src_compile defined; doing nothing ..." + return 0 +} + +# dummy function, used if that does not exist in smage file +src_check() +{ + echo "no src_check defined; doing nothing ..." return 0 } -# dummy function, used if that not exist in smage file +# dummy function, used if that does not exist in smage file src_install() { - echo "no src_install defined" - sleep 2 + echo "no src_install defined; doing nothing ..." return 0 } @@ -386,6 +239,28 @@ mconfigure() { + local myopts + if [[ ! -z ${CTARGET} ]] + then + myopts+=" --target=${CTARGET}" + fi + # if requested disable-static + if [[ ! -z $(./configure --help | grep -- '--.*able-static') ]] + then + if mqueryfeature '!static' + then + myopts+=" --disable-static" + else + myopts+=" --enable-static" + fi + fi + + # always enable shared by default + if [[ ! -z $(./configure --help | grep -- '--.*able-shared') ]] + then + myopts+=" --enable-shared" + fi + if [ -x ./configure ] then ./configure \ @@ -398,6 +273,7 @@ --sysconfdir=/etc \ --localstatedir=/var/lib \ --libdir=/usr/$(mlibdir) \ + ${myopts} \ "$@" || die "mconfigure failed" else echo "configure is not an executable ..." @@ -493,7 +369,7 @@ rar) unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed." ;; - zip|xpi) + zip|xpi|jar) unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed." ;; rpm) @@ -559,6 +435,7 @@ minstalldocs() { local docfiles + local doc docfiles="$@" if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] @@ -566,14 +443,17 @@ install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." fi - local i - for i in ${docfiles} + for doc in ${docfiles} do - if [ -f ${i} ] + if [ -f ${doc} ] then - cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." - install -m 0644 ${SRCDIR}/${i}.gz \ - ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." + if mqueryfeature "compressdoc" + then + cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "gzipping +installing ${doc}." + chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "fixing permissions of ${doc}." + else + install -m 0644 ${SRCDIR}/${i} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}." + fi fi done } @@ -582,24 +462,56 @@ { local stripdir="$@" - [ -z "${stripdir}" ] && stripdir=${BINDIR} - find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip ${STRIP_DYN_LIB} 2> /dev/null + [[ -z ${stripdir} ]] && stripdir="${BINDIR}" + [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug" + find ${stripdir} ! -type d | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null } mstripbins() { local stripdir="$@" - [ -z "${stripdir}" ] && stripdir=${BINDIR} - find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip ${STRIP_DYN_BIN} 2> /dev/null + [[ -z ${stripdir} ]] && stripdir="${BINDIR}" + [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug" + find ${stripdir} ! -type d | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null } mstripstatic() { local stripdir="$@" - [ -z "${stripdir}" ] && stripdir=${BINDIR} - find ${stripdir} | xargs file | grep "ar archive" | cut -f 1 -d : | xargs strip ${STRIP_STATIC_LIB} 2> /dev/null + [[ -z ${stripdir} ]] && stripdir="${BINDIR}" + [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug" + find ${stripdir} ! -type d | xargs file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null +} + +mstriplibtoolarchive() +{ + local stripdir="$@" + + [[ -z ${stripdir} ]] && stripdir="${BINDIR}" + find ${stripdir} ! -type d -name \*.la | xargs | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null +} + +mpurgetargets() +{ + local stripdir="$@" + local target + + [[ -z ${stripdir} ]] && stripdir=${BINDIR} + # nothing to do in this case + [[ -z ${PURGE_TARGETS[*]} ]] && return + + for target in ${PURGE_TARGETS[*]} + do + # check if target is a regex pattern without any slashes + if [[ ${target} = ${target//\/} ]] + then + find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null + else + rm -f -- ${target} 2> /dev/null + fi + done } mcompressdocs() @@ -658,7 +570,6 @@ fi } - # fixes given dependencies to match a MAGE_TARGET # fix_mage_deps -target s/depend # <-- note -target ! fix_mage_deps() @@ -845,7 +756,7 @@ local subpackage # build them only if requested - if [[ ${REGEN_MAGE_TREE} = true ]] + if mqueryfeature regentree then # run it without targets if [[ -n ${MAGE_TARGETS} ]] @@ -908,7 +819,7 @@ unset STATE unset DESCRIPTION unset HOMEPAGE - unset PKGTYPE + # unset PKGTYPE <-- don't do that either; smage needs this var unset INHERITS unset DEPEND unset SDEPEND @@ -934,7 +845,21 @@ export SAVED_DEPEND="${DEPEND}" export SAVED_SDEPEND="${SDEPEND}" export SAVED_PROVIDE="${PROVIDE}" - export SAVED_NOPKGBUILD="${NOPKGBUILD}" + export SAVED_PKGTYPE="${PKGTYPE}" + + # special handling needed for mage features + # pkgbuild + mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild" + mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild" + # strip + mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip" + mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip" + # libtool + mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool" + mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool" + # compressdoc + mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc" + mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc" # bindir too export SAVED_BINDIR="${BINDIR}" @@ -995,7 +920,17 @@ export DEPEND="${SAVED_DEPEND}" export SDEPEND="${SAVED_SDEPEND}" export PROVIDE="${SAVED_PROVIDE}" - export NOPKGBUILD="${SAVED_NOPKGBUILD}" + export PKGTYPE="${SAVED_PKGTYPE}" + + # special handling needed for mage features + # pkgbuild + FVERBOSE=off msetfeature "${SAVED_FEATURE_PKGBUILD}" + # strip + FVERBOSE=off msetfeature "${SAVED_FEATURE_STRIP}" + # libtool + FVERBOSE=off msetfeature "${SAVED_FEATURE_LIBTOOL}" + # compressdoc + FVERBOSE=off msetfeature "${SAVED_FEATURE_COMPRESSDOC}" # bindir too export BINDIR="${SAVED_BINDIR}" @@ -1055,7 +990,11 @@ unset SAVED_SDEPEND unset SAVED_PROVIDE unset SAVED_BINDIR - unset SAVED_NOPKGBUILD + unset SAVED_PKGTYPE + unset SAVED_FEATURE_PKGBUILD + unset SAVED_FEATURE_STRIP + unset SAVED_FEATURE_LIBTOOL + unset SAVED_FEATURE_COMPRESSDOC unset SPLIT_PACKAGE_BASE unset -f SAVED_preinstall unset -f SAVED_postinstall @@ -1155,12 +1094,11 @@ # fix target as it may be empty ! [ -n "${target}" ] && target="-${target}" - # build pkgname pkgname="${pname}${target}-${pver}-${parch}-${pbuild}" # build pkg-md5-sum only if requested - if [[ ${REGEN_MAGE_TREE} = true ]] + if mqueryfeature regentree then echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}" @@ -1215,7 +1153,7 @@ step_by_step() { - if [[ ${STEP_BY_STEP} = true ]] + if mqueryfeature stepbystep then echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}" echo "Press [enter] to continue" @@ -1223,6 +1161,25 @@ fi } +resume_stamp() +{ + local step="$1" + [[ ! -d ${BUILDDIR}/.stamps ]] && install -d ${BUILDDIR}/.stamps + touch ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} +} + +run_resume() +{ + local step="$1" + + if mqueryfeature "resume" && [[ -f ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} ]] + then + echo -e "${COLMAGENTA}${step} already processed; doing nothing${COLDEFAULT}" + return 0 + else + return 1 + fi +} # print out our version showversion @@ -1235,6 +1192,9 @@ exit 1 fi +# load supported mage features +load_mage_features + # updating smage2-scripts if [[ $1 = update ]] then @@ -1419,7 +1379,7 @@ if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ] then SRCPKGTARBALL="${2}" - USE_SRC_PKG_TARBALL=true + msetfeature "srcpkgtarball" # abort if given file is not a source pkg [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file." @@ -1440,6 +1400,11 @@ [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}" fi +if [ "$1" == "--resume" -a -n "$2" ] +then + msetfeature "resume" + SMAGENAME="$2" +fi [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] && @@ -1463,7 +1428,7 @@ # auto regen mage tree if requested regen_mage_tree -if [[ ${CREATE_SRC_PKG_TARBALL} = true ]] +if mqueryfeature "srcpkg" then if [[ -d ${SOURCEDIR}/${PNAME} ]] then @@ -1473,182 +1438,285 @@ fi # download sources -[[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources +mqueryfeature "srcpkgtarball" || download_sources # fixes some issues with these functions export -f src_prepare || die "src_prepare export failed" export -f src_compile || die "src_compile export failed" +export -f src_check || die "src_check export failed" export -f src_install || die "src_install export failed" # fixes some compile issues export CHOST="${CHOST}" || die "CHOST export failed" export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" -export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" +if [[ -z ${CXXFLAGS} ]] +then + export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" +else + export CXXFLAGS="${CXXFLAGS}" || die "CXXFLAGS export failed" +fi +export LDFLAGS="${LDFLAGS}" || die "LDFLAGS export failed" export BINDIR="${BINDIR}" || die "BINDIR export failed" export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" - # setup distcc # setup for distcc goes *before* ccache, so ccache comes before distcc in path -[[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment +mqueryfeature "distcc" && setup_distcc_environment # setup ccache -[[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment - -# small sleep to show our settings -sleep 1 +mqueryfeature "ccache" && setup_ccache_environment -# cleans up build if a previously one exists -if [ -d ${BUILDDIR} ] +if mqueryfeature "resume" then - rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." -fi -install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." + echo -e "${COLMAGENTA}Resume requested; continuing previous build${COLDEFAULT}" -# cleans up srcdir if a previously unpacked one exists -if [ -d ${SRCDIR} ] -then - rm -rf ${SRCDIR} -fi + # setup build logging + [[ ! -d /var/log/smage ]] && install -d /var/log/smage + if [[ -f /var/log/smage/${PKGNAME}.log.bz2 ]] + then + bunzip2 -f /var/log/smage/${PKGNAME}.log.bz2 + fi + echo -e "### Resume started on $(date) ###\n" >> /var/log/smage/${PKGNAME}.log -# cleans up bindir if a previous build exists or creates a new one -if [ -d ${BINDIR} ] -then - rm -rf ${BINDIR} -fi -install -d ${BINDIR} || die "couldn't create \$BINDIR." +else + # clean up builddir if a previously one exist + if [ -d ${BUILDDIR} ] + then + rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." + fi + install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." -# cleans up package temp dir if a previous build exists -if [ -d ${BUILDDIR}/${PKGNAME} ] -then - rm -rf ${BUILDDIR}/${PKGNAME} + # clean up srcdir if a previously unpacked one exist + if [ -d ${SRCDIR} ] + then + rm -rf ${SRCDIR} + fi + + # clean up bindir if a previous build exist or create a new one + if [ -d ${BINDIR} ] + then + rm -rf ${BINDIR} + fi + install -d ${BINDIR} || die "couldn't create \$BINDIR." + + # clean up package temp dir if a previous build exist + if [ -d ${BUILDDIR}/${PKGNAME} ] + then + rm -rf ${BUILDDIR}/${PKGNAME} + fi + + # clean up stamps dir + if [ -d ${BUILDDIR}/.stamps ] + then + rm -rf ${BUILDDIR}/.stamps + fi + + # setup build logging + [[ ! -d /var/log/smage ]] && install -d /var/log/smage + echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log fi -# cleans up timestamp if one exists -if [ -f /var/tmp/timestamp ] +if [[ ${PKGTYPE} = virtual ]] then - mage rmstamp -fi + echo "virtual package detected; nothing will be build ..." + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" +else + ( run_resume src_prepare || src_prepare ) | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_prepare failed" + resume_stamp src_prepare + step_by_step src_prepare + + ( run_resume src_compile || src_compile ) | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_compile failed" + resume_stamp src_compile + step_by_step src_compile -# setup build loggins -[[ ! -d /var/log/smage ]] && install -d /var/log/smage -echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log - -src_prepare | ${SMAGE_LOG_CMD} -die_pipestatus 0 "src_prepare failed" -step_by_step $_ - -src_compile | ${SMAGE_LOG_CMD} -die_pipestatus 0 "src_compile failed" -step_by_step $_ + # only run checks if requested + if mqueryfeature "!check" + then + echo "!check detected; src_check() will not be run!" | ${SMAGE_LOG_CMD} + else + ( run_resume src_check || src_check ) | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_check failed" + resume_stamp src_check + fi + step_by_step src_check -# build several subpackages -if [[ -n ${SPLIT_PACKAGES} ]] -then - # save bindir & pname - split_save_variables - export SAVED_BINDIR="${BINDIR}" - for subpackage in ${SPLIT_PACKAGES} - do - if typeset -f src_install_${subpackage} > /dev/null - then - # export subpackage bindir - export BINDIR="${SAVED_BINDIR}_${subpackage}" - # export PNAME, several internal function and include - # rely on this variable - export PNAME="${subpackage}" + # build several subpackages + if [[ -n ${SPLIT_PACKAGES} ]] + then + # save bindir & pname + split_save_variables + export SAVED_BINDIR="${BINDIR}" + for subpackage in ${SPLIT_PACKAGES} + do + if typeset -f src_install_${subpackage} > /dev/null + then + # export subpackage bindir + export BINDIR="${SAVED_BINDIR}_${subpackage}" + # export PNAME, several internal function and include + # rely on this variable + export PNAME="${subpackage}" - echo - echo -en "${COLBLUE}*** ${COLDEFAULT}" - echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}" - echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}" - echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..." - - src_install_${subpackage} | ${SMAGE_LOG_CMD} - die_pipestatus 0 "src_install_${subpackage} failed" - step_by_step $_ - fi - done - # restore bindir & pname - split_restore_variables - # unset all saved smage variables - split_unset_variables -else - src_install | ${SMAGE_LOG_CMD} - die_pipestatus 0 "src_install failed" - step_by_step $_ + echo + echo -en "${COLBLUE}*** ${COLDEFAULT}" + echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}" + echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}" + echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..." + + ( run_resume src_install_${subpackage} || src_install_${subpackage} ) | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install_${subpackage} failed" + resume_stamp src_install_${subpackage} + step_by_step src_install_${subpackage} + fi + done + # restore bindir & pname + split_restore_variables + # unset all saved smage variables + split_unset_variables + else + ( run_resume src_install || src_install ) | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install failed" + resume_stamp src_install + step_by_step src_install + fi fi -# compressing doc, info & man files -if [[ -n ${SPLIT_PACKAGES} ]] +# echo for sake of good-looking +echo + +if mqueryfeature "!compressdoc" then - for subpackage in ${SPLIT_PACKAGES} - do - mcompressdocs ${BINDIR}_${subpackage} - done + echo -e "!compressdoc detected; documentation will not be compressed ..." +elif mqueryfeature "!pkgbuild" +then + echo "!pkgbuild detected; skipping documentation compression..." else - mcompressdocs ${BINDIR} + # compressing doc, info & man files + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + run_resume mcompressdoc_${subpackage} || mcompressdocs ${BINDIR}_${subpackage} + resume_stamp mcompressdoc_${subpackage} + done + else + run_resume mcompressdoc || mcompressdocs ${BINDIR} + resume_stamp mcompressdoc + fi fi +if mqueryfeature "!libtool" +then + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping libtool archive stripping ..." + else + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}" + run_resume mstriplibtoolarchive_${subpackage} || mstriplibtoolarchive ${BINDIR}_${subpackage} + resume_stamp mstriplibtoolarchive_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}" + run_resume mstriplibtoolarchive || mstriplibtoolarchive ${BINDIR} + resume_stamp mstriplibtoolarchive + fi + fi +fi -# stripping all bins and libs -case ${NOSTRIP} in - true|TRUE|yes|y) - echo -e "NOSTRIP=true detected; Package will not be stripped ..." - ;; - *) +if mqueryfeature "purge" +then + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping file purgation..." + else if [[ -n ${SPLIT_PACKAGES} ]] then for subpackage in ${SPLIT_PACKAGES} do - echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" - mstripbins ${BINDIR}_${subpackage} - echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}" - mstriplibs ${BINDIR}_${subpackage} - echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}" - mstripstatic ${BINDIR}_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}" + run_resume mpurgetargets_${subpackage} || mpurgetargets ${BINDIR}_${subpackage} + resume_stamp mpurgetargets_${subpackage} done else - echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" - mstripbins ${BINDIR} - echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}" - mstriplibs ${BINDIR} - echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" - mstripstatic ${BINDIR} + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}" + run_resume mpurgetargets || mpurgetargets ${BINDIR} + resume_stamp mpurgetargets fi - ;; -esac + fi +fi -# the new buildpkg command -case ${NOPKGBUILD} in - true|TRUE|yes|y) - echo -e "NOPGKBUILD=true detected; Package will not be build ..." - ;; - *) +# stripping all bins and libs +if mqueryfeature "!strip" +then + echo -e "!strip detected; Package will not be stripped ..." +elif mqueryfeature "!pkgbuild" +then + echo "!pkgbuild detected; skipping stripping of the package ..." +else + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" + run_resume mstripbins_${subpackage} || mstripbins ${BINDIR}_${subpackage} + resume_stamp mstripbins_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}" + run_resume mstriplibs_${subpackage} || mstriplibs ${BINDIR}_${subpackage} + resume_stamp mstriplibs_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}" + run_resume mstripstatic_${subpackage} || mstripstatic ${BINDIR}_${subpackage} + resume_stamp mstripstatic_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" + run_resume mstripbins || mstripbins ${BINDIR} + resume_stamp mstripbins + echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}" + run_resume mstriplibs || mstriplibs ${BINDIR} + resume_stamp mstriplibs + echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" + run_resume mstripstatic || mstripstatic ${BINDIR} + resume_stamp mstripstatic + fi +fi + +if mqueryfeature "!pkgbuild" +then + echo -e "!pkgbuild detected; Package will not be build ..." +else # build several targets if [[ -n ${MAGE_TARGETS} ]] then for target in ${MAGE_TARGETS} do - # check if an special target_pkgbuild exists + # check if a special target_pkgbuild exists if typeset -f ${target}_pkgbuild > /dev/null then # run it - ${target}_pkgbuild + run_resume ${target}_pkgbuild || ${target}_pkgbuild + resume_stamp ${target}_pkgbuild fi # now create the target package - ${MLIBDIR}/pkgbuild_dir.sh \ + run_resume pkg_builddir_${target} || ${MLIBDIR}/pkgbuild_dir.sh \ "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \ ${BINDIR} || die "target: ${target} package-build failed" + resume_stamp pkg_builddir_${target} # build pkg-md5-sum if requested - generate_package_md5sum \ + run_resume md5sum_${target} || generate_package_md5sum \ --pcat "${PCATEGORIE}" \ --pname "${PNAME}" \ --pver "${PVER}" \ --pbuild "${PBUILD}" \ --parch "${ARCH}" \ --target "${target}" + resume_stamp md5sum_${target} echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" done @@ -1663,29 +1731,30 @@ export PNAME="${subpackage}" split_info_${PNAME} - # jump to next one if NOPKGBUILD is set in split_info - case ${NOPKGBUILD} in - true|TRUE|yes|y) continue ;; - esac + # jump to next one if !pkgbuild is set in split_info + mqueryfeature "!pkgbuild" && continue # check if an special subpackage_pkgbuild exists if typeset -f ${PNAME}_pkgbuild > /dev/null then # run it - ${PNAME}_pkgbuild + run_resume ${PNAME}_pkgbuild || ${PNAME}_pkgbuild + resume_stamp ${PNAME}_pkgbuild fi # now create the target package - ${MLIBDIR}/pkgbuild_dir.sh \ + run_resume pkg_builddir_${PNAME} || ${MLIBDIR}/pkgbuild_dir.sh \ "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \ "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed" + resume_stamp pkg_builddir_${PNAME} # build pkg-md5-sum if requested - generate_package_md5sum \ + run_resume md5sum_${PNAME} || generate_package_md5sum \ --pcat "${PCATEGORIE}" \ --pname "${PNAME}" \ --pver "${PVER}" \ --pbuild "${PBUILD}" \ --parch "${ARCH}" + resume_stamp md5sum_${PNAME} echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" @@ -1696,33 +1765,34 @@ split_unset_variables else - ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" + run_resume pkg_builddir || ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" + resume_stamp pkg_builddir # build pkg-md5-sum if requested - generate_package_md5sum \ + run_resume md5sum || generate_package_md5sum \ --pcat "${PCATEGORIE}" \ --pname "${PNAME}" \ --pver "${PVER}" \ --pbuild "${PBUILD}" \ --parch "${ARCH}" + resume_stamp md5sum echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}" fi # build src-pkg-tarball if requested - [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME} - ;; -esac + if mqueryfeature "srcpkg" + then + run_resume srcpkgbuild || source_pkg_build ${SMAGENAME} + resume_stamp srcpkgbuild + fi +fi -if [[ ${SMAGE_BUILD_LOGGING} != false ]] +if mqueryfeature "buildlog" then bzip2 -9f /var/log/smage/${PKGNAME}.log else [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log fi -# for sure -unset NOPKGBUILD -unset NOSTRIP - xtitleclean