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-trunk${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-trunk\"${OFF} builder tool (development) \$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 | # If the user has not saved his configuration file, let's ask
|
---|
87 | # if he or she really wants to run this stuff
|
---|
88 | if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \
|
---|
89 | -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ]
|
---|
90 | then echo -n "Do you want to run jhalfs? yes/no (yes): "
|
---|
91 | read ANSWER
|
---|
92 | if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then
|
---|
93 | echo "${nl_}Exiting gracefully.${nl_}"
|
---|
94 | exit
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 |
|
---|
98 | # Change this to 0 to suppress almost all messages
|
---|
99 | VERBOSITY=1
|
---|
100 |
|
---|
101 | [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
|
---|
102 | source configuration
|
---|
103 | [[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
|
---|
104 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
105 |
|
---|
106 | # These are boolean vars generated from Config.in.
|
---|
107 | # ISSUE: If a boolean parameter is not set to y(es) there
|
---|
108 | # is no variable defined by the menu app. This can
|
---|
109 | # cause a headache if you are not aware.
|
---|
110 | # The following variables MUST exist. If they don't, the
|
---|
111 | # default value is n(o).
|
---|
112 | RUNMAKE=${RUNMAKE:-n}
|
---|
113 | GETPKG=${GETPKG:-n}
|
---|
114 | COMPARE=${COMPARE:-n}
|
---|
115 | RUN_FARCE=${RUN_FARCE:-n}
|
---|
116 | RUN_ICA=${RUN_ICA:-n}
|
---|
117 | PKGMNGT=${PKGMNGT:-n}
|
---|
118 | BOMB_TEST=${BOMB_TEST:-n}
|
---|
119 | STRIP=${STRIP:=n}
|
---|
120 | REPORT=${REPORT:=n}
|
---|
121 | VIMLANG=${VIMLANG:-n}
|
---|
122 | FULL_LOCALE=${FULL_LOCALE:-n}
|
---|
123 | GRSECURITY_HOST=${GRSECURITY_HOST:-n}
|
---|
124 | CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
|
---|
125 | REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
|
---|
126 | INSTALL_LOG=${INSTALL_LOG:-n}
|
---|
127 | CLEAN=${CLEAN:=n}
|
---|
128 | SET_SSP=${SET_SSP:=n}
|
---|
129 | SET_ASLR=${SET_ASLR:=n}
|
---|
130 | SET_PAX=${SET_PAX:=n}
|
---|
131 | SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
|
---|
132 | SET_WARNINGS=${SET_WARNINGS:=n}
|
---|
133 | SET_MISC=${SET_MISC:=n}
|
---|
134 | SET_BLOWFISH=${SET_BLOWFISH:=n}
|
---|
135 |
|
---|
136 | if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
|
---|
137 | NO_PROGRESS="#"
|
---|
138 | fi
|
---|
139 |
|
---|
140 |
|
---|
141 | # Sanity check on the location of $BUILDDIR / $JHALFSDIR
|
---|
142 | CWD=$(cd `dirname $0` && pwd)
|
---|
143 | if [[ $JHALFSDIR == $CWD ]]; then
|
---|
144 | echo " The jhalfs source directory conflicts with the jhalfs build directory."
|
---|
145 | echo " Please move the source directory or change the build directory."
|
---|
146 | exit 2
|
---|
147 | fi
|
---|
148 |
|
---|
149 | # Book sources envars
|
---|
150 | BRANCH_ID=${BRANCH_ID:=development}
|
---|
151 |
|
---|
152 | case $BRANCH_ID in
|
---|
153 | development )
|
---|
154 | case $PROGNAME in
|
---|
155 | clfs* ) TREE="" ;;
|
---|
156 | *) TREE=trunk/BOOK ;;
|
---|
157 | esac
|
---|
158 | LFSVRS=development
|
---|
159 | ;;
|
---|
160 | *EDIT* ) echo " You forgot to set the branch or stable book version."
|
---|
161 | echo " Please rerun make and fix the configuration."
|
---|
162 | exit 2 ;;
|
---|
163 | branch-* )
|
---|
164 | LFSVRS=${BRANCH_ID}
|
---|
165 | TREE=branches/${BRANCH_ID#branch-}/BOOK
|
---|
166 | ;;
|
---|
167 | * )
|
---|
168 | case $PROGNAME in
|
---|
169 | lfs )
|
---|
170 | LFSVRS=${BRANCH_ID}
|
---|
171 | TREE=tags/${BRANCH_ID}
|
---|
172 | if (( ${BRANCH_ID:0:1} < 7 )) ; then
|
---|
173 | TREE=${TREE}/BOOK
|
---|
174 | fi
|
---|
175 | ;;
|
---|
176 | hlfs )
|
---|
177 | LFSVRS=${BRANCH_ID}
|
---|
178 | TREE=tags/${BRANCH_ID}/BOOK
|
---|
179 | ;;
|
---|
180 | clfs* )
|
---|
181 | LFSVRS=${BRANCH_ID}
|
---|
182 | TREE=clfs-${BRANCH_ID}
|
---|
183 | ;;
|
---|
184 | * )
|
---|
185 | esac
|
---|
186 | ;;
|
---|
187 | esac
|
---|
188 |
|
---|
189 | # Set the document location...
|
---|
190 | BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
|
---|
191 |
|
---|
192 |
|
---|
193 | #--- Envars not sourced from configuration
|
---|
194 | case $PROGNAME in
|
---|
195 | # TODO: clfs is now on git
|
---|
196 | clfs ) declare -r GIT="git://git.cross-lfs.org/cross-lfs" ;;
|
---|
197 | clfs2 ) declare -r GIT="git://git.cross-lfs.org/clfs-sysroot" ;;
|
---|
198 | clfs3 ) declare -r GIT="git://git.cross-lfs.org/clfs-embedded" ;;
|
---|
199 | *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
|
---|
200 | esac
|
---|
201 | declare -r LOG=000-masterscript.log
|
---|
202 | # Needed for fetching BLFS book sources when building CLFS
|
---|
203 | declare -r SVN_2="svn://svn.linuxfromscratch.org"
|
---|
204 |
|
---|
205 | # Set true internal variables
|
---|
206 | COMMON_DIR="common"
|
---|
207 | PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
|
---|
208 | MODULE=$PACKAGE_DIR/master.sh
|
---|
209 | PKGMNGTDIR="pkgmngt"
|
---|
210 | # The name packageManager.xml is hardcoded in *.xsl, so no variable.
|
---|
211 |
|
---|
212 | [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
|
---|
213 | source $COMMON_DIR/common-functions
|
---|
214 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
215 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
216 | [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
|
---|
217 | source $MODULE
|
---|
218 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
219 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
220 | #
|
---|
221 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
222 |
|
---|
223 |
|
---|
224 | #*******************************************************************#
|
---|
225 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
|
---|
226 | source $COMMON_DIR/libs/func_check_version.sh
|
---|
227 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
228 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
229 |
|
---|
230 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
|
---|
231 | source $COMMON_DIR/libs/func_validate_configs.sh
|
---|
232 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
233 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
234 |
|
---|
235 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
|
---|
236 | source $COMMON_DIR/libs/func_custom_pkgs
|
---|
237 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
238 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
239 |
|
---|
240 |
|
---|
241 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
242 |
|
---|
243 | # blfs-tool envars
|
---|
244 | BLFS_TOOL=${BLFS_TOOL:-n}
|
---|
245 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
246 | BLFS_BRANCH_ID=${BLFS_BRANCH_ID:=development}
|
---|
247 | case $BLFS_BRANCH_ID in
|
---|
248 | development ) BLFS_TREE=trunk/BOOK ;;
|
---|
249 | *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
|
---|
250 | echo " Please rerun make and fix the configuration."
|
---|
251 | exit 2 ;;
|
---|
252 | branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
|
---|
253 | * ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
|
---|
254 | esac
|
---|
255 | [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
|
---|
256 | source $COMMON_DIR/libs/func_install_blfs
|
---|
257 | [[ $? > 0 ]] && echo "function module did not load.." && exit 1
|
---|
258 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
259 | fi
|
---|
260 |
|
---|
261 | ###################################
|
---|
262 | ### MAIN ###
|
---|
263 | ###################################
|
---|
264 |
|
---|
265 |
|
---|
266 | validate_config
|
---|
267 | echo "${SD_BORDER}${nl_}"
|
---|
268 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
269 | read ANSWER
|
---|
270 | if [ x$ANSWER != "xyes" ] ; then
|
---|
271 | echo "${nl_}Rerun make to fix the configuration options.${nl_}"
|
---|
272 | exit 1
|
---|
273 | fi
|
---|
274 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
275 |
|
---|
276 | # Load additional modules or configuration files based on global settings
|
---|
277 | # compare module
|
---|
278 | if [[ "$COMPARE" = "y" ]]; then
|
---|
279 | [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
|
---|
280 | source $COMMON_DIR/libs/func_compare.sh
|
---|
281 | [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
|
---|
282 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
283 | fi
|
---|
284 | #
|
---|
285 | # optimize module
|
---|
286 | if [[ "$OPTIMIZE" != "0" ]]; then
|
---|
287 | [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
|
---|
288 | source optimize/optimize_functions
|
---|
289 | [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
|
---|
290 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
291 | #
|
---|
292 | # optimize configurations
|
---|
293 | [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
|
---|
294 | source optimize/opt_config
|
---|
295 | [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
|
---|
296 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
297 | # Validate optimize settings, if required
|
---|
298 | validate_opt_settings
|
---|
299 | fi
|
---|
300 | #
|
---|
301 |
|
---|
302 | if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
|
---|
303 |
|
---|
304 | # If requested, clean the build directory
|
---|
305 | clean_builddir
|
---|
306 |
|
---|
307 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
308 | mkdir -p $JHALFSDIR
|
---|
309 | fi
|
---|
310 |
|
---|
311 | # Create $BUILDDIR/sources even though it could be created by get_sources()
|
---|
312 | if [[ ! -d $BUILDDIR/sources ]]; then
|
---|
313 | mkdir -p $BUILDDIR/sources
|
---|
314 | fi
|
---|
315 | #
|
---|
316 | # Create the log directory
|
---|
317 | if [[ ! -d $LOGDIR ]]; then
|
---|
318 | mkdir $LOGDIR
|
---|
319 | fi
|
---|
320 | >$LOGDIR/$LOG
|
---|
321 | #
|
---|
322 | # Copy common helper files
|
---|
323 | cp $COMMON_DIR/{makefile-functions,progress_bar.sh,packages.xsl} $JHALFSDIR/
|
---|
324 | #
|
---|
325 | # Fix the XSL book parser
|
---|
326 | case $PROGNAME in
|
---|
327 | clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
|
---|
328 | lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
|
---|
329 | * ) ;;
|
---|
330 | esac
|
---|
331 | export XSL=$JHALFSDIR/${XSL}
|
---|
332 | #
|
---|
333 |
|
---|
334 | # Copy packageManager.xml, if needed
|
---|
335 | [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] &&
|
---|
336 | cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/ &&
|
---|
337 | cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
|
---|
338 | #
|
---|
339 | # Copy urls.xsl, if needed
|
---|
340 | [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
|
---|
341 | #
|
---|
342 | # Create the test-log directory, if needed
|
---|
343 | [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
|
---|
344 | #
|
---|
345 | # Create the installed-files directory, if needed
|
---|
346 | [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
|
---|
347 | #
|
---|
348 | # Prepare report creation, if needed
|
---|
349 | if [[ "$REPORT" = "y" ]]; then
|
---|
350 | cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
|
---|
351 | # After making sure that all looks sane, dump the settings to a file
|
---|
352 | # This file will be used to create the REPORT header
|
---|
353 | validate_config > $JHALFSDIR/jhalfs.config
|
---|
354 | fi
|
---|
355 | #
|
---|
356 | # Copy optimize files, if needed
|
---|
357 | [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
|
---|
358 | #
|
---|
359 | # Copy compare files, if needed
|
---|
360 | if [[ "$COMPARE" = "y" ]]; then
|
---|
361 | mkdir -p $JHALFSDIR/extras
|
---|
362 | cp extras/* $JHALFSDIR/extras
|
---|
363 | fi
|
---|
364 | #
|
---|
365 | # Copy custom tools config files, if requested
|
---|
366 | if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
|
---|
367 | echo "Copying custom tool scripts to $JHALFSDIR"
|
---|
368 | mkdir -p $JHALFSDIR/custom-commands
|
---|
369 | cp -f custom/config/* $JHALFSDIR/custom-commands
|
---|
370 | fi
|
---|
371 | #
|
---|
372 | # Install blfs-tool, if requested.
|
---|
373 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
374 | echo Downloading and validating the BLFS book
|
---|
375 | echo '(may take some time...)'
|
---|
376 | install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
|
---|
377 | fi
|
---|
378 | #
|
---|
379 |
|
---|
380 | # Download or updates the book source
|
---|
381 | get_book
|
---|
382 | extract_commands
|
---|
383 | echo "${SD_BORDER}${nl_}"
|
---|
384 |
|
---|
385 | fi
|
---|
386 |
|
---|
387 | # When regenerating the Makefile, we need to know also the
|
---|
388 | # canonical book version
|
---|
389 | if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
|
---|
390 | case $PROGNAME in
|
---|
391 | clfs* )
|
---|
392 | VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
393 | *)
|
---|
394 | VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
395 | esac
|
---|
396 | fi
|
---|
397 |
|
---|
398 | build_Makefile
|
---|
399 |
|
---|
400 | echo "${SD_BORDER}${nl_}"
|
---|
401 |
|
---|
402 | # Check for build prerequisites.
|
---|
403 | echo
|
---|
404 | cd $CWD
|
---|
405 | check_prerequisites
|
---|
406 | echo "${SD_BORDER}${nl_}"
|
---|
407 | # All is well, run the build (if requested)
|
---|
408 | run_make
|
---|