X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions;h=1fb9fa43c3af5728aede071c0b4586a48b338fb0;hb=6a47d6d86ad7ac2d58c56499baaedb9fdd0aa800;hp=a986466fa5baaa971a88aedcbe09d76cc9f4eb76;hpb=16cc35ba4890382ee9368a176e4f5a7fa773b7a6;p=hvlinux.git diff --git a/functions b/functions index a986466..1fb9fa4 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" | sed 's!\.$!!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 @@ -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,7 +522,7 @@ 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. @@ -559,7 +539,6 @@ apply_patches() return $? } - # Applying patch # First argument is the name of the patch # Second argument is the package name @@ -586,7 +565,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) @@ -610,11 +588,9 @@ decompress_package() 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 +600,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 +608,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 +647,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 +669,6 @@ ipkg_ac_nb() static_ipkg ${PACKAGE} cis-ac-nobuild ${PACKAGE} ${CONFIGURE_OPTS} } - # Installation of a GNOME package. # # First argument: package name @@ -707,7 +685,6 @@ ipkg_gnome() static_ipkg ${1} cis-gnome ${1} } - # Installation of a PERL module # # First argument: package name @@ -724,7 +701,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 +721,6 @@ ipkg_mult() static_ipkg ${1} ${2} ${3} } - # Installation of a package # # First argument: Real package name @@ -779,7 +754,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} \ @@ -796,11 +771,15 @@ static_ipkg() decompress_package ${PACKAGE_NAME} 1>> ${PACKAGE_LOG} 2>&1 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 @@ -817,14 +796,14 @@ 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 + rm -v -rf ${LFS_TMP}/${PACKAGE_NAME} 1>> ${PACKAGE_LOG} 2>&1 eval_retval2 fi if [ -d ${LFS_TMP}/${PACKAGE_NAME}-build ]; then @@ -845,7 +824,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 +849,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 +882,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 +918,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 +936,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 +978,6 @@ run_cmd_log() return $EXIT_SUCCESS } - get_total_build_time() { INFILE=${1} @@ -1030,7 +1005,6 @@ get_total_build_time() echo "${HOURS}.${MIN}" } - display_build_time() { END_TIME=$(echo `date +%s`) @@ -1059,7 +1033,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 +1063,6 @@ print_status() $NORMAL } - # Testing GCC toolchain gcc_toolchain_test_stage1() {