source: BLFS/gen_pkg_book.sh@ 794f94f

ablfs-more legacy trunk
Last change on this file since 794f94f 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
Line 
1#!/bin/bash
2#
3# Read and parse the configuration parameters..
4#
5set -e
6
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
15LFS_FULL=$3
16if test -z "$LFS_FULL"; then
17 LFS_FULL=${TOPDIR}/lfs-xml/tmp/lfs-full.xml
18fi
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
29declare DEP_LEVEL
30declare SUDO
31declare LANGUAGE
32declare WRAP_INSTALL
33declare PACK_INSTALL
34declare DEL_LA_FILES
35declare STATS
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
45
46#--------------------------#
47parse_configuration() { #
48#--------------------------#
49 local -i cntr=0
50 local -a optTARGET
51
52 while read; do
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=* | \
63 WRAP_INSTALL=* | \
64 PACK_INSTALL=* | \
65 DEL_LA_FILES=* | \
66 STATS=* | \
67 LANGUAGE=* | \
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..
78 continue ;;
79 esac
80
81 if [[ "${REPLY}" =~ ^CONFIG_ ]]; then
82 echo "$REPLY"
83 optTARGET[$((cntr++))]=$( echo $REPLY | sed -e 's@CONFIG_@@' -e 's@=y@@' )
84 fi
85 done < $ConfigFile
86
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"
90 exit 0
91 fi
92 TARGET=(${optTARGET[*]})
93 DEP_LEVEL=$optDependency
94 SUDO=${SUDO:-n}
95 WRAP_INSTALL=${WRAP_INSTALL:-n}
96 DEL_LA_FILES=${DEL_LA_FILES:-n}
97 STATS=${STATS:-n}
98# Other boolean variables are supposed to be either set or unset. Their values
99# are not relevant
100}
101
102#--------------------------#
103validate_configuration() { #
104#--------------------------#
105 local -r dotSTR=".................."
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"
107 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
108 local config_param
109 local -i index
110
111 for config_param in ${PARAM_LIST}; do
112 echo -e "`eval echo $PARAM_VALS`"
113 done
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
117}
118
119#
120# Generates the root of the dependency tree
121#
122#--------------------------#
123generate_deps() { #
124#--------------------------#
125
126 local -i index
127 local DepDir=$1
128 rm -f $DepDir/*.{tree,dep}
129 for (( index=0 ; index < ${#TARGET[*]} ; index ++ )); do
130 echo 1 b ${TARGET[${index}]} >> $DepDir/root.dep
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
143tail -n 15 ${ConfigFile} > ${ConfigFile}.tmp
144mv ${ConfigFile}.tmp ${ConfigFile}
145
146}
147
148#---------------------
149# Constants
150source ${LibDir}/constants.inc
151[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
152
153#---------------------
154# Dependencies module
155source ${LibDir}/func_dependencies
156[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
157
158#------- MAIN --------
159if [[ ! -f ${PackFile} ]] ; then
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_}"
176
177rm -rf $DepDir
178mkdir $DepDir
179generate_deps $DepDir
180pushd $DepDir > /dev/null
181set +e
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)"
199set -e
200popd > /dev/null
201rm -f ${BookXml}
202echo Making XML book
203xsltproc --stringparam list "$LIST" \
204 --stringparam MTA "$MAIL_SERVER" \
205 --stringparam lfsbook "$LFS_FULL" \
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
223 do sed -i 's@\.\./stylesheets@stylesheets@' $ht
224 sed -i 's@\.\./images@images@' $ht
225done
226echo -en "\n\tGenerating the build scripts ...\n"
227rm -rf scripts
228if test $STATS = y; then
229 LIST_STAT="${TARGET[*]}"
230else
231 LIST_STAT=""
232fi
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} \
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.