--- trunk/mage/usr/lib/mage/smage2.sh 2011/07/25 11:01:48 1435 +++ trunk/mage/usr/lib/mage/smage2.sh 2011/12/28 10:54:49 1578 @@ -1,50 +1,19 @@ #!/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 @@ -352,27 +321,31 @@ 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 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 return 0 } -# dummy function, used if that not exist in smage file +# dummy function, used if that does not exist in smage file +src_check() +{ + echo "no src_check defined" + return 0 +} + +# dummy function, used if that does not exist in smage file src_install() { echo "no src_install defined" - sleep 2 return 0 } @@ -582,16 +555,27 @@ { local stripdir="$@" - [ -z "${stripdir}" ] && stripdir=${BINDIR} - find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 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-unneeded 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}" + [[ -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 } mcompressdocs() @@ -834,7 +818,7 @@ regen_mage_tree() { - local i + local subpackage # build them only if requested if [[ ${REGEN_MAGE_TREE} = true ]] @@ -845,9 +829,9 @@ # build for each target a mage file # run it with several targets echo - for i in ${MAGE_TARGETS} + for subpackage in ${MAGE_TARGETS} do - build_mage_script --target "${i}" + build_mage_script --target "${subpackage}" done echo @@ -860,12 +844,16 @@ # build for each subpackage a mage file # run it with several targets echo - for i in ${SPLIT_PACKAGES} + for subpackage in ${SPLIT_PACKAGES} do # get the right variables for the split - export PNAME="${i}" - split_info_${i} + export PNAME="${subpackage}" + split_info_${subpackage} + # get the preinstall etc + split_export_inherits ${subpackage} build_mage_script --split-pkg-base "${split_pkg_base}" + # delete split preinstall etc + split_delete_inherits ${subpackage} # restore smage environment split_restore_variables done @@ -1051,6 +1039,37 @@ unset -f SAVED_postremove } +split_export_inherits() +{ + local subpackage="$1" + local func + local newfunc + + for func in preinstall postinstall preremove postremove + do + if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] + then + newfunc=$(typeset -f ${func}_${subpackage}) + newfunc="${newfunc/_${subpackage} (/ (}" + eval "${newfunc}" + fi + done +} + +split_delete_inherits() +{ + local subpackage="$1" + local func + + for func in preinstall postinstall preremove postremove + do + if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] + then + unset -f ${func} + fi + done + } + export_inherits() { local include="$1" @@ -1435,6 +1454,7 @@ # 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 @@ -1452,23 +1472,20 @@ # setup ccache [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment -# small sleep to show our settings -sleep 1 - -# cleans up build if a previously one exists +# 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 srcdir if a previously unpacked one exists +# clean up srcdir if a previously unpacked one exist if [ -d ${SRCDIR} ] then rm -rf ${SRCDIR} fi -# cleans up bindir if a previous build exists or creates a new one +# clean up bindir if a previous build exist or create a new one if [ -d ${BINDIR} ] then rm -rf ${BINDIR} @@ -1481,13 +1498,7 @@ rm -rf ${BUILDDIR}/${PKGNAME} fi -# cleans up timestamp if one exists -if [ -f /var/tmp/timestamp ] -then - mage rmstamp -fi - -# setup build loggins +# setup build logging [[ ! -d /var/log/smage ]] && install -d /var/log/smage echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log @@ -1499,6 +1510,17 @@ die_pipestatus 0 "src_compile failed" step_by_step $_ +# only run checks if requested +if [[ ${MAGE_CHECK} != true ]] +then + echo "MAGE_CHECK not requested; 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 @@ -1560,14 +1582,18 @@ do echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" mstripbins ${BINDIR}_${subpackage} - echo -e "${COLBLUE}===${COLGREEN} stripping libraries for '${subpackage}' ...${COLDEFAULT}" + 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} done else echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" mstripbins ${BINDIR} - echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" + echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}" mstriplibs ${BINDIR} + echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" + mstripstatic ${BINDIR} fi ;; esac @@ -1583,7 +1609,7 @@ 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