source: BLFS/gen_pkg_book.sh@ dedd502

ablfs-more trunk
Last change on this file since dedd502 was dedd502, checked in by Pierre Labastie <pierre.labastie@…>, 20 months ago

Implementation of dependency checking 2

Check the configuration variable in gen_pkg_book

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