source: jhalfs@ c4ad7bf

2.4 ablfs-more legacy new_features trunk
Last change on this file since c4ad7bf was c4ad7bf, checked in by Pierre Labastie <pierre@…>, 10 years ago

Make the use of branches clearer, and allow branches to be used
for CLFS

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