X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions%2Fmain;h=7c167e53310df08d7d8704d2b46dc23c9d82e472;hb=10a9a4a4045ee1e6bc30df5de9bb857d1fd0dc1f;hp=d8881684c4126bc7a6ce497c616035e1c496976f;hpb=d9702c4a5c6fbf2c738ffbf9c3563daf552c91d8;p=hvlinux.git diff --git a/functions/main b/functions/main index d888168..7c167e5 100644 --- a/functions/main +++ b/functions/main @@ -2,8 +2,8 @@ set -o errtrace # Let shell functions inherit ERR trap. set -o errexit -# Don' t locate and remember (hash) commands as they are looked up for -# execution (don' t remember path): +# Don't locate and remember (hash) commands as they are looked up for +# execution (don't remember path): set +h hvtrap_setup() @@ -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 @@ -83,50 +94,24 @@ DEFAULT_IPKG_SCRIPT="ipkg.def" HVMAKE="make -j ${MAKEJOBS}" -case "${HVL_TARGET}" in - arm*) - CLFS_BUILDFLAGS="-mabi=aapcs-linux -mfloat-abi=soft" - CLFS_TARGET="arm-linux-gnueabi" - CLFS_ARCH=$(echo ${CLFS_TARGET} | sed -e 's/-.*//' -e 's/arm.*/arm/g') - CLFS_ENDIAN=$(echo ${CLFS_ARCH} | sed -e 's/armeb/BIG/' -e 's/arm/LITTLE/') - if [ "${CLFS_ENDIAN}" = "LITTLE" ]; then - CLFS_NOT_ENDIAN="BIG" - else - CLFS_NOT_ENDIAN="LITTLE" - fi - ;; - "x86_64") - CLFS_BUILDFLAGS="-m64" - CLFS_TARGET="${HVL_TARGET}-unknown-linux-gnu" - CLFS_ARCH=${HVL_TARGET} - ;; - "x86") - # No special flags - CLFS_BUILDFLAGS="" - CLFS_TARGET="i686-unknown-linux-gnu" - CLFS_ARCH=${HVL_TARGET} - ;; - *) - echo "Unsupported target architecture: ${HVL_TARGET}" - return ${EXIT_FAILURE} - ;; -esac +# Load default values. They can be overriden +# by a target-specific file +source ../targets/default -CLFS_HOST="$(echo $MACHTYPE | \ - sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" - -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} +if [ -f ../targets/${HVL_TARGET} ]; then + source ../targets/${HVL_TARGET} fi -if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ]; then - LFS="" +# 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=${LFS} +CLFS_HOST="$(echo $MACHTYPE | \ + sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" + +export CLFS_BUILDFLAGS CLFS_TARGET CLFS_ARCH CLFS_HOST test_presence_of_packages_directory() { @@ -137,17 +122,26 @@ test_presence_of_packages_directory() } # Create log directory and log file for current stage if necessary -# This should be done automatically... -init_log_file() +# Arg #1: log file name +static_init_log_file() { + # Checking for correct number of arguments + if [ $# -ne 1 ]; then + echo "${FUNCNAME}(), wrong number of arguments: ${*}" + return 1 + fi + + local LOG_FILE_NAME=${1} + # Scripts directory export SCRDIR=$(pwd) test_presence_of_packages_directory - export LFS_PKG_DIR="$(dirname $(pwd))/packages/${LFS_STAGE}" + export LFS_PKG_BASE="$(dirname $(pwd))/packages" + export LFS_PKG_DIR="${LFS_PKG_BASE}/${LFS_STAGE}" export LFS_LOG_DIR=${LFS}/var/log/hvlinux-install/${LFS_STAGE} - export LFS_LOG_FILE=${LFS_LOG_DIR}/install.log + export LFS_LOG_FILE=${LFS_LOG_DIR}/${LOG_FILE_NAME} export LFS_TMP="${LFS}/tmp" mkdir -p ${LFS_LOG_DIR} && @@ -156,6 +150,20 @@ init_log_file() fi } +# Create log directory and install log file for current stage if necessary +init_log_file() +{ + static_init_log_file "install.log" + export LFS_PATCHES_DIR="${SCRDIR}/patches" +} + +# Create log directory and update log file for current stage if necessary +init_log_file_update() +{ + static_init_log_file "pkg-update.log" + export LFS_PATCHES_DIR="${LFS_PKG_DIR}/patches" +} + # Check that we are logged in as the root user, and exit if this is not the case. check_for_root_user() { @@ -178,6 +186,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() @@ -571,15 +592,17 @@ hv_useradd() # Applying patch # First argument is the name of the patch # Second argument is the package name -# Third argument: optional target directory (default is $LFS_TMP) +# Third argument is the subdirectory inside the patches directory +# Fourth argument: optional target directory (default is $LFS_TMP) apply_patch() { local PATCH_FILE=${1} local PACKAGE=${2} + local PDIR=${3} local TARGET_DIR="" - if [ $# -eq 3 ]; then - TARGET_DIR=${3}/${PACKAGE} + if [ $# -eq 4 ]; then + TARGET_DIR=${4}/${PACKAGE} else TARGET_DIR=${LFS_TMP}/${PACKAGE} fi @@ -590,14 +613,14 @@ apply_patch() return ${EXIT_FAILURE} fi - if [ ! -f ${LFS_PKG_DIR}/${PATCH_FILE} ]; then + if [ ! -f ${PDIR}/${PATCH_FILE} ]; then echo echo "${FUNCNAME}(): patch file '${PATCH_FILE}' not found." return ${EXIT_FAILURE} fi echo "Applying patch: ${PATCH_FILE}" - patch -Np1 -d ${TARGET_DIR} -i ${LFS_PKG_DIR}/${PATCH_FILE} + patch -Np1 -d ${TARGET_DIR} -i ${PDIR}/${PATCH_FILE} } # Applying any patch(es) found for the current package. @@ -623,13 +646,17 @@ apply_patches() TARGET_DIR=${2} fi - # Checking if we can find at least one patch. - if ls ${LFS_PKG_DIR}/${1}-*.patch 1> /dev/null 2>&1; then - cd ${LFS_PKG_DIR} - for patch in ${1}-*.patch; do - apply_patch ${patch} ${PACKAGE} ${TARGET_DIR} - done - fi + for s in common ${HVL_TARGET}; do + pdir=${LFS_PATCHES_DIR}/${s} + if [ -d ${pdir} ]; then + if ls ${pdir}/${1}-*.patch 1> /dev/null 2>&1; then + cd ${pdir} + for patch in ${1}-*.patch; do + apply_patch ${patch} ${PACKAGE} ${pdir} ${TARGET_DIR} + done + fi + fi + done return $? } @@ -1125,15 +1152,15 @@ get_total_build_time() for time in ${TIMES}; do HOURS=$(( $HOURS + $(echo ${time} | sed "s!^\([0-9]*\)\..*!\1!g") )) - + # The first SED command extracts the minutes (fractions of an hour). # The second SED command removed the leading zero, if applicable. MIN=$(( $MIN + $(echo ${time} | sed "s!.*\.\([0-9][0-9]\)!\1!g" | sed "s!^0\([0-9]\)!\1!g" ) )) done - + HOURS=$(( ${HOURS} + ( ${MIN} / 100 ) )) MIN=$(( ${MIN} % 100 )) - + echo "${HOURS}.${MIN}" }