source: jhalfs@ 4b80795

trunk
Last change on this file since 4b80795 was cacc6c5, checked in by Pierre Labastie <pierre.labastie@…>, 10 months ago

Allow users to pass a cpuset

If using a new book, MAKEFLAGS is set to -j$(nproc), so that if
we want to easure timings with 4 processors and our computer has
more than that, we need to restrict the number of processors.
Jhalfs allows to do that using th cpuset cgroup controller, so that
it only restrits the make job and not the whole machine. For that
use a small scripts written by Xi Ruoyao that restarts make this
the cpuset set.

  • Property mode set to 100755
File size: 11.8 KB
RevLine 
[4da2512]1#!/bin/bash
2set -e
[bbcdeab]3# Pass trap handlers to functions
4set -E
[4da2512]5
6# VT100 colors
7declare -r RED=$'\e[31m'
8declare -r GREEN=$'\e[32m'
9declare -r YELLOW=$'\e[33m'
10
[0e4ddfa]11# shellcheck disable=SC2034
12declare -r BLUE=$'\e[34m'
[4da2512]13declare -r OFF=$'\e[0m'
14declare -r BOLD=$'\e[1m'
15declare -r tab_=$'\t'
16declare -r nl_=$'\n'
17
[0e4ddfa]18# shellcheck disable=SC2034
[4da2512]19declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
[0e4ddfa]20# shellcheck disable=SC2034
[4da2512]21declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
[0e4ddfa]22# shellcheck disable=SC2034
[4da2512]23declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
24
25# bold yellow > < pair
26declare -r R_arrow=$'\e[1;33m>\e[0m'
27declare -r L_arrow=$'\e[1;33m<\e[0m'
28
29
30#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
31#-----------------------#
32simple_error() { # Basic error trap.... JUST DIE
33#-----------------------#
[0e4ddfa]34 LASTLINE="$1"
35 LASTERR="$2"
36 LASTSOURCE="$4"
37 error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
[4da2512]38}
39
40see_ya() {
[0e4ddfa]41 printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
[4da2512]42}
43##### Simple error TRAPS
44# ctrl-c SIGINT
45# ctrl-y
46# ctrl-z SIGTSTP
47# SIGHUP 1 HANGUP
48# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
49# SIGQUIT 3
50# SIGKILL 9 KILL
51# SIGTERM 15 TERMINATION
52# SIGSTOP 17,18,23 STOP THE PROCESS
53#####
54set -e
55trap see_ya 0
[bbcdeab]56trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
[d505128]57trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' \
58 HUP INT QUIT TERM # STOP stops tterminal output and does not seem to
59 # execute the handler
[4da2512]60#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
61
[0e4ddfa]62simple_message() {
63 # Prevents having to check $VERBOSITY everywhere
64 if [ "$VERBOSITY" -ne 0 ] ; then
65 # shellcheck disable=SC2059
66 printf "$*"
67 fi
68}
69
70warning_message() {
71 simple_message "${YELLOW}\\nWARNING:${OFF} $*\\n\\n"
72}
73
74error_message() {
75 # Prints an error message and exits with LASTERR or 1
76 if [ -n "$LASTERR" ] ; then
77 LASTERR=$(printf '%d' "$LASTERR")
78 else
79 LASTERR=1
80 fi
81 # If +e then disable text output
82 if [[ "$-" =~ e ]]; then
83 printf '\n\n%bERROR:%b %s\n' "$RED" "$OFF" "$*" >&2
84 fi
85 exit "$LASTERR"
86}
87
88load_file() {
89 # source files in a consistent way with an optional message
90 file="$1"
91 shift
92 msg="Loading file ${file}..."
93 [ -z "$*" ] || msg="$*..."
94 simple_message "$msg"
95
96 # shellcheck disable=SC1090
97 source "$file" 2>/dev/null || error_message "$file did not load"
98 simple_message "OK\\n"
99}
100
[e5518fd]101git_commit=$(git log -1 --format=format:"%h %ad")
[4da2512]102version="
[e5518fd]103${BOLD} \"jhalfs\"${OFF} builder tool (development) $git_commit
[4da2512]104
[4ba94ad]105 Copyright (C) 2005-2023, the jhalfs team:
[f596dde]106 Jeremy Huntwork
107 George Boudreau
108 Manuel Canales Esparcia
109 Thomas Pegg
110 Matthew Burgess
111 Pierre Labastie
[4da2512]112
[f596dde]113 Unless specified, all the files in this directory and its sub-directories
114 are subjected to the ${BOLD}MIT license${OFF}. See the ${BOLD}LICENSE${OFF} file.
[4da2512]115
[f596dde]116 The files in the ${BOLD}menu${OFF} directory are subjected to the ${BOLD}ISC License${OFF}.
117 See ${BOLD}LICENSE.txt${OFF} and ${BOLD}README${OFF} in that directory.
[4da2512]118"
119
[f596dde]120usage="${nl_}${tab_}${BOLD}${RED}This script cannot be called directly${OFF}
121${tab_}Type ${BOLD}make${OFF} to run the tool, or
122${tab_}Type ${BOLD}./jhalfs -v${OFF} to display version information."
123
[4da2512]124case $1 in
[909ee37]125 -v ) echo "$version" && exit ;;
[4da2512]126 run ) : ;;
[f596dde]127 * ) echo "$usage" && exit 1 ;;
[4da2512]128esac
129
[65c998b]130# If the user has not saved his configuration file, let's ask
131# if he or she really wants to run this stuff
[a22bfe1]132time_current=$(stat -c '%Y' configuration 2>/dev/null || date +%s)
[cf2f109]133time_old=$(stat -c '%Y' configuration.old 2>/dev/null || printf '%s' "$time_current")
[a22bfe1]134if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then
135 printf 'Do you want to run jhalfs? yes/no (yes): '
[0e4ddfa]136 read -r ANSWER
[a22bfe1]137 case ${ANSWER:0:1} in
138 n|N) printf "\nExiting gracefully.\n"; exit ;;
139 esac
[65c998b]140fi
141
142# Change this to 0 to suppress almost all messages
[4da2512]143VERBOSITY=1
144
[0e4ddfa]145load_file configuration "Loading config params from <configuration>"
[4da2512]146
147# These are boolean vars generated from Config.in.
[7072e1f]148# ISSUE: If a boolean parameter is not set to y(es) there
149# is no variable defined by the menu app. This can
150# cause a headache if you are not aware.
151# The following variables MUST exist. If they don't, the
152# default value is n(o).
[4da2512]153RUNMAKE=${RUNMAKE:-n}
154GETPKG=${GETPKG:-n}
155COMPARE=${COMPARE:-n}
156RUN_ICA=${RUN_ICA:-n}
[7072e1f]157PKGMNGT=${PKGMNGT:-n}
[945ccaa]158WRAP_INSTALL=${WRAP_INSTALL:-n}
[4da2512]159STRIP=${STRIP:=n}
160REPORT=${REPORT:=n}
[085435e]161NCURSES5=${NCURSES5:-n}
[dc7fd7b]162DEL_LA_FILES=${DEL_LA_FILES:-n}
[b339c94]163FULL_LOCALE=${FULL_LOCALE:-n}
[4da2512]164GRSECURITY_HOST=${GRSECURITY_HOST:-n}
[9a536f7]165CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
[a16f769]166REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
[93346ee]167INSTALL_LOG=${INSTALL_LOG:-n}
[486e9a7]168CLEAN=${CLEAN:=n}
[d035526]169SET_SSP=${SET_SSP:=n}
170SET_ASLR=${SET_ASLR:=n}
171SET_PAX=${SET_PAX:=n}
172SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
173SET_WARNINGS=${SET_WARNINGS:=n}
174SET_MISC=${SET_MISC:=n}
175SET_BLOWFISH=${SET_BLOWFISH:=n}
[945ccaa]176UNICODE=${UNICODE:=n}
[3b43e17b]177LOCAL=${LOCAL:=n}
[645ec47]178ALL_CORES=${ALL_CORES:=n}
[84a3fda]179REALSBU=${REALSBU:=n}
[f5ecc28]180SAVE_CH5=${SAVE_CH5:=n}
[4da2512]181
[75d6d1c]182if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
[0e4ddfa]183# shellcheck disable=SC2034
184 NO_PROGRESS="#"
[75d6d1c]185fi
186
[38ae01f]187# Sanity check on the location of $BUILDDIR / $JHALFSDIR
[0e4ddfa]188CWD="$(cd "$(dirname "$0")" && pwd)"
189if [[ $JHALFSDIR == "$CWD" ]]; then
190 echo " The jhalfs source directory conflicts with the jhalfs build directory."
191 echo " Please move the source directory or change the build directory."
192 exit 2
[38ae01f]193fi
194
[4da2512]195# Set the document location...
[2fd624d]196BOOK=${BOOK:=$JHALFSDIR/book-source}
[4da2512]197
[4965fa8]198
[728955b]199#--- Envars not sourced from configuration
[0e4ddfa]200# shellcheck disable=SC2034
[875366f]201declare -r REPO=https://git.linuxfromscratch.org/lfs.git
[728955b]202declare -r LOG=000-masterscript.log
[2bd2fb8]203declare -r COMMANDS=lfs-commands
[728955b]204
[4da2512]205# Set true internal variables
206COMMON_DIR="common"
[8825e69]207PACKAGE_DIR=LFS
[4da2512]208MODULE=$PACKAGE_DIR/master.sh
[7072e1f]209PKGMNGTDIR="pkgmngt"
210# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[4da2512]211
[0e4ddfa]212for file in \
213 "$COMMON_DIR/common-functions" \
214 "$COMMON_DIR/libs/func_book_parser" \
215 "$COMMON_DIR/libs/func_download_pkgs" \
216 "$COMMON_DIR/libs/func_wrt_Makefile" \
217 "$MODULE" ; do
218 load_file "$file"
219done
[9a536f7]220
[0e4ddfa]221simple_message "${SD_BORDER}${nl_}"
[9a536f7]222
223
[0e4ddfa]224#*******************************************************************#
225LASTERR=2
226for file in \
227 "$COMMON_DIR/libs/func_check_version.sh" \
228 "$COMMON_DIR/libs/func_validate_configs.sh" \
229 "$COMMON_DIR/libs/func_custom_pkgs" ; do
230 load_file "$file"
231done
232unset LASTERR
233
234simple_message "${SD_BORDER}${nl_}"
[183cc33]235simple_message "Checking tools required for jhalfs${nl_}"
[6ed3dd7]236check_alfs_tools
[0e4ddfa]237simple_message "${SD_BORDER}${nl_}"
[4da2512]238
[e576789]239# blfs-tool envars
240BLFS_TOOL=${BLFS_TOOL:-n}
241if [[ "${BLFS_TOOL}" = "y" ]] ; then
[0870a7c]242#not needed now that the check is in alfs_tools
243# simple_message 'Checking supplementary tools for installing BLFS'
244# check_blfs_tools
[0e4ddfa]245 simple_message "${SD_BORDER}${nl_}"
[854854e]246 BLFS_BRANCH=${BLFS_BRANCH:-n}
[9b99ada]247 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
248 if [[ "${BLFS_WORKING_COPY}" = "y" ]] &&
249 [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
[854854e]250 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
251 echo " Please rerun make and fix the configuration."
252 exit 2
253 fi
[0e4ddfa]254 load_file "${COMMON_DIR}/libs/func_install_blfs"
[e576789]255fi
[4da2512]256
257###################################
258### MAIN ###
259###################################
260
261
262validate_config
263echo "${SD_BORDER}${nl_}"
264echo -n "Are you happy with these settings? yes/no (no): "
[0e4ddfa]265read -r ANSWER
266if [ "x$ANSWER" != "xyes" ] ; then
[881c96f]267 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
[d023a35]268 exit
[4da2512]269fi
270echo "${nl_}${SD_BORDER}${nl_}"
271
272# Load additional modules or configuration files based on global settings
273# compare module
274if [[ "$COMPARE" = "y" ]]; then
[0e4ddfa]275 load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
[4da2512]276fi
277#
[f5ecc28]278# save module
279if [[ "$SAVE_CH5" = "y" ]]; then
280 load_file "${COMMON_DIR}/libs/func_save.sh" 'Loading save module'
281fi
282#
[4da2512]283# optimize module
[f32cd50]284# the optimize_functions file is needed for wrt_makeflags even
285# if optimize=0, because we need to pass NINJAJOBS=1
286load_file optimize/optimize_functions 'Loading optimization module'
[4da2512]287if [[ "$OPTIMIZE" != "0" ]]; then
288 #
289 # optimize configurations
[0e4ddfa]290 load_file optimize/opt_config 'Loading optimization config'
[4da2512]291 # Validate optimize settings, if required
292 validate_opt_settings
293fi
[645ec47]294# Parallelization is outside optimization, because it is now in the book
295if [[ "$ALL_CORES" = "n" ]]; then
296 # shellcheck disable=SC2034
297 JH_MAKEFLAGS="-j${N_PARALLEL}"
298fi
[4da2512]299#
300
[a16f769]301if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
[4da2512]302
[200fbde]303# If requested, clean the build directory
[7b6ecc5]304 clean_builddir
[4da2512]305
[7b6ecc5]306 if [[ ! -d $JHALFSDIR ]]; then
[0e4ddfa]307 sudo mkdir -p "$JHALFSDIR"
[106157fd]308# Do not assume there is a group named as $USER, do not use
309# $USER:$USER...
310 sudo chown "$USER" "$JHALFSDIR"
[7b6ecc5]311 fi
[3e7ceed]312
[200fbde]313# Create $BUILDDIR/sources even though it could be created by get_sources()
[7b6ecc5]314 if [[ ! -d $BUILDDIR/sources ]]; then
[0e4ddfa]315 sudo mkdir -p "$BUILDDIR/sources"
316 sudo chmod a+wt "$BUILDDIR/sources"
[7b6ecc5]317 fi
[200fbde]318
319# Create the log directory
[7b6ecc5]320 if [[ ! -d $LOGDIR ]]; then
[0e4ddfa]321 mkdir "$LOGDIR"
[7b6ecc5]322 fi
[0e4ddfa]323 true >"$LOGDIR/$LOG"
[200fbde]324
325# Copy common helper files
[cacc6c5]326 cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh,run-in-cgroup.sh} "$JHALFSDIR/"
[200fbde]327
328# Copy needed stylesheets
[0e4ddfa]329 cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
[c412a07]330 cp "$PACKAGE_DIR/$XSL" "$JHALFSDIR/"
[200fbde]331
[3e7ceed]332 export XSL=$JHALFSDIR/${XSL}
[7b6ecc5]333
[200fbde]334# Copy packageManager.xml, if needed
[8825e69]335 [[ "$PKGMNGT" = "y" ]] && {
[5a965ad]336 sed s@BOOK@"$BOOK"@ "$PKGMNGTDIR/packageManager.xml" > \
337 "$JHALFSDIR/"packageManager.xml
[0e4ddfa]338 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
[3aa1acd]339 }
[200fbde]340
341# Copy urls.xsl, if needed
[0e4ddfa]342 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
[200fbde]343
[c672fa8]344# Always create the test-log directory to allow user to "uncomment" test
345# instructions
[0e4ddfa]346 install -d -m 1777 "$TESTLOGDIR"
[200fbde]347
348# Create the installed-files directory, if needed
[0e4ddfa]349 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
[200fbde]350
351# Prepare report creation, if needed
[7b6ecc5]352 if [[ "$REPORT" = "y" ]]; then
[0e4ddfa]353 cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
[7072e1f]354 # After making sure that all looks sane, dump the settings to a file
[7b6ecc5]355 # This file will be used to create the REPORT header
[0e4ddfa]356 validate_config >"$JHALFSDIR/jhalfs.config"
[7b6ecc5]357 fi
[200fbde]358
359# Copy optimize files, if needed
[0e4ddfa]360 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
[200fbde]361
362# Copy compare files, if needed
[3e7ceed]363 if [[ "$COMPARE" = "y" ]]; then
[0e4ddfa]364 mkdir -p "$JHALFSDIR/extras"
365 cp extras/* "$JHALFSDIR/extras"
[3e7ceed]366 fi
[200fbde]367
368# Copy custom tools config files, if requested
[3e7ceed]369 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
370 echo "Copying custom tool scripts to $JHALFSDIR"
[0e4ddfa]371 mkdir -p "$JHALFSDIR/custom-commands"
372 cp -f custom/config/* "$JHALFSDIR/custom-commands"
[3e7ceed]373 fi
[200fbde]374
[f733772]375# Download or updates the book source
376# Note that all customization to $JHALFSDIR have to be done before this.
377# But the LFS book is needed for BLFS tools.
378 get_book
379 extract_commands
380 echo "${SD_BORDER}${nl_}"
[0e4ddfa]381 cd "$CWD" # the functions above change directory
[f733772]382
[200fbde]383# Install blfs-tool, if requested.
[7b6ecc5]384 if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]385 echo Installing BLFS book and tools
[0e4ddfa]386 install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
[bbcdeab]387 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
[7b6ecc5]388 fi
389
[4965fa8]390fi
391
[0e4ddfa]392# shellcheck disable=SC2034
[a16f769]393if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
[8b85dae]394# Sanity check: users tend to tick "rebuild Makefile"
395# without generating one first. Check we have one:
396 if [ ! -f $MKFILE ]; then
397 set -e
398 error_message "You cannot \"rebuild Makefile\" without first building one"
399 fi
400# When regenerating the Makefile, we need to know also the
401# canonical book version
[0fa52f2]402VERSION=$(grep 'echo.*lfs-release' "$JHALFSDIR/prbook.xml" | sed 's/.*echo[ ]*\([^ ]*\).*/\1/')
[a16f769]403fi
404
[4da2512]405build_Makefile
[3e7ceed]406
[4da2512]407echo "${SD_BORDER}${nl_}"
408
[1cf621b]409# Check for build prerequisites.
410 echo
[0e4ddfa]411 cd "$CWD"
[1cf621b]412 check_prerequisites
413 echo "${SD_BORDER}${nl_}"
414# All is well, run the build (if requested)
[4da2512]415run_make
Note: See TracBrowser for help on using the repository browser.