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