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