2 set -e # Enable error trapping
6 ###################################
8 ###################################
11 #----------------------------#
12 process_toolchain
() { # embryo,cocoon and butterfly need special handling
13 #----------------------------#
18 local gcc_core_tarball
22 tc_phase
=`echo $toolchain | sed -e 's@[0-9]\{3\}-@@' -e 's@-toolchain@@' -e 's,'$N',,'`
25 cocoon
) # Vars for LUSER phase
26 remove_existing
="remove_existing_dirs"
27 TC_MountPT
="\$(MOUNT_PT)\$(SRC)"
29 butterfly
) # Vars for CHROOT phase
30 remove_existing
="remove_existing_dirs2"
36 # Safe method to remove existing toolchain dirs
37 binutil_tarball
=$
(get_package_tarball_name
"binutils")
38 gcc_core_tarball
=$
(get_package_tarball_name
"gcc-core")
41 @\$(call ${remove_existing},$binutil_tarball)
42 @\$(call ${remove_existing},$gcc_core_tarball)
47 # Manually remove the toolchain directories..
50 @rm -rf ${TC_MountPT}/${tc_phase}-toolchain && \\
51 rm -rf ${TC_MountPT}/${tc_phase}-build
58 @echo "export PKGDIR=${TC_MountPT}" > envars
64 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log
"${toolchain}"
65 CHROOT_wrt_RunAsRoot
"$this_file"
67 *) LUSER_wrt_RunAsUser
"$this_file"
73 @\$(call ${remove_existing},$binutil_tarball)
74 @\$(call ${remove_existing},$gcc_core_tarball)
79 # Manually remove the toolchain directories..
82 @rm -rf ${TC_MountPT}/${tc_phase}-toolchain && \\
83 rm -rf ${TC_MountPT}/${tc_phase}-build
90 #----------------------------#
91 chapter3_Makefiles
() { # Initialization of the system
92 #----------------------------#
94 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter3 ( SETUP ) ${R_arrow}"
96 # If $LUSER_HOME is already present in the host, we asume that the
97 # hlfs user and group are also presents in the host, and a backup
98 # of their bash init files is made.
101 020-creatingtoolsdir:
102 @\$(call echo_message, Building)
103 @mkdir \$(MOUNT_PT)/tools && \\
105 ln -s \$(MOUNT_PT)/tools /
106 @\$(call housekeeping)
108 021-addinguser: 020-creatingtoolsdir
109 @\$(call echo_message, Building)
110 @if [ ! -d \$(LUSER_HOME) ]; then \\
111 groupadd \$(LGROUP); \\
112 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
114 touch luser-exist; \\
116 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
117 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
118 chmod a+wt \$(SRCSDIR)
119 @\$(call housekeeping)
121 022-settingenvironment: 021-addinguser
122 @\$(call echo_message, Building)
123 @if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
124 mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
126 @if [ -f \$(LUSER_HOME)/.bash_profile -a ! -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
127 mv \$(LUSER_HOME)/.bash_profile \$(LUSER_HOME)/.bash_profile.XXX; \\
129 @echo "set +h" > \$(LUSER_HOME)/.bashrc && \\
130 echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
131 echo "HLFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
132 echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
133 echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
134 echo "export HLFS LC_ALL PATH" >> \$(LUSER_HOME)/.bashrc && \\
135 echo "" >> \$(LUSER_HOME)/.bashrc && \\
136 echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
137 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc && \\
138 chmod -R a+wt \$(MOUNT_PT) && \\
140 chown \$(LUSER) envars
141 @\$(call housekeeping)
144 chapter3
=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
147 #----------------------------#
148 chapter5_Makefiles
() { # Bootstrap or temptools phase
149 #----------------------------#
153 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
155 for file in chapter05
/* ; do
156 # Keep the script file name
157 this_script
=`basename $file`
159 # Skip this script depending on jhalfs.conf flags set.
161 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
162 *tcl
* ) [[ "$TEST" = "0" ]] && continue; ;;
163 *expect
* ) [[ "$TEST" = "0" ]] && continue; ;;
164 *dejagnu
* ) [[ "$TEST" = "0" ]] && continue; ;;
165 # Test if the stripping phase must be skipped
166 *stripping
* ) [[ "$STRIP" = "n" ]] && continue ;;
170 # First append each name of the script files to a list (this will become
171 # the names of the targets in the Makefile
172 chapter5
="$chapter5 $this_script"
174 # Grab the name of the target
175 name
=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
179 uclibc
) name
="uClibc" ;;
182 # Set the dependency for the first target.
183 if [ -z $PREV ] ; then PREV
=022-settingenvironment ; fi
185 #--------------------------------------------------------------------#
186 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
187 #--------------------------------------------------------------------#
189 # Drop in the name of the target on a new line, and the previous target
190 # as a dependency. Also call the echo_message function.
192 # This is a very special script and requires manual processing
193 # NO Optimization allowed
194 if [[ ${name} = "embryo-toolchain" ]] || \
195 [[ ${name} = "cocoon-toolchain" ]]; then
196 LUSER_wrt_target
"$this_script" "$PREV"
197 process_toolchain
"${this_script}" "${file}"
203 LUSER_wrt_target
"$this_script" "$PREV"
204 # Find the version of the command files, if it corresponds with the building of
205 # a specific package. Fix GCC tarball name for 2.4-branch.
207 gcc
) pkg_tarball
=$
(get_package_tarball_name gcc-core
) ;;
208 * ) pkg_tarball
=$
(get_package_tarball_name
$name) ;;
210 # If $pkg_tarball isn't empty, we've got a package...
211 if [ "$pkg_tarball" != "" ] ; then
212 # Insert instructions for unpacking the package and to set the PKGDIR variable.
213 LUSER_wrt_unpack
"$pkg_tarball"
214 # If using optimizations, write the instructions
215 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize
"$name" && wrt_makeflags
"$name"
217 # Insert date and disk usage at the top of the log file, the script run
218 # and date and disk usage again at the bottom of the log file.
219 LUSER_wrt_RunAsUser
"${file}"
221 # Remove the build directory(ies) except if the package build fails
222 # (so we can review config.cache, config.log, etc.)
223 if [ "$pkg_tarball" != "" ] ; then
224 LUSER_RemoveBuildDirs
"$name"
227 # Include a touch of the target name so make can check if it's already been made.
230 #--------------------------------------------------------------------#
231 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
232 #--------------------------------------------------------------------#
234 # Keep the script file name for Makefile dependencies.
236 done # end for file in chapter05/*
240 #----------------------------#
241 chapter6_Makefiles
() { # sysroot or chroot build phase
242 #----------------------------#
245 # Set envars and scripts for iteration targets
246 if [[ -z "$1" ]] ; then
252 cp chapter06
/* chapter06
$N
253 for script in chapter06
$N/* ; do
254 # Overwrite existing symlinks, files, and dirs
255 sed -e 's/ln -s /ln -sf /g' \
257 -e 's/mkdir -v/&p/g' -i ${script}
259 mv ${script} ${script}$N
261 # Remove Bzip2 binaries before make install
262 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06
$N/*-bzip2$N
263 # Fix how Module-Init-Tools do the install target
264 sed -e 's@make install@make INSTALL=install install@' -i chapter06
$N/*-module-init-tools$N
265 # Don't readd already existing groups
266 sed -e '/groupadd/d' -i chapter06
$N/*-udev$N
269 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
271 for file in chapter06
$N/* ; do
272 # Keep the script file name
273 this_script
=`basename $file`
275 # Skip this script depending on jhalfs.conf flags set.
277 # We'll run the chroot commands differently than the others, so skip them in the
278 # dependencies and target creation.
279 *chroot
* ) continue ;;
280 # Test if the stripping phase must be skipped
281 *-stripping* ) [[ "$STRIP" = "n" ]] && continue ;;
282 # Skip linux-headers in iterative builds
283 *linux-headers
*) [[ -n "$N" ]] && continue ;;
286 # Grab the name of the target
287 name
=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
290 uclibc
) name
="uClibc" ;;
293 # Find the version of the command files, if it corresponds with the building of
294 # a specific package. Fix GCC tarball name for 2.4-branch.
296 gcc
) pkg_tarball
=$
(get_package_tarball_name gcc-core
) ;;
297 * ) pkg_tarball
=$
(get_package_tarball_name
$name) ;;
300 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
301 case "${this_script}" in
307 # Append each name of the script files to a list (this will become
308 # the names of the targets in the Makefile
309 case "${this_script}" in
310 *kernfs
* ) runasroot
=" ${this_script}" ;;
311 * ) chapter6
="$chapter6 ${this_script}" ;;
315 #--------------------------------------------------------------------#
316 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
317 #--------------------------------------------------------------------#
319 # Drop in the name of the target on a new line, and the previous target
320 # as a dependency. Also call the echo_message function.
321 if [[ ${name} = "butterfly-toolchain" ]]; then
322 CHROOT_wrt_target
"${this_script}" "$PREV"
323 # Touch timestamp file if installed files logs will be created.
324 # But only for the firt build when running iterative builds.
325 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
326 CHROOT_wrt_TouchTimestamp
328 process_toolchain
"${this_script}" "${file}"
329 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
330 CHROOT_wrt_LogNewFiles
"$name"
336 # kernfs is run in SUDO target
337 case "${this_script}" in
338 *kernfs
* ) LUSER_wrt_target
"${this_script}" "$PREV" ;;
339 * ) CHROOT_wrt_target
"${this_script}" "$PREV" ;;
342 # If $pkg_tarball isn't empty, we've got a package...
343 # Insert instructions for unpacking the package and changing directories
344 if [ "$pkg_tarball" != "" ] ; then
345 # Touch timestamp file if installed files logs will be created.
346 # But only for the firt build when running iterative builds.
347 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
348 CHROOT_wrt_TouchTimestamp
350 CHROOT_Unpack
"$pkg_tarball"
351 # If the testsuites must be run, initialize the log file
352 # butterfly-toolchain tests are enabled in 'process_tookchain' function
353 # 2.4-branch toolchain is ernabled here.
355 glibc | gcc | binutils
)
356 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log
"${this_script}" ;;
357 * ) [[ "$TEST" > "1" ]] && CHROOT_wrt_test_log
"${this_script}" ;;
359 # If using optimizations, write the instructions
360 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize
"$name" && wrt_makeflags
"$name"
363 # In kernfs we need to set HLFS and not to use chroot.
364 case "${this_script}" in
365 *kernfs
* ) wrt_RunAsRoot
"${file}" ;;
366 * ) CHROOT_wrt_RunAsRoot
"${file}" ;;
369 # Write installed files log and remove the build directory(ies)
370 # except if the package build fails.
371 if [ "$pkg_tarball" != "" ] ; then
372 CHROOT_wrt_RemoveBuildDirs
"$name"
373 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
374 CHROOT_wrt_LogNewFiles
"$name"
378 # Include a touch of the target name so make can check if it's already been made.
381 #--------------------------------------------------------------------#
382 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
383 #--------------------------------------------------------------------#
385 # Keep the script file name for Makefile dependencies.
387 # Set system_build envar for iteration targets
388 system_build
=$chapter6
389 done # end for file in chapter06/*
393 #----------------------------#
394 chapter7_Makefiles
() { # Create a bootable system.. kernel, bootscripts..etc
395 #----------------------------#
399 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7 ( BOOT ) ${R_arrow}"
400 for file in chapter07
/*; do
401 # Keep the script file name
402 this_script
=`basename $file`
405 *grub
) continue ;; # Grub must be configured manually.
406 *console
) continue ;; # Use the file generated by lfs-bootscripts
407 *fstab
) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources
/fstab
409 *kernel
) # If no .config file is supplied, the kernel build is skipped
410 [[ -z $CONFIG ]] && continue
411 cp $CONFIG $BUILDDIR/sources
/kernel-config
415 # First append then name of the script file to a list (this will become
416 # the names of the targets in the Makefile
417 chapter7
="$chapter7 $this_script"
419 #--------------------------------------------------------------------#
420 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
421 #--------------------------------------------------------------------#
423 # Drop in the name of the target on a new line, and the previous target
424 # as a dependency. Also call the echo_message function.
425 CHROOT_wrt_target
"$this_script" "$PREV"
427 case "${this_script}" in
429 if [ "${INSTALL_LOG}" = "y" ] ; then
430 CHROOT_wrt_TouchTimestamp
432 CHROOT_Unpack $
(get_package_tarball_name
"lfs-bootscripts")
433 blfs_bootscripts
=$
(get_package_tarball_name
"blfs-bootscripts" |
sed -e 's/.tar.*//' )
434 echo -e "\t@echo \"\$(MOUNT_PT)\$(SRC)/$blfs_bootscripts\" >> sources-dir" >> $MKFILE.tmp
438 pkg_tarball
=$
(get_package_tarball_name
$name)
439 if [ "${INSTALL_LOG}" = "y" ] ; then
440 CHROOT_wrt_TouchTimestamp
442 CHROOT_Unpack
"$pkg_tarball"
446 case "${this_script}" in
447 *fstab
*) # Check if we have a real /etc/fstab file
448 if [[ -n "$FSTAB" ]] ; then
451 CHROOT_wrt_RunAsRoot
"$file"
454 *) # All other scripts
455 CHROOT_wrt_RunAsRoot
"${file}"
459 # Remove the build directory except if the package build fails.
460 case "${this_script}" in
464 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
465 rm -r \$(SRC)/\$\$ROOT
466 @rm -rf \`cat sources-dir\` && \\
470 if [ "${INSTALL_LOG}" = "y" ] ; then
471 CHROOT_wrt_LogNewFiles
"$name"
474 *kernel
) CHROOT_wrt_RemoveBuildDirs
"dummy"
475 if [ "${INSTALL_LOG}" = "y" ] ; then
476 CHROOT_wrt_LogNewFiles
"$name"
480 # Include a touch of the target name so make can check if it's already been made.
483 #--------------------------------------------------------------------#
484 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
485 #--------------------------------------------------------------------#
487 # Keep the script file name for Makefile dependencies.
489 done # for file in chapter07/*
493 #----------------------------#
494 build_Makefile
() { # Construct a Makefile from the book scripts
495 #----------------------------#
496 echo "Creating Makefile... ${BOLD}START${OFF}"
498 cd $JHALFSDIR/${PROGNAME}-commands
499 # Start with a clean Makefile.tmp file
505 # Add the iterations targets, if needed
506 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
508 # Add the CUSTOM_TOOLS targets, if needed
509 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
510 # Add the BLFS_TOOL targets, if needed
511 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
513 # Add a header, some variables and include the function file
514 # to the top of the real Makefile.
517 # Add chroot commands
518 CHROOT_LOC
="`whereis -b chroot | cut -d " " -f2`"
520 for file in chapter06
/*chroot
* ; do
521 chroot
=`cat $file | \
522 sed -e "s@chroot@$CHROOT_LOC@" \
523 -e '/#!\/bin\/bash/d' \
532 -e 's|"$$HLFS"|$(MOUNT_PT)|'\
535 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
539 # Drop in the main target 'all:' and the chapter targets with each sub-target
544 all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
545 @sudo make do-housekeeping
546 @echo "$VERSION - jhalfs build" > hlfs-release && \\
547 sudo install -m444 hlfs-release \$(MOUNT_PT)/etc/hlfs-release
548 @\$(call echo_finished,$VERSION)
551 @if [ \`id -u\` = "0" ]; then \\
552 echo "--------------------------------------------------"; \\
553 echo "You cannot run this makefile from the root account"; \\
554 echo "--------------------------------------------------"; \\
559 @\$(call echo_SU_request)
560 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
564 @\$(call echo_SULUSER_request)
565 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
566 @sudo make restore-luser-env
574 @if [ ! -e \$(MOUNT_PT)/dev ]; then \\
575 mkdir \$(MOUNT_PT)/dev && \\
576 sudo mknod -m 666 \$(MOUNT_PT)/dev/null c 1 3 && \\
577 sudo mknod -m 600 \$(MOUNT_PT)/dev/console c 5 1 && \\
578 sudo chown -R 0:0 \$(MOUNT_PT)/dev; \\
580 @\$(call echo_CHROOT_request)
581 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
585 @\$(call echo_CHROOT_request)
586 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
589 mk_CUSTOM_TOOLS: create-sbu_du-report
590 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
591 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
592 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
593 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
597 mk_BLFS_TOOL: mk_CUSTOM_TOOLS
598 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
599 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
600 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
601 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
609 CHROOT: SHELL=/tools/bin/bash
612 CUSTOM_TOOLS: $custom_list
613 BLFS_TOOL: $blfs_tool
616 create-sbu_du-report: mk_BOOT
617 @\$(call echo_message, Building)
618 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
619 ./create-sbu_du-report.sh logs $VERSION; \\
620 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
625 @\$(call echo_message, Building)
626 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
627 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
629 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
630 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
632 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash* && \\
634 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
635 echo --------------------------------------------------------------------------------\$(WHITE)
638 @-umount \$(MOUNT_PT)/dev/pts
639 @-umount \$(MOUNT_PT)/dev/shm
640 @-umount \$(MOUNT_PT)/dev
641 @-umount \$(MOUNT_PT)/sys
642 @-umount \$(MOUNT_PT)/proc
644 @-if [ ! -f luser-exist ]; then \\
645 userdel \$(LUSER); \\
646 rm -rf \$(LUSER_HOME); \\
654 # Bring over the items from the Makefile.tmp
655 cat $MKFILE.tmp
>> $MKFILE
657 echo "Creating Makefile... ${BOLD}DONE${OFF}"