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