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