This repository has been archived on 2024-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
MahiroOS-jhalfs/jhalfs
2012-02-22 09:18:56 +00:00

485 lines
15 KiB
Bash
Executable file

#!/bin/bash
# $Id$
set -e
# VT100 colors
declare -r BLACK=$'\e[1;30m'
declare -r DK_GRAY=$'\e[0;30m'
declare -r RED=$'\e[31m'
declare -r GREEN=$'\e[32m'
declare -r YELLOW=$'\e[33m'
declare -r BLUE=$'\e[34m'
declare -r MAGENTA=$'\e[35m'
declare -r CYAN=$'\e[36m'
declare -r WHITE=$'\e[37m'
declare -r OFF=$'\e[0m'
declare -r BOLD=$'\e[1m'
declare -r REVERSE=$'\e[7m'
declare -r HIDDEN=$'\e[8m'
declare -r tab_=$'\t'
declare -r nl_=$'\n'
declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
# bold yellow > < pair
declare -r R_arrow=$'\e[1;33m>\e[0m'
declare -r L_arrow=$'\e[1;33m<\e[0m'
#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
#-----------------------#
simple_error() { # Basic error trap.... JUST DIE
#-----------------------#
# If +e then disable text output
if [[ "$-" =~ e ]]; then
echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
fi
}
see_ya() {
echo -e "\n${L_arrow}${BOLD}jhalfs-trunk${R_arrow} exit${OFF}\n"
}
##### Simple error TRAPS
# ctrl-c SIGINT
# ctrl-y
# ctrl-z SIGTSTP
# SIGHUP 1 HANGUP
# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
# SIGQUIT 3
# SIGKILL 9 KILL
# SIGTERM 15 TERMINATION
# SIGSTOP 17,18,23 STOP THE PROCESS
#####
set -e
trap see_ya 0
trap simple_error ERR
trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
version="
${BOLD} \"jhalfs-trunk\"${OFF} builder tool (development) \$Rev$
\$Date$
Written by George Boudreau and Manuel Canales Esparcia,
plus several contributions.
Based on an idea from Jeremy Huntwork
This set of files are published under the
${BOLD}Gnu General Public License, Version 2.${OFF}
"
case $1 in
-v ) echo "$version" && exit 1 ;;
run ) : ;;
* )
echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
exit 1
;;
esac
VERBOSITY=1
[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
source configuration
[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[[ $VERBOSITY > 0 ]] && echo "OK"
# These are boolean vars generated from Config.in.
# ISSUE: If a boolean parameter is not set to y(es) there
# is no variable defined by the menu app. This can
# cause a headache if you are not aware.
# The following variables MUST exist. If they don't, the
# default value is n(o).
RUNMAKE=${RUNMAKE:-n}
GETPKG=${GETPKG:-n}
COMPARE=${COMPARE:-n}
RUN_FARCE=${RUN_FARCE:-n}
RUN_ICA=${RUN_ICA:-n}
PKGMNGT=${PKGMNGT:-n}
BOMB_TEST=${BOMB_TEST:-n}
STRIP=${STRIP:=n}
REPORT=${REPORT:=n}
VIMLANG=${VIMLANG:-n}
FULL_LOCALE=${FULL_LOCALE:-n}
GRSECURITY_HOST=${GRSECURITY_HOST:-n}
CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
INSTALL_LOG=${INSTALL_LOG:-n}
CLEAN=${CLEAN:=n}
SET_SSP=${SET_SSP:=n}
SET_ASLR=${SET_ASLR:=n}
SET_PAX=${SET_PAX:=n}
SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
SET_WARNINGS=${SET_WARNINGS:=n}
SET_MISC=${SET_MISC:=n}
SET_BLOWFISH=${SET_BLOWFISH:=n}
if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
NO_PROGRESS="#"
fi
# Sanity check on the location of $BUILDDIR / $JHALFSDIR
CWD=$(cd `dirname $0` && pwd)
if [[ $JHALFSDIR == $CWD ]]; then
echo " The jhalfs source directory conflicts with the jhalfs build directory."
echo " Please move the source directory or change the build directory."
exit 2
fi
# Book sources envars
BRANCH_ID=${BRANCH_ID:=development}
case $BRANCH_ID in
development )
case $PROGNAME in
clfs2 ) TREE=branches/clfs-sysroot/BOOK ;;
clfs3 ) TREE=branches/clfs-embedded/BOOK ;;
*) TREE=trunk/BOOK ;;
esac
LFSVRS=development
;;
*EDIT* ) echo " You forgot to set the branch or stable book version."
echo " Please rerun make and fix the configuration."
exit 2 ;;
branch-* )
LFSVRS=${BRANCH_ID}
TREE=branches/${BRANCH_ID#branch-}/BOOK
;;
* )
case $PROGNAME in
lfs )
LFSVRS=${BRANCH_ID}
TREE=tags/${BRANCH_ID}
if (( ${BRANCH_ID:0:1} < 7 )) ; then
TREE=${TREE}/BOOK
fi
;;
hlfs )
LFSVRS=${BRANCH_ID}
TREE=tags/${BRANCH_ID}/BOOK
;;
clfs | clfs2 | clfs3)
LFSVRS=${BRANCH_ID}
TREE=tags/${BRANCH_ID}
;;
esac
;;
esac
# Set the document location...
BOOK=${BOOK:=$PROGNAME-$LFSVRS}
# blfs-tool envars
BLFS_TOOL=${BLFS_TOOL:-n}
if [[ "${BLFS_TOOL}" = "y" ]] ; then
BLFS_BRANCH_ID=${BLFS_BRANCH_ID:=development}
case $BLFS_BRANCH_ID in
development ) BLFS_TREE=trunk/BOOK ;;
*EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
echo " Please rerun make and fix the configuration."
exit 2 ;;
branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
* ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
esac
# Dependencies envars, easier to update.
# Tidy and Unzip version are harcoded also in wrt_blfs_tool_targets()
# libxml2
LIBXML_PKG="libxml2-2.7.8.tar.gz"
LIBXML_URL="ftp://xmlsoft.org/libxml2/${LIBXML_PKG}"
LIBXML_MD5="8127a65e8c3b08856093099b52599c86"
# libxslt
LIBXSLT_PKG="libxslt-1.1.26.tar.gz"
LIBXSLT_URL="ftp://xmlsoft.org/libxslt/${LIBXSLT_PKG}"
LIBXSLT_MD5="e61d0364a30146aaa3001296f853b2b9"
# tidy
TIDY_PKG="tidy-cvs_20101110.tar.bz2"
TIDY_URL="http://anduin.linuxfromscratch.org/sources/BLFS/svn/t/${TIDY_PKG}"
TIDY_MD5="dd1fe109b4259ad3f364b175787ad5e9"
# unzip
UNZIP_PKG="unzip60.tar.gz"
UNZIP_URL="http://downloads.sourceforge.net/infozip/${UNZIP_PKG}"
UNZIP_MD5="62b490407489521db863b523a7f86375"
# DocBook XML DTD
DBXML_PKG="docbook-xml-4.5.zip"
DBXML_URL="http://www.docbook.org/xml/4.5/${DBXML_PKG}"
DBXML_MD5="03083e288e87a7e829e437358da7ef9e"
# DocBook XSL
# DBXSL_PKG="docbook-xsl-1.69.1.tar.bz2"
# DBXSL_URL="http://prdownloads.sourceforge.net/docbook/${DBXSL_PKG}"
# DBXSL_MD5="6ebd29a67f2dcc3f2220f475ee6f6552"
# Lynx
LYNX_PKG="lynx2.8.8dev.10.tar.bz2"
LYNX_URL="http://lynx.isc.org/current/${LYNX_PKG}"
LYNX_MD5="1c9ef3746520c69914b461f88de6b12e"
# sudo
SUDO_PKG="sudo-1.8.2.tar.gz"
SUDO_URL="http://www.sudo.ws/sudo/dist/${SUDO_PKG}"
SUDO_MD5="000f458e7391be9fdf459a9ad6a4912a"
# wget
WGET_PKG="wget-1.13.4.tar.xz"
WGET_URL="ftp://ftp.gnu.org/gnu/wget/${WGET_PKG}"
WGET_MD5="7f518b3a71e9efd330e9a0c3714f8463"
# SQLite (for subversion)
SQLITE_PKG="sqlite-autoconf-3071000.tar.gz"
SQLITE_URL="http://sqlite.org/${SQLITE_PKG}"
SQLITE_MD5="9ed2ca93577b58cfa0d01f64b9312ab9"
# Apache Portable Runtime (for subversion)
APR_PKG="apr-1.4.5.tar.bz2"
APR_URL="http://mirror.speednetwork.de/apache/apr/$APR_PKG"
APR_MD5="8b53f5a5669d0597f2da889a2f576eb6"
# APR config patch
APR_PATCH_1="apr-1.4.5-config.patch"
APR_PATCH_1_URL="file:///sources/local-patches/${APR_PATCH_1}"
APR_PATCH_1_MD5="fff6eddf998f4e956915f8053c15e41e"
# Apache Portable Runtime Utilities (for subversion)
APR_U_PKG="apr-util-1.4.1.tar.bz2"
APR_U_URL="http://mirrors.ircam.fr/pub/apache/apr/$APR_U_PKG"
APR_U_MD5="52b31b33fb1aa16e65ddaefc76e41151"
# APR-util config patch
APR_U_PATCH_1="apr-util-1.4.1-config.patch"
APR_U_PATCH_1_URL="file:///sources/local-patches/${APR_U_PATCH_1}"
APR_U_PATCH_1_MD5="4c07cb0d298ae9ddc75cd2d5acdedb2b"
# Subversion
SVN_PKG="subversion-1.7.1.tar.bz2"
SVN_URL="http://archive.apache.org/dist/subversion/${SVN_PKG}"
SVN_MD5="8a4fa74385df85a9702141b6b68b8307"
# GPM
GPM_PKG="gpm-1.20.6.tar.bz2"
GPM_URL="http://www.nico.schottelius.org/software/gpm/archives/$GPM_PKG"
GPM_MD5="6b534da16dc1b28ba828dea89e520f6f"
fi
#--- Envars not sourced from configuration
case $PROGNAME in
# TODO: clfs is now on git
# clfs* ) declare -r SVN="http://svn.cross-lfs.org/svn/repos" ;;
* ) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
esac
declare -r LOG=000-masterscript.log
# Needed for fetching BLFS book sources when building CLFS
declare -r SVN_2="svn://svn.linuxfromscratch.org"
# Set true internal variables
COMMON_DIR="common"
PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
MODULE=$PACKAGE_DIR/master.sh
PKGMNGTDIR="pkgmngt"
# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
source $COMMON_DIR/common-functions
[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
source $MODULE
[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
#
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
#*******************************************************************#
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
source $COMMON_DIR/libs/func_check_version.sh
[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
source $COMMON_DIR/libs/func_validate_configs.sh
[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
source $COMMON_DIR/libs/func_custom_pkgs
[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
###################################
### MAIN ###
###################################
# Check for build prerequisites.
echo
check_prerequisites
echo "${SD_BORDER}${nl_}"
validate_config
echo "${SD_BORDER}${nl_}"
echo -n "Are you happy with these settings? yes/no (no): "
read ANSWER
if [ x$ANSWER != "xyes" ] ; then
echo "${nl_}Rerun make to fix the configuration options.${nl_}"
exit 1
fi
echo "${nl_}${SD_BORDER}${nl_}"
# Load additional modules or configuration files based on global settings
# compare module
if [[ "$COMPARE" = "y" ]]; then
[[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
source $COMMON_DIR/libs/func_compare.sh
[[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
fi
#
# optimize module
if [[ "$OPTIMIZE" != "0" ]]; then
[[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
source optimize/optimize_functions
[[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
#
# optimize configurations
[[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
source optimize/opt_config
[[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
# Validate optimize settings, if required
validate_opt_settings
fi
#
if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
# and notify the user about that.
if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
eval "$no_empty_builddir"
fi
# If requested, clean the build directory
clean_builddir
if [[ ! -d $JHALFSDIR ]]; then
mkdir -p $JHALFSDIR
fi
# Create $BUILDDIR/sources even though it could be created by get_sources()
if [[ ! -d $BUILDDIR/sources ]]; then
mkdir -p $BUILDDIR/sources
fi
#
# Create the log directory
if [[ ! -d $LOGDIR ]]; then
mkdir $LOGDIR
fi
>$LOGDIR/$LOG
#
# Copy common helper files
cp $COMMON_DIR/{makefile-functions,progress_bar.sh,packages.xsl} $JHALFSDIR/
#
# Fix the XSL book parser
sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
export XSL=$JHALFSDIR/${XSL}
#
# Copy packageManager.xml, if needed
[[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] &&
cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/ &&
cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
#
# Copy urls.xsl, if needed
[[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
#
# Copy APR patches, if needed
[[ "$DEP_SVN" = "y" ]] &&
cp $COMMON_DIR/blfs-tool-deps/apr*.patch $BUILDDIR/sources
#
# Create the test-log directory, if needed
[[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
#
# Create the installed-files directory, if needed
[[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
#
# Prepare report creation, if needed
if [[ "$REPORT" = "y" ]]; then
cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
# After making sure that all looks sane, dump the settings to a file
# This file will be used to create the REPORT header
validate_config > $JHALFSDIR/jhalfs.config
fi
#
# Copy optimize files, if needed
[[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
#
# Copy compare files, if needed
if [[ "$COMPARE" = "y" ]]; then
mkdir -p $JHALFSDIR/extras
cp extras/* $JHALFSDIR/extras
fi
#
# Copy custom tools config files, if requested
if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
echo "Copying custom tool scripts to $JHALFSDIR"
mkdir -p $JHALFSDIR/custom-commands
cp -f custom/config/* $JHALFSDIR/custom-commands
fi
#
# Install blfs-tool, if requested.
if [[ "${BLFS_TOOL}" = "y" ]] ; then
# Install the files
[[ ! -d ${BUILDDIR}${BLFS_ROOT} ]] && mkdir -p ${BUILDDIR}${BLFS_ROOT}
cp -r BLFS/* ${BUILDDIR}${BLFS_ROOT}
cp -r menu ${BUILDDIR}${BLFS_ROOT}
cp $COMMON_DIR/progress_bar.sh ${BUILDDIR}${BLFS_ROOT}
cp README.BLFS ${BUILDDIR}${BLFS_ROOT}
# Clean-up
rm -rf ${BUILDDIR}${BLFS_ROOT}/libs/.svn
rm -rf ${BUILDDIR}${BLFS_ROOT}/menu/.svn
rm -rf ${BUILDDIR}${BLFS_ROOT}/menu/lxdialog/.svn
# Set some harcoded envars to their proper values
sed -i 's,blfs-xml,'$BLFS_XML',' ${BUILDDIR}${BLFS_ROOT}/{update_book.sh,libs/book.xsl}
sed -i 's,tracking-dir,'$TRACKING_DIR',' ${BUILDDIR}${BLFS_ROOT}/{update_book.sh,gen-makefile.sh}
# Copy the dependencies build scripts
cp -r $COMMON_DIR/blfs-tool-deps $JHALFSDIR/
rm -rf $JHALFSDIR/blfs-tool-deps/.svn
fi
#
get_book
echo "${SD_BORDER}${nl_}"
# Get the BLFS book, if requested.
if [[ "${BLFS_TOOL}" = "y" ]] ; then
echo -n "Downloading the BLFS document, $BLFS_BRANCH_ID version... "
if [[ ! -d ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} ]] ; then
mkdir -p ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML}
svn co $SVN_2/BLFS/$BLFS_TREE ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} >>$LOGDIR/$LOG 2>&1
else
pushd ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} 1> /dev/null
svn up >>$LOGDIR/$LOG 2>&1
popd 1> /dev/null
fi
echo -ne "done\n"
echo "${SD_BORDER}${nl_}"
fi
fi
# When regenerating the Makefile, we need to know also the canonical book version
if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
case $PROGNAME in
clfs | clfs2 | clfs3 )
VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
*)
VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
esac
fi
build_Makefile
echo "${SD_BORDER}${nl_}"
run_make