[4da2512] | 1 | #!/bin/bash
|
---|
| 2 | # $Id$
|
---|
| 3 | set -e
|
---|
[bbcdeab] | 4 | # Pass trap handlers to functions
|
---|
| 5 | set -E
|
---|
[4da2512] | 6 |
|
---|
| 7 | # VT100 colors
|
---|
| 8 | declare -r RED=$'\e[31m'
|
---|
| 9 | declare -r GREEN=$'\e[32m'
|
---|
| 10 | declare -r YELLOW=$'\e[33m'
|
---|
| 11 |
|
---|
[0e4ddfa] | 12 | # shellcheck disable=SC2034
|
---|
| 13 | declare -r BLUE=$'\e[34m'
|
---|
[4da2512] | 14 | declare -r OFF=$'\e[0m'
|
---|
| 15 | declare -r BOLD=$'\e[1m'
|
---|
| 16 | declare -r tab_=$'\t'
|
---|
| 17 | declare -r nl_=$'\n'
|
---|
| 18 |
|
---|
[0e4ddfa] | 19 | # shellcheck disable=SC2034
|
---|
[4da2512] | 20 | declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
|
---|
[0e4ddfa] | 21 | # shellcheck disable=SC2034
|
---|
[4da2512] | 22 | declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
|
---|
[0e4ddfa] | 23 | # shellcheck disable=SC2034
|
---|
[4da2512] | 24 | declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
|
---|
| 25 |
|
---|
| 26 | # bold yellow > < pair
|
---|
| 27 | declare -r R_arrow=$'\e[1;33m>\e[0m'
|
---|
| 28 | declare -r L_arrow=$'\e[1;33m<\e[0m'
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
|
---|
| 32 | #-----------------------#
|
---|
| 33 | simple_error() { # Basic error trap.... JUST DIE
|
---|
| 34 | #-----------------------#
|
---|
[0e4ddfa] | 35 | LASTLINE="$1"
|
---|
| 36 | LASTERR="$2"
|
---|
| 37 | LASTSOURCE="$4"
|
---|
| 38 | error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
|
---|
[4da2512] | 39 | }
|
---|
| 40 |
|
---|
| 41 | see_ya() {
|
---|
[0e4ddfa] | 42 | printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
|
---|
[4da2512] | 43 | }
|
---|
| 44 | ##### Simple error TRAPS
|
---|
| 45 | # ctrl-c SIGINT
|
---|
| 46 | # ctrl-y
|
---|
| 47 | # ctrl-z SIGTSTP
|
---|
| 48 | # SIGHUP 1 HANGUP
|
---|
| 49 | # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
|
---|
| 50 | # SIGQUIT 3
|
---|
| 51 | # SIGKILL 9 KILL
|
---|
| 52 | # SIGTERM 15 TERMINATION
|
---|
| 53 | # SIGSTOP 17,18,23 STOP THE PROCESS
|
---|
| 54 | #####
|
---|
| 55 | set -e
|
---|
| 56 | trap see_ya 0
|
---|
[bbcdeab] | 57 | trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
|
---|
[d505128] | 58 | trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' \
|
---|
| 59 | HUP INT QUIT TERM # STOP stops tterminal output and does not seem to
|
---|
| 60 | # execute the handler
|
---|
[4da2512] | 61 | #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
---|
| 62 |
|
---|
[0e4ddfa] | 63 | simple_message() {
|
---|
| 64 | # Prevents having to check $VERBOSITY everywhere
|
---|
| 65 | if [ "$VERBOSITY" -ne 0 ] ; then
|
---|
| 66 | # shellcheck disable=SC2059
|
---|
| 67 | printf "$*"
|
---|
| 68 | fi
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | warning_message() {
|
---|
| 72 | simple_message "${YELLOW}\\nWARNING:${OFF} $*\\n\\n"
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | error_message() {
|
---|
| 76 | # Prints an error message and exits with LASTERR or 1
|
---|
| 77 | if [ -n "$LASTERR" ] ; then
|
---|
| 78 | LASTERR=$(printf '%d' "$LASTERR")
|
---|
| 79 | else
|
---|
| 80 | LASTERR=1
|
---|
| 81 | fi
|
---|
| 82 | # If +e then disable text output
|
---|
| 83 | if [[ "$-" =~ e ]]; then
|
---|
| 84 | printf '\n\n%bERROR:%b %s\n' "$RED" "$OFF" "$*" >&2
|
---|
| 85 | fi
|
---|
| 86 | exit "$LASTERR"
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | load_file() {
|
---|
| 90 | # source files in a consistent way with an optional message
|
---|
| 91 | file="$1"
|
---|
| 92 | shift
|
---|
| 93 | msg="Loading file ${file}..."
|
---|
| 94 | [ -z "$*" ] || msg="$*..."
|
---|
| 95 | simple_message "$msg"
|
---|
| 96 |
|
---|
| 97 | # shellcheck disable=SC1090
|
---|
| 98 | source "$file" 2>/dev/null || error_message "$file did not load"
|
---|
| 99 | simple_message "OK\\n"
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[4da2512] | 102 | version="
|
---|
[8d56c87] | 103 | ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
|
---|
[0a0753d] | 104 | \$Date$
|
---|
[4da2512] | 105 |
|
---|
[f596dde] | 106 | Copyright (C) 2005-2019, the jhalfs team:
|
---|
| 107 | Jeremy Huntwork
|
---|
| 108 | George Boudreau
|
---|
| 109 | Manuel Canales Esparcia
|
---|
| 110 | Thomas Pegg
|
---|
| 111 | Matthew Burgess
|
---|
| 112 | Pierre Labastie
|
---|
[4da2512] | 113 |
|
---|
[f596dde] | 114 | Unless specified, all the files in this directory and its sub-directories
|
---|
| 115 | are subjected to the ${BOLD}MIT license${OFF}. See the ${BOLD}LICENSE${OFF} file.
|
---|
[4da2512] | 116 |
|
---|
[f596dde] | 117 | The files in the ${BOLD}menu${OFF} directory are subjected to the ${BOLD}ISC License${OFF}.
|
---|
| 118 | See ${BOLD}LICENSE.txt${OFF} and ${BOLD}README${OFF} in that directory.
|
---|
[4da2512] | 119 | "
|
---|
| 120 |
|
---|
[f596dde] | 121 | usage="${nl_}${tab_}${BOLD}${RED}This script cannot be called directly${OFF}
|
---|
| 122 | ${tab_}Type ${BOLD}make${OFF} to run the tool, or
|
---|
| 123 | ${tab_}Type ${BOLD}./jhalfs -v${OFF} to display version information."
|
---|
| 124 |
|
---|
[4da2512] | 125 | case $1 in
|
---|
[909ee37] | 126 | -v ) echo "$version" && exit ;;
|
---|
[4da2512] | 127 | run ) : ;;
|
---|
[f596dde] | 128 | * ) echo "$usage" && exit 1 ;;
|
---|
[4da2512] | 129 | esac
|
---|
| 130 |
|
---|
[65c998b] | 131 | # If the user has not saved his configuration file, let's ask
|
---|
| 132 | # if he or she really wants to run this stuff
|
---|
[a22bfe1] | 133 | time_current=$(stat -c '%Y' configuration 2>/dev/null || date +%s)
|
---|
[cf2f109] | 134 | time_old=$(stat -c '%Y' configuration.old 2>/dev/null || printf '%s' "$time_current")
|
---|
[a22bfe1] | 135 | if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then
|
---|
| 136 | printf 'Do you want to run jhalfs? yes/no (yes): '
|
---|
[0e4ddfa] | 137 | read -r ANSWER
|
---|
[a22bfe1] | 138 | case ${ANSWER:0:1} in
|
---|
| 139 | n|N) printf "\nExiting gracefully.\n"; exit ;;
|
---|
| 140 | esac
|
---|
[65c998b] | 141 | fi
|
---|
| 142 |
|
---|
| 143 | # Change this to 0 to suppress almost all messages
|
---|
[4da2512] | 144 | VERBOSITY=1
|
---|
| 145 |
|
---|
[0e4ddfa] | 146 | load_file configuration "Loading config params from <configuration>"
|
---|
[4da2512] | 147 |
|
---|
| 148 | # These are boolean vars generated from Config.in.
|
---|
[7072e1f] | 149 | # ISSUE: If a boolean parameter is not set to y(es) there
|
---|
| 150 | # is no variable defined by the menu app. This can
|
---|
| 151 | # cause a headache if you are not aware.
|
---|
| 152 | # The following variables MUST exist. If they don't, the
|
---|
| 153 | # default value is n(o).
|
---|
[4da2512] | 154 | RUNMAKE=${RUNMAKE:-n}
|
---|
| 155 | GETPKG=${GETPKG:-n}
|
---|
| 156 | COMPARE=${COMPARE:-n}
|
---|
| 157 | RUN_ICA=${RUN_ICA:-n}
|
---|
[7072e1f] | 158 | PKGMNGT=${PKGMNGT:-n}
|
---|
[945ccaa] | 159 | WRAP_INSTALL=${WRAP_INSTALL:-n}
|
---|
[4da2512] | 160 | BOMB_TEST=${BOMB_TEST:-n}
|
---|
| 161 | STRIP=${STRIP:=n}
|
---|
| 162 | REPORT=${REPORT:=n}
|
---|
[085435e] | 163 | NCURSES5=${NCURSES5:-n}
|
---|
[dc7fd7b] | 164 | DEL_LA_FILES=${DEL_LA_FILES:-n}
|
---|
[b339c94] | 165 | FULL_LOCALE=${FULL_LOCALE:-n}
|
---|
[4da2512] | 166 | GRSECURITY_HOST=${GRSECURITY_HOST:-n}
|
---|
[9a536f7] | 167 | CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
|
---|
[a16f769] | 168 | REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
|
---|
[93346ee] | 169 | INSTALL_LOG=${INSTALL_LOG:-n}
|
---|
[486e9a7] | 170 | CLEAN=${CLEAN:=n}
|
---|
[d035526] | 171 | SET_SSP=${SET_SSP:=n}
|
---|
| 172 | SET_ASLR=${SET_ASLR:=n}
|
---|
| 173 | SET_PAX=${SET_PAX:=n}
|
---|
| 174 | SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
|
---|
| 175 | SET_WARNINGS=${SET_WARNINGS:=n}
|
---|
| 176 | SET_MISC=${SET_MISC:=n}
|
---|
| 177 | SET_BLOWFISH=${SET_BLOWFISH:=n}
|
---|
[945ccaa] | 178 | UNICODE=${UNICODE:=n}
|
---|
[3b43e17b] | 179 | LOCAL=${LOCAL:=n}
|
---|
[84a3fda] | 180 | REALSBU=${REALSBU:=n}
|
---|
[f5ecc28] | 181 | SAVE_CH5=${SAVE_CH5:=n}
|
---|
[4da2512] | 182 |
|
---|
[75d6d1c] | 183 | if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
|
---|
[0e4ddfa] | 184 | # shellcheck disable=SC2034
|
---|
| 185 | NO_PROGRESS="#"
|
---|
[75d6d1c] | 186 | fi
|
---|
| 187 |
|
---|
[38ae01f] | 188 | # Sanity check on the location of $BUILDDIR / $JHALFSDIR
|
---|
[0e4ddfa] | 189 | CWD="$(cd "$(dirname "$0")" && pwd)"
|
---|
| 190 | if [[ $JHALFSDIR == "$CWD" ]]; then
|
---|
| 191 | echo " The jhalfs source directory conflicts with the jhalfs build directory."
|
---|
| 192 | echo " Please move the source directory or change the build directory."
|
---|
| 193 | exit 2
|
---|
[38ae01f] | 194 | fi
|
---|
| 195 |
|
---|
[0873ccc] | 196 | # Book sources envars
|
---|
[4965fa8] | 197 | BRANCH_ID=${BRANCH_ID:=development}
|
---|
| 198 |
|
---|
| 199 | case $BRANCH_ID in
|
---|
| 200 | development )
|
---|
| 201 | case $PROGNAME in
|
---|
[92b7cb8] | 202 | clfs* ) TREE="" ;;
|
---|
[c4ad7bf] | 203 | * ) TREE=trunk/BOOK ;;
|
---|
[4965fa8] | 204 | esac
|
---|
| 205 | LFSVRS=development
|
---|
| 206 | ;;
|
---|
| 207 | *EDIT* ) echo " You forgot to set the branch or stable book version."
|
---|
| 208 | echo " Please rerun make and fix the configuration."
|
---|
| 209 | exit 2 ;;
|
---|
| 210 | branch-* )
|
---|
[c4ad7bf] | 211 | case $PROGNAME in
|
---|
| 212 | lfs )
|
---|
| 213 | LFSVRS=${BRANCH_ID}
|
---|
[bb2862d] | 214 | TREE=branches/${BRANCH_ID#branch-}
|
---|
[dd08e14] | 215 | if [ ${BRANCH_ID:7:1} = 6 ]; then
|
---|
[bb2862d] | 216 | TREE=${TREE}/BOOK
|
---|
| 217 | fi
|
---|
[c4ad7bf] | 218 | ;;
|
---|
| 219 | clfs* )
|
---|
| 220 | LFSVRS=${BRANCH_ID}
|
---|
| 221 | TREE=${BRANCH_ID#branch-}
|
---|
| 222 | ;;
|
---|
| 223 | esac
|
---|
[4965fa8] | 224 | ;;
|
---|
| 225 | * )
|
---|
| 226 | case $PROGNAME in
|
---|
[e650dc7] | 227 | lfs )
|
---|
| 228 | LFSVRS=${BRANCH_ID}
|
---|
| 229 | TREE=tags/${BRANCH_ID}
|
---|
[7e9e66f] | 230 | case ${BRANCH_ID:0:2} in
|
---|
[f7c6c3c] | 231 | [1-9][0-9]) ;;
|
---|
[7e9e66f] | 232 | [789]*) ;;
|
---|
| 233 | *) TREE=${TREE}/BOOK ;;
|
---|
| 234 | esac
|
---|
[e650dc7] | 235 | ;;
|
---|
| 236 | hlfs )
|
---|
[4965fa8] | 237 | LFSVRS=${BRANCH_ID}
|
---|
| 238 | TREE=tags/${BRANCH_ID}/BOOK
|
---|
| 239 | ;;
|
---|
[92b7cb8] | 240 | clfs* )
|
---|
[4965fa8] | 241 | LFSVRS=${BRANCH_ID}
|
---|
[34d1b6a] | 242 | TREE=clfs-${BRANCH_ID}
|
---|
[4965fa8] | 243 | ;;
|
---|
[92b7cb8] | 244 | * )
|
---|
[4965fa8] | 245 | esac
|
---|
| 246 | ;;
|
---|
| 247 | esac
|
---|
| 248 |
|
---|
[4da2512] | 249 | # Set the document location...
|
---|
[1cf621b] | 250 | BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
|
---|
[4da2512] | 251 |
|
---|
[4965fa8] | 252 |
|
---|
[728955b] | 253 | #--- Envars not sourced from configuration
|
---|
[0e4ddfa] | 254 | # shellcheck disable=SC2034
|
---|
[728955b] | 255 | case $PROGNAME in
|
---|
[0e4ddfa] | 256 | clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
|
---|
| 257 | clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
|
---|
| 258 | clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
|
---|
| 259 | *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
|
---|
[728955b] | 260 | esac
|
---|
[0e4ddfa] | 261 |
|
---|
[728955b] | 262 | declare -r LOG=000-masterscript.log
|
---|
[0e4ddfa] | 263 | # Needed for fetching BLFS book sources when building CLFS
|
---|
| 264 | # shellcheck disable=SC2034
|
---|
[728955b] | 265 | declare -r SVN_2="svn://svn.linuxfromscratch.org"
|
---|
| 266 |
|
---|
[4da2512] | 267 | # Set true internal variables
|
---|
| 268 | COMMON_DIR="common"
|
---|
[0e4ddfa] | 269 | PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]')
|
---|
[4da2512] | 270 | MODULE=$PACKAGE_DIR/master.sh
|
---|
[7072e1f] | 271 | PKGMNGTDIR="pkgmngt"
|
---|
| 272 | # The name packageManager.xml is hardcoded in *.xsl, so no variable.
|
---|
[4da2512] | 273 |
|
---|
[0e4ddfa] | 274 | for file in \
|
---|
| 275 | "$COMMON_DIR/common-functions" \
|
---|
| 276 | "$COMMON_DIR/libs/func_book_parser" \
|
---|
| 277 | "$COMMON_DIR/libs/func_download_pkgs" \
|
---|
| 278 | "$COMMON_DIR/libs/func_wrt_Makefile" \
|
---|
| 279 | "$MODULE" ; do
|
---|
| 280 | load_file "$file"
|
---|
| 281 | done
|
---|
[9a536f7] | 282 |
|
---|
[0e4ddfa] | 283 | simple_message "${SD_BORDER}${nl_}"
|
---|
[9a536f7] | 284 |
|
---|
| 285 |
|
---|
[0e4ddfa] | 286 | #*******************************************************************#
|
---|
| 287 | LASTERR=2
|
---|
| 288 | for file in \
|
---|
| 289 | "$COMMON_DIR/libs/func_check_version.sh" \
|
---|
| 290 | "$COMMON_DIR/libs/func_validate_configs.sh" \
|
---|
| 291 | "$COMMON_DIR/libs/func_custom_pkgs" ; do
|
---|
| 292 | load_file "$file"
|
---|
| 293 | done
|
---|
| 294 | unset LASTERR
|
---|
| 295 |
|
---|
| 296 | simple_message "${SD_BORDER}${nl_}"
|
---|
[183cc33] | 297 | simple_message "Checking tools required for jhalfs${nl_}"
|
---|
[6ed3dd7] | 298 | check_alfs_tools
|
---|
[0e4ddfa] | 299 | simple_message "${SD_BORDER}${nl_}"
|
---|
[4da2512] | 300 |
|
---|
[e576789] | 301 | # blfs-tool envars
|
---|
| 302 | BLFS_TOOL=${BLFS_TOOL:-n}
|
---|
| 303 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
[0e4ddfa] | 304 | simple_message 'Checking supplementary tools for installing BLFS'
|
---|
[6ed3dd7] | 305 | check_blfs_tools
|
---|
[0e4ddfa] | 306 | simple_message "${SD_BORDER}${nl_}"
|
---|
[854854e] | 307 | BLFS_SVN=${BLFS_SVN:-n}
|
---|
| 308 | BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
|
---|
| 309 | BLFS_BRANCH=${BLFS_BRANCH:-n}
|
---|
| 310 | if [[ "${BLFS_SVN}" = "y" ]]; then
|
---|
| 311 | BLFS_BRANCH_ID=development
|
---|
| 312 | BLFS_TREE=trunk/BOOK
|
---|
| 313 | elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
|
---|
[0e4ddfa] | 314 | if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
|
---|
[854854e] | 315 | echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
|
---|
| 316 | echo " Please rerun make and fix the configuration."
|
---|
| 317 | exit 2
|
---|
[0e4ddfa] | 318 | fi
|
---|
| 319 | BLFS_TREE=$(cd "$BLFS_WC_LOCATION"; svn info | grep '^URL' | sed 's@.*BLFS/@@')
|
---|
| 320 | BLFS_BRANCH_ID=$(echo "$BLFS_TREE" | sed -e 's@trunk/BOOK@development@' \
|
---|
| 321 | -e 's@branches/@branch-@' \
|
---|
| 322 | -e 's@tags/@@' \
|
---|
| 323 | -e 's@/BOOK@@')
|
---|
[0ba80be] | 324 | elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
|
---|
[854854e] | 325 | case $BLFS_BRANCH_ID in
|
---|
| 326 | *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
|
---|
| 327 | echo " Please rerun make and fix the configuration."
|
---|
| 328 | exit 2 ;;
|
---|
[dd08e14] | 329 | branch-6.* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-}/BOOK ;;
|
---|
| 330 | branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
|
---|
[91b5249] | 331 | [isv]* | 6.3* ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
|
---|
| 332 | * ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
|
---|
[854854e] | 333 | esac
|
---|
| 334 | fi
|
---|
[0e4ddfa] | 335 | load_file "${COMMON_DIR}/libs/func_install_blfs"
|
---|
[e576789] | 336 | fi
|
---|
[4da2512] | 337 |
|
---|
| 338 | ###################################
|
---|
| 339 | ### MAIN ###
|
---|
| 340 | ###################################
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | validate_config
|
---|
| 344 | echo "${SD_BORDER}${nl_}"
|
---|
| 345 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
[0e4ddfa] | 346 | read -r ANSWER
|
---|
| 347 | if [ "x$ANSWER" != "xyes" ] ; then
|
---|
[881c96f] | 348 | echo "${nl_}Rerun make to fix the configuration options.${nl_}"
|
---|
[d023a35] | 349 | exit
|
---|
[4da2512] | 350 | fi
|
---|
| 351 | echo "${nl_}${SD_BORDER}${nl_}"
|
---|
| 352 |
|
---|
| 353 | # Load additional modules or configuration files based on global settings
|
---|
| 354 | # compare module
|
---|
| 355 | if [[ "$COMPARE" = "y" ]]; then
|
---|
[0e4ddfa] | 356 | load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
|
---|
[4da2512] | 357 | fi
|
---|
| 358 | #
|
---|
[f5ecc28] | 359 | # save module
|
---|
| 360 | if [[ "$SAVE_CH5" = "y" ]]; then
|
---|
| 361 | load_file "${COMMON_DIR}/libs/func_save.sh" 'Loading save module'
|
---|
| 362 | fi
|
---|
| 363 | #
|
---|
[4da2512] | 364 | # optimize module
|
---|
| 365 | if [[ "$OPTIMIZE" != "0" ]]; then
|
---|
[0e4ddfa] | 366 | load_file optimize/optimize_functions 'Loading optimization module'
|
---|
[4da2512] | 367 | #
|
---|
| 368 | # optimize configurations
|
---|
[0e4ddfa] | 369 | load_file optimize/opt_config 'Loading optimization config'
|
---|
[854854e] | 370 | # The number of parallel jobs is taken from configuration now
|
---|
[0e4ddfa] | 371 | # shellcheck disable=SC2034
|
---|
[9ef12f7] | 372 | JH_MAKEFLAGS="-j${N_PARALLEL}"
|
---|
[4da2512] | 373 | # Validate optimize settings, if required
|
---|
| 374 | validate_opt_settings
|
---|
| 375 | fi
|
---|
| 376 | #
|
---|
| 377 |
|
---|
[a16f769] | 378 | if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
|
---|
[4da2512] | 379 |
|
---|
[200fbde] | 380 | # If requested, clean the build directory
|
---|
[7b6ecc5] | 381 | clean_builddir
|
---|
[4da2512] | 382 |
|
---|
[7b6ecc5] | 383 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
[0e4ddfa] | 384 | sudo mkdir -p "$JHALFSDIR"
|
---|
| 385 | sudo chown "$USER":"$USER" "$JHALFSDIR"
|
---|
[7b6ecc5] | 386 | fi
|
---|
[3e7ceed] | 387 |
|
---|
[200fbde] | 388 | # Create $BUILDDIR/sources even though it could be created by get_sources()
|
---|
[7b6ecc5] | 389 | if [[ ! -d $BUILDDIR/sources ]]; then
|
---|
[0e4ddfa] | 390 | sudo mkdir -p "$BUILDDIR/sources"
|
---|
| 391 | sudo chmod a+wt "$BUILDDIR/sources"
|
---|
[7b6ecc5] | 392 | fi
|
---|
[200fbde] | 393 |
|
---|
| 394 | # Create the log directory
|
---|
[7b6ecc5] | 395 | if [[ ! -d $LOGDIR ]]; then
|
---|
[0e4ddfa] | 396 | mkdir "$LOGDIR"
|
---|
[7b6ecc5] | 397 | fi
|
---|
[0e4ddfa] | 398 | true >"$LOGDIR/$LOG"
|
---|
[200fbde] | 399 |
|
---|
| 400 | # Copy common helper files
|
---|
[0e4ddfa] | 401 | cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/"
|
---|
[200fbde] | 402 |
|
---|
| 403 | # Copy needed stylesheets
|
---|
[0e4ddfa] | 404 | cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
|
---|
[200fbde] | 405 |
|
---|
| 406 | # Fix the XSL book parser
|
---|
[92b7cb8] | 407 | case $PROGNAME in
|
---|
[0e4ddfa] | 408 | clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
|
---|
| 409 | lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
|
---|
[92b7cb8] | 410 | * ) ;;
|
---|
| 411 | esac
|
---|
[3e7ceed] | 412 | export XSL=$JHALFSDIR/${XSL}
|
---|
[7b6ecc5] | 413 |
|
---|
[200fbde] | 414 | # Copy packageManager.xml, if needed
|
---|
[3aa1acd] | 415 | [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
|
---|
[5a965ad] | 416 | sed s@BOOK@"$BOOK"@ "$PKGMNGTDIR/packageManager.xml" > \
|
---|
| 417 | "$JHALFSDIR/"packageManager.xml
|
---|
[0e4ddfa] | 418 | cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
|
---|
[3aa1acd] | 419 | }
|
---|
[200fbde] | 420 |
|
---|
| 421 | # Copy urls.xsl, if needed
|
---|
[0e4ddfa] | 422 | [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
|
---|
[200fbde] | 423 |
|
---|
[c672fa8] | 424 | # Always create the test-log directory to allow user to "uncomment" test
|
---|
| 425 | # instructions
|
---|
[0e4ddfa] | 426 | install -d -m 1777 "$TESTLOGDIR"
|
---|
[200fbde] | 427 |
|
---|
| 428 | # Create the installed-files directory, if needed
|
---|
[0e4ddfa] | 429 | [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
|
---|
[200fbde] | 430 |
|
---|
| 431 | # Prepare report creation, if needed
|
---|
[7b6ecc5] | 432 | if [[ "$REPORT" = "y" ]]; then
|
---|
[0e4ddfa] | 433 | cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
|
---|
[7072e1f] | 434 | # After making sure that all looks sane, dump the settings to a file
|
---|
[7b6ecc5] | 435 | # This file will be used to create the REPORT header
|
---|
[0e4ddfa] | 436 | validate_config >"$JHALFSDIR/jhalfs.config"
|
---|
[7b6ecc5] | 437 | fi
|
---|
[200fbde] | 438 |
|
---|
| 439 | # Copy optimize files, if needed
|
---|
[0e4ddfa] | 440 | [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
|
---|
[200fbde] | 441 |
|
---|
| 442 | # Copy compare files, if needed
|
---|
[3e7ceed] | 443 | if [[ "$COMPARE" = "y" ]]; then
|
---|
[0e4ddfa] | 444 | mkdir -p "$JHALFSDIR/extras"
|
---|
| 445 | cp extras/* "$JHALFSDIR/extras"
|
---|
[3e7ceed] | 446 | fi
|
---|
[200fbde] | 447 |
|
---|
| 448 | # Copy custom tools config files, if requested
|
---|
[3e7ceed] | 449 | if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
|
---|
| 450 | echo "Copying custom tool scripts to $JHALFSDIR"
|
---|
[0e4ddfa] | 451 | mkdir -p "$JHALFSDIR/custom-commands"
|
---|
| 452 | cp -f custom/config/* "$JHALFSDIR/custom-commands"
|
---|
[3e7ceed] | 453 | fi
|
---|
[200fbde] | 454 |
|
---|
[f733772] | 455 | # Download or updates the book source
|
---|
| 456 | # Note that all customization to $JHALFSDIR have to be done before this.
|
---|
| 457 | # But the LFS book is needed for BLFS tools.
|
---|
| 458 | get_book
|
---|
[ebe1ba6] | 459 | # At this point, we should have a way to know whether we have a cross
|
---|
| 460 | # or regular book... In case of cross, prohibite TEST=3
|
---|
| 461 | # the position of gcc-pass2 (chapter 6 or 5) tells us (not valid for
|
---|
| 462 | # cross-chap5 branch).
|
---|
| 463 | if (( TEST == 3 )) && \
|
---|
[6447575] | 464 | [ -f "$BOOK/chapter06/gcc-pass2.xml" ]; then
|
---|
[ebe1ba6] | 465 | TEST=2
|
---|
| 466 | fi
|
---|
[f733772] | 467 | extract_commands
|
---|
| 468 | echo "${SD_BORDER}${nl_}"
|
---|
[0e4ddfa] | 469 | cd "$CWD" # the functions above change directory
|
---|
[f733772] | 470 |
|
---|
[200fbde] | 471 | # Install blfs-tool, if requested.
|
---|
[7b6ecc5] | 472 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
[6ed3dd7] | 473 | echo Installing BLFS book and tools
|
---|
[0e4ddfa] | 474 | install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
|
---|
[bbcdeab] | 475 | [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
|
---|
[7b6ecc5] | 476 | fi
|
---|
| 477 |
|
---|
[4965fa8] | 478 | fi
|
---|
| 479 |
|
---|
[0e4ddfa] | 480 | # shellcheck disable=SC2034
|
---|
[a16f769] | 481 | if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
|
---|
[8b85dae] | 482 | # Sanity check: users tend to tick "rebuild Makefile"
|
---|
| 483 | # without generating one first. Check we have one:
|
---|
| 484 | if [ ! -f $MKFILE ]; then
|
---|
| 485 | set -e
|
---|
| 486 | error_message "You cannot \"rebuild Makefile\" without first building one"
|
---|
| 487 | fi
|
---|
| 488 | # When regenerating the Makefile, we need to know also the
|
---|
| 489 | # canonical book version
|
---|
[a16f769] | 490 | case $PROGNAME in
|
---|
[92b7cb8] | 491 | clfs* )
|
---|
[0e4ddfa] | 492 | VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
[c9598f2] | 493 | lfs)
|
---|
| 494 | if [[ "$INITSYS" = "sysv" ]] ; then
|
---|
[0e4ddfa] | 495 | VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2)
|
---|
[c9598f2] | 496 | else
|
---|
[0e4ddfa] | 497 | VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2)
|
---|
[c9598f2] | 498 | fi
|
---|
| 499 | ;;
|
---|
[a16f769] | 500 | *)
|
---|
[0e4ddfa] | 501 | VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
[a16f769] | 502 | esac
|
---|
| 503 | fi
|
---|
| 504 |
|
---|
[4da2512] | 505 | build_Makefile
|
---|
[3e7ceed] | 506 |
|
---|
[4da2512] | 507 | echo "${SD_BORDER}${nl_}"
|
---|
| 508 |
|
---|
[1cf621b] | 509 | # Check for build prerequisites.
|
---|
| 510 | echo
|
---|
[0e4ddfa] | 511 | cd "$CWD"
|
---|
[1cf621b] | 512 | check_prerequisites
|
---|
| 513 | echo "${SD_BORDER}${nl_}"
|
---|
| 514 | # All is well, run the build (if requested)
|
---|
[4da2512] | 515 | run_make
|
---|