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