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