source: jhalfs@ 1318902

ablfs-more legacy trunk
Last change on this file since 1318902 was b3825c3, checked in by Pierre Labastie <pierre.labastie@…>, 4 years ago

Adapt jhalfs to git

Note that the *_TREE var names should be changed to something related to
branch

  • Property mode set to 100755
File size: 14.3 KB
Line 
1#!/bin/bash
2set -e
3# Pass trap handlers to functions
4set -E
5
6# VT100 colors
7declare -r RED=$'\e[31m'
8declare -r GREEN=$'\e[32m'
9declare -r YELLOW=$'\e[33m'
10
11# shellcheck disable=SC2034
12declare -r BLUE=$'\e[34m'
13declare -r OFF=$'\e[0m'
14declare -r BOLD=$'\e[1m'
15declare -r tab_=$'\t'
16declare -r nl_=$'\n'
17
18# shellcheck disable=SC2034
19declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
20# shellcheck disable=SC2034
21declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
22# shellcheck disable=SC2034
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#-----------------------#
34 LASTLINE="$1"
35 LASTERR="$2"
36 LASTSOURCE="$4"
37 error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
38}
39
40see_ya() {
41 printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
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
56trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
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
60#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
61
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
101git_commit=$(git log -1 --format=format:"%h %ad")
102version="
103${BOLD} \"jhalfs\"${OFF} builder tool (development) $git_commit
104
105 Copyright (C) 2005-2021, the jhalfs team:
106 Jeremy Huntwork
107 George Boudreau
108 Manuel Canales Esparcia
109 Thomas Pegg
110 Matthew Burgess
111 Pierre Labastie
112
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.
115
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.
118"
119
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
124case $1 in
125 -v ) echo "$version" && exit ;;
126 run ) : ;;
127 * ) echo "$usage" && exit 1 ;;
128esac
129
130# If the user has not saved his configuration file, let's ask
131# if he or she really wants to run this stuff
132time_current=$(stat -c '%Y' configuration 2>/dev/null || date +%s)
133time_old=$(stat -c '%Y' configuration.old 2>/dev/null || printf '%s' "$time_current")
134if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then
135 printf 'Do you want to run jhalfs? yes/no (yes): '
136 read -r ANSWER
137 case ${ANSWER:0:1} in
138 n|N) printf "\nExiting gracefully.\n"; exit ;;
139 esac
140fi
141
142# Change this to 0 to suppress almost all messages
143VERBOSITY=1
144
145load_file configuration "Loading config params from <configuration>"
146
147# These are boolean vars generated from Config.in.
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).
153RUNMAKE=${RUNMAKE:-n}
154GETPKG=${GETPKG:-n}
155COMPARE=${COMPARE:-n}
156RUN_ICA=${RUN_ICA:-n}
157PKGMNGT=${PKGMNGT:-n}
158WRAP_INSTALL=${WRAP_INSTALL:-n}
159BOMB_TEST=${BOMB_TEST:-n}
160STRIP=${STRIP:=n}
161REPORT=${REPORT:=n}
162NCURSES5=${NCURSES5:-n}
163DEL_LA_FILES=${DEL_LA_FILES:-n}
164FULL_LOCALE=${FULL_LOCALE:-n}
165GRSECURITY_HOST=${GRSECURITY_HOST:-n}
166CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
167REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
168INSTALL_LOG=${INSTALL_LOG:-n}
169CLEAN=${CLEAN:=n}
170SET_SSP=${SET_SSP:=n}
171SET_ASLR=${SET_ASLR:=n}
172SET_PAX=${SET_PAX:=n}
173SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
174SET_WARNINGS=${SET_WARNINGS:=n}
175SET_MISC=${SET_MISC:=n}
176SET_BLOWFISH=${SET_BLOWFISH:=n}
177UNICODE=${UNICODE:=n}
178LOCAL=${LOCAL:=n}
179REALSBU=${REALSBU:=n}
180SAVE_CH5=${SAVE_CH5:=n}
181
182if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
183# shellcheck disable=SC2034
184 NO_PROGRESS="#"
185fi
186
187# Sanity check on the location of $BUILDDIR / $JHALFSDIR
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
193fi
194
195# Book sources envars
196BRANCH_ID=${BRANCH_ID:=development}
197
198case $BRANCH_ID in
199 development )
200 case $PROGNAME in
201 clfs* ) TREE="" ;;
202 * ) TREE=trunk ;;
203 esac
204 LFSVRS=development
205 ;;
206 *EDIT* ) echo " You forgot to set the branch or stable book version."
207 echo " Please rerun make and fix the configuration."
208 exit 2 ;;
209 branch-* )
210 case $PROGNAME in
211 lfs )
212 LFSVRS=${BRANCH_ID}
213 TREE=${BRANCH_ID#branch-}
214 ;;
215 clfs* )
216 LFSVRS=${BRANCH_ID}
217 TREE=${BRANCH_ID#branch-}
218 ;;
219 esac
220 ;;
221 * )
222 case $PROGNAME in
223 lfs )
224 LFSVRS=${BRANCH_ID}
225 TREE=${BRANCH_ID}
226 ;;
227 hlfs )
228 LFSVRS=${BRANCH_ID}
229 TREE=tags/${BRANCH_ID}/BOOK
230 ;;
231 clfs* )
232 LFSVRS=${BRANCH_ID}
233 TREE=clfs-${BRANCH_ID}
234 ;;
235 * )
236 esac
237 ;;
238esac
239
240# Set the document location...
241BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
242
243
244#--- Envars not sourced from configuration
245# shellcheck disable=SC2034
246case $PROGNAME in
247 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
248 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
249 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
250 *) declare -r GIT="git://git.linuxfromscratch.org" ;;
251esac
252
253declare -r LOG=000-masterscript.log
254# Needed for fetching BLFS book sources when building CLFS
255# shellcheck disable=SC2034
256# declare -r GIT="git://git.linuxfromscratch.org"
257
258# Set true internal variables
259COMMON_DIR="common"
260PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]')
261MODULE=$PACKAGE_DIR/master.sh
262PKGMNGTDIR="pkgmngt"
263# The name packageManager.xml is hardcoded in *.xsl, so no variable.
264
265for file in \
266 "$COMMON_DIR/common-functions" \
267 "$COMMON_DIR/libs/func_book_parser" \
268 "$COMMON_DIR/libs/func_download_pkgs" \
269 "$COMMON_DIR/libs/func_wrt_Makefile" \
270 "$MODULE" ; do
271 load_file "$file"
272done
273
274simple_message "${SD_BORDER}${nl_}"
275
276
277#*******************************************************************#
278LASTERR=2
279for file in \
280 "$COMMON_DIR/libs/func_check_version.sh" \
281 "$COMMON_DIR/libs/func_validate_configs.sh" \
282 "$COMMON_DIR/libs/func_custom_pkgs" ; do
283 load_file "$file"
284done
285unset LASTERR
286
287simple_message "${SD_BORDER}${nl_}"
288simple_message "Checking tools required for jhalfs${nl_}"
289check_alfs_tools
290simple_message "${SD_BORDER}${nl_}"
291
292# blfs-tool envars
293BLFS_TOOL=${BLFS_TOOL:-n}
294if [[ "${BLFS_TOOL}" = "y" ]] ; then
295 simple_message 'Checking supplementary tools for installing BLFS'
296 check_blfs_tools
297 simple_message "${SD_BORDER}${nl_}"
298 BLFS_GIT=${BLFS_GIT:-n}
299 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
300 BLFS_BRANCH=${BLFS_BRANCH:-n}
301 if [[ "${BLFS_GIT}" = "y" ]]; then
302 BLFS_BRANCH_ID=development
303 BLFS_TREE=trunk
304 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
305 if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
306 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
307 echo " Please rerun make and fix the configuration."
308 exit 2
309 fi
310 BLFS_TREE=$(cd $BLFS_WC_LOCATION; git branch --show-current)
311 BLFS_BRANCH_ID=${BLFS_TREE/trunk/development}
312 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
313 case $BLFS_BRANCH_ID in
314 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
315 echo " Please rerun make and fix the configuration."
316 exit 2 ;;
317 * ) BLFS_TREE=${BLFS_BRANCH_ID#branch-}
318 esac
319 fi
320 load_file "${COMMON_DIR}/libs/func_install_blfs"
321fi
322
323###################################
324### MAIN ###
325###################################
326
327
328validate_config
329echo "${SD_BORDER}${nl_}"
330echo -n "Are you happy with these settings? yes/no (no): "
331read -r ANSWER
332if [ "x$ANSWER" != "xyes" ] ; then
333 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
334 exit
335fi
336echo "${nl_}${SD_BORDER}${nl_}"
337
338# Load additional modules or configuration files based on global settings
339# compare module
340if [[ "$COMPARE" = "y" ]]; then
341 load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
342fi
343#
344# save module
345if [[ "$SAVE_CH5" = "y" ]]; then
346 load_file "${COMMON_DIR}/libs/func_save.sh" 'Loading save module'
347fi
348#
349# optimize module
350if [[ "$OPTIMIZE" != "0" ]]; then
351 load_file optimize/optimize_functions 'Loading optimization module'
352 #
353 # optimize configurations
354 load_file optimize/opt_config 'Loading optimization config'
355 # The number of parallel jobs is taken from configuration now
356 # shellcheck disable=SC2034
357 JH_MAKEFLAGS="-j${N_PARALLEL}"
358 # Validate optimize settings, if required
359 validate_opt_settings
360fi
361#
362
363if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
364
365# If requested, clean the build directory
366 clean_builddir
367
368 if [[ ! -d $JHALFSDIR ]]; then
369 sudo mkdir -p "$JHALFSDIR"
370 sudo chown "$USER":"$USER" "$JHALFSDIR"
371 fi
372
373# Create $BUILDDIR/sources even though it could be created by get_sources()
374 if [[ ! -d $BUILDDIR/sources ]]; then
375 sudo mkdir -p "$BUILDDIR/sources"
376 sudo chmod a+wt "$BUILDDIR/sources"
377 fi
378
379# Create the log directory
380 if [[ ! -d $LOGDIR ]]; then
381 mkdir "$LOGDIR"
382 fi
383 true >"$LOGDIR/$LOG"
384
385# Copy common helper files
386 cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/"
387
388# Copy needed stylesheets
389 cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
390
391# Fix the XSL book parser
392 case $PROGNAME in
393 clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
394 lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
395 * ) ;;
396 esac
397 export XSL=$JHALFSDIR/${XSL}
398
399# Copy packageManager.xml, if needed
400 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
401 sed s@BOOK@"$BOOK"@ "$PKGMNGTDIR/packageManager.xml" > \
402 "$JHALFSDIR/"packageManager.xml
403 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
404 }
405
406# Copy urls.xsl, if needed
407 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
408
409# Always create the test-log directory to allow user to "uncomment" test
410# instructions
411 install -d -m 1777 "$TESTLOGDIR"
412
413# Create the installed-files directory, if needed
414 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
415
416# Prepare report creation, if needed
417 if [[ "$REPORT" = "y" ]]; then
418 cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
419 # After making sure that all looks sane, dump the settings to a file
420 # This file will be used to create the REPORT header
421 validate_config >"$JHALFSDIR/jhalfs.config"
422 fi
423
424# Copy optimize files, if needed
425 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
426
427# Copy compare files, if needed
428 if [[ "$COMPARE" = "y" ]]; then
429 mkdir -p "$JHALFSDIR/extras"
430 cp extras/* "$JHALFSDIR/extras"
431 fi
432
433# Copy custom tools config files, if requested
434 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
435 echo "Copying custom tool scripts to $JHALFSDIR"
436 mkdir -p "$JHALFSDIR/custom-commands"
437 cp -f custom/config/* "$JHALFSDIR/custom-commands"
438 fi
439
440# Download or updates the book source
441# Note that all customization to $JHALFSDIR have to be done before this.
442# But the LFS book is needed for BLFS tools.
443 get_book
444# At this point, we should have a way to know whether we have a cross
445# or regular book... In case of cross, prohibite TEST=3
446# the position of gcc-pass2 (chapter 6 or 5) tells us (not valid for
447# cross-chap5 branch).
448 if (( TEST == 3 )) && \
449 [ -f "$BOOK/chapter06/gcc-pass2.xml" ]; then
450 TEST=2
451 fi
452 extract_commands
453 echo "${SD_BORDER}${nl_}"
454 cd "$CWD" # the functions above change directory
455
456# Install blfs-tool, if requested.
457 if [[ "${BLFS_TOOL}" = "y" ]] ; then
458 echo Installing BLFS book and tools
459 install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
460 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
461 fi
462
463fi
464
465# shellcheck disable=SC2034
466if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
467# Sanity check: users tend to tick "rebuild Makefile"
468# without generating one first. Check we have one:
469 if [ ! -f $MKFILE ]; then
470 set -e
471 error_message "You cannot \"rebuild Makefile\" without first building one"
472 fi
473# When regenerating the Makefile, we need to know also the
474# canonical book version
475 case $PROGNAME in
476 clfs* )
477 VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
478 lfs)
479 if [[ "$INITSYS" = "sysv" ]] ; then
480 VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2)
481 else
482 VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2)
483 fi
484 ;;
485 *)
486 VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
487 esac
488fi
489
490build_Makefile
491
492echo "${SD_BORDER}${nl_}"
493
494# Check for build prerequisites.
495 echo
496 cd "$CWD"
497 check_prerequisites
498 echo "${SD_BORDER}${nl_}"
499# All is well, run the build (if requested)
500run_make
Note: See TracBrowser for help on using the repository browser.