# 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
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()
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()
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()
echo ${1} | sed "s!^\(.*\)-.*!\1!g"
}
-
# Saves the content of CFLAGS and CXXFLAGS environment variables.
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()
return ${EXIT_SUCCESS}
}
-
# Restores the previous values of CFLAGS and CXXFLAGS environment variables. These
# must have been saved first using save_flags().
restore_flags()
return ${EXIT_SUCCESS}
}
-
# Create log directory and log file for current stage if necessary
# This should be done automatically...
init_log_file()
fi
}
-
# Create symbolic links for start/stop scripts in /etc/rc.d
#
# Arg #1: script name
fi
}
-
# Create symbolic links for start/stop scripts in /etc/rc.d
#
# Arg #1: level
fi
}
-
# Create symbolic links for start/stop scripts in /etc/rc.d
#
# Arg #1: script name
static_bootscript_add ${*} 3
}
-
# Create symbolic links for start/stop scripts in /etc/rc.d
#
# Arg #1: script name
static_bootscript_add ${*} S
}
-
# Add "export" before the variable name
#
# Arg #1: variable name
sed -i "s!\(^${VARIABLE}=.*\)!export \1!" ${FILE}
}
-
# Adding a new environment variable to a file.
#
# Arg #1: variable name
return $?
}
-
# Adding a new path environment variable to a file.
#
# Arg #1: variable name
var_add ${1} ${2} "${3}" ":" 1>> ${LFS_LOG_FILE} 2>&1
}
-
# Adding a new string environment variable to a file.
#
# Arg #1: variable name
var_add ${1} ${2} "${3}" " "
}
-
# Adding a new string to a file.
#
# Arg #1: string
echo "${STRING}" >> ${FILE}
}
-
# Adding a new environment variable to a shadow password suite file (login.defs)
#
# Arg #1: variable name
# 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
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()
fi
}
-
# Evaluates the return value of the process that was run just before this
# function was called.
evaluate_retval()
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:
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
return $?
}
-
# Applying patch
# First argument is the name of the patch
# Second argument is the package name
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)
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
cd - 1> /dev/null 2>&1
}
-
# Installation of a package, removing source and build directories after.
#
# First argument: package name
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
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.
#
static_ipkg ${PACKAGE} cis-ac-nobuild ${PACKAGE} ${CONFIGURE_OPTS}
}
-
# Installation of a GNOME package.
#
# First argument: package name
static_ipkg ${1} cis-gnome ${1}
}
-
# Installation of a PERL module
#
# First argument: package name
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.
static_ipkg ${1} ${2} ${3}
}
-
# Installation of a package
#
# First argument: Real package name
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} \
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
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
return $EXIT_SUCCESS
}
-
# Display the action name, run a command, log its output and display it's
# status
# First argument: action name (string)
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
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
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}
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.
return $EXIT_SUCCESS
}
-
get_total_build_time()
{
INFILE=${1}
echo "${HOURS}.${MIN}"
}
-
display_build_time()
{
END_TIME=$(echo `date +%s`)
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()
$NORMAL
}
-
# Testing GCC toolchain
gcc_toolchain_test_stage1()
{