+lfsmake2() {
+ lfsmakecommoncheck $*
+ [ $? == 1 ] && return 0
+
+ local PS1='\u:\w$ '
+
+ enterchroot \
+ bash -x -c "cd /usr/src/lfs && \
+ MAKETUNING=${MAKETUNING} \
+ make -f $* \
+ LFS_BASEDIR=/usr/src install" \
+ >> ${LOGFILE} 2>&1 &
+
+ if ! wait_until_finished $!; then
+ print_status FAIL
+ exiterror "Building $*"
+ fi
+
+ print_status DONE
+}
+
+ipfiredist() {
+ lfsmakecommoncheck $*
+ [ $? == 1 ] && return 0
+
+ local PS1='\u:\w$ '
+
+ enterchroot \
+ bash -x -c "cd /usr/src/lfs && make -f $* LFS_BASEDIR=/usr/src dist" \
+ >> ${LOGFILE} 2>&1 &
+
+ if ! wait_until_finished $!; then
+ print_status FAIL
+ exiterror "Packaging $*"
+ fi
+
+ print_status DONE
+}
+
+wait_until_finished() {
+ local pid=${1}
+
+ local start_time=$(now)
+
+ # Show progress
+ if ${INTERACTIVE}; then
+ # Wait a little just in case the process
+ # has finished very quickly.
+ sleep 0.1
+
+ local runtime
+ while kill -0 ${pid} 2>/dev/null; do
+ print_runtime $(( $(now) - ${start_time} ))
+
+ # Wait a little
+ sleep 1
+ done
+ fi
+
+ # Returns the exit code of the child process
+ wait ${pid}
+ local ret=$?
+
+ if ! ${INTERACTIVE}; then
+ print_runtime $(( $(now) - ${start_time} ))
+ fi
+
+ return ${ret}
+}
+
+fake_environ() {
+ [ -e "${BASEDIR}/build${TOOLS_DIR}/lib/libpakfire_preload.so" ] || return
+
+ local env="LD_PRELOAD=${TOOLS_DIR}/lib/libpakfire_preload.so"
+
+ # Fake kernel version, because some of the packages do not compile
+ # with kernel 3.0 and later.
+ env="${env} UTS_RELEASE=${KVER}"
+
+ # Fake machine version.
+ env="${env} UTS_MACHINE=${BUILD_ARCH}"
+
+ echo "${env}"
+}
+
+qemu_environ() {
+ local env
+
+ # Don't add anything if qemu is not used.
+ if ! qemu_is_required; then
+ return
+ fi
+
+ # Set default qemu options
+ case "${BUILD_ARCH}" in
+ arm*)
+ QEMU_CPU="${QEMU_CPU:-cortex-a9}"
+
+ env="${env} QEMU_CPU=${QEMU_CPU}"
+ ;;
+ esac
+
+ # Enable QEMU strace
+ #env="${env} QEMU_STRACE=1"
+
+ echo "${env}"
+}
+
+qemu_is_required() {
+ local build_arch="${1}"
+
+ if [ -z "${build_arch}" ]; then
+ build_arch="${BUILD_ARCH}"
+ fi
+
+ case "${HOST_ARCH},${build_arch}" in
+ x86_64,arm*|i?86,arm*|i?86,x86_64)
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
+
+qemu_install_helper() {
+ # Do nothing, if qemu is not required
+ if ! qemu_is_required; then
+ return 0
+ fi
+
+ if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then
+ exiterror "binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
+ fi
+
+ if [ ! $(cat /proc/sys/fs/binfmt_misc/status) = 'enabled' ]; then
+ exiterror "binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
+ fi
+
+
+ if [ -z "${QEMU_TARGET_HELPER}" ]; then
+ exiterror "QEMU_TARGET_HELPER not set"
+ fi
+
+ # Check if the helper is already installed.
+ if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
+ return 0
+ fi
+
+ # Try to find a suitable binary that we can install
+ # to the build environment.
+ local file
+ for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
+ # file must exist and be executable.
+ [ -x "${file}" ] || continue
+
+ # Must be static.
+ file_is_static "${file}" || continue
+
+ local dirname="${LFS}$(dirname "${file}")"
+ mkdir -p "${dirname}"
+
+ install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
+ return 0
+ done
+
+ exiterror "Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
+}
+
+qemu_find_build_helper_name() {
+ local build_arch="${1}"
+
+ local magic
+ case "${build_arch}" in
+ arm*)
+ magic="7f454c4601010100000000000000000002002800"
+ ;;
+ x86_64)
+ magic="7f454c4602010100000000000000000002003e00"
+ ;;
+ esac
+
+ [ -z "${magic}" ] && return 1
+
+ local file
+ for file in /proc/sys/fs/binfmt_misc/*; do
+ # skip write only register entry
+ [ $(basename "${file}") = "register" ] && continue
+ # Search for the file with the correct magic value.
+ grep -qE "^magic ${magic}$" "${file}" || continue
+
+ local interpreter="$(grep "^interpreter" "${file}" | awk '{ print $2 }')"
+
+ [ -n "${interpreter}" ] || continue
+ [ "${interpreter:0:1}" = "/" ] || continue
+ [ -x "${interpreter}" ] || continue
+
+ echo "${interpreter}"
+ return 0
+ done
+
+ return 1
+}
+
+file_is_static() {
+ local file="${1}"
+
+ file ${file} 2>/dev/null | grep -q "statically linked"
+}
+
+update_language_list() {
+ local path="${1}"
+
+ local lang
+ for lang in ${path}/*.po; do
+ lang="$(basename "${lang}")"
+ echo "${lang%*.po}"
+ done | sort -u > "${path}/LINGUAS"
+}
+
+# Load configuration file
+if [ -f .config ]; then
+ . .config
+fi
+
+# TARGET_ARCH is BUILD_ARCH now
+if [ -n "${TARGET_ARCH}" ]; then
+ BUILD_ARCH="${TARGET_ARCH}"
+ unset TARGET_ARCH
+fi
+
+# Get the amount of memory in this build system
+HOST_MEM=$(system_memory)
+
+if [ -n "${BUILD_ARCH}" ]; then
+ configure_build "${BUILD_ARCH}"
+else
+ configure_build "default"
+fi
+