Corrected get_pkg_name not woriking for udev
[hvlinux.git] / functions
index 3ca8396..9a6496f 100644 (file)
--- a/functions
+++ b/functions
@@ -70,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()
@@ -119,7 +130,8 @@ get_pkg_name()
        return 1
     fi
 
-    echo ${1} | sed "s!^\(.*\)-[0-9]*\.[0-9]*.*!\1!g"
+    # \1 matches anything followed by a dash and a number
+    echo ${1} | sed "s!^\(.*\)-[0-9].*!\1!g"
 }
 
 # Saves the content of CFLAGS and CXXFLAGS environment variables.
@@ -714,6 +726,12 @@ ipkg()
        exit ${EXIT_FAILURE}
     fi
 
+    # Checking if there is a corresponding config.cache file
+    local cache_file=$(pwd)/config.cache.$(get_pkg_name ${PACKAGE_NAME})
+    if [ -f ${cache_file} ]; then
+        CONFIGURE_OPTS="${CONFIGURE_OPTS} --cache-file=${cache_file}"
+    fi
+
     PACKAGE_LOG=${LFS_LOG_DIR}/${LABEL}.log
 
     # Checking if package was previously successfully installed
@@ -788,6 +806,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
@@ -803,8 +822,8 @@ ipkg_cust()
     fi
 
     local PACKAGE=${1}
-    local CUSTOM_SCRIPT=${2}
     local LABEL=${PACKAGE}
+    local CUSTOM_SCRIPT=${2}
     shift
     shift
     local CONFIGURE_OPTS=${*}
@@ -812,28 +831,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,
@@ -843,20 +878,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.
@@ -865,20 +887,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