--- trunk/mage/usr/lib/mage/smage2.sh 2005/08/22 00:07:32 204 +++ trunk/mage/usr/lib/mage/smage2.sh 2014/01/06 12:56:50 2365 @@ -1,658 +1,54 @@ #!/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.34 2005-08-22 00:07:32 niro Exp $ +# TODO: record dynlib, gz | xz database -#01.10.2004 -# added ccache support -# added distcc support -## setup ## -PKGSUFFIX="mpk" -SMAGENAME="$1" -SMAGESUFFIX="smage2" -#SOURCEDIR="/bootstrap/sources" -#SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" -#SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" -MLIBDIR=/usr/lib/mage -SMAGEVERSION="$( < ${MLIBDIR}/version)" +# set default user mage.rc +: ${MAGERC="/etc/mage.rc"} # export default C locale export LC_ALL=C -source /etc/mage.rc - -showversion() { - echo -en "Magellan Source Install v${SMAGEVERSION} " - echo -e "-- Niels Rogalla (niro@magellan-linux.de)" -} - -die() { - xtitleclean - echo "SMAGE failed: $@" - exit 1 -} - -xtitle() { - if [ ${TERM} == "xterm" ] - then - echo -ne "\033]0;[sMage: $@]\007" - fi - return 0 -} - -xtitleclean() { - if [ ${TERM} == "xterm" ] - then - echo -ne "\033]0;\007" - fi - return 0 -} - -syncsmage2() { - xtitle "Updating smage2-script tree ..." - local i - for i in ${SMAGE2RSYNC} - do - rsync \ - --recursive \ - --links \ - --perms \ - --times \ - --devices \ - --timeout=600 \ - --verbose \ - --compress \ - --progress \ - --stats \ - --delete \ - --delete-after \ - ${i} ${SMAGESCRIPTSDIR} - - if [ "$?" == "0" ] - then - break - else - continue - fi - - done - - #clean up backup files (foo~) - find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' - - xtitleclean -} - -# $1 filename -get_db_md5_sum() { - local DB_FILE - local MD5_FILE - local i - - DB_ENTRY="$(basename $1)" - MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" - - i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" - - echo "${i}" -} - -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 - - - #install SRCDIR/PNAME if not exist - [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} - - # check if FETCHING is needed - ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null ) - if [[ $? == 0 ]] - then - # md5's ok, not fetching needed - FETCHING=false - else - 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 - - # 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")" +source /etc/mage.rc.global +source ${MAGERC} +source ${MLIBDIR}/mage4.functions.sh +source ${MLIBDIR}/smage2.functions.sh - #echo "DEBUG: ${MY_SRC_URI}" - if [[ ${FETCHING} == true ]] - then - echo "==> fetching ${my_SRC_URI_MIRROR}" - wget \ - --passive-ftp \ - --tries 3 \ - --continue \ - --progress bar \ - --directory-prefix="${my_SOURCEDIR}" \ - "${my_SRC_URI_MIRROR}" - if [ "$?" == "0" ] - then - break - else - continue - fi - fi - done - else - #echo "DEBUG: ${SRC_URI[${i}]}" - if [[ ${FETCHING} == true ]] - then - echo "==> fetching ${my_SRC_URI}" - wget \ - --passive-ftp \ - --tries 3 \ - --continue \ - --progress bar \ - --directory-prefix="${my_SOURCEDIR}" \ - "${my_SRC_URI}" -# only needed to run through a list of mirrors -# if [ "$?" == "0" ] -# then -# break -# else -# continue -# fi - 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 +# export default path +export PATH="${PATH}:${MLIBDIR}" - # recheck md5 sums - echo - echo ">== Checking MD5 sums:" - ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed" - echo - - # not needed anymore - unset SRC_URI -} - -# dummy function, used if that 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 -src_compile() { - echo "no src_compile defined" - sleep 2 - return 0 -} - -# dummy function, used if that not exist in smage file -src_install() { - echo "no src_install defined" - sleep 2 - return 0 -} - -mconfigure() { - if [ -x ./configure ] - then - ./configure \ - --prefix=/usr \ - --host=${CHOST} \ - --mandir=/usr/share/man \ - --infodir=/usr/share/info \ - --datadir=/usr/share \ - --sysconfdir=/etc \ - --localstatedir=/var/lib \ - "$@" || die "mconfigure failed" - else - echo "configure is not an executable ..." - exit 1 - fi -} - -minstall() { - if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then - make prefix=${BINDIR}/usr \ - datadir=${BINDIR}/usr/share \ - infodir=${BINDIR}/usr/share/info \ - localstatedir=${BINDIR}/var/lib \ - mandir=${BINDIR}/usr/share/man \ - sysconfdir=${BINDIR}/etc \ - "$@" install || die "minstall failed" - else - die "no Makefile found" - fi -} - -mmake() { - make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" -} - -munpack() { - local SRCFILE - local IFTAR - local DEST - - SRCFILE=$1 - - if [ -z "$2" ] - then - DEST=${BUILDDIR} - else - DEST=$2 - fi - - case "${SRCFILE##*.}" in - bz2) - IFTAR="$(basename $SRCFILE .bz2)" - IFTAR="${IFTAR##*.}" - if [ "${IFTAR}" == "tar" ] - then - tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} - fi - ;; - gz) - IFTAR="$(basename $SRCFILE .gz)" - IFTAR="${IFTAR##*.}" - if [ "${IFTAR}" == "tar" ] - then - tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} - fi - ;; - tbz2) - tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} - ;; - tgz) - tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} - ;; - *) - die "munpack failed" - ;; - esac -} - -mpatch() { - local PATCHOPTS - local PATCHFILE - - PATCHOPTS=$1 - PATCHFILE=$2 - - patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} -} - - -minstalldocs() { - local docfiles - - docfiles="$@" - - if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] - then - install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." - fi - - for i in ${docfiles} - do - cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." - install -m 0644 ${SRCDIR}/${i}.gz \ - ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." - done -} - -mstriplibs() { - 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 -} - -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 -} - -sminclude() { - local i - - if [[ -n "$@" ]] - then - for i in $@ - do - echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" - source ${SMAGESCRIPTSDIR}/include/${i}.sminc - done - echo - fi -} - -setup_distcc_environment(){ - if [ -x /usr/bin/distcc ] - then - echo "Using DistCC for compilation ..." - export PATH=/usr/lib/distcc/bin:${PATH} || die "distcc: could not export new $PATH" - - #export distcc as compiler -# export CC="distcc" -# export CXX=distcc - - export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" - - - #ccache + distcc together - if [ "${SMAGE_USE_CCACHE}" == "true" ] - then - if [ -x /usr/bin/ccache ] - then - echo "Preparing DistCC to work together with CCache ..." - #export CCACHE_PREFIX="distcc" || die "distcc: could not set ccach_prefix" -# export CC="ccache distcc" -# export CXX="ccache distcc" - fi - fi - - #creating distcc tempdir - install -o distcc -g daemon -d ${DISTCC_DIR} - chmod 1777 ${DISTCC_DIR} - fi -} - -setup_ccache_environment(){ - if [ -x /usr/bin/ccache ] - then - echo "Using CCache for compilation ..." - export PATH=/usr/lib/ccache/bin:${PATH} || die "ccache: could not export new $PATH" - #unset CC CXX - fi -} - - -# fixes given dependencies to match a MAGE_TARGET -# fix_mage_deps -target s/depend # <-- note -target ! -fix_mage_deps() { - local target="$1" - local depend="$2" - local NDEPEND - local sym dep cat pver pname - - # deps and provides are special - # they must be fixed to match the target - - # run this only if target and depend is not empty - if [ -n "${target}" ] && [ -n "${depend}" ] - then - # fix DEPEND - while read sym dep - do - cat="$(dirname ${dep})" - # change if not virtual - if [[ ${cat} = virtual ]] - then - pname="$(basename ${dep})" - else - # fix pver to target-pver - # to get pname-target-pver - - # doing it backwards ! - pver="${dep##*-}" - # full pver - pname="$(basename ${dep/-${pver}/})${target}-${pver}" - fi - - # do not add empty lines - if [ -z "${NDEPEND}" ] - then - NDEPEND="${sym} ${cat}/${pname}" - else - NDEPEND="${NDEPEND} - ${sym} ${cat}/${pname}" - fi - - unset cat pname pver - done << EOF -${depend} -EOF - # set NDEPEND to DEPEND - depend="${NDEPEND}" - fi - - echo "${depend}" -} - -# build_mage_script(): helper functions for regen_mage_tree() -# generates an mage file with given information in smage file -# needs at least: -# PNAME name of pkg -# PVER version -# PBUILD revision -# PCATEGORIE categorie of the pkg -# STATE state of pkg stable|unstable|old -# DESCRIPTION va short description (opt) -# HOMEPAGE homepage (opt) -# DEPEND runtime dependencies (opt) -# SDEPEND add. needed deps to build the pkg (opt) -# PROVIDE provides a virtual (opt) -# -# special tags: -# PKGTYPE type of pkg -# INHERITS which functions get included -# SPECIAL_FUNCTIONS special functions wich should also be added -# warning: they get killed before the build starts ! -# -# MAGE_TREE_DEST target destination of the generated tree -# REGEN_MAGE_TREE set to 'true' to enable this -# -# gets called with build_mage_script target -build_mage_script() -{ - local magefile - local dest - local target - local sym - local depname - - # if MAGE_TREE_DEST not set use BUILDDIR - : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} - - # determinate which suffix this mage file should get, if any - [ -n "$1" ] && target="-$1" - - # name of magefile - magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" - - # destination to magefile - dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" - - # show what we are doing - echo "Generating Mage file:" - echo " ${dest}" - - install -d "$(dirname ${dest})" - # now build the mage file - > ${dest} - - # header - echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.34 2005-08-22 00:07:32 niro Exp $' >> ${dest} - echo >> ${dest} - - # pgkname and state - echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} - echo "STATE=\"${STATE}\"" >> ${dest} - echo >> ${dest} - - # description and homepage - echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} - echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} - echo >> ${dest} - - # special tags and vars - echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} - # add special vars - if [ -n "${SPECIAL_VARS}" ] - then - local i - for i in ${SPECIAL_VARS} - do - # being tricky here :) - echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} - done - echo >> ${dest} - fi - # add at least all includes - if [ -n "${INHERITS}" ] - then - echo -n "minclude" >> ${dest} - local i - for i in ${INHERITS} - do - echo -n " ${i}" >> ${dest} - done - echo >> ${dest} - fi - echo >> ${dest} - - # deps and provides - echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} - echo >> ${dest} - echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} - echo >> ${dest} - echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} - echo >> ${dest} - - # add special functions - if [ -n "${SPECIAL_FUNCTIONS}" ] - then - local i - for i in ${SPECIAL_FUNCTIONS} - do - # add to mage (quotes needed !) - typeset -f "${i}" >> ${dest} - # unset to be safe (quotes needed !) - #unset "${i}" <-- later to get every target built - done - echo >> ${dest} - fi - - # pre|post-install|removes - typeset -f preinstall >> ${dest} - echo >> ${dest} - typeset -f postinstall >> ${dest} - echo >> ${dest} - typeset -f preremove >> ${dest} - echo >> ${dest} - typeset -f postremove >> ${dest} - echo >> ${dest} - - # echo MAGE_TARGETS ## note -target is needed ! - echo "MAGE_TARGETS=\"${targets}\"" >> ${dest} -} - -regen_mage_tree() -{ - local i - - # build them only if requested - if [[ ${REGEN_MAGE_TREE} = true ]] - then - # run it without targets - if [ -z "${MAGE_TARGETS}" ] - then - echo - build_mage_script - echo - else - - # build for each target an mage file - # run it with several targets - for i in ${MAGE_TARGETS} - do - echo - build_mage_script "${i}" - echo - done - fi - fi +## setup ## +SMAGENAME="$1" +SMAGEVERSION="$(< ${MLIBDIR}/version)" - # now unset all uneeded vars to be safe - # unset PKGNAME <-- don't do that; smage needs this var - # unset to be safe (quotes needed !) - for i in ${SPECIAL_FUNCTIONS} - do - unset "${i}" - done - unset SPECIAL_FUNCTIONS - for i in ${SPECIAL_VARS} - do - unset "${i}" - done - unset SPECIAL_VARS - unset STATE - unset DESCRIPTION - unset HOMEPAGE - unset PKGTYPE - unset INHERITS - unset DEPEND - unset SDEPEND - unset PROVIDE - unset preinstall - unset postinstall - unset preremove - unset postremove -} +# expand PKGDIR, BUILDDIR and BINDIR with MROOT +if [[ -n ${MROOT} ]] +then + export PKGDIR=${MROOT}/${PKGDIR} + export BUILDDIR=${MROOT}/${BUILDDIR} + export BINDIR=${MROOT}/${BINDIR} +fi # print out our version showversion echo -if [ -z "$1" ] +if [[ -z ${SMAGENAME} ]] then echo "No .smage2 file given. Exiting." echo exit 1 fi +# load supported mage features +load_mage_features + # updating smage2-scripts -if [ "$1" == "update" ] +if [[ $1 = update ]] then if [ ! -d ${SOURCEDIR} ] then @@ -663,13 +59,15 @@ fi # creates md5sums for smages to given dir -if [ "$1" == "calcmd5" ] +if [[ $1 = calcmd5 ]] then - if [ $# -ge 3 ] + if [ $# -ge 2 ] then SMAGENAME="$2" MD5DIR="$3" - source ${SMAGENAME} || die "download source failed" + [[ -z ${MD5DIR} ]] && MD5DIR="$(dirname ${SMAGENAME})/md5" + + smagesource ${SMAGENAME} || die "download source failed" # overridable sourcedir; must be declared after source of the smage2 CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" @@ -715,20 +113,20 @@ unset my_SRC_URI_MIRROR unset my_SOURCEDIR done - + echo echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." echo else echo "Usage: Calculating MD5 Sums:" - echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR" + echo " $(basename $0) calcmd5 /path/to/SMAGENAME [/path/to/MD5DIR]" echo echo echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." echo exit 1 fi - + exit 0 fi @@ -743,7 +141,7 @@ # get smage SMAGENAME="$2" MD5DIR="$(dirname ${SMAGENAME})/md5" - source ${SMAGENAME} || die "download source failed" + smagesource ${SMAGENAME} || die "download source failed" download_sources exit 0 @@ -755,209 +153,626 @@ # set correct SMAGENAME SMAGENAME="$2" MD5DIR="$(dirname ${SMAGENAME})/md5" - source ${SMAGENAME} || die "regen: smage2 not found" + smagesource ${SMAGENAME} || die "regen: smage2 not found" regen_mage_tree + + # build several subpackages + if [[ -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_${subpackage} + # fix PCATEGORIE -> PCAT + if [[ ! -z ${PCATEGORIE} ]] + then + PCAT="${PCATEGORIE}" + unset PCATEGORIE + fi + # build md5sum for existing packages + generate_package_md5sum \ + --pcat "${PCAT}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + # restore smage environment + split_restore_variables + done + # unset all saved smage variables + split_unset_variables + + else + # build md5sum for existing packages + generate_package_md5sum \ + --pcat "${PCAT}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + fi + exit 0 fi -if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] +if [ "$1" == "--create-src-tarball" -a -n "$2" ] then - die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." -fi + # set correct SMAGENAME + SMAGENAME="$2" + MD5DIR="$(dirname ${SMAGENAME})/md5" -if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ] -then - die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting." -fi + echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}" -if [ -z "${SOURCEDIR}" ] -then - die "\$SOURCEDIR not found. Please setup your mage.rc correctly." -fi + smagesource ${SMAGENAME} || die "regen: smage2 not found" -if [ -z "${SMAGESCRIPTSDIR}" ] -then - die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly." -fi + if [[ -d ${SOURCEDIR}/${PNAME} ]] + then + echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" + rm -rf ${SOURCEDIR}/${PKGNAME} + fi -if [ -z "${SMAGE2RSYNC}" ] -then - echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly." - exit 1 + download_sources + source_pkg_build ${SMAGENAME} + exit 0 fi -if [ -z "${BINDIR}" ] +if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ] then - die "no BINDIR variable found in /etc/mage.rc" -fi + SRCPKGTARBALL="${2}" + msetfeature "srcpkgtarball" -if [ -z "${CHOST}" ] -then - die "no CHOST variable found in /etc/mage.rc" -fi + # abort if given file is not a source pkg + [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file." -if [ -z "${CFLAGS}" ] -then - die "no CFLAGS variable found in /etc/mage.rc" + # set correct SMAGENAME; use the one that the src_pkg provide + # /path/to/SOURCEDIR/PNAME/SMAGENAME + SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}" + + echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}" + + [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR} + + # unpack srctarball + [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting." + + tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}" + + [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}" fi -if [ -z "${CXXFLAGS}" ] +if [ "$1" == "--resume" -a -n "$2" ] then - die "no CXXFLAGS variable found in /etc/mage.rc" + msetfeature "resume" + SMAGENAME="$2" fi +[ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." +[ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] && + die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting." +[ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly." +[ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly." +[ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly." +[ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}" +[ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}" +[ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}" +[ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}" -source ${SMAGENAME} || die "source failed" -PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}" +smagesource ${SMAGENAME} || die "source failed" +PKGNAME="${PNAME}-${PVER}-${ARCH}$(print_distrotag)-${PBUILD}" MD5DIR="$(dirname ${SMAGENAME})/md5" +SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log" xtitle "Compiling ${PKGNAME}" -echo "Compiling ${PKGNAME}" +echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}" # auto regen mage tree if requested regen_mage_tree +if mqueryfeature "srcpkgbuild" +then + if [[ -d ${SOURCEDIR}/${PNAME} ]] + then + echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" + rm -rf ${SOURCEDIR}/${PNAME} + fi +fi + # download sources -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 -# distcc mus be setup *before* ccache, as ccache need to be before distcc in path -if [ "${SMAGE_USE_DISTCC}" == "true" ] -then - setup_distcc_environment -fi +# setup for distcc goes *before* ccache, so ccache comes before distcc in path +mqueryfeature "distcc" && setup_distcc_environment + +# setup icecc +# setup for icecc goes *before* ccache, so ccache comes before icecc in path +mqueryfeature "icecc" && setup_icecc_environment # setup ccache -if [ "${SMAGE_USE_CCACHE}" == "true" ] +mqueryfeature "ccache" && setup_ccache_environment + +if mqueryfeature "resume" then - setup_ccache_environment -fi + echo -e "${COLMAGENTA}Resume requested; continuing previous build${COLDEFAULT}" + # 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 -# small sleep to show our settings -sleep 1 +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." -#debug -#echo "CC=${CC}" -#echo "CXX=${CXX}" -#echo "DISTCC_DIR=${DISTCC_DIR}" -#echo "PATH: ${PATH}" -#echo "--------------------------------------" -#env -#echo "--------------------------------------" -#read -#debug end + # clean up srcdir if a previously unpacked one exist + if [ -d ${SRCDIR} ] + then + rm -rf ${SRCDIR} + fi -# cleans up build if a previously one exists -if [ -d ${BUILDDIR} ] -then - rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." + # 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 -install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." -# cleans up srcdir if a previously unpacked one exists -if [ -d ${SRCDIR} ] +if [[ ${PKGTYPE} = virtual ]] then - rm -rf ${SRCDIR} + 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 + + # 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 + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + echo + echo -en "${COLBLUE}*** ${COLDEFAULT}" + echo -en "Virtual package detected" + echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}" + echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..." + + echo "virtual package detected; nothing will be build ..." + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + else + 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} ..." + + ( 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 + fi + # restore smage environment + split_restore_variables + done + # 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 -# cleans up bindir if a previous build exists or creates a new one -if [ -d ${BINDIR} ] +# echo for sake of good-looking +echo + +if mqueryfeature "!compressdoc" +then + echo -e "!compressdoc detected; documentation will not be compressed ..." +elif mqueryfeature "!pkgbuild" then - rm -rf ${BINDIR} + echo "!pkgbuild detected; skipping documentation compression..." +else + # compressing doc, info & man files + if [[ -n ${SPLIT_PACKAGES} ]] + then + # save smage environment + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # honor split_info + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi + + if mqueryfeature "!compressdoc" + then + echo -e "!compressdoc detected; documentation of '${subpackage}' will not be compressed ..." + elif mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping documentation compression for '${subpackage}' ..." + else + run_resume post-mcompressdoc_${subpackage} || mcompressdocs ${BINDIR}_${subpackage} + resume_stamp post-mcompressdoc_${subpackage} + fi + # restore smage environment + split_restore_variables + done + # unset saved variables + split_unset_variables + else + run_resume post-mcompressdoc || mcompressdocs ${BINDIR} + resume_stamp post-mcompressdoc + fi fi -install -d ${BINDIR} || die "couldn't create \$BINDIR." -# cleans up package temp dir if a previous build exists -if [ -d ${BUILDDIR}/${PKGNAME} ] +if mqueryfeature "!libtool" then - rm -rf ${BUILDDIR}/${PKGNAME} + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping libtool archive stripping ..." + else + if [[ -n ${SPLIT_PACKAGES} ]] + then + # save smage environment + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # honor split_info + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi + + if mqueryfeature "!libtool" + then + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping libtool archive stripping for '${subpackage}'..." + else + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}" + run_resume post-mstriplibtoolarchive_${subpackage} || mstriplibtoolarchive ${BINDIR}_${subpackage} + resume_stamp post-mstriplibtoolarchive_${subpackage} + fi + fi + + # restore smage environment + split_restore_variables + done + # unset saved variables + split_unset_variables + else + echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}" + run_resume post-mstriplibtoolarchive || mstriplibtoolarchive ${BINDIR} + resume_stamp post-mstriplibtoolarchive + fi + fi fi -# cleans up timestamp if one exists -if [ -f /var/tmp/timestamp ] +if mqueryfeature "purge" then - mage rmstamp -fi + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping file purgation ..." + else + if [[ -n ${SPLIT_PACKAGES} ]] + then + # save smage environment + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # honor split_info + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi -src_prepare || die "src_prepare failed" -src_compile || die "src_compile failed" -src_install || die "src_install failed" + if mqueryfeature "purge" + then + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping file purgation for '${subpackage}' ..." + else + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}" + run_resume post-mpurgetargets_${subpackage} || mpurgetargets ${BINDIR}_${subpackage} + resume_stamp post-mpurgetargets_${subpackage} + fi + fi + # restore smage environment + split_restore_variables + done + # unset saved variables + split_unset_variables + else + echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}" + run_resume post-mpurgetargets || mpurgetargets ${BINDIR} + resume_stamp post-mpurgetargets + fi + fi +fi -# compressing doc, info & man files -echo -e "Compressing man-pages ..." -if [ -d ${BUILDDIR}/builded/usr/share/man ] +# stripping all bins and libs +if mqueryfeature "!strip" then - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man + 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 + # save smage environment + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # honor split_info + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi + + if mqueryfeature "!strip" + then + echo -e "!strip detected; package '${subpackage}' will not be stripped ..." + elif mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping stripping of the package '${subpackage}' ..." + else + echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" + run_resume post-mstripbins_${subpackage} || mstripbins ${BINDIR}_${subpackage} + resume_stamp post-mstripbins_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}" + run_resume post-mstriplibs_${subpackage} || mstriplibs ${BINDIR}_${subpackage} + resume_stamp post-mstriplibs_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}" + run_resume post-mstripstatic_${subpackage} || mstripstatic ${BINDIR}_${subpackage} + resume_stamp post-mstripstatic_${subpackage} + fi + + # restore smage environment + split_restore_variables + done + # unset saved variables + split_unset_variables + else + echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" + run_resume post-mstripbins || mstripbins ${BINDIR} + resume_stamp post-mstripbins + echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}" + run_resume post-mstriplibs || mstriplibs ${BINDIR} + resume_stamp post-mstriplibs + echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" + run_resume post-mstripstatic || mstripstatic ${BINDIR} + resume_stamp post-mstripstatic + fi fi -echo -e "Compressing info-pages ..." -if [ -d ${BUILDDIR}/builded/usr/share/info ] +if mqueryfeature "qalint" then - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping QA lint checks ..." + else + if [[ -n ${SPLIT_PACKAGES} ]] + then + # save smage environment + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # honor split_info + split_info_${subpackage} + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi + + if mqueryfeature "qalint" + then + if mqueryfeature "!pkgbuild" + then + echo "!pkgbuild detected; skipping QA lint checks for '${subpackage}' ..." + else + echo -e "${COLBLUE}===${COLGREEN} running QA lint checks for '${subpackage}' ...${COLDEFAULT}" + mqalint ${BINDIR}_${subpackage} + fi + fi + + # restore smage environment + split_restore_variables + done + # unset saved variables + split_unset_variables + else + echo -e "${COLBLUE}===${COLGREEN} running QA lint checks ...${COLDEFAULT}" + mqalint ${BINDIR} + 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 ..." - ;; - *) - echo -e "Stripping binaries ..." - mstripbins ${BINDIR} - echo -e "Stripping libraries ..." - mstriplibs ${BINDIR} - ;; -esac - -# the new buildpkg command -case ${NOPKGBUILD} in - true|TRUE|yes|y) - echo -e "NOPGKBUILD=true detected; Package will not be build ..." - ;; - *) - # build serveral targets - if [ -n "${MAGE_TARGETS}" ] +if mqueryfeature "!pkgbuild" +then + echo -e "!pkgbuild detected; Package will not be build ..." +else + # build several subpackages + if [[ -n ${SPLIT_PACKAGES} ]] then - for target in ${MAGE_TARGETS} + split_save_variables + for subpackage in ${SPLIT_PACKAGES} do - # check if an special target_pkgbuild exists - if typeset -f ${target}_pkgbuild > /dev/null + # get the right variables for the split + export PNAME="${subpackage}" + split_info_${PNAME} + # fix PCATEGORIE -> PCAT + if [[ ! -z ${PCATEGORIE} ]] + then + PCAT="${PCATEGORIE}" + unset PCATEGORIE + fi + if [[ ${PKGTYPE} = virtual ]] + then + # automatically set !pkgbuild here too + msetfeature "!pkgbuild" + fi + + # jump to next one if !pkgbuild is set in split_info + if mqueryfeature "!pkgbuild" + then + # restore smage environment + split_restore_variables + continue + fi + + # check if an special subpackage_pkgbuild exists + if typeset -f ${PNAME}_pkgbuild > /dev/null then # run it - ${target}_pkgbuild + run_resume post-${PNAME}_pkgbuild || ${PNAME}_pkgbuild + resume_stamp post-${PNAME}_pkgbuild fi # now create the target package - ${MLIBDIR}/pkgbuild_dir.sh \ - "${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \ - ${BINDIR} || die "target: ${target} package-build failed" - echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n" + run_resume post-pkg_builddir_${PNAME} || ${MLIBDIR}/pkgbuild_dir.sh \ + "${PNAME}-${PVER}-${ARCH}$(print_distrotag)-${PBUILD}" \ + "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed" + resume_stamp post-pkg_builddir_${PNAME} + + # build pkg-md5-sum if requested + run_resume post-md5sum_${PNAME} || generate_package_md5sum \ + --pcat "${PCAT}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + resume_stamp post-md5sum_${PNAME} + + echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}$(print_distrotag)-${PBUILD} successfully builded.\n${COLDEFAULT}" + + # restore smage environment + split_restore_variables done + # unset all saved smage variables + split_unset_variables + else - ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" - echo -e "\nPackage ${PKGNAME} successfully builded.\n" + run_resume post-pkg_builddir || ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" + resume_stamp post-pkg_builddir + + # build pkg-md5-sum if requested + run_resume post-md5sum || generate_package_md5sum \ + --pcat "${PCAT}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + resume_stamp post-md5sum + + echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}" + fi + + # build src-pkg-tarball if requested + if mqueryfeature "srcpkgbuild" + then + run_resume post-srcpkgbuild || source_pkg_build ${SMAGENAME} + resume_stamp post-srcpkgbuild fi - ;; -esac +fi + +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 -#echo -e "\nPackage ${PKGNAME} successfully builded.\n"