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