X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions;h=53747fd616c9bea2f1d4ff3c8579846e664cdea1;hb=3605ab38ca7604b1fe43c3bce5e4963730a85d39;hp=79a57e1b835491bc040e3af9e5ef67b5cdefc27d;hpb=07bb6026cea496a885d217cc5f505ca3896d78b8;p=hvlinux.git diff --git a/functions b/functions index 79a57e1..53747fd 100644 --- a/functions +++ b/functions @@ -24,6 +24,8 @@ TAR_OPTS="-b8" HV_FONTS_PATH="/usr/share/fonts" +DEFAULT_EDITOR=nano + # It seems that when compiling bash-4.0, using # "make -j 1" is causing problems... if [ "x${MAKEJOBS}" = "x1" ]; then @@ -68,6 +70,17 @@ export CLFS_BUILDFLAGS CLFS_TARGET CLFS_ARCH CLFS_HOST CLFS_ENDIAN CLFS_NOT_ENDI CLFS=${LFS} +function function_exists +{ + local FUNCTION_NAME=$1 + + [ -z "$FUNCTION_NAME" ] && return 1 + + declare -F "$FUNCTION_NAME" > /dev/null 2>&1 + + return $? +} + # Extracting the version number from a complete package name. # Arg. #1: Complete package name with version (ex: firefox-3.5.5.source will output 3.5.5) get_pkg_ver() @@ -117,7 +130,10 @@ get_pkg_name() return 1 fi - echo ${1} | sed "s!^\(.*\)-[0-9]*\.[0-9]*.*!\1!g" + # SED do not support non-greedy regexp: + # We want to match any characters preceeding a dash followed by a number + # (shortest match -> non-greedy) + echo ${1} | sed "s!\([^-][^0-9]*\)-[0-9].*!\1!" } # Saves the content of CFLAGS and CXXFLAGS environment variables. @@ -530,11 +546,36 @@ static_decompressed_dirname() { local PACKAGE=${1} - # Remove optional "./" leading component with sed - # and extract base directory name with awk. - local DIRNAME=$(tar ${TAR_OPTS} -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}') + # List of default archive extensions to try + local MY_ARCH_EXT="tar.bz2 tar.gz tgz tar.Z zip" - echo ${DIRNAME} + for arch_ext in ${MY_ARCH_EXT}; do + if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ]; then + # Try next archive extension. + continue; + fi + + case ${arch_ext} in + tar.bz2|tar.gz|tgz|tar.Z) + # Remove optional "./" leading component with sed + # and extract base directory name with awk. + # tar 1.23 reports an error when using pipes, so + # remove error message with "2> /dev/null" + local DIRNAME=$(tar ${TAR_OPTS} -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 2> /dev/null | head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}') + echo ${DIRNAME} + ;; + zip) + # TODO + echo ${PACKAGE} + ;; + esac + + return $? + done + + # Failure or file not found + echo "${FUNCNAME}(): Missing source package for \"${PACKAGE}\"" > /dev/stderr + return ${EXIT_FAILURE} } # Applying patch @@ -614,21 +655,44 @@ decompress_package() local PACKAGE=${1} - if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 ]; then - echo "${FUNCNAME}(): Missing source package: \"${PACKAGE}.tar.bz2\"" > /dev/stderr - return ${EXIT_FAILURE} - fi - - if [ -d ${TOPDIR}/${PACKAGE} ]; then - # Removing old source directory (if any) - rm -v -rf ${TOPDIR}/${PACKAGE} || exit 1 - fi + # List of default archive extensions to try + local MY_ARCH_EXT="tar.bz2 tar.gz tgz tar.Z zip" + + for arch_ext in ${MY_ARCH_EXT}; do + if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ]; then + # Try next archive extension. + continue; + fi + + if [ -d ${TOPDIR}/${PACKAGE} ]; then + # Removing old source directory (if any) + rm -v -rf ${TOPDIR}/${PACKAGE} || exit 1 + fi + + cd ${TOPDIR} + + # Decompressing package + case ${arch_ext} in + tar.bz2) + tar ${TAR_OPTS} -jxvf ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} || return 1 + ;; + tar.gz|tgz|tar.Z) + tar ${TAR_OPTS} -zxvf ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} || return 1 + ;; + zip) + echo ZIPZIPZIP + unzip ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} || return 1 + ;; + esac + + cd - 1> /dev/null 2>&1 + + return $? + done - # Decompressing package - # Option 'U' of tar is to remove each file prior to extracting over it - cd ${TOPDIR} && - tar ${TAR_OPTS} -jxvf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 && - cd - 1> /dev/null 2>&1 + # Failure or file not found + echo "${FUNCNAME}(): Missing source package for \"${PACKAGE}\"" > /dev/stderr + return ${EXIT_FAILURE} } # Installation of a package @@ -738,6 +802,7 @@ ipkg() } # Installation of a package, removing source and build directories after. +# Try to merge this function with static_ipkg()??? # # First argument: package name # Second argument: script name @@ -753,8 +818,8 @@ ipkg_cust() fi local PACKAGE=${1} - local CUSTOM_SCRIPT=${2} local LABEL=${PACKAGE} + local CUSTOM_SCRIPT=${2} shift shift local CONFIGURE_OPTS=${*} @@ -762,28 +827,44 @@ ipkg_cust() ipkg ${PACKAGE} ${CUSTOM_SCRIPT} ${LABEL} ${CONFIGURE_OPTS} } -# Installation of a package conforming to GNU autotools. -# The package must be able to be built outside the -# source directory. +# Static function called by: +# ipkg_ac +# ipkg_ac_nb +# ipkg_gnome # -# First argument: package name +# First argument: script name +# Second argument: package name # Remaining arguments: additional configure options -ipkg_ac() +static_ipkg() { # Checking for correct number of arguments - if [ $# -lt 1 ]; then + if [ $# -lt 2 ]; then echo echo "${FUNCNAME}(): Wrong number of arguments" echo " command was: \"${FUNCNAME}() $*\"" exit ${EXIT_FAILURE} fi - local PACKAGE=${1} + local SCRIPT=${1} + local PACKAGE=${2} local LABEL=${PACKAGE} shift + shift local CONFIGURE_OPTS=${*} - ipkg ${PACKAGE} cis-ac ${LABEL} ${CONFIGURE_OPTS} + ipkg ${PACKAGE} ${SCRIPT} ${LABEL} ${CONFIGURE_OPTS} +} + + +# Installation of a package conforming to GNU autotools. +# The package must be able to be built outside the +# source directory. +# +# First argument: package name +# Remaining arguments: additional configure options +ipkg_ac() +{ + static_ipkg cis-ac ${*} } # Installation of a package conforming to GNU autotools, @@ -793,20 +874,7 @@ ipkg_ac() # Remaining arguments: additional configure options ipkg_ac_nb() { - # Checking for correct number of arguments - if [ $# -lt 1 ]; then - echo - echo "${FUNCNAME}(): Wrong number of arguments" - echo " command was: \"${FUNCNAME}() $*\"" - exit ${EXIT_FAILURE} - fi - - local PACKAGE=${1} - local LABEL=${PACKAGE} - shift - local CONFIGURE_OPTS=${*} - - ipkg ${PACKAGE} cis-ac-nobuild ${LABEL} ${CONFIGURE_OPTS} + static_ipkg cis-ac-nobuild ${*} } # Installation of a GNOME package. @@ -815,20 +883,7 @@ ipkg_ac_nb() # Remaining arguments: additional configure options ipkg_gnome() { - # Checking for correct number of arguments - if [ $# -ne 1 ]; then - echo - echo "${FUNCNAME}(): Wrong number of arguments" - echo " command was: \"${FUNCNAME}() $*\"" - exit ${EXIT_FAILURE} - fi - - local PACKAGE=${1} - local LABEL=${PACKAGE} - shift - local CONFIGURE_OPTS=${*} - - ipkg ${PACKAGE} cis-gnome ${LABEL} ${CONFIGURE_OPTS} + static_ipkg cis-gnome ${*} } # Installation of a PERL module