X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;ds=inline;f=functions;h=218df79852237dd6c4e76fbbed0c991355ca3319;hb=f63a78e04ec65397472cda88061558f4e3a30fb2;hp=a986466fa5baaa971a88aedcbe09d76cc9f4eb76;hpb=16cc35ba4890382ee9368a176e4f5a7fa773b7a6;p=hvlinux.git diff --git a/functions b/functions index a986466..218df79 100644 --- a/functions +++ b/functions @@ -20,9 +20,16 @@ WARNING="echo -en \\033[1;33m" # FAILURE prints text in a red colour FAILURE="echo -en \\033[1;31m" +# It seems that when compiling bash-4.0, using +# "make -j 1" is causing problems... +if [ "x${MAKEJOBS}" == "x1" ]; then + HVMAKE="make" +else + HVMAKE="make -j ${MAKEJOBS}" +fi # Extracting the version number from a complete package name. -# Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3.4.4) +# Arg. #1: Complete package name with version (ex: firefox-3.5.5.source will output 3.5.5) get_pkg_ver() { # Checking for correct number of arguments @@ -31,10 +38,9 @@ get_pkg_ver() return 1 fi - echo ${1} | sed "s!^.*-\(.*\)!\1!g" + echo ${1} | sed "s!.*-\([0-9].*\)!\1!g" } - # Extracting the base 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_ver_base() @@ -48,7 +54,6 @@ get_pkg_ver_base() echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\).*!\1!g" } - # Extracting the base version number from a complete package name. # Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3) get_pkg_ver_major() @@ -62,7 +67,6 @@ get_pkg_ver_major() echo ${1} | sed "s!^.*-\([0-9]*\)\..*!\1!g" } - # Extracting the name from a complete package name. # Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output gcc) get_pkg_name() @@ -76,7 +80,6 @@ get_pkg_name() echo ${1} | sed "s!^\(.*\)-.*!\1!g" } - # Saves the content of CFLAGS and CXXFLAGS environment variables. save_flags() { @@ -86,7 +89,6 @@ save_flags() return ${EXIT_SUCCESS} } - # Saves the content of CFLAGS and CXXFLAGS environment variables, and then # set them to empty strings. save_flags_no_optimizations() @@ -99,7 +101,6 @@ save_flags_no_optimizations() return ${EXIT_SUCCESS} } - # Restores the previous values of CFLAGS and CXXFLAGS environment variables. These # must have been saved first using save_flags(). restore_flags() @@ -110,7 +111,6 @@ restore_flags() return ${EXIT_SUCCESS} } - # Create log directory and log file for current stage if necessary # This should be done automatically... init_log_file() @@ -121,7 +121,6 @@ init_log_file() fi } - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: script name @@ -175,7 +174,6 @@ static_bootscript_add() fi } - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: level @@ -209,7 +207,6 @@ bootscript_add_manual() fi } - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: script name @@ -220,7 +217,6 @@ bootscript_add_rc3() static_bootscript_add ${*} 3 } - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: script name @@ -231,7 +227,6 @@ bootscript_add_rcS() static_bootscript_add ${*} S } - # Add "export" before the variable name # # Arg #1: variable name @@ -275,7 +270,6 @@ var_export() sed -i "s!\(^${VARIABLE}=.*\)!export \1!" ${FILE} } - # Adding a new environment variable to a file. # # Arg #1: variable name @@ -342,7 +336,6 @@ var_add() return $? } - # Adding a new path environment variable to a file. # # Arg #1: variable name @@ -353,7 +346,6 @@ var_add_path() var_add ${1} ${2} "${3}" ":" 1>> ${LFS_LOG_FILE} 2>&1 } - # Adding a new string environment variable to a file. # # Arg #1: variable name @@ -364,7 +356,6 @@ var_add_str() var_add ${1} ${2} "${3}" " " } - # Adding a new string to a file. # # Arg #1: string @@ -395,7 +386,6 @@ string_add() echo "${STRING}" >> ${FILE} } - # Adding a new environment variable to a shadow password suite file (login.defs) # # Arg #1: variable name @@ -421,8 +411,8 @@ var_add_shadow() # Checking if variable contains the new value if egrep "^${VARIABLE}" ${FILE} | grep "${VALUE}" 1> /dev/null 2>&1; then - echo "variable ${VARIABLE} already contains value: ${VALUE}" - exit 0 + echo "${FUNCNAME}(), variable ${VARIABLE} already contains value: ${VALUE}" + return 0 fi # Adding new value to variable @@ -432,7 +422,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() @@ -476,7 +465,6 @@ hv_useradd() fi } - # Evaluates the return value of the process that was run just before this # function was called. evaluate_retval() @@ -501,25 +489,17 @@ eval_retval2() fi } - - - # Obtain the name of the base directory for the decompressed package. # First argument: package name static_decompressed_dirname() { local PACKAGE=${1} - local DIRNAME=$(dirname $(tar -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1)) - - if [ "x${DIRNAME}" == "x." ]; then - DIRNAME=$(basename $(tar -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1)) - fi + local DIRNAME=$(tar -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1 | awk -F \/ '{print $1}') echo ${DIRNAME} } - # Applying any patch(es) found for the current package. # Will work only if patches have the same base name as # the package, followed by a dash: @@ -542,16 +522,14 @@ apply_patches() if [ $# -eq 2 ]; then TARGET_DIR=${2} else - TARGET_DIR=$(static_decompressed_dirname ${PACKAGE}) + TARGET_DIR=${PACKAGE} 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 - echo "******************************" - echo "* Applying patch: ${patch}" - echo "******************************" + echo "Applying patch: ${patch}:" patch -Np1 -d ${LFS_TMP}/${TARGET_DIR} -i ${LFS_PKG_DIR}/${patch} || exit 1 done fi @@ -559,7 +537,6 @@ apply_patches() return $? } - # Applying patch # First argument is the name of the patch # Second argument is the package name @@ -586,7 +563,6 @@ apply_patch() patch -Np1 -d ${LFS_TMP}/${PACKAGE} -i ${LFS_PKG_DIR}/${PATCH_FILE} } - # Decompression of a package # First argument: package name # Second argument: directory where decompressing (optional) @@ -598,23 +574,20 @@ decompress_package() elif [ $# -eq 2 ]; then local TOPDIR=${2} else - echo - echo "${FUNCNAME}(): Incorrect number of arguments (must be 1 or 2)" + echo "${FUNCNAME}(): Incorrect number of arguments (must be 1 or 2)" > /dev/stderr return ${EXIT_FAILURE} fi local PACKAGE=${1} if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 ]; then - echo "${FUNCNAME}(): Missing source package: \"${PACKAGE}.tar.bz2\"" + echo "${FUNCNAME}(): Missing source package: \"${PACKAGE}.tar.bz2\"" > /dev/stderr return ${EXIT_FAILURE} fi - local DECOMPRESSED_DIRNAME=$(static_decompressed_dirname ${PACKAGE}) - - if [ -d ${TOPDIR}/${DECOMPRESSED_DIRNAME} ]; then + if [ -d ${TOPDIR}/${PACKAGE} ]; then # Removing old source directory (if any) - rm -v -rf ${TOPDIR}/${DECOMPRESSED_DIRNAME} || exit 1 + rm -v -rf ${TOPDIR}/${PACKAGE} || exit 1 fi # Decompressing package @@ -624,7 +597,6 @@ decompress_package() cd - 1> /dev/null 2>&1 } - # Installation of a package, removing source and build directories after. # # First argument: package name @@ -633,16 +605,21 @@ decompress_package() ipkg() { # Checking for correct number of arguments - if [ $# -ne 2 ]; then + if [ $# -lt 2 ]; then echo echo "${FUNCNAME}(): Wrong number of arguments" echo " command was: \"${FUNCNAME}() $*\"" exit ${EXIT_FAILURE} fi - static_ipkg ${1} ${2} ${1} -} + local PACKAGE=${1} + shift + local CUSTOM_SCRIPT=${1} + shift + local CONFIGURE_OPTS=${*} + static_ipkg ${PACKAGE} ${CUSTOM_SCRIPT} ${PACKAGE} ${CONFIGURE_OPTS} +} # Installation of a package conforming to GNU autotools. # The package must be able to be built outside the @@ -667,7 +644,6 @@ ipkg_ac() static_ipkg ${PACKAGE} cis-ac ${PACKAGE} ${CONFIGURE_OPTS} } - # Installation of a package conforming to GNU autotools, # but that must be built inside the source directory. # @@ -690,7 +666,6 @@ ipkg_ac_nb() static_ipkg ${PACKAGE} cis-ac-nobuild ${PACKAGE} ${CONFIGURE_OPTS} } - # Installation of a GNOME package. # # First argument: package name @@ -707,7 +682,6 @@ ipkg_gnome() static_ipkg ${1} cis-gnome ${1} } - # Installation of a PERL module # # First argument: package name @@ -724,7 +698,6 @@ ipkg_pm() static_ipkg ${1} cis-pm ${1} } - # Multiple installation of a package. This is usefull for packages # that may need to be installed multiple times, at different # times of the build process, like for GCC pas 1 and GCC pass 2. @@ -745,7 +718,6 @@ ipkg_mult() static_ipkg ${1} ${2} ${3} } - # Installation of a package # # First argument: Real package name @@ -779,7 +751,7 @@ static_ipkg() exit ${EXIT_FAILURE} fi - PACKAGE_LOG=${LFS_LOG_DIR}/${PACKAGE_NAME}.log + PACKAGE_LOG=${LFS_LOG_DIR}/${LABEL}.log # Checking if package was previously successfully installed if grep "^${LABEL} successfully installed" ${LFS_LOG_FILE} \ @@ -793,18 +765,24 @@ static_ipkg() echo "------------------------" 1>> ${LFS_LOG_FILE} echo "Installing" ${LABEL} 1>> ${LFS_LOG_FILE} - decompress_package ${PACKAGE_NAME} 1>> ${PACKAGE_LOG} 2>&1 + echo "Decompressing package" 1>> ${PACKAGE_LOG} 2>&1 && + decompress_package ${PACKAGE_NAME} 1> /dev/null 2>> ${PACKAGE_LOG} eval_retval2 - # Get the name of the decompressed directory local DECOMPRESSED_DIRNAME=$(static_decompressed_dirname ${PACKAGE_NAME}) + # Rename the decompressed package as per the package name if necessary + if [ "x${DECOMPRESSED_DIRNAME}" != "x${PACKAGE_NAME}" ]; then + mv ${LFS_TMP}/${DECOMPRESSED_DIRNAME} ${LFS_TMP}/${PACKAGE_NAME} || exit 1 + fi + # Displaying package source size in log file - echo " Source size:" $(du -h -s ${LFS_TMP}/${DECOMPRESSED_DIRNAME} | awk '{ print $1 }') 1>> ${LFS_LOG_FILE} + echo " Source size:" $(du -h -s ${LFS_TMP}/${PACKAGE_NAME} | awk '{ print $1 }') 1>> ${LFS_LOG_FILE} # Removing old build directory (if any) if [ -d ${LFS_TMP}/${PACKAGE_NAME}-build ]; then - rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1>> ${PACKAGE_LOG} 2>&1 + echo "Removing old build directory" 1>> ${PACKAGE_LOG} 2>&1 && + rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1> /dev/null 2>> ${PACKAGE_LOG} eval_retval2 fi @@ -817,19 +795,21 @@ static_ipkg() eval_retval2 # Displaying package build size in log file - BUILD_SIZE=$(du -h -s -c ${LFS_TMP}/${DECOMPRESSED_DIRNAME} ${LFS_TMP}/${PACKAGE_NAME}-build | grep total | awk '{ print $1 }') + BUILD_SIZE=$(du -h -s -c ${LFS_TMP}/${PACKAGE_NAME} ${LFS_TMP}/${PACKAGE_NAME}-build | grep total | awk '{ print $1 }') echo " Build size : ${BUILD_SIZE}" 1>> ${LFS_LOG_FILE} # Some scripts need to preserve the source or build directory. They can # do so by renaming them. - if [ -d ${LFS_TMP}/${DECOMPRESSED_DIRNAME} ]; then + if [ -d ${LFS_TMP}/${PACKAGE_NAME} ]; then # Removing source directory - rm -v -rf ${LFS_TMP}/${DECOMPRESSED_DIRNAME} 1>> ${PACKAGE_LOG} 2>&1 + echo "Removing source directory" 1>> ${PACKAGE_LOG} 2>&1 && + rm -v -rf ${LFS_TMP}/${PACKAGE_NAME} 1> /dev/null 2>> ${PACKAGE_LOG} eval_retval2 fi if [ -d ${LFS_TMP}/${PACKAGE_NAME}-build ]; then # Removing build directory - rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1>> ${PACKAGE_LOG} 2>&1 + echo "Removing build directory" 1>> ${PACKAGE_LOG} 2>&1 && + rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1> /dev/null 2>> ${PACKAGE_LOG} eval_retval2 fi @@ -845,7 +825,6 @@ static_ipkg() return $EXIT_SUCCESS } - # Display the action name, run a command, log its output and display it's # status # First argument: action name (string) @@ -871,7 +850,6 @@ action_checkbox() return $EXIT_SUCCESS } - # Display the action name, run a command, log its output and display it's # status and the time it took to execute. # Note: In case of errors, this function returns an error code instead @@ -905,16 +883,16 @@ action_checkbox_time() fi } - # Display the action name, run a command, log its output and display it's # status. Write to install log file when successfully completed so it # won't be called again after a successfull installation. -# First argument: label (string) -# Second argument: script name +# First argument: Message to display during action +# Second argument: script name (will be label) run_script_log() { - LABEL=${1} + MSGSTRING=${1} SCRIPT=${2} + LABEL=${SCRIPT} # Checking for correct number of arguments if [ $# -lt 2 ]; then @@ -941,7 +919,7 @@ run_script_log() fi # Displaying script name - echo -n "[ ] ${LABEL}" + echo -n "[ ] ${MSGSTRING}" echo "------------------------" 1>> ${LFS_LOG_FILE} echo "Running " ${LABEL} 1>> ${LFS_LOG_FILE} echo 1>> ${LFS_LOG_FILE} @@ -959,7 +937,6 @@ run_script_log() return $EXIT_SUCCESS } - # Display the action name, run a command, log its output and display it's # status. Write to install log file when successfully completed so it # won't be called again after a successfull installation. @@ -1002,7 +979,6 @@ run_cmd_log() return $EXIT_SUCCESS } - get_total_build_time() { INFILE=${1} @@ -1030,7 +1006,6 @@ get_total_build_time() echo "${HOURS}.${MIN}" } - display_build_time() { END_TIME=$(echo `date +%s`) @@ -1059,7 +1034,6 @@ display_build_time() echo "h" 1>> ${LFS_LOG_FILE} } - # The print_status prints a coloured "X" letter inside the checkbox to the left # of the screen (the checkbox is displayed with the action_checkbox function). print_status() @@ -1090,7 +1064,6 @@ print_status() $NORMAL } - # Testing GCC toolchain gcc_toolchain_test_stage1() {