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