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