Add dia
[hvlinux.git] / functions / main
index 9e4fc4d..2801230 100644 (file)
@@ -62,6 +62,9 @@ fi
 
 CLFS=${LFS}
 
+CROSS_TOOLS_DIR=${CLFS}/cross-tools
+TOOLS_DIR=${CLFS}/tools
+
 # Load functions
 source ../functions/fpkg
 source ../functions/lpkg
@@ -102,7 +105,11 @@ if [ -f ../targets/${HVL_TARGET} ]; then
     source ../targets/${HVL_TARGET}
 fi
 
-CLFS_TARGET="${CLFS_ARCH}-${CLFS_OS}-${CLFS_ABI}"
+# When CLFS_OS is defined, define target as the standard triplet:
+CLFS_TARGET="${CLFS_ARCH}"
+if [ x"${CLFS_OS}" != x ]; then
+    CLFS_TARGET+="-${CLFS_OS}-${CLFS_ABI}"
+fi
 
 CLFS_HOST="$(echo $MACHTYPE | \
     sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
@@ -195,6 +202,40 @@ get_pkg_ver_underscore()
     echo ${1} | sed "s!.*_\([0-9].*\)!\1!g"
 }
 
+# Extracting the version number from a complete package name
+# when the package name uses the underscore as the separator.
+# Arg. #1: Complete package name with version (ex: icu4c-54_1 will output 54.1)
+get_pkg_ver_underscore2()
+{
+    # Checking for correct number of arguments
+    if [ $# -ne 1 ]; then
+       echo "${FUNCNAME}(), wrong number of arguments: ${*}"
+       return 1
+    fi
+
+    local v=$(get_pkg_ver ${1})
+
+    # Replace underscore by dot
+    echo ${v} | sed "s!_!\.!g"
+}
+
+# Convert package version dots to uderscore.
+# Ex: gcc-3.4.6 will output 3_4_6
+# Arg. #1: Complete package name with version
+ver_dots_to_underscore()
+{
+    # Checking for correct number of arguments
+    if [ $# -ne 1 ]; then
+       echo "${FUNCNAME}(), wrong number of arguments: ${*}"
+       return 1
+    fi
+
+    local v=$(get_pkg_ver ${1})
+
+    # Replace dots by underscores
+    echo ${v} | sed "s!\.!_!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()
@@ -208,6 +249,20 @@ get_pkg_ver1()
     echo ${1} | sed "s!^.*-\([0-9]*\)\..*!\1!g"
 }
 
+# Extracting the first digit version number from a complete package name,
+# when the package name uses the underscore as the separator.
+# Arg. #1: Complete package name with version (ex: icu4c-54_1 will output 54)
+get_pkg_ver1_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 2 digits version number from a complete package name.
 # Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3.4)
 get_pkg_ver2()
@@ -551,23 +606,6 @@ var_add_shadow()
     sed -i "s!\(^${VARIABLE}.*\)!\1:${VALUE}!" ${FILE}
 }
 
-# Adding a new group, checking if it already exist before.
-# Arguments: same arguments as for standard groupadd command.
-hv_groupadd()
-{
-    arguments=${*}
-
-    # The last argument is the group name
-    while [ $# -ne 0 ]; do
-       groupname=${*}
-       shift
-    done
-
-    if ! cat /etc/group | egrep -q "^${groupname}:"; then
-        groupadd ${arguments}
-    fi
-}
-
 # Adding a new user, checking if it already exist before
 # Arguments: same arguments as for standard useradd command.
 hv_useradd()
@@ -831,6 +869,8 @@ indicate_pkg_build_complete()
 # Remaining arguments: Additional configure options
 # Options:
 #   -c     Do not decompress package
+#   -d DIR Change to directory DIR before configuring and building.
+#   -i DIR Installation directory (for cross-compilation, stage1)
 #   -j     Disable parallel make for this package
 #   -l     Unique identification label in 'install.log'
 #          (default is package name and version)
@@ -838,8 +878,6 @@ indicate_pkg_build_complete()
 #            ac   Standard autoconf package, build in separate dir (default)
 #            acnb Standard autoconf package, build in source dir
 #            noac No autoconf (configure)
-#            gnome
-#            xorg
 #            pm
 #   -t     Enable dependency tracking
 #   -s     Name of script to source (default is from name of package)
@@ -852,16 +890,26 @@ ipkg()
     export DECOMPRESS="1"
     export IPKG_MODE="ac" # Default mode if not specified
     export HVLABEL="" # Global variable
+    export SRC_DIR="" # Global variable, source directory
+    export BUILD_DIR="" # Global variable, build directory
+    export SRC_SUBDIR="" # Global variable
+    export INSTALL_DIR="" # Global variable, installation directory
     export ENABLE_DEPENDENCY_TRACKING="0"
 
     local HVMAKE_ORIG=${HVMAKE}
 
-    while getopts "cjl:m:s:t" flag ;do
+    while getopts "cd:i:jl:m:s:t" flag ;do
         case ${flag} in
             c)
                 # Do not decompress package
                 DECOMPRESS="0"
                 ;;
+            d)
+                SRC_SUBDIR=${OPTARG}
+               ;;
+            i)
+                INSTALL_DIR=${OPTARG}
+               ;;
             j)
                 # Disable parallel make only for this package
                 HVMAKE="make"
@@ -873,7 +921,7 @@ ipkg()
            m)
                 # Installation mode
                 case ${OPTARG} in
-                   ac|acnb|noac|gnome|xorg|pm)
+                   ac|acnb|noac|pm)
                         IPKG_MODE=${OPTARG}
                        ;;
                     *)
@@ -923,6 +971,21 @@ ipkg()
     PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log
     PACKAGE_DONE=${LFS_LOG_DIR}/${HVLABEL}.done
     PACKAGE_STATUS=${LFS_LOG_DIR}/${HVLABEL}.status
+    SRC_DIR="${LFS_TMP}/${PACKAGE}"
+    BUILD_DIR="${LFS_TMP}/${PACKAGE}"
+
+    if [ -n "${SRC_SUBDIR}" ]; then
+        SRC_DIR+="/${SRC_SUBDIR}"
+    fi
+
+    case "${IPKG_MODE}" in
+        ac)
+            BUILD_DIR="${LFS_TMP}/${PACKAGE}-build"
+           ;;
+        acnb|noac|xpm)
+            BUILD_DIR="${SRC_DIR}"
+           ;;
+    esac
 
     # Checking if package was previously successfully installed
     if [ -f ${PACKAGE_DONE} ]; then