[f4ed135] | 1 | #!/bin/bash
|
---|
| 2 | #
|
---|
| 3 | # Read and parse the configuration parameters..
|
---|
| 4 | #
|
---|
| 5 | set -e
|
---|
| 6 |
|
---|
[e576789] | 7 | TOPDIR=$1
|
---|
| 8 | if test -z "$TOPDIR"; then
|
---|
| 9 | TOPDIR=$(pwd)
|
---|
| 10 | fi
|
---|
| 11 | BLFS_FULL=$2
|
---|
| 12 | if test -z "$BLFS_FULL"; then
|
---|
| 13 | BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
|
---|
| 14 | fi
|
---|
[607ef21] | 15 | LFS_FULL=$3
|
---|
| 16 | if test -z "$LFS_FULL"; then
|
---|
| 17 | LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
|
---|
| 18 | fi
|
---|
[e576789] | 19 | declare -r ConfigFile="${TOPDIR}/configuration"
|
---|
| 20 | declare DepDir="${TOPDIR}/dependencies"
|
---|
| 21 | declare LibDir="${TOPDIR}/libs"
|
---|
| 22 | declare PackFile="${TOPDIR}/packages.xml"
|
---|
| 23 | declare BookXml="${TOPDIR}/book.xml"
|
---|
| 24 | declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
|
---|
[a690d42] | 25 | declare GetVersion="${TOPDIR}/xsl/get_version.xsl"
|
---|
[e576789] | 26 | declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
|
---|
| 27 | declare BookHtml="${TOPDIR}/book-html"
|
---|
| 28 | declare BLFS_XML="${TOPDIR}/blfs-xml"
|
---|
| 29 | declare -a TARGET
|
---|
[f4ed135] | 30 | declare DEP_LEVEL
|
---|
| 31 | declare SUDO
|
---|
[625cb14] | 32 | declare LANGUAGE
|
---|
[945ccaa] | 33 | declare WRAP_INSTALL
|
---|
[9daa202] | 34 | declare PACK_INSTALL
|
---|
[625cb14] | 35 | declare DEL_LA_FILES
|
---|
| 36 | declare STATS
|
---|
[9daa202] | 37 | declare SRC_ARCHIVE
|
---|
| 38 | declare SRC_SUBDIRS
|
---|
| 39 | declare BUILD_ROOT
|
---|
| 40 | declare BUILD_SUBDIRS
|
---|
| 41 | declare KEEP_FILES
|
---|
| 42 | declare -i JOBS
|
---|
| 43 | declare CFG_CFLAGS
|
---|
| 44 | declare CFG_CXXFLAGS
|
---|
| 45 | declare CFG_LDFLAGS
|
---|
[f4ed135] | 46 |
|
---|
| 47 | #--------------------------#
|
---|
| 48 | parse_configuration() { #
|
---|
| 49 | #--------------------------#
|
---|
[e576789] | 50 | local -i cntr=0
|
---|
| 51 | local -a optTARGET
|
---|
[f4ed135] | 52 |
|
---|
[e576789] | 53 | while read; do
|
---|
[f4ed135] | 54 |
|
---|
| 55 | # Garbage collection
|
---|
| 56 | case ${REPLY} in
|
---|
| 57 | \#* | '') continue ;;
|
---|
| 58 | esac
|
---|
| 59 |
|
---|
| 60 | case "${REPLY}" in
|
---|
| 61 | # Create global variables for these parameters.
|
---|
| 62 | optDependency=* | \
|
---|
| 63 | MAIL_SERVER=* | \
|
---|
[945ccaa] | 64 | WRAP_INSTALL=* | \
|
---|
[9daa202] | 65 | PACK_INSTALL=* | \
|
---|
[dc7fd7b] | 66 | DEL_LA_FILES=* | \
|
---|
[67c3df4] | 67 | STATS=* | \
|
---|
[625cb14] | 68 | LANGUAGE=* | \
|
---|
[9daa202] | 69 | SUDO=* | \
|
---|
| 70 | SRC_ARCHIVE=* | \
|
---|
| 71 | SRC_SUBDIRS=* | \
|
---|
| 72 | BUILD_ROOT=* | \
|
---|
| 73 | BUILD_SUBDIRS=* | \
|
---|
| 74 | KEEP_FILES=* | \
|
---|
| 75 | JOBS=* | \
|
---|
| 76 | CFG_CFLAGS=* | \
|
---|
| 77 | CFG_CXXFLAGS=* | \
|
---|
| 78 | CFG_LDFLAGS=* ) eval ${REPLY} # Define/set a global variable..
|
---|
[f4ed135] | 79 | continue ;;
|
---|
| 80 | esac
|
---|
| 81 |
|
---|
[a96109a] | 82 | if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
|
---|
[e576789] | 83 | echo "$REPLY"
|
---|
| 84 | optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
|
---|
[f4ed135] | 85 | fi
|
---|
[e576789] | 86 | done < $ConfigFile
|
---|
[f4ed135] | 87 |
|
---|
[e576789] | 88 | if (( $cntr == 0 )); then
|
---|
| 89 | echo -e "\n>>> NO TARGET SELECTED.. application terminated"
|
---|
| 90 | echo -e " Run <make> again and select (a) package(s) to build\n"
|
---|
[f4ed135] | 91 | exit 0
|
---|
| 92 | fi
|
---|
[e576789] | 93 | TARGET=(${optTARGET[*]})
|
---|
[f4ed135] | 94 | DEP_LEVEL=$optDependency
|
---|
| 95 | SUDO=${SUDO:-n}
|
---|
[945ccaa] | 96 | WRAP_INSTALL=${WRAP_INSTALL:-n}
|
---|
[dc7fd7b] | 97 | DEL_LA_FILES=${DEL_LA_FILES:-n}
|
---|
[67c3df4] | 98 | STATS=${STATS:-n}
|
---|
[9daa202] | 99 | # Other boolean variables are supposed to be either set or unset. Their values
|
---|
| 100 | # are not relevant
|
---|
[f4ed135] | 101 | }
|
---|
| 102 |
|
---|
| 103 | #--------------------------#
|
---|
| 104 | validate_configuration() { #
|
---|
| 105 | #--------------------------#
|
---|
| 106 | local -r dotSTR=".................."
|
---|
[9daa202] | 107 | local -r PARAM_LIST="DEP_LEVEL SUDO LANGUAGE MAIL_SERVER WRAP_INSTALL PACK_INSTALL DEL_LA_FILES STATS SRC_ARCHIVE SRC_SUBDIRS BUILD_ROOT BUILD_SUBDIRS KEEP_FILES JOBS CFG_CFLAGS CFG_CXXFLAGS CFG_LDFLAGS"
|
---|
[f4ed135] | 108 | local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
| 109 | local config_param
|
---|
[e576789] | 110 | local -i index
|
---|
[f4ed135] | 111 |
|
---|
| 112 | for config_param in ${PARAM_LIST}; do
|
---|
| 113 | echo -e "`eval echo $PARAM_VALS`"
|
---|
| 114 | done
|
---|
[e576789] | 115 | for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
|
---|
| 116 | echo -e "TARGET${index}${dotSTR:6} ${L_arrow}${BOLD}${TARGET[${index}]}${OFF}${R_arrow}"
|
---|
| 117 | done
|
---|
[f4ed135] | 118 | }
|
---|
| 119 |
|
---|
| 120 | #
|
---|
[e576789] | 121 | # Generates the root of the dependency tree
|
---|
[f4ed135] | 122 | #
|
---|
| 123 | #--------------------------#
|
---|
[67c3df4] | 124 | generate_deps() { #
|
---|
[f4ed135] | 125 | #--------------------------#
|
---|
| 126 |
|
---|
[e576789] | 127 | local -i index
|
---|
| 128 | local DepDir=$1
|
---|
[2140f22] | 129 | rm -f $DepDir/*.{tree,dep}
|
---|
[e576789] | 130 | for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
|
---|
[2140f22] | 131 | echo 1 b ${TARGET[${index}]} >> $DepDir/root.dep
|
---|
[f4ed135] | 132 | done
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | #
|
---|
| 136 | # Clean configuration file keeping only global default settings.
|
---|
| 137 | # That prevent "trying to assign nonexistent symbol" messages
|
---|
| 138 | # and assures that there is no TARGET selected from a previous run
|
---|
| 139 | #
|
---|
| 140 | #--------------------------#
|
---|
| 141 | clean_configuration() { #
|
---|
| 142 | #--------------------------#
|
---|
| 143 |
|
---|
[e576789] | 144 | tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
|
---|
| 145 | mv ${ConfigFile}.tmp ${ConfigFile}
|
---|
[f4ed135] | 146 |
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | #---------------------
|
---|
| 150 | # Constants
|
---|
[e576789] | 151 | source ${LibDir}/constants.inc
|
---|
[f4ed135] | 152 | [[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
|
---|
| 153 |
|
---|
| 154 | #---------------------
|
---|
| 155 | # Dependencies module
|
---|
[e576789] | 156 | source ${LibDir}/func_dependencies
|
---|
[f4ed135] | 157 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
|
---|
| 158 |
|
---|
| 159 | #------- MAIN --------
|
---|
[e576789] | 160 | if [[ ! -f ${PackFile} ]] ; then
|
---|
[f4ed135] | 161 | echo -e "\tNo packages file has been found.\n"
|
---|
| 162 | echo -e "\tExecution aborted.\n"
|
---|
| 163 | exit 1
|
---|
| 164 | fi
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | parse_configuration
|
---|
| 168 | validate_configuration
|
---|
| 169 | echo "${SD_BORDER}${nl_}"
|
---|
| 170 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
| 171 | read ANSWER
|
---|
| 172 | if [ x$ANSWER != "xyes" ] ; then
|
---|
| 173 | echo "${nl_}Rerun make and fix your settings.${nl_}"
|
---|
| 174 | exit 1
|
---|
| 175 | fi
|
---|
| 176 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
[e576789] | 177 |
|
---|
| 178 | rm -rf $DepDir
|
---|
| 179 | mkdir $DepDir
|
---|
| 180 | generate_deps $DepDir
|
---|
| 181 | pushd $DepDir > /dev/null
|
---|
| 182 | set +e
|
---|
[2140f22] | 183 | generate_subgraph root.dep 1 1 b
|
---|
| 184 | echo -e "\n${SD_BORDER}"
|
---|
| 185 | echo Graph contains $(ls |wc -l) nodes
|
---|
| 186 | echo -e "${SD_BORDER}"
|
---|
| 187 | echo Cleaning subgraph...
|
---|
| 188 | clean_subgraph
|
---|
| 189 | echo done
|
---|
| 190 | echo Generating the tree
|
---|
| 191 | echo 1 > root.tree
|
---|
| 192 | echo 1 >> root.tree
|
---|
| 193 | cat root.dep >> root.tree
|
---|
| 194 | generate_dependency_tree root.tree 1
|
---|
| 195 | echo -e "\n${SD_BORDER}"
|
---|
[a690d42] | 196 | echo Generating the ordered full dependency list
|
---|
| 197 | FULL_LIST="$(tree_browse root.tree)"
|
---|
| 198 | set -e
|
---|
| 199 | popd > /dev/null
|
---|
| 200 | #echo "$FULL_LIST"
|
---|
[2140f22] | 201 | #echo -e \\n provisional end...
|
---|
| 202 | #exit
|
---|
| 203 | echo Generating the ordered package list
|
---|
[a690d42] | 204 | LIST=
|
---|
| 205 | while read p; do
|
---|
[5e1d9dd] | 206 | p=${p%-pass1}
|
---|
[a690d42] | 207 | versions=$(xsltproc --stringparam package "$p" $GetVersion $PackFile)
|
---|
| 208 | if [ "$versions" != "$(sort -V <<<$versions)" ]; then
|
---|
| 209 | LIST="$LIST $p"
|
---|
| 210 | fi
|
---|
| 211 | done <<<$FULL_LIST
|
---|
| 212 | #echo \""$LIST"\"
|
---|
| 213 | #echo -e \\n provisional end...
|
---|
| 214 | #exit
|
---|
[e576789] | 215 | rm -f ${BookXml}
|
---|
| 216 | echo Making XML book
|
---|
[607ef21] | 217 | xsltproc --stringparam list "$LIST" \
|
---|
[2140f22] | 218 | --stringparam MTA "$MAIL_SERVER" \
|
---|
[607ef21] | 219 | --stringparam lfsbook "$LFS_FULL" \
|
---|
[e576789] | 220 | -o ${BookXml} \
|
---|
| 221 | ${MakeBook} \
|
---|
| 222 | $BLFS_FULL
|
---|
| 223 | echo "making HTML book (may take some time...)"
|
---|
| 224 | xsltproc -o ${BookHtml}/ \
|
---|
| 225 | -stringparam chunk.quietly 1 \
|
---|
| 226 | ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
|
---|
| 227 | ${BookXml}
|
---|
| 228 | if [ ! -d ${BookHtml}/stylesheets ]
|
---|
| 229 | then mkdir -p ${BookHtml}/stylesheets
|
---|
| 230 | cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
|
---|
| 231 | fi
|
---|
| 232 | if [ ! -d ${BookHtml}/images ]
|
---|
| 233 | then mkdir -p ${BookHtml}/images
|
---|
| 234 | cp ${BLFS_XML}/images/*.png ${BookHtml}/images
|
---|
| 235 | fi
|
---|
| 236 | for ht in ${BookHtml}/*.html
|
---|
[c5650f9] | 237 | do sed -i 's@\.\./stylesheets@stylesheets@' $ht
|
---|
| 238 | sed -i 's@\.\./images@images@' $ht
|
---|
[e576789] | 239 | done
|
---|
| 240 | echo -en "\n\tGenerating the build scripts ...\n"
|
---|
| 241 | rm -rf scripts
|
---|
[67c3df4] | 242 | if test $STATS = y; then
|
---|
| 243 | LIST_STAT="${TARGET[*]}"
|
---|
| 244 | else
|
---|
| 245 | LIST_STAT=""
|
---|
| 246 | fi
|
---|
[9daa202] | 247 | xsltproc --xinclude --nonet \
|
---|
| 248 | --stringparam language "$LANGUAGE" \
|
---|
| 249 | --stringparam sudo "$SUDO" \
|
---|
| 250 | --stringparam wrap-install "$WRAP_INSTALL" \
|
---|
| 251 | --stringparam pack-install "$PACK_INSTALL" \
|
---|
| 252 | --stringparam del-la-files "$DEL_LA_FILES" \
|
---|
| 253 | --stringparam list-stat "$LIST_STAT" \
|
---|
| 254 | --stringparam src-archive "$SRC_ARCHIVE" \
|
---|
| 255 | --stringparam src-subdirs "$SRC_SUBDIRS" \
|
---|
| 256 | --stringparam build-root "$BUILD_ROOT" \
|
---|
| 257 | --stringparam build-subdirs "$BUILD_SUBDIRS" \
|
---|
| 258 | --stringparam keep-files "$KEEP_FILES" \
|
---|
| 259 | --param jobs "$JOBS" \
|
---|
| 260 | --stringparam cfg-cflags "$CFG_CFLAGS" \
|
---|
| 261 | --stringparam cfg-cxxflags "$CFG_CXXFLAGS" \
|
---|
| 262 | --stringparam cfg-ldflags "$CFG_LDFLAGS" \
|
---|
| 263 | --stringparam fqdn "$(hostname -f)" \
|
---|
| 264 | --output ./scripts/ \
|
---|
| 265 | ${MakeScripts} \
|
---|
[e576789] | 266 | ${BookXml}
|
---|
| 267 | # Make the scripts executable.
|
---|
| 268 | chmod -R +x scripts
|
---|
| 269 | echo -e "done\n"
|
---|
| 270 |
|
---|
| 271 | #clean_configuration
|
---|