source: jhalfs@ c57747d

ablfs-more legacy trunk
Last change on this file since c57747d 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
RevLine 
[4da2512]1#!/bin/bash
2# $Id$
3set -e
[bbcdeab]4# Pass trap handlers to functions
5set -E
[4da2512]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
[a96109a]41 if [[ "$-" =~ e ]]; then
[bbcdeab]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
[4da2512]48 fi
[bbcdeab]49 exit $LASTERR
[4da2512]50}
51
52see_ya() {
[8d56c87]53 echo -e "\n${L_arrow}${BOLD}jhalfs${R_arrow} exit${OFF}\n"
[4da2512]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
[bbcdeab]68trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
[4da2512]69trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
70#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
71
72version="
[8d56c87]73${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
[4da2512]74 \$Date$
75
[8d56c87]76 Written by George Boudreau, Manuel Canales Esparcia, Pierre Labastie,
[4da2512]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}
[8d56c87]83 See the ${BOLD}LICENCE${OFF} file in this directory.
[4da2512]84"
85
86case $1 in
[909ee37]87 -v ) echo "$version" && exit ;;
[4da2512]88 run ) : ;;
89 * )
90 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
91 exit 1
92 ;;
93esac
94
[65c998b]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
[4da2512]108VERBOSITY=1
109
110[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
111source configuration
[7072e1f]112[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[4da2512]113[[ $VERBOSITY > 0 ]] && echo "OK"
114
115# These are boolean vars generated from Config.in.
[7072e1f]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).
[4da2512]121RUNMAKE=${RUNMAKE:-n}
122GETPKG=${GETPKG:-n}
123COMPARE=${COMPARE:-n}
124RUN_FARCE=${RUN_FARCE:-n}
125RUN_ICA=${RUN_ICA:-n}
[7072e1f]126PKGMNGT=${PKGMNGT:-n}
[945ccaa]127WRAP_INSTALL=${WRAP_INSTALL:-n}
[4da2512]128BOMB_TEST=${BOMB_TEST:-n}
129STRIP=${STRIP:=n}
130REPORT=${REPORT:=n}
131VIMLANG=${VIMLANG:-n}
[b339c94]132FULL_LOCALE=${FULL_LOCALE:-n}
[4da2512]133GRSECURITY_HOST=${GRSECURITY_HOST:-n}
[9a536f7]134CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
[a16f769]135REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
[93346ee]136INSTALL_LOG=${INSTALL_LOG:-n}
[486e9a7]137CLEAN=${CLEAN:=n}
[d035526]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}
[945ccaa]145UNICODE=${UNICODE:=n}
[4da2512]146
[75d6d1c]147if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
148 NO_PROGRESS="#"
149fi
150
151
[38ae01f]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
[0873ccc]160# Book sources envars
[4965fa8]161BRANCH_ID=${BRANCH_ID:=development}
162
163case $BRANCH_ID in
164 development )
165 case $PROGNAME in
[92b7cb8]166 clfs* ) TREE="" ;;
[c4ad7bf]167 * ) TREE=trunk/BOOK ;;
[4965fa8]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-* )
[c4ad7bf]175 case $PROGNAME in
176 lfs )
177 LFSVRS=${BRANCH_ID}
[bb2862d]178 TREE=branches/${BRANCH_ID#branch-}
179 if [ ${BRANCH_ID#branch-} = 6 ]; then
180 TREE=${TREE}/BOOK
181 fi
[c4ad7bf]182 ;;
183 clfs* )
184 LFSVRS=${BRANCH_ID}
185 TREE=${BRANCH_ID#branch-}
186 ;;
187 esac
[4965fa8]188 ;;
189 * )
190 case $PROGNAME in
[e650dc7]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 )
[4965fa8]199 LFSVRS=${BRANCH_ID}
200 TREE=tags/${BRANCH_ID}/BOOK
201 ;;
[92b7cb8]202 clfs* )
[4965fa8]203 LFSVRS=${BRANCH_ID}
[34d1b6a]204 TREE=clfs-${BRANCH_ID}
[4965fa8]205 ;;
[92b7cb8]206 * )
[4965fa8]207 esac
208 ;;
209esac
210
[4da2512]211# Set the document location...
[1cf621b]212BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
[4da2512]213
[4965fa8]214
[728955b]215#--- Envars not sourced from configuration
216case $PROGNAME in
[4195a40]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" ;;
[92b7cb8]220 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
[728955b]221esac
222declare -r LOG=000-masterscript.log
[7072e1f]223 # Needed for fetching BLFS book sources when building CLFS
[728955b]224declare -r SVN_2="svn://svn.linuxfromscratch.org"
225
[4da2512]226# Set true internal variables
227COMMON_DIR="common"
[52b0d10]228PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
[4da2512]229MODULE=$PACKAGE_DIR/master.sh
[7072e1f]230PKGMNGTDIR="pkgmngt"
231# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[4da2512]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>..."
[d517356]247source $COMMON_DIR/libs/func_check_version.sh
[4da2512]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>..."
[d517356]252source $COMMON_DIR/libs/func_validate_configs.sh
[4da2512]253[[ $? > 0 ]] && echo " function module did not load.." && exit 2
254[[ $VERBOSITY > 0 ]] && echo "OK"
[9a536f7]255
[fe30c61]256[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
257source $COMMON_DIR/libs/func_custom_pkgs
[9a536f7]258[[ $? > 0 ]] && echo " function module did not load.." && exit 2
259[[ $VERBOSITY > 0 ]] && echo "OK"
260
261
[6ed3dd7]262[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
263
264[[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs
265check_alfs_tools
266
[4da2512]267[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
268
[e576789]269# blfs-tool envars
270BLFS_TOOL=${BLFS_TOOL:-n}
271if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]272 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS
273 check_blfs_tools
274 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[854854e]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 }
[2c4be7f]288 BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@')
[854854e]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@@')
[0ba80be]293 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
[854854e]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 ;;
[6c97d02]300 6.2* | 7.* ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
[854854e]301 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
302 esac
303 fi
[e576789]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
[4da2512]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
[881c96f]320 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
[d023a35]321 exit
[4da2512]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..."
[d517356]329 source $COMMON_DIR/libs/func_compare.sh
330 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[4da2512]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"
[854854e]346 # The number of parallel jobs is taken from configuration now
347 MAKEFLAGS="-j${N_PARALLEL}"
[4da2512]348 # Validate optimize settings, if required
349 validate_opt_settings
350fi
351#
352
[a16f769]353if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
[4da2512]354
[7b6ecc5]355 # If requested, clean the build directory
356 clean_builddir
[4da2512]357
[7b6ecc5]358 if [[ ! -d $JHALFSDIR ]]; then
359 mkdir -p $JHALFSDIR
360 fi
[3e7ceed]361
[7b6ecc5]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 #
[3e7ceed]373 # Copy common helper files
[d68eb1b]374 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
375 # Copy needed stylesheets
376 cp $COMMON_DIR/{packages.xsl,chroot.xsl} $JHALFSDIR/
[7b6ecc5]377 #
[3e7ceed]378 # Fix the XSL book parser
[92b7cb8]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
[3e7ceed]384 export XSL=$JHALFSDIR/${XSL}
[7b6ecc5]385 #
386
[7072e1f]387 # Copy packageManager.xml, if needed
[3aa1acd]388 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
389 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/
[7072e1f]390 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
[3aa1acd]391 }
[7072e1f]392 #
[3e7ceed]393 # Copy urls.xsl, if needed
394 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
[7b6ecc5]395 #
[3e7ceed]396 # Create the test-log directory, if needed
397 [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
398 #
[93346ee]399 # Create the installed-files directory, if needed
400 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
401 #
[3e7ceed]402 # Prepare report creation, if needed
[7b6ecc5]403 if [[ "$REPORT" = "y" ]]; then
404 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
[7072e1f]405 # After making sure that all looks sane, dump the settings to a file
[7b6ecc5]406 # This file will be used to create the REPORT header
407 validate_config > $JHALFSDIR/jhalfs.config
408 fi
409 #
[3e7ceed]410 # Copy optimize files, if needed
411 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[7b6ecc5]412 #
[3e7ceed]413 # Copy compare files, if needed
414 if [[ "$COMPARE" = "y" ]]; then
415 mkdir -p $JHALFSDIR/extras
416 cp extras/* $JHALFSDIR/extras
417 fi
[7b6ecc5]418 #
[3e7ceed]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 #
[7b6ecc5]426 # Install blfs-tool, if requested.
427 if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]428 echo Installing BLFS book and tools
[e576789]429 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
[bbcdeab]430 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
[7b6ecc5]431 fi
[3e7ceed]432 #
[7b6ecc5]433
[1cf621b]434# Download or updates the book source
[7b6ecc5]435 get_book
[1cf621b]436 extract_commands
[4965fa8]437 echo "${SD_BORDER}${nl_}"
[7b6ecc5]438
[4965fa8]439fi
440
[e576789]441# When regenerating the Makefile, we need to know also the
442# canonical book version
[a16f769]443if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
444 case $PROGNAME in
[92b7cb8]445 clfs* )
[46ac330]446 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[c9598f2]447 lfs)
448 if [[ "$INITSYS" = "sysv" ]] ; then
[46ac330]449 VERSION=$(grep 'ENTITY version ' $BOOK/general.ent| cut -d\" -f2)
[c9598f2]450 else
[46ac330]451 VERSION=$(grep 'ENTITY versiond' $BOOK/general.ent| cut -d\" -f2)
[c9598f2]452 fi
453 ;;
[a16f769]454 *)
[46ac330]455 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[a16f769]456 esac
457fi
458
[4da2512]459build_Makefile
[3e7ceed]460
[4da2512]461echo "${SD_BORDER}${nl_}"
462
[1cf621b]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)
[4da2512]469run_make
Note: See TracBrowser for help on using the repository browser.