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