# Function library for buildpkg build.sh # This is only for build.sh helper functions. # Copyright (C) 2003 Jens-Henrik Leonhard Jensen # Copyright (C) 2003-2008,2010,2012 Tom G. Christensen # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Written by Tom G. Christensen . # Automatic logging is enabled by default autolog=1 # Don't log these methods nolog="prep distclean" # date format string dateformat="%Y%m%d%H%M%S" # Define script functions and register them METHODS="" reg() { METHODS="$METHODS $1" } all() { for METHOD in $METHODS do case $METHOD in all*|*clean|check) ;; *) $METHOD ;; esac done } usage() { echo Usage $0 "{"$(echo $METHODS | tr " " "|")"}" exit 1 } build_sh() { # Register internal functions last # The empty reg is trickery to get exactly 1 space at each end of the METHODS string reg all reg # local OK=0 for METHOD in $* do METHOD=" $METHOD *" if [ "${METHODS%$METHOD}" == "$METHODS" ] ; then usage fi OK=1 done if [ $OK = 0 ] ; then usage; fi for METHOD in $* do ( log_start $METHOD; $METHOD; log_stop $METHOD ) done } # Write out a timestamp timestamp() { date +$dateformat } # Start a logfile # Note this should only be used *after* the buildpkg.* libraries # have been sourced, otherwise most of the variables used to construct # the logfile name are undefined. log_start() { local func=$1 build_sh_logfile=${topdir}-${version}_${pkgver}-${os}-${arch}-${func}-$(timestamp).log if [ $autolog -eq 1 ]; then if [ -z "$(${__expr} "$nolog" : ".*\($func\)")" ]; then # save stdout and stderr to file descriptors 3 and 4 # then redirect them to $build_sh_logfile echo "Opening logfile: $build_sh_logfile" exec 3>&1 4>&2 >$build_sh_logfile 2>&1 # Log a timestamp timestamp # Get information about the compiler into the logfile identify_compiler log else # $nolog function, just add a timestamp timestamp fi fi } # Stop logging log_stop() { local func=$1 if [ $autolog -eq 1 -a -z "$(${__expr} "$nolog" : ".*\($func\)")" ]; then # Log a timestamp timestamp # restore stdout and stderr exec 1>&3 2>&4 echo "Closing logfile: $build_sh_logfile" fi }