--- trunk/mage/usr/lib/mage/smage2.sh 2009/11/20 21:53:33 942 +++ trunk/mage/usr/lib/mage/smage2.sh 2009/11/20 22:39:11 943 @@ -75,10 +75,15 @@ die_pipestatus() { - local pos="$1" - local comment="$2" - - [ ${PIPESTATUS[${pos}]} -gt 0 ] && die "${comment}" + # the status change if we do any parameter declarations!! + # dont do this anymore, keep this in mind! + # + # local pos="$1" + # local comment="$2" + # + # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}" + # + [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2" } xtitle() @@ -549,6 +554,23 @@ find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null } +mcompressdocs() +{ + local bindir="$@" + + if [ -d ${bindir}/usr/share/man ] + then + echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" + ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man + fi + + if [ -d ${bindir}/usr/share/info ] + then + echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" + ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info + fi +} + sminclude() { local i @@ -664,6 +686,9 @@ # INHERITS which functions get included # SPECIAL_FUNCTIONS special functions which should also be added # warning: they get killed before the build starts ! +# SPLIT_PACKAGES names of all subpackages which are splitted from parent +# SPLIT_PACKAGE_BASE base package name for splitpackages +# (only in the resulting magefile} # # MAGE_TREE_DEST target destination of the generated tree # REGEN_MAGE_TREE set to 'true' to enable this @@ -674,6 +699,7 @@ local magefile local dest local target + local split_pkg_base local sym local depname @@ -681,7 +707,10 @@ : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} # determinate which suffix this mage file should get, if any - [ -n "$1" ] && target="-$1" + [[ $1 = --target ]] && shift && target="-$1" + + # mark package as splitpackage + [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1" # name of magefile magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" @@ -718,6 +747,10 @@ echo "MAGE_TARGETS=\"${target}\"" >> ${dest} echo >> ${dest} + # split package base + echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest} + echo >> ${dest} + # add special vars if [ -n "${SPECIAL_VARS}" ] then @@ -785,21 +818,41 @@ if [[ ${REGEN_MAGE_TREE} = true ]] then # run it without targets - if [ -z "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then + # build for each target a mage file + # run it with several targets echo - build_mage_script + for i in ${MAGE_TARGETS} + do + build_mage_script --target "${i}" + done echo - else - # build for each target an mage file + # run it for splitpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + local split_pkg_base="${PNAME}" + # save smage environment + split_save_variables + # build for each subpackage a mage file # run it with several targets - for i in ${MAGE_TARGETS} + echo + for i in ${SPLIT_PACKAGES} do - echo - build_mage_script "${i}" - echo + # get the right variables for the split + export PNAME="${i}" + split_info_${i} + build_mage_script --split-pkg-base "${split_pkg_base}" done + echo + # restore smage environment + split_restore_variables + + else + echo + build_mage_script + echo fi fi @@ -830,6 +883,133 @@ unset postremove } +split_save_variables() +{ + export SAVED_PNAME="${PNAME}" + export SAVED_PVER="${PVER}" + export SAVED_PBUILD="${PBUILD}" + export SAVED_PCATEGORIE="${PCATEGORIE}" + export SAVED_DESCRIPTION="${DESCRIPTION}" + export SAVED_HOMEPAGE="${HOMEPAGE}" + export SAVED_SPECIAL_VARS="${SPECIAL_VARS}" + export SAVED_STATE="${STATE}" + export SAVED_PKGTYPE="${PKGTYPE}" + export SAVED_INHERITS="${INHERITS}" + export SAVED_DEPEND="${DEPEND}" + export SAVED_SDEPEND="${SDEPEND}" + export SAVED_PROVIDE="${PROVIDE}" + + # functions + if [[ ! -z $(typeset -f preinstall) ]] + then + # rename the old one + local saved_preinstall + saved_preinstall=SAVED_$(typeset -f preinstall) + eval "${saved_preinstall}" + export -f SAVED_preinstall + fi + + if [[ ! -z $(typeset -f postinstall) ]] + then + # rename the old one + local saved_postinstall + saved_postinstall=SAVED_$(typeset -f postinstall) + eval "${saved_postinstall}" + export -f SAVED_postinstall + fi + + if [[ ! -z $(typeset -f preremove) ]] + then + # rename the old one + local saved_preremove + saved_preremove=SAVED_$(typeset -f preremove) + eval "${saved_preremove}" + export -f SAVED_preremove + fi + + if [[ ! -z $(typeset -f postremove) ]] + then + # rename the old one + local saved_postremove + saved_postremove=SAVED_$(typeset -f postremove) + eval "${saved_postremove}" + export -f SAVED_postremove + fi +} + +split_restore_variables() +{ + export PNAME="${SAVED_PNAME}" + export PVER="${SAVED_PVER}" + export PBUILD="${SAVED_PBUILD}" + export PCATEGORIE="${SAVED_PCATEGORIE}" + export DESCRIPTION="${SAVED_DESCRIPTION}" + export HOMEPAGE="${SAVED_HOMEPAGE}" + export SPECIAL_VARS="${SAVED_SPECIAL_VARS}" + export STATE="${SAVED_STATE}" + export PKGTYPE="${SAVED_PKGTYPE}" + export INHERITS="${SAVED_INHERITS}" + export DEPEND="${SAVED_DEPEND}" + export SDEPEND="${SAVED_SDEPEND}" + export PROVIDE="${SAVED_PROVIDE}" + + # functions + if [[ ! -z $(typeset -f SAVED_preinstall) ]] + then + # rename the old one + local saved_preinstall + saved_preinstall=$(typeset -f SAVED_preinstall) + eval "${saved_preinstall/SAVED_/}" + export -f preinstall + fi + + if [[ ! -z $(typeset -f SAVED_postinstall) ]] + then + # rename the old one + local saved_postinstall + saved_postinstall=$(typeset -f SAVED_postinstall) + eval "${saved_postinstall/SAVED_/}" + export -f postinstall + fi + + if [[ ! -z $(typeset -f SAVED_preremove) ]] + then + # rename the old one + local saved_preremove + saved_preremove=$(typeset -f SAVED_preremove) + eval "${saved_preremove/SAVED_/}" + export -f preremove + fi + + if [[ ! -z $(typeset -f SAVED_postremove) ]] + then + # rename the old one + local saved_postremove + saved_postremove=$(typeset -f SAVED_postremove) + eval "${saved_postremove/SAVED_/}" + export -f postremove + fi + + # unset saved vars; not needed anymore + unset SAVED_PNAME + unset SAVED_PVER + unset SAVED_PBUILD + unset SAVED_PCATEGORIE + unset SAVED_DESCRIPTION + unset SAVED_HOMEPAGE + unset SAVED_SPECIAL_VARS + unset SAVED_STATE + unset SAVED_PKGTYPE + unset SAVED_INHERITS + unset SAVED_DEPEND + unset SAVED_SDEPEND + unset SAVED_PROVIDE + unset -f SAVED_preinstall + unset -f SAVED_postinstall + unset -f SAVED_preremove + unset -f SAVED_postremove +} + export_inherits() { local include="$1" @@ -1080,7 +1260,7 @@ regen_mage_tree # build several targets - if [ -n "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then for target in ${MAGE_TARGETS} do @@ -1093,6 +1273,26 @@ --parch "${ARCH}" \ --target "${target}" done + + # build several subpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + split_save_variables + for subpackage in ${SPLIT_PACKAGE} + do + # get the right variables for the split + export PNAME="${subpackage}" + split_info_${subpackage} + # build md5sum for existing packages + generate_package_md5sum \ + --pcat "${PCATEGORIE}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + done + split_restore_variables + else # build md5sum for existing packages generate_package_md5sum \ @@ -1100,8 +1300,7 @@ --pname "${PNAME}" \ --pver "${PVER}" \ --pbuild "${PBUILD}" \ - --parch "${ARCH}" \ - --target "${target}" + --parch "${ARCH}" fi exit 0 @@ -1254,23 +1453,44 @@ die_pipestatus 0 "src_compile failed" step_by_step $_ -src_install | ${SMAGE_LOG_CMD} -die_pipestatus 0 "src_install failed" -step_by_step $_ +# build several subpackages +if [[ -n ${SPLIT_PACKAGES} ]] +then + # save bindir + 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}" + src_install_${subpackage} | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install_${subpackage} failed" + step_by_step $_ + fi + done + # restore bindir + export BINDIR="${SAVED_BINDIR}" + unset SAVED_BINDIR +else + src_install | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install failed" + step_by_step $_ +fi +echo -e "${COLGREEN}DEB${COLRED}UG!${COLDEFAULT}" # compressing doc, info & man files -if [ -d ${BUILDDIR}/builded/usr/share/man ] +if [[ -n ${SPLIT_PACKAGES} ]] then - echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man + for subpackage in ${SPLIT_PACKAGE} + do + mcompressdocs ${BINDIR}_${subpackage} + done +else + mcompressdocs ${BINDIR} fi -if [ -d ${BUILDDIR}/builded/usr/share/info ] -then - echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info -fi # stripping all bins and libs case ${NOSTRIP} in @@ -1278,10 +1498,21 @@ echo -e "NOSTRIP=true detected; Package will not be stripped ..." ;; *) - echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" - mstripbins ${BINDIR} - echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" - mstriplibs ${BINDIR} + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGE} + do + echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" + mstripbins ${BINDIR}_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" + mstriplibs ${BINDIR}_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" + mstripbins ${BINDIR} + echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" + mstriplibs ${BINDIR} + fi ;; esac @@ -1292,7 +1523,7 @@ ;; *) # build several targets - if [ -n "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then for target in ${MAGE_TARGETS} do @@ -1318,6 +1549,40 @@ echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" done + + # build several subpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # get the right variables for the split + export PNAME="${subpackage}" + split_info_${PNAME} + + # check if an special subpackage_pkgbuild exists + if typeset -f ${PNAME}_pkgbuild > /dev/null + then + # run it + ${PNAME}_pkgbuild + fi + # now create the target package + ${MLIBDIR}/pkgbuild_dir.sh \ + "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \ + "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed" + + # build pkg-md5-sum if requested + generate_package_md5sum \ + --pcat "${PCATEGORIE}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + + echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" + done + split_restore_variables + else ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"