source: jhalfs@ 51dba86

ablfs-more legacy trunk
Last change on this file since 51dba86 was 46ac330, checked in by Pierre Labastie <pierre@…>, 8 years ago

Fix the path to the book used when "Rebuild the Makefile" has been selected

  • Property mode set to 100755
File size: 14.1 KB
Line 
1#!/bin/bash
2# $Id$
3set -e
4# Pass trap handlers to functions
5set -E
6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
37#-----------------------#
38simple_error() { # Basic error trap.... JUST DIE
39#-----------------------#
40 # If +e then disable text output
41 if [[ "$-" =~ e ]]; then
42 LASTLINE="$1"
43 LASTERR="$2"
44 LASTFUNC="$3"
45 LASTSOURCE="$4"
46# echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
47 echo -e "\n${RED}ERROR:${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!${OFF}\n" >&2
48 fi
49 exit $LASTERR
50}
51
52see_ya() {
53 echo -e "\n${L_arrow}${BOLD}jhalfs${R_arrow} exit${OFF}\n"
54}
55##### Simple error TRAPS
56# ctrl-c SIGINT
57# ctrl-y
58# ctrl-z SIGTSTP
59# SIGHUP 1 HANGUP
60# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
61# SIGQUIT 3
62# SIGKILL 9 KILL
63# SIGTERM 15 TERMINATION
64# SIGSTOP 17,18,23 STOP THE PROCESS
65#####
66set -e
67trap see_ya 0
68trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
69trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
70#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
71
72version="
73${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
74 \$Date$
75
76 Written by George Boudreau, Manuel Canales Esparcia, Pierre Labastie,
77 plus several contributions.
78
79 Based on an idea from Jeremy Huntwork
80
81 This set of files are published under the
82 ${BOLD}Gnu General Public License, Version 2.${OFF}
83 See the ${BOLD}LICENCE${OFF} file in this directory.
84"
85
86case $1 in
87 -v ) echo "$version" && exit ;;
88 run ) : ;;
89 * )
90 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
91 exit 1
92 ;;
93esac
94
95# If the user has not saved his configuration file, let's ask
96# if he or she really wants to run this stuff
97if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \
98 -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ]
99 then echo -n "Do you want to run jhalfs? yes/no (yes): "
100 read ANSWER
101 if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then
102 echo "${nl_}Exiting gracefully.${nl_}"
103 exit
104 fi
105fi
106
107# Change this to 0 to suppress almost all messages
108VERBOSITY=1
109
110[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
111source configuration
112[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
113[[ $VERBOSITY > 0 ]] && echo "OK"
114
115# These are boolean vars generated from Config.in.
116# ISSUE: If a boolean parameter is not set to y(es) there
117# is no variable defined by the menu app. This can
118# cause a headache if you are not aware.
119# The following variables MUST exist. If they don't, the
120# default value is n(o).
121RUNMAKE=${RUNMAKE:-n}
122GETPKG=${GETPKG:-n}
123COMPARE=${COMPARE:-n}
124RUN_FARCE=${RUN_FARCE:-n}
125RUN_ICA=${RUN_ICA:-n}
126PKGMNGT=${PKGMNGT:-n}
127WRAP_INSTALL=${WRAP_INSTALL:-n}
128BOMB_TEST=${BOMB_TEST:-n}
129STRIP=${STRIP:=n}
130REPORT=${REPORT:=n}
131VIMLANG=${VIMLANG:-n}
132FULL_LOCALE=${FULL_LOCALE:-n}
133GRSECURITY_HOST=${GRSECURITY_HOST:-n}
134CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
135REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
136INSTALL_LOG=${INSTALL_LOG:-n}
137CLEAN=${CLEAN:=n}
138SET_SSP=${SET_SSP:=n}
139SET_ASLR=${SET_ASLR:=n}
140SET_PAX=${SET_PAX:=n}
141SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
142SET_WARNINGS=${SET_WARNINGS:=n}
143SET_MISC=${SET_MISC:=n}
144SET_BLOWFISH=${SET_BLOWFISH:=n}
145UNICODE=${UNICODE:=n}
146
147if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
148 NO_PROGRESS="#"
149fi
150
151
152# Sanity check on the location of $BUILDDIR / $JHALFSDIR
153CWD=$(cd `dirname $0` && pwd)
154if [[ $JHALFSDIR == $CWD ]]; then
155 echo " The jhalfs source directory conflicts with the jhalfs build directory."
156 echo " Please move the source directory or change the build directory."
157 exit 2
158fi
159
160# Book sources envars
161BRANCH_ID=${BRANCH_ID:=development}
162
163case $BRANCH_ID in
164 development )
165 case $PROGNAME in
166 clfs* ) TREE="" ;;
167 * ) TREE=trunk/BOOK ;;
168 esac
169 LFSVRS=development
170 ;;
171 *EDIT* ) echo " You forgot to set the branch or stable book version."
172 echo " Please rerun make and fix the configuration."
173 exit 2 ;;
174 branch-* )
175 case $PROGNAME in
176 lfs )
177 LFSVRS=${BRANCH_ID}
178 TREE=branches/${BRANCH_ID#branch-}
179 if [ ${BRANCH_ID#branch-} = 6 ]; then
180 TREE=${TREE}/BOOK
181 fi
182 ;;
183 clfs* )
184 LFSVRS=${BRANCH_ID}
185 TREE=${BRANCH_ID#branch-}
186 ;;
187 esac
188 ;;
189 * )
190 case $PROGNAME in
191 lfs )
192 LFSVRS=${BRANCH_ID}
193 TREE=tags/${BRANCH_ID}
194 if (( ${BRANCH_ID:0:1} < 7 )) ; then
195 TREE=${TREE}/BOOK
196 fi
197 ;;
198 hlfs )
199 LFSVRS=${BRANCH_ID}
200 TREE=tags/${BRANCH_ID}/BOOK
201 ;;
202 clfs* )
203 LFSVRS=${BRANCH_ID}
204 TREE=clfs-${BRANCH_ID}
205 ;;
206 * )
207 esac
208 ;;
209esac
210
211# Set the document location...
212BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
213
214
215#--- Envars not sourced from configuration
216case $PROGNAME in
217 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
218 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
219 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
220 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
221esac
222declare -r LOG=000-masterscript.log
223 # Needed for fetching BLFS book sources when building CLFS
224declare -r SVN_2="svn://svn.linuxfromscratch.org"
225
226# Set true internal variables
227COMMON_DIR="common"
228PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
229MODULE=$PACKAGE_DIR/master.sh
230PKGMNGTDIR="pkgmngt"
231# The name packageManager.xml is hardcoded in *.xsl, so no variable.
232
233[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
234source $COMMON_DIR/common-functions
235[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
236[[ $VERBOSITY > 0 ]] && echo "OK"
237[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
238source $MODULE
239[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
240[[ $VERBOSITY > 0 ]] && echo "OK"
241#
242[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
243
244
245#*******************************************************************#
246[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
247source $COMMON_DIR/libs/func_check_version.sh
248[[ $? > 0 ]] && echo " function module did not load.." && exit 2
249[[ $VERBOSITY > 0 ]] && echo "OK"
250
251[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
252source $COMMON_DIR/libs/func_validate_configs.sh
253[[ $? > 0 ]] && echo " function module did not load.." && exit 2
254[[ $VERBOSITY > 0 ]] && echo "OK"
255
256[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
257source $COMMON_DIR/libs/func_custom_pkgs
258[[ $? > 0 ]] && echo " function module did not load.." && exit 2
259[[ $VERBOSITY > 0 ]] && echo "OK"
260
261
262[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
263
264[[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs
265check_alfs_tools
266
267[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
268
269# blfs-tool envars
270BLFS_TOOL=${BLFS_TOOL:-n}
271if [[ "${BLFS_TOOL}" = "y" ]] ; then
272 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS
273 check_blfs_tools
274 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
275 BLFS_SVN=${BLFS_SVN:-n}
276 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
277 BLFS_BRANCH=${BLFS_BRANCH:-n}
278 if [[ "${BLFS_SVN}" = "y" ]]; then
279 BLFS_BRANCH_ID=development
280 BLFS_TREE=trunk/BOOK
281 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
282 [[ -d "$BLFS_WC_LOCATION" ]] &&
283 [[ -d "$BLFS_WC_LOCATION/postlfs" ]] || {
284 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
285 echo " Please rerun make and fix the configuration."
286 exit 2
287 }
288 BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@')
289 BLFS_BRANCH_ID=$(echo $BLFS_TREE | sed -e 's@trunk/BOOK@development@' \
290 -e 's@branches/@branch-@' \
291 -e 's@tags/@@' \
292 -e 's@/BOOK@@')
293 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
294 case $BLFS_BRANCH_ID in
295 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
296 echo " Please rerun make and fix the configuration."
297 exit 2 ;;
298 branch-systemd ) BLFS_TREE=branches/systemd ;;
299 branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-}/BOOK ;;
300 6.2* | 7.* ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
301 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
302 esac
303 fi
304 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
305 source $COMMON_DIR/libs/func_install_blfs
306 [[ $? > 0 ]] && echo "function module did not load.." && exit 1
307 [[ $VERBOSITY > 0 ]] && echo "OK"
308fi
309
310###################################
311### MAIN ###
312###################################
313
314
315validate_config
316echo "${SD_BORDER}${nl_}"
317echo -n "Are you happy with these settings? yes/no (no): "
318read ANSWER
319if [ x$ANSWER != "xyes" ] ; then
320 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
321 exit
322fi
323echo "${nl_}${SD_BORDER}${nl_}"
324
325# Load additional modules or configuration files based on global settings
326# compare module
327if [[ "$COMPARE" = "y" ]]; then
328 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
329 source $COMMON_DIR/libs/func_compare.sh
330 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
331 [[ $VERBOSITY > 0 ]] && echo "OK"
332fi
333#
334# optimize module
335if [[ "$OPTIMIZE" != "0" ]]; then
336 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
337 source optimize/optimize_functions
338 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
339 [[ $VERBOSITY > 0 ]] && echo "OK"
340 #
341 # optimize configurations
342 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
343 source optimize/opt_config
344 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
345 [[ $VERBOSITY > 0 ]] && echo "OK"
346 # The number of parallel jobs is taken from configuration now
347 MAKEFLAGS="-j${N_PARALLEL}"
348 # Validate optimize settings, if required
349 validate_opt_settings
350fi
351#
352
353if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
354
355 # If requested, clean the build directory
356 clean_builddir
357
358 if [[ ! -d $JHALFSDIR ]]; then
359 mkdir -p $JHALFSDIR
360 fi
361
362 # Create $BUILDDIR/sources even though it could be created by get_sources()
363 if [[ ! -d $BUILDDIR/sources ]]; then
364 mkdir -p $BUILDDIR/sources
365 fi
366 #
367 # Create the log directory
368 if [[ ! -d $LOGDIR ]]; then
369 mkdir $LOGDIR
370 fi
371 >$LOGDIR/$LOG
372 #
373 # Copy common helper files
374 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
375 # Copy needed stylesheets
376 cp $COMMON_DIR/{packages.xsl,chroot.xsl} $JHALFSDIR/
377 #
378 # Fix the XSL book parser
379 case $PROGNAME in
380 clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
381 lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
382 * ) ;;
383 esac
384 export XSL=$JHALFSDIR/${XSL}
385 #
386
387 # Copy packageManager.xml, if needed
388 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
389 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/
390 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
391 }
392 #
393 # Copy urls.xsl, if needed
394 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
395 #
396 # Create the test-log directory, if needed
397 [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
398 #
399 # Create the installed-files directory, if needed
400 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
401 #
402 # Prepare report creation, if needed
403 if [[ "$REPORT" = "y" ]]; then
404 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
405 # After making sure that all looks sane, dump the settings to a file
406 # This file will be used to create the REPORT header
407 validate_config > $JHALFSDIR/jhalfs.config
408 fi
409 #
410 # Copy optimize files, if needed
411 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
412 #
413 # Copy compare files, if needed
414 if [[ "$COMPARE" = "y" ]]; then
415 mkdir -p $JHALFSDIR/extras
416 cp extras/* $JHALFSDIR/extras
417 fi
418 #
419 # Copy custom tools config files, if requested
420 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
421 echo "Copying custom tool scripts to $JHALFSDIR"
422 mkdir -p $JHALFSDIR/custom-commands
423 cp -f custom/config/* $JHALFSDIR/custom-commands
424 fi
425 #
426 # Install blfs-tool, if requested.
427 if [[ "${BLFS_TOOL}" = "y" ]] ; then
428 echo Installing BLFS book and tools
429 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
430 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
431 fi
432 #
433
434# Download or updates the book source
435 get_book
436 extract_commands
437 echo "${SD_BORDER}${nl_}"
438
439fi
440
441# When regenerating the Makefile, we need to know also the
442# canonical book version
443if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
444 case $PROGNAME in
445 clfs* )
446 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
447 lfs)
448 if [[ "$INITSYS" = "sysv" ]] ; then
449 VERSION=$(grep 'ENTITY version ' $BOOK/general.ent| cut -d\" -f2)
450 else
451 VERSION=$(grep 'ENTITY versiond' $BOOK/general.ent| cut -d\" -f2)
452 fi
453 ;;
454 *)
455 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
456 esac
457fi
458
459build_Makefile
460
461echo "${SD_BORDER}${nl_}"
462
463# Check for build prerequisites.
464 echo
465 cd $CWD
466 check_prerequisites
467 echo "${SD_BORDER}${nl_}"
468# All is well, run the build (if requested)
469run_make
Note: See TracBrowser for help on using the repository browser.