#!/bin/bash # compiles/installs .smage2 source install scripts # needs pkgbuild_dir (mage) # SMAGE2 # version: 0.3.6-r9 #01.10.2004 # added ccache support # added distcc support ## setup ## SMAGEVERSION=0.3.6-r8 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 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 } # 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 } build_mage_script() { 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 } 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 } if [ -z "$1" ] then showversion echo echo "No .smage2 file given. Exiting." echo exit 1 fi #updating smage2-scripts if [ "$1" == "update" ] then showversion if [ ! -d ${SMAGESCRIPTSDIR} ] then install -d ${SMAGESCRIPTSDIR} fi syncsmage2 exit 0 fi if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] then die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." fi if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ] then die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting." fi if [ -z "${SOURCEDIR}" ] then die "\$SOURCEDIR not found. Please setup your mage.rc correctly." fi if [ -z "${SMAGESCRIPTSDIR}" ] then die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly." fi if [ -z "${SMAGE2RSYNC}" ] then echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly." exit 1 fi if [ -z "${BINDIR}" ] then die "no BINDIR variable found in /etc/mage.rc" fi if [ -z "${CHOST}" ] then die "no CHOST variable found in /etc/mage.rc" fi if [ -z "${CFLAGS}" ] then die "no CFLAGS variable found in /etc/mage.rc" fi if [ -z "${CXXFLAGS}" ] then die "no CXXFLAGS variable found in /etc/mage.rc" fi source ${SMAGENAME} || die "source failed" PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}" xtitle "Compiling ${PKGNAME}" #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_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" 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 ccache if [ "${SMAGE_USE_CCACHE}" == "true" ] then setup_ccache_environment fi # small sleep to show our settings sleep 1 #debug #echo "CC=${CC}" #echo "CXX=${CXX}" #echo "DISTCC_DIR=${DISTCC_DIR}" #echo "PATH: ${PATH}" #echo "--------------------------------------" #env #echo "--------------------------------------" #read #debug end #cleans up build if a previously one exists 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 if [ -d ${SRCDIR} ] then rm -rf ${SRCDIR} fi #cleans up bindir if a previous build exists or creates a new one if [ -d ${BINDIR} ] then rm -rf ${BINDIR} fi install -d ${BINDIR} || die "couldn't create \$BINDIR." #cleans up package temp dir if a previous build exists 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 src_prepare || die "src_prepare failed" src_compile || die "src_compile failed" src_install || die "src_install failed" #compressing doc, info & man files echo -e "Compressing man-pages ..." if [ -d ${BUILDDIR}/builded/usr/share/man ] then ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man fi echo -e "Compressing info-pages ..." if [ -d ${BUILDDIR}/builded/usr/share/info ] then ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info fi #the new buildpkg command case ${NOPKGBUILD} in true|TRUE|yes|y) echo -e "NOPGKBUILD=true detected; Package will not be build ..." ;; *) ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" echo -e "\nPackage ${PKGNAME} successfully builded.\n" ;; esac #for sure unset NOPKGBUILD xtitleclean #echo -e "\nPackage ${PKGNAME} successfully builded.\n"