--- trunk/mage/usr/lib/mage/smage2.sh 2011/12/28 10:56:10 1579 +++ trunk/mage/usr/lib/mage/smage2.sh 2011/12/28 11:58:28 1580 @@ -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 @@ -578,6 +455,35 @@ 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() { local bindir="$@" @@ -1569,6 +1475,35 @@ mcompressdocs ${BINDIR} fi +if [[ ${SMAGE_STRIP_LIBTOOL} = true ]] +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 [[ ${SMAGE_PURGE} = true ]] +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