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