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