1 | #!/bin/bash
|
---|
2 | # $Id$
|
---|
3 | set -e
|
---|
4 |
|
---|
5 | # VT100 colors
|
---|
6 | declare -r BLACK=$'\e[1;30m'
|
---|
7 | declare -r DK_GRAY=$'\e[0;30m'
|
---|
8 |
|
---|
9 | declare -r RED=$'\e[31m'
|
---|
10 | declare -r GREEN=$'\e[32m'
|
---|
11 | declare -r YELLOW=$'\e[33m'
|
---|
12 | declare -r BLUE=$'\e[34m'
|
---|
13 | declare -r MAGENTA=$'\e[35m'
|
---|
14 | declare -r CYAN=$'\e[36m'
|
---|
15 | declare -r WHITE=$'\e[37m'
|
---|
16 |
|
---|
17 | declare -r OFF=$'\e[0m'
|
---|
18 | declare -r BOLD=$'\e[1m'
|
---|
19 | declare -r REVERSE=$'\e[7m'
|
---|
20 | declare -r HIDDEN=$'\e[8m'
|
---|
21 |
|
---|
22 | declare -r tab_=$'\t'
|
---|
23 | declare -r nl_=$'\n'
|
---|
24 |
|
---|
25 | declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
|
---|
26 | declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
|
---|
27 | declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
|
---|
28 |
|
---|
29 | # bold yellow > < pair
|
---|
30 | declare -r R_arrow=$'\e[1;33m>\e[0m'
|
---|
31 | declare -r L_arrow=$'\e[1;33m<\e[0m'
|
---|
32 |
|
---|
33 |
|
---|
34 | #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
|
---|
35 | #-----------------------#
|
---|
36 | simple_error() { # Basic error trap.... JUST DIE
|
---|
37 | #-----------------------#
|
---|
38 | # If +e then disable text output
|
---|
39 | if [[ "$-" =~ e ]]; then
|
---|
40 | echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
|
---|
41 | fi
|
---|
42 | }
|
---|
43 |
|
---|
44 | see_ya() {
|
---|
45 | echo -e "\n${L_arrow}${BOLD}jhalfs-X${R_arrow} exit${OFF}\n"
|
---|
46 | }
|
---|
47 | ##### Simple error TRAPS
|
---|
48 | # ctrl-c SIGINT
|
---|
49 | # ctrl-y
|
---|
50 | # ctrl-z SIGTSTP
|
---|
51 | # SIGHUP 1 HANGUP
|
---|
52 | # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
|
---|
53 | # SIGQUIT 3
|
---|
54 | # SIGKILL 9 KILL
|
---|
55 | # SIGTERM 15 TERMINATION
|
---|
56 | # SIGSTOP 17,18,23 STOP THE PROCESS
|
---|
57 | #####
|
---|
58 | set -e
|
---|
59 | trap see_ya 0
|
---|
60 | trap simple_error ERR
|
---|
61 | trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
|
---|
62 | #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
---|
63 |
|
---|
64 | version="
|
---|
65 | ${BOLD} \"jhalfs-X\"${OFF} builder tool (experimental) \$Rev$
|
---|
66 | \$Date$
|
---|
67 |
|
---|
68 | Written by George Boudreau and Manuel Canales Esparcia,
|
---|
69 | plus several contributions.
|
---|
70 |
|
---|
71 | Based on an idea from Jeremy Huntwork
|
---|
72 |
|
---|
73 | This set of files are published under the
|
---|
74 | ${BOLD}Gnu General Public License, Version 2.${OFF}
|
---|
75 | "
|
---|
76 |
|
---|
77 | case $1 in
|
---|
78 | -v ) echo "$version" && exit 1 ;;
|
---|
79 | run ) : ;;
|
---|
80 | * )
|
---|
81 | echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
|
---|
82 | exit 1
|
---|
83 | ;;
|
---|
84 | esac
|
---|
85 |
|
---|
86 | VERBOSITY=1
|
---|
87 |
|
---|
88 | [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
|
---|
89 | source configuration
|
---|
90 | [[ $? > 0 ]] && echo "file:configuration did not load.." && exit 1
|
---|
91 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
92 |
|
---|
93 | # These are boolean vars generated from Config.in.
|
---|
94 | # ISSUE: If a boolean parameter is not set <true> that
|
---|
95 | # variable is not defined by the menu app. This can
|
---|
96 | # cause a headache if you are not careful.
|
---|
97 | # The following parameters MUST be created and have a
|
---|
98 | # default value.
|
---|
99 | RUNMAKE=${RUNMAKE:-n}
|
---|
100 | GETPKG=${GETPKG:-n}
|
---|
101 | GETKERNEL=${GETKERNEL:-n}
|
---|
102 | COMPARE=${COMPARE:-n}
|
---|
103 | RUN_FARCE=${RUN_FARCE:-n}
|
---|
104 | RUN_ICA=${RUN_ICA:-n}
|
---|
105 | BOMB_TEST=${BOMB_TEST:-n}
|
---|
106 | STRIP=${STRIP:=n}
|
---|
107 | REPORT=${REPORT:=n}
|
---|
108 | VIMLANG=${VIMLANG:-n}
|
---|
109 | GRSECURITY_HOST=${GRSECURITY_HOST:-n}
|
---|
110 | CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
|
---|
111 | REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
|
---|
112 | INSTALL_LOG=${INSTALL_LOG:-n}
|
---|
113 | CLEAN=${CLEAN:=n}
|
---|
114 | SET_SSP=${SET_SSP:=n}
|
---|
115 | SET_ASLR=${SET_ASLR:=n}
|
---|
116 | SET_PAX=${SET_PAX:=n}
|
---|
117 | SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
|
---|
118 | SET_WARNINGS=${SET_WARNINGS:=n}
|
---|
119 | SET_MISC=${SET_MISC:=n}
|
---|
120 | SET_BLOWFISH=${SET_BLOWFISH:=n}
|
---|
121 |
|
---|
122 | # Sanity check on the location of $BUILDDIR / $JHALFSDIR
|
---|
123 | CWD=$(cd `dirname $0` && pwd)
|
---|
124 | if [[ $JHALFSDIR == $CWD ]]; then
|
---|
125 | echo " The jhalfs source directory conflicts with the jhalfs build directory."
|
---|
126 | echo " Please move the source directory or change the build directory."
|
---|
127 | exit 2
|
---|
128 | fi
|
---|
129 |
|
---|
130 | # Book surces envars
|
---|
131 | BRANCH_ID=${BRANCH_ID:=development}
|
---|
132 |
|
---|
133 | case $BRANCH_ID in
|
---|
134 | development )
|
---|
135 | case $PROGNAME in
|
---|
136 | clfs2 ) TREE=branches/clfs-sysroot/BOOK ;;
|
---|
137 | clfs3 ) TREE=branches/clfs-embedded/BOOK ;;
|
---|
138 | *) TREE=trunk/BOOK ;;
|
---|
139 | esac
|
---|
140 | LFSVRS=development
|
---|
141 | ;;
|
---|
142 | *EDIT* ) echo " You forgot to set the branch or stable book version."
|
---|
143 | echo " Please rerun make and fix the configuration."
|
---|
144 | exit 2 ;;
|
---|
145 | branch-* )
|
---|
146 | LFSVRS=${BRANCH_ID}
|
---|
147 | TREE=branches/${BRANCH_ID#branch-}/BOOK
|
---|
148 | ;;
|
---|
149 | * )
|
---|
150 | case $PROGNAME in
|
---|
151 | lfs | hlfs )
|
---|
152 | LFSVRS=${BRANCH_ID}
|
---|
153 | TREE=tags/${BRANCH_ID}/BOOK
|
---|
154 | ;;
|
---|
155 | clfs | clfs2 | clfs3)
|
---|
156 | LFSVRS=${BRANCH_ID}
|
---|
157 | TREE=tags/${BRANCH_ID}
|
---|
158 | ;;
|
---|
159 | esac
|
---|
160 | ;;
|
---|
161 | esac
|
---|
162 |
|
---|
163 | # Set the document location...
|
---|
164 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
165 |
|
---|
166 | # blfs-tool envars
|
---|
167 | BLFS_TOOL=${BLFS_TOOL:-n}
|
---|
168 | DEP_LIBXML=${DEP_LIBXML:-n}
|
---|
169 | DEP_LIBXSLT=${DEP_LIBXSLT:-n}
|
---|
170 | DEP_TIDY=${DEP_TIDY:-n}
|
---|
171 | DEP_UNZIP=${DEP_UNZIP:-n}
|
---|
172 | DEP_DBXML=${DEP_DBXML:-n}
|
---|
173 | DEP_DBXSL=${DEP_DBXSL:-n}
|
---|
174 | DEP_GPM=${DEP_GPM:-n}
|
---|
175 | DEP_LYNX=${DEP_LYNX:-n}
|
---|
176 | DEP_SUDO=${DEP_SUDO:-n}
|
---|
177 | DEP_WGET=${DEP_WGET:-n}
|
---|
178 | DEP_SVN=${DEP_SVN:-n}
|
---|
179 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
180 | BLFS_BRANCH_ID=${BLFS_BRANCH_ID:=development}
|
---|
181 | case $BLFS_BRANCH_ID in
|
---|
182 | development ) BLFS_TREE=trunk/BOOK ;;
|
---|
183 | *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
|
---|
184 | echo " Please rerun make and fix the configuration."
|
---|
185 | exit 2 ;;
|
---|
186 | branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
|
---|
187 | * ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
|
---|
188 | esac
|
---|
189 | fi
|
---|
190 |
|
---|
191 | #--- Envars not sourced from configuration
|
---|
192 | case $PROGNAME in
|
---|
193 | clfs* ) declare -r SVN="http://svn.cross-lfs.org/svn/repos" ;;
|
---|
194 | * ) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
|
---|
195 | esac
|
---|
196 | declare -r LOG=000-masterscript.log
|
---|
197 | # Needed to can fetch BLFS book sources when building CLFS
|
---|
198 | declare -r SVN_2="svn://svn.linuxfromscratch.org"
|
---|
199 |
|
---|
200 | # Set true internal variables
|
---|
201 | CODE_DIR=`pwd`
|
---|
202 | COMMON_DIR="common"
|
---|
203 | PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
|
---|
204 | MODULE=$PACKAGE_DIR/master.sh
|
---|
205 |
|
---|
206 | # Qick fix until have the new code ready
|
---|
207 | XSL=$CODE_DIR/$PACKAGE_DIR/$XSL
|
---|
208 |
|
---|
209 | [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
|
---|
210 | source $COMMON_DIR/common-functions
|
---|
211 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
212 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
213 | [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
|
---|
214 | source $MODULE
|
---|
215 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
216 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
217 | #
|
---|
218 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
219 |
|
---|
220 |
|
---|
221 | #*******************************************************************#
|
---|
222 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
|
---|
223 | source $COMMON_DIR/libs/func_check_version.sh
|
---|
224 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
225 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
226 |
|
---|
227 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
|
---|
228 | source $COMMON_DIR/libs/func_validate_configs.sh
|
---|
229 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
230 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
231 |
|
---|
232 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
|
---|
233 | source $COMMON_DIR/libs/func_custom_pkgs
|
---|
234 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
235 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
236 |
|
---|
237 |
|
---|
238 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
239 |
|
---|
240 |
|
---|
241 | ###################################
|
---|
242 | ### MAIN ###
|
---|
243 | ###################################
|
---|
244 |
|
---|
245 | # Check for build prereequisites.
|
---|
246 | echo
|
---|
247 | check_prerequisites
|
---|
248 | echo "${SD_BORDER}${nl_}"
|
---|
249 |
|
---|
250 | validate_config
|
---|
251 | echo "${SD_BORDER}${nl_}"
|
---|
252 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
253 | read ANSWER
|
---|
254 | if [ x$ANSWER != "xyes" ] ; then
|
---|
255 | echo "${nl_}Rerun make to fix the configuration options.${nl_}"
|
---|
256 | exit 1
|
---|
257 | fi
|
---|
258 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
259 |
|
---|
260 | # Load additional modules or configuration files based on global settings
|
---|
261 | # compare module
|
---|
262 | if [[ "$COMPARE" = "y" ]]; then
|
---|
263 | [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
|
---|
264 | source $COMMON_DIR/libs/func_compare.sh
|
---|
265 | [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
|
---|
266 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
267 | fi
|
---|
268 | #
|
---|
269 | # optimize module
|
---|
270 | if [[ "$OPTIMIZE" != "0" ]]; then
|
---|
271 | [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
|
---|
272 | source optimize/optimize_functions
|
---|
273 | [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
|
---|
274 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
275 | #
|
---|
276 | # optimize configurations
|
---|
277 | [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
|
---|
278 | source optimize/opt_config
|
---|
279 | [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
|
---|
280 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
281 | # Validate optimize settings, if required
|
---|
282 | validate_opt_settings
|
---|
283 | fi
|
---|
284 | #
|
---|
285 |
|
---|
286 | if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
|
---|
287 |
|
---|
288 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
289 | # and notify the user about that.
|
---|
290 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
291 | eval "$no_empty_builddir"
|
---|
292 | fi
|
---|
293 |
|
---|
294 | # If requested, clean the build directory
|
---|
295 | clean_builddir
|
---|
296 |
|
---|
297 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
298 | mkdir -p $JHALFSDIR
|
---|
299 | fi
|
---|
300 |
|
---|
301 | # Create $BUILDDIR/sources even though it could be created by get_sources()
|
---|
302 | if [[ ! -d $BUILDDIR/sources ]]; then
|
---|
303 | mkdir -p $BUILDDIR/sources
|
---|
304 | fi
|
---|
305 | #
|
---|
306 | # Create the log directory
|
---|
307 | if [[ ! -d $LOGDIR ]]; then
|
---|
308 | mkdir $LOGDIR
|
---|
309 | fi
|
---|
310 | >$LOGDIR/$LOG
|
---|
311 | #
|
---|
312 | # Copy common helper files
|
---|
313 | cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
|
---|
314 | #
|
---|
315 |
|
---|
316 | # Create the test-log directory, if needed
|
---|
317 | [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
|
---|
318 | #
|
---|
319 | # Create the installed-files directory, if needed
|
---|
320 | [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
|
---|
321 | #
|
---|
322 | # Prepare report creation, if needed
|
---|
323 | if [[ "$REPORT" = "y" ]]; then
|
---|
324 | cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
|
---|
325 | # After being sure that all looks sane, dump the settings to a file
|
---|
326 | # This file will be used to create the REPORT header
|
---|
327 | validate_config > $JHALFSDIR/jhalfs.config
|
---|
328 | fi
|
---|
329 | #
|
---|
330 | # Copy optimize files, if needed
|
---|
331 | [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
|
---|
332 | #
|
---|
333 | # Copy compare files, if needed
|
---|
334 | if [[ "$COMPARE" = "y" ]]; then
|
---|
335 | mkdir -p $JHALFSDIR/extras
|
---|
336 | cp extras/* $JHALFSDIR/extras
|
---|
337 | fi
|
---|
338 | #
|
---|
339 |
|
---|
340 | # Copy custom tools config files, if requested
|
---|
341 | if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
|
---|
342 | echo "Copying custom tool scripts to $JHALFSDIR"
|
---|
343 | mkdir -p $JHALFSDIR/custom-commands
|
---|
344 | cp -f custom/config/* $JHALFSDIR/custom-commands
|
---|
345 | fi
|
---|
346 | #
|
---|
347 | # Install blfs-tool, if requested.
|
---|
348 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
349 | # Install the files
|
---|
350 | [[ ! -d ${BUILDDIR}${BLFS_ROOT} ]] && mkdir -p ${BUILDDIR}${BLFS_ROOT}
|
---|
351 | cp -r BLFS/* ${BUILDDIR}${BLFS_ROOT}
|
---|
352 | cp -r menu ${BUILDDIR}${BLFS_ROOT}
|
---|
353 | cp $COMMON_DIR/progress_bar.sh ${BUILDDIR}${BLFS_ROOT}
|
---|
354 | cp README.BLFS ${BUILDDIR}${BLFS_ROOT}
|
---|
355 | # Clean-up
|
---|
356 | rm -rf ${BUILDDIR}${BLFS_ROOT}/libs/.svn
|
---|
357 | rm -rf ${BUILDDIR}${BLFS_ROOT}/menu/.svn
|
---|
358 | rm -rf ${BUILDDIR}${BLFS_ROOT}/menu/lxdialog/.svn
|
---|
359 | # Set some harcoded envars to their proper values
|
---|
360 | sed -i 's,blfs-xml,'$BLFS_XML',' ${BUILDDIR}${BLFS_ROOT}/{update_book.sh,libs/book.xsl}
|
---|
361 | sed -i 's,tracking-dir,'$TRACKING_DIR',' ${BUILDDIR}${BLFS_ROOT}/{update_book.sh,gen-makefile.sh}
|
---|
362 | fi
|
---|
363 | #
|
---|
364 |
|
---|
365 | get_book
|
---|
366 | echo "${SD_BORDER}${nl_}"
|
---|
367 |
|
---|
368 | # Get the BLFS book, if requested.
|
---|
369 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
370 | echo -n "Downloading the BLFS document, $BLFS_BRANCH_ID version... "
|
---|
371 | if [[ ! -d ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} ]] ; then
|
---|
372 | mkdir -p ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML}
|
---|
373 | svn co $SVN_2/BLFS/$BLFS_TREE ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} >>$LOGDIR/$LOG 2>&1
|
---|
374 | else
|
---|
375 | pushd ${BUILDDIR}${BLFS_ROOT}/${BLFS_XML} 1> /dev/null
|
---|
376 | svn up >>$LOGDIR/$LOG 2>&1
|
---|
377 | popd 1> /dev/null
|
---|
378 | fi
|
---|
379 | echo -ne "done\n"
|
---|
380 | echo "${SD_BORDER}${nl_}"
|
---|
381 | fi
|
---|
382 |
|
---|
383 | fi
|
---|
384 |
|
---|
385 | # When regenerating the Makefile we need to know also the canonical book version
|
---|
386 | if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
|
---|
387 | case $PROGNAME in
|
---|
388 | clfs | clfs2 | clfs3 )
|
---|
389 | VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
390 | *)
|
---|
391 | VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
392 | esac
|
---|
393 | fi
|
---|
394 |
|
---|
395 | build_Makefile
|
---|
396 |
|
---|
397 | echo "${SD_BORDER}${nl_}"
|
---|
398 |
|
---|
399 | run_make
|
---|