[f4ed135] | 1 | #!/bin/bash
|
---|
| 2 | #
|
---|
| 3 | # $Id$
|
---|
| 4 | #
|
---|
| 5 | # Read and parse the configuration parameters..
|
---|
| 6 | #
|
---|
| 7 | set -e
|
---|
| 8 |
|
---|
[e576789] | 9 | TOPDIR=$1
|
---|
| 10 | if test -z "$TOPDIR"; then
|
---|
| 11 | TOPDIR=$(pwd)
|
---|
| 12 | fi
|
---|
| 13 | BLFS_FULL=$2
|
---|
| 14 | if test -z "$BLFS_FULL"; then
|
---|
| 15 | BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
|
---|
| 16 | fi
|
---|
| 17 | declare -r ConfigFile="${TOPDIR}/configuration"
|
---|
| 18 | declare DepDir="${TOPDIR}/dependencies"
|
---|
| 19 | declare LibDir="${TOPDIR}/libs"
|
---|
| 20 | declare PackFile="${TOPDIR}/packages.xml"
|
---|
| 21 | declare BookXml="${TOPDIR}/book.xml"
|
---|
| 22 | declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
|
---|
| 23 | declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
|
---|
| 24 | declare BookHtml="${TOPDIR}/book-html"
|
---|
| 25 | declare BLFS_XML="${TOPDIR}/blfs-xml"
|
---|
| 26 | declare -a TARGET
|
---|
[f4ed135] | 27 | declare DEP_LEVEL
|
---|
| 28 | declare SUDO
|
---|
| 29 |
|
---|
| 30 | #--------------------------#
|
---|
| 31 | parse_configuration() { #
|
---|
| 32 | #--------------------------#
|
---|
[e576789] | 33 | local -i cntr=0
|
---|
| 34 | local -a optTARGET
|
---|
[f4ed135] | 35 |
|
---|
[e576789] | 36 | while read; do
|
---|
[f4ed135] | 37 |
|
---|
| 38 | # Garbage collection
|
---|
| 39 | case ${REPLY} in
|
---|
| 40 | \#* | '') continue ;;
|
---|
| 41 | esac
|
---|
| 42 |
|
---|
| 43 | case "${REPLY}" in
|
---|
| 44 | # Create global variables for these parameters.
|
---|
| 45 | optDependency=* | \
|
---|
| 46 | MAIL_SERVER=* | \
|
---|
| 47 | SUDO=* ) eval ${REPLY} # Define/set a global variable..
|
---|
| 48 | continue ;;
|
---|
| 49 | esac
|
---|
| 50 |
|
---|
[a96109a] | 51 | if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
|
---|
[e576789] | 52 | echo "$REPLY"
|
---|
| 53 | optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
|
---|
[f4ed135] | 54 | fi
|
---|
[e576789] | 55 | done < $ConfigFile
|
---|
[f4ed135] | 56 |
|
---|
[e576789] | 57 | if (( $cntr == 0 )); then
|
---|
| 58 | echo -e "\n>>> NO TARGET SELECTED.. application terminated"
|
---|
| 59 | echo -e " Run <make> again and select (a) package(s) to build\n"
|
---|
[f4ed135] | 60 | exit 0
|
---|
| 61 | fi
|
---|
[e576789] | 62 | TARGET=(${optTARGET[*]})
|
---|
[f4ed135] | 63 | DEP_LEVEL=$optDependency
|
---|
| 64 | SUDO=${SUDO:-n}
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | #--------------------------#
|
---|
| 68 | validate_configuration() { #
|
---|
| 69 | #--------------------------#
|
---|
| 70 | local -r dotSTR=".................."
|
---|
[e576789] | 71 | local -r PARAM_LIST="DEP_LEVEL SUDO MAIL_SERVER"
|
---|
[f4ed135] | 72 | local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
| 73 | local config_param
|
---|
[e576789] | 74 | local -i index
|
---|
[f4ed135] | 75 |
|
---|
| 76 | for config_param in ${PARAM_LIST}; do
|
---|
| 77 | echo -e "`eval echo $PARAM_VALS`"
|
---|
| 78 | done
|
---|
[e576789] | 79 | for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
|
---|
| 80 | echo -e "TARGET${index}${dotSTR:6} ${L_arrow}${BOLD}${TARGET[${index}]}${OFF}${R_arrow}"
|
---|
| 81 | done
|
---|
[f4ed135] | 82 | }
|
---|
| 83 |
|
---|
| 84 | #
|
---|
[e576789] | 85 | # Generates the root of the dependency tree
|
---|
[f4ed135] | 86 | #
|
---|
| 87 | #--------------------------#
|
---|
[e576789] | 88 | generate_deps() { #
|
---|
[f4ed135] | 89 | #--------------------------#
|
---|
| 90 |
|
---|
[e576789] | 91 | local -i index
|
---|
| 92 | local DepDir=$1
|
---|
[7dc8595] | 93 | rm -f $DepDir/*.{o,}dep
|
---|
[e576789] | 94 | for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
|
---|
[7dc8595] | 95 | echo 1 ${TARGET[${index}]} >> $DepDir/root.odep
|
---|
[f4ed135] | 96 | done
|
---|
[7dc8595] | 97 | echo 1 > $DepDir/root.dep
|
---|
| 98 | echo 1 >> $DepDir/root.dep
|
---|
| 99 | cat $DepDir/root.odep >> $DepDir/root.dep
|
---|
[f4ed135] | 100 | }
|
---|
| 101 |
|
---|
| 102 | #
|
---|
| 103 | # Clean configuration file keeping only global default settings.
|
---|
| 104 | # That prevent "trying to assign nonexistent symbol" messages
|
---|
| 105 | # and assures that there is no TARGET selected from a previous run
|
---|
| 106 | #
|
---|
| 107 | #--------------------------#
|
---|
| 108 | clean_configuration() { #
|
---|
| 109 | #--------------------------#
|
---|
| 110 |
|
---|
[e576789] | 111 | tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
|
---|
| 112 | mv ${ConfigFile}.tmp ${ConfigFile}
|
---|
[f4ed135] | 113 |
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | #---------------------
|
---|
| 117 | # Constants
|
---|
[e576789] | 118 | source ${LibDir}/constants.inc
|
---|
[f4ed135] | 119 | [[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
|
---|
| 120 |
|
---|
| 121 | #---------------------
|
---|
| 122 | # Dependencies module
|
---|
[e576789] | 123 | source ${LibDir}/func_dependencies
|
---|
[f4ed135] | 124 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
|
---|
| 125 |
|
---|
| 126 | #------- MAIN --------
|
---|
[e576789] | 127 | if [[ ! -f ${PackFile} ]] ; then
|
---|
[f4ed135] | 128 | echo -e "\tNo packages file has been found.\n"
|
---|
| 129 | echo -e "\tExecution aborted.\n"
|
---|
| 130 | exit 1
|
---|
| 131 | fi
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | parse_configuration
|
---|
| 135 | validate_configuration
|
---|
| 136 | echo "${SD_BORDER}${nl_}"
|
---|
| 137 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
| 138 | read ANSWER
|
---|
| 139 | if [ x$ANSWER != "xyes" ] ; then
|
---|
| 140 | echo "${nl_}Rerun make and fix your settings.${nl_}"
|
---|
| 141 | exit 1
|
---|
| 142 | fi
|
---|
| 143 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
[e576789] | 144 |
|
---|
| 145 | rm -rf $DepDir
|
---|
| 146 | mkdir $DepDir
|
---|
| 147 | generate_deps $DepDir
|
---|
| 148 | pushd $DepDir > /dev/null
|
---|
| 149 | set +e
|
---|
[7dc8595] | 150 | generate_dependency_tree root.dep 1
|
---|
[e576789] | 151 | echo
|
---|
| 152 | LIST="$(tree_browse root.dep)"
|
---|
| 153 | set -e
|
---|
| 154 | popd > /dev/null
|
---|
| 155 | rm -f ${BookXml}
|
---|
| 156 | echo Making XML book
|
---|
| 157 | xsltproc --stringparam list "$LIST" \
|
---|
| 158 | -o ${BookXml} \
|
---|
| 159 | ${MakeBook} \
|
---|
| 160 | $BLFS_FULL
|
---|
| 161 | echo "making HTML book (may take some time...)"
|
---|
| 162 | xsltproc -o ${BookHtml}/ \
|
---|
| 163 | -stringparam chunk.quietly 1 \
|
---|
| 164 | ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
|
---|
| 165 | ${BookXml}
|
---|
| 166 | if [ ! -d ${BookHtml}/stylesheets ]
|
---|
| 167 | then mkdir -p ${BookHtml}/stylesheets
|
---|
| 168 | cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
|
---|
| 169 | fi
|
---|
| 170 | if [ ! -d ${BookHtml}/images ]
|
---|
| 171 | then mkdir -p ${BookHtml}/images
|
---|
| 172 | cp ${BLFS_XML}/images/*.png ${BookHtml}/images
|
---|
| 173 | fi
|
---|
| 174 | for ht in ${BookHtml}/*.html
|
---|
[c5650f9] | 175 | do sed -i 's@\.\./stylesheets@stylesheets@' $ht
|
---|
| 176 | sed -i 's@\.\./images@images@' $ht
|
---|
[e576789] | 177 | done
|
---|
| 178 | echo -en "\n\tGenerating the build scripts ...\n"
|
---|
| 179 | rm -rf scripts
|
---|
| 180 | xsltproc --xinclude --nonet \
|
---|
| 181 | --stringparam sudo $SUDO \
|
---|
| 182 | -o ./scripts/ ${MakeScripts} \
|
---|
| 183 | ${BookXml}
|
---|
| 184 | # Make the scripts executable.
|
---|
| 185 | chmod -R +x scripts
|
---|
| 186 | echo -e "done\n"
|
---|
| 187 |
|
---|
| 188 | #clean_configuration
|
---|