source: BLFS/gen_pkg_book.sh@ eec87db

ablfs-more legacy trunk
Last change on this file since eec87db was 9daa202, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

BLFS tools: Take variables from config instead of envars.conf

Get them in gen_pkg_book, and pass them to sripts.xsl
use them in scripts.xsl. We set them at the beginning of
of the scriptlet, so that it is easy to modify them.

  • Property mode set to 100755
File size: 7.1 KB
RevLine 
[f4ed135]1#!/bin/bash
2#
3# Read and parse the configuration parameters..
4#
5set -e
6
[e576789]7TOPDIR=$1
8if test -z "$TOPDIR"; then
9 TOPDIR=$(pwd)
10fi
11BLFS_FULL=$2
12if test -z "$BLFS_FULL"; then
13 BLFS_FULL=${TOPDIR}/blfs-xml/tmp/blfs-full.xml
14fi
[607ef21]15LFS_FULL=$3
16if test -z "$LFS_FULL"; then
17 LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
18fi
[e576789]19declare -r ConfigFile="${TOPDIR}/configuration"
20declare DepDir="${TOPDIR}/dependencies"
21declare LibDir="${TOPDIR}/libs"
22declare PackFile="${TOPDIR}/packages.xml"
23declare BookXml="${TOPDIR}/book.xml"
24declare MakeBook="${TOPDIR}/xsl/make_book.xsl"
25declare MakeScripts="${TOPDIR}/xsl/scripts.xsl"
26declare BookHtml="${TOPDIR}/book-html"
27declare BLFS_XML="${TOPDIR}/blfs-xml"
28declare -a TARGET
[f4ed135]29declare DEP_LEVEL
30declare SUDO
[625cb14]31declare LANGUAGE
[945ccaa]32declare WRAP_INSTALL
[9daa202]33declare PACK_INSTALL
[625cb14]34declare DEL_LA_FILES
35declare STATS
[9daa202]36declare SRC_ARCHIVE
37declare SRC_SUBDIRS
38declare BUILD_ROOT
39declare BUILD_SUBDIRS
40declare KEEP_FILES
41declare -i JOBS
42declare CFG_CFLAGS
43declare CFG_CXXFLAGS
44declare CFG_LDFLAGS
[f4ed135]45
46#--------------------------#
47parse_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#--------------------------#
103validate_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]123generate_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#--------------------------#
140clean_configuration() { #
141#--------------------------#
142
[e576789]143tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
144mv ${ConfigFile}.tmp ${ConfigFile}
[f4ed135]145
146}
147
148#---------------------
149# Constants
[e576789]150source ${LibDir}/constants.inc
[f4ed135]151[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
152
153#---------------------
154# Dependencies module
[e576789]155source ${LibDir}/func_dependencies
[f4ed135]156[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
157
158#------- MAIN --------
[e576789]159if [[ ! -f ${PackFile} ]] ; then
[f4ed135]160 echo -e "\tNo packages file has been found.\n"
161 echo -e "\tExecution aborted.\n"
162 exit 1
163fi
164
165
166parse_configuration
167validate_configuration
168echo "${SD_BORDER}${nl_}"
169echo -n "Are you happy with these settings? yes/no (no): "
170read ANSWER
171if [ x$ANSWER != "xyes" ] ; then
172 echo "${nl_}Rerun make and fix your settings.${nl_}"
173 exit 1
174fi
175echo "${nl_}${SD_BORDER}${nl_}"
[e576789]176
177rm -rf $DepDir
178mkdir $DepDir
179generate_deps $DepDir
180pushd $DepDir > /dev/null
181set +e
[2140f22]182generate_subgraph root.dep 1 1 b
183echo -e "\n${SD_BORDER}"
184echo Graph contains $(ls |wc -l) nodes
185echo -e "${SD_BORDER}"
186echo Cleaning subgraph...
187clean_subgraph
188echo done
189echo Generating the tree
190echo 1 > root.tree
191echo 1 >> root.tree
192cat root.dep >> root.tree
193generate_dependency_tree root.tree 1
194echo -e "\n${SD_BORDER}"
195#echo -e \\n provisional end...
196#exit
197echo Generating the ordered package list
198LIST="$(tree_browse root.tree)"
[e576789]199set -e
200popd > /dev/null
201rm -f ${BookXml}
202echo Making XML book
[607ef21]203xsltproc --stringparam list "$LIST" \
[2140f22]204 --stringparam MTA "$MAIL_SERVER" \
[607ef21]205 --stringparam lfsbook "$LFS_FULL" \
[e576789]206 -o ${BookXml} \
207 ${MakeBook} \
208 $BLFS_FULL
209echo "making HTML book (may take some time...)"
210xsltproc -o ${BookHtml}/ \
211 -stringparam chunk.quietly 1 \
212 ${BLFS_XML}/stylesheets/blfs-chunked.xsl \
213 ${BookXml}
214if [ ! -d ${BookHtml}/stylesheets ]
215 then mkdir -p ${BookHtml}/stylesheets
216 cp ${BLFS_XML}/stylesheets/lfs-xsl/*.css ${BookHtml}/stylesheets
217fi
218if [ ! -d ${BookHtml}/images ]
219 then mkdir -p ${BookHtml}/images
220 cp ${BLFS_XML}/images/*.png ${BookHtml}/images
221fi
222for ht in ${BookHtml}/*.html
[c5650f9]223 do sed -i 's@\.\./stylesheets@stylesheets@' $ht
224 sed -i 's@\.\./images@images@' $ht
[e576789]225done
226echo -en "\n\tGenerating the build scripts ...\n"
227rm -rf scripts
[67c3df4]228if test $STATS = y; then
229 LIST_STAT="${TARGET[*]}"
230else
231 LIST_STAT=""
232fi
[9daa202]233xsltproc --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.
254chmod -R +x scripts
255echo -e "done\n"
256
257#clean_configuration
Note: See TracBrowser for help on using the repository browser.