--- trunk/mage/usr/lib/mage/smage2.sh 2011/12/28 10:41:44 1573 +++ trunk/mage/usr/lib/mage/smage2.sh 2011/12/28 15:08:52 1589 @@ -10,10 +10,6 @@ # set default user mage.rc : ${MAGERC="/etc/mage.rc"} -## setup ## -SMAGENAME="$1" -SMAGEVERSION="$( < ${MLIBDIR}/version)" - # export default C locale export LC_ALL=C @@ -21,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 @@ -139,183 +139,60 @@ 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}" + mdownload --uri "${uri}" --dir "${outputdir}" || die "Could not download '${uri}'" - # 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 + # unset them to be sure + unset uri + unset subdir + unset outputdir + done + + # 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 @@ -325,7 +202,6 @@ src_prepare() { echo "no src_prepare defined" - sleep 2 return 0 } @@ -333,7 +209,13 @@ src_compile() { echo "no src_compile defined" - sleep 2 + return 0 +} + +# dummy function, used if that does not exist in smage file +src_check() +{ + echo "no src_check defined" return 0 } @@ -341,7 +223,6 @@ src_install() { echo "no src_install defined" - sleep 2 return 0 } @@ -528,6 +409,7 @@ minstalldocs() { local docfiles + local doc docfiles="$@" if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] @@ -535,14 +417,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}/${doc}.gz || die "gzipping +installing ${doc}." + chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/${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 } @@ -551,24 +436,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 file | 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() @@ -627,7 +544,6 @@ fi } - # fixes given dependencies to match a MAGE_TARGET # fix_mage_deps -target s/depend # <-- note -target ! fix_mage_deps() @@ -814,7 +730,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} ]] @@ -903,7 +819,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}" @@ -964,7 +894,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 + msetfeature "${SAVED_FEATURE_PKGBUILD}" + # strip + msetfeature "${SAVED_FEATURE_STRIP}" + # libtool + msetfeature "${SAVED_FEATURE_LIBTOOL}" + # compressdoc + msetfeature "${SAVED_FEATURE_COMPRESSDOC}" # bindir too export BINDIR="${SAVED_BINDIR}" @@ -1024,7 +964,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 @@ -1124,12 +1068,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}" @@ -1184,7 +1127,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" @@ -1204,6 +1147,9 @@ exit 1 fi +# load supported mage features +load_mage_features + # updating smage2-scripts if [[ $1 = update ]] then @@ -1388,7 +1334,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." @@ -1432,7 +1378,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 @@ -1442,11 +1388,12 @@ 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 @@ -1456,16 +1403,12 @@ 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 # clean up builddir if a previously one exist if [ -d ${BUILDDIR} ] @@ -1487,18 +1430,12 @@ fi install -d ${BINDIR} || die "couldn't create \$BINDIR." -# cleans up package temp dir if a previous build exists +# clean up package temp dir if a previous build exist if [ -d ${BUILDDIR}/${PKGNAME} ] then rm -rf ${BUILDDIR}/${PKGNAME} fi -# cleans up timestamp if one exists -if [ -f /var/tmp/timestamp ] -then - mage rmstamp -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 @@ -1511,6 +1448,17 @@ 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} + step_by_step src_check +else + src_check | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_check failed" + step_by_step $_ +fi + # build several subpackages if [[ -n ${SPLIT_PACKAGES} ]] then @@ -1548,24 +1496,57 @@ step_by_step $_ fi -# compressing doc, info & man files -if [[ -n ${SPLIT_PACKAGES} ]] +if mqueryfeature "!compressdoc" then - for subpackage in ${SPLIT_PACKAGES} - do - mcompressdocs ${BINDIR}_${subpackage} - done + echo -e "!compressdoc detected; documentation will not be compressed ..." else - mcompressdocs ${BINDIR} + # compressing doc, info & man files + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + mcompressdocs ${BINDIR}_${subpackage} + done + else + mcompressdocs ${BINDIR} + fi fi +if mqueryfeature "!libtool" +then + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}" + mstriplibtoolarchive ${BINDIR}_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}" + mstriplibtoolarchive ${BINDIR} + fi +fi + +if mqueryfeature "purge" +then + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}" + mpurgetargets ${BINDIR}_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}" + mpurgetargets ${BINDIR} + 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 "!strip" +then + echo -e "!strip detected; Package will not be stripped ..." +else if [[ -n ${SPLIT_PACKAGES} ]] then for subpackage in ${SPLIT_PACKAGES} @@ -1585,15 +1566,12 @@ echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" mstripstatic ${BINDIR} fi - ;; -esac +fi -# the new buildpkg command -case ${NOPKGBUILD} in - true|TRUE|yes|y) - echo -e "NOPGKBUILD=true detected; Package will not be build ..." - ;; - *) +if mqueryfeature "!buildpkg" +then + echo -e "!buildpkg detected; Package will not be build ..." +else # build several targets if [[ -n ${MAGE_TARGETS} ]] then @@ -1632,10 +1610,8 @@ 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 !buildpkg is set in split_info + mqueryfeature "!buildpkg" && continue # check if an special subpackage_pkgbuild exists if typeset -f ${PNAME}_pkgbuild > /dev/null @@ -1679,19 +1655,14 @@ fi # build src-pkg-tarball if requested - [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME} - ;; -esac + mqueryfeature "srcpkg" && source_pkg_build ${SMAGENAME} +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