Add function to get package version using underscore separator
[hvlinux.git] / functions / main
index 14f39a9..0adc06d 100644 (file)
@@ -51,6 +51,17 @@ fi
 # Load stage number definition
 source ./stage.def
 
+if [ -z "${LFS_STAGE}" ]; then
+    echo "LFS_STAGE is undefined (see stage.def)"
+    return ${EXIT_FAILURE}
+fi
+
+if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ]; then
+    LFS=""
+fi
+
+CLFS=${LFS}
+
 # Load functions
 source ../functions/fpkg
 source ../functions/lpkg
@@ -117,17 +128,6 @@ CLFS_HOST="$(echo $MACHTYPE | \
 
 export CLFS_BUILDFLAGS CLFS_TARGET CLFS_ARCH CLFS_HOST CLFS_ENDIAN CLFS_NOT_ENDIAN
 
-if [ -z "${LFS_STAGE}" ]; then
-    echo "LFS_STAGE is undefined (see stage.def)"
-    return ${EXIT_FAILURE}
-fi
-
-if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ]; then
-    LFS=""
-fi
-
-CLFS=${LFS}
-
 test_presence_of_packages_directory()
 {
     if [ ! -d "$(dirname $(pwd))/packages" ]; then
@@ -178,6 +178,19 @@ get_pkg_ver()
     echo ${1} | sed "s!.*-\([0-9].*\)!\1!g"
 }
 
+# Extracting the version number from a complete package name using underscore as separator.
+# Arg. #1: Complete package name with version (ex: ecryptfs-utils_103 will output 103)
+get_pkg_ver_underscore()
+{
+    # Checking for correct number of arguments
+    if [ $# -ne 1 ]; then
+       echo "${FUNCNAME}(), wrong number of arguments: ${*}"
+       return 1
+    fi
+
+    echo ${1} | sed "s!.*_\([0-9].*\)!\1!g"
+}
+
 # Extracting the first digit version number from a complete package name.
 # Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3)
 get_pkg_ver1()
@@ -654,9 +667,10 @@ static_decompressed_dirname()
                 # and extract base directory name with awk.
                 # tar 1.23 reports an error when using pipes, so
                 # remove error message with "2> /dev/null"
+                # (we extract the last line from tar output)
                 DIRNAME=$(tar ${TAR_OPTS} -tf \
                     ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} 2> /dev/null | \
-                    head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}')
+                    tail -n 1 | sed 's!^\./!!' | awk -F \/ '{print $1}')
                 ;;
             zip)
                 DIRNAME=$(unzip -l \
@@ -817,6 +831,7 @@ indicate_pkg_build_complete()
 #            gnome
 #            xorg
 #            pm
+#   -t     Enable dependency tracking
 #   -s     Name of script to source (default is from name of package)
 ipkg()
 {
@@ -827,10 +842,11 @@ ipkg()
     export DECOMPRESS="1"
     export IPKG_MODE="ac" # Default mode if not specified
     export HVLABEL="" # Global variable
+    export ENABLE_DEPENDENCY_TRACKING="0"
 
     local HVMAKE_ORIG=${HVMAKE}
 
-    while getopts "cjl:m:s:" flag ;do
+    while getopts "cjl:m:s:t" flag ;do
         case ${flag} in
             c)
                 # Do not decompress package
@@ -860,6 +876,10 @@ ipkg()
                 # Alternate script name
                 ALT_SCRIPT_NAME=${OPTARG}
                ;;
+            t)
+                # Do not disable dependency tracking
+                ENABLE_DEPENDENCY_TRACKING="1"
+               ;;
            ?)
                echo "${FUNCNAME}(): Invalid option: ${OPTARG}."
                return 1