source: LFS/master.sh@ b515be7

2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since b515be7 was 7072e1f, checked in by Thomas Pegg <thomasp@…>, 13 years ago

Commit Pierre Labastie's patch for including package management support in jhalfs. NOTE: Package management is by default disabled.

  • Property mode set to 100644
File size: 18.6 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10#############################################################
11
12
13#----------------------------#
14chapter4_Makefiles() { #
15#----------------------------#
16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
17
18# If $LUSER_HOME is already present in the host, we asume that the
19# lfs user and group are also presents in the host, and a backup
20# of their bash init files is made.
21(
22 cat << EOF
23020-creatingtoolsdir:
24 @\$(call echo_message, Building)
25 @mkdir \$(MOUNT_PT)/tools && \\
26 rm -f /tools && \\
27 ln -s \$(MOUNT_PT)/tools /
28 @\$(call housekeeping)
29
30021-addinguser: 020-creatingtoolsdir
31 @\$(call echo_message, Building)
32 @if [ ! -d \$(LUSER_HOME) ]; then \\
33 groupadd \$(LGROUP); \\
34 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
35 else \\
36 touch luser-exist; \\
37 fi;
38 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
39 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
40 chmod a+wt \$(SRCSDIR)
41 @\$(call housekeeping)
42
43022-settingenvironment: 021-addinguser
44 @\$(call echo_message, Building)
45 @if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
46 mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
47 fi;
48 @if [ -f \$(LUSER_HOME)/.bash_profile -a ! -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
49 mv \$(LUSER_HOME)/.bash_profile \$(LUSER_HOME)/.bash_profile.XXX; \\
50 fi;
51 @echo "set +h" > \$(LUSER_HOME)/.bashrc && \\
52 echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
53 echo "LFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
54 echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
55 echo "LFS_TGT=`uname -m`-lfs-linux-gnu" >> \$(LUSER_HOME)/.bashrc && \\
56 echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
57 echo "export LFS LC_ALL LFS_TGT PATH" >> \$(LUSER_HOME)/.bashrc && \\
58 echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
59 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc && \\
60 touch envars && \\
61 chown \$(LUSER) envars
62 @\$(call housekeeping)
63EOF
64) > $MKFILE.tmp
65
66 chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
67}
68
69
70
71#----------------------------#
72chapter5_Makefiles() {
73#----------------------------#
74 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
75
76 for file in chapter05/* ; do
77 # Keep the script file name
78 this_script=`basename $file`
79
80 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
81 # Fix also locales creation when running chapter05 testsuites (ugly)
82 case "${this_script}" in
83 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
84 *expect) [[ "${TEST}" = "0" ]] && continue ;;
85 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
86 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
87 *glibc) [[ "${TEST}" = "3" ]] && \
88 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
89 esac
90
91 # First append each name of the script files to a list (this will become
92 # the names of the targets in the Makefile
93 # DO NOT append the changingowner script, it need be run as root.
94 # A hack is necessary: create script in chap5 BUT run as a dependency for
95 # SUDO target
96 case "${this_script}" in
97 *changingowner) runasroot="$runasroot ${this_script}" ;;
98 *) chapter5="$chapter5 ${this_script}" ;;
99 esac
100
101 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
102 # and binutils in chapter 5)
103 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
104
105 # Set the dependency for the first target.
106 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
107
108 #--------------------------------------------------------------------#
109 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
110 #--------------------------------------------------------------------#
111 #
112 # Drop in the name of the target on a new line, and the previous target
113 # as a dependency. Also call the echo_message function.
114 LUSER_wrt_target "${this_script}" "$PREV"
115
116 # Find the version of the command files, if it corresponds with the building of
117 # a specific package
118 pkg_tarball=$(get_package_tarball_name $name)
119
120 # If $pkg_tarball isn't empty, we've got a package...
121 if [ "$pkg_tarball" != "" ] ; then
122 # Insert instructions for unpacking the package and to set the PKGDIR variable.
123 LUSER_wrt_unpack "$pkg_tarball"
124 # If the testsuites must be run, initialize the log file
125 [[ "$TEST" = "3" ]] && LUSER_wrt_test_log "${this_script}"
126 # If using optimizations, write the instructions
127 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
128 fi
129
130 # Insert date and disk usage at the top of the log file, the script run
131 # and date and disk usage again at the bottom of the log file.
132 # The changingowner script must be run as root.
133 case "${this_script}" in
134 *changingowner) wrt_RunAsRoot "$file" ;;
135 *) LUSER_wrt_RunAsUser "$file" ;;
136 esac
137
138 # Remove the build directory(ies) except if the package build fails
139 # (so we can review config.cache, config.log, etc.)
140 if [ "$pkg_tarball" != "" ] ; then
141 case "${name}" in
142 *xz-utils) LUSER_RemoveBuildDirs "xz" ;;
143 *) LUSER_RemoveBuildDirs "$name" ;;
144 esac
145 fi
146
147 # Include a touch of the target name so make can check
148 # if it's already been made.
149 wrt_touch
150 #
151 #--------------------------------------------------------------------#
152 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
153 #--------------------------------------------------------------------#
154
155 # Keep the script file name for Makefile dependencies.
156 PREV=${this_script}
157 done # end for file in chapter05/*
158}
159
160
161#----------------------------#
162chapter6_Makefiles() {
163#----------------------------#
164
165 # Set envars and scripts for iteration targets
166 if [[ -z "$1" ]] ; then
167 local N=""
168 else
169 local N=-build_$1
170 local chapter6=""
171 mkdir chapter06$N
172 cp chapter06/* chapter06$N
173 for script in chapter06$N/* ; do
174 # Overwrite existing symlinks, files, and dirs
175 sed -e 's/ln -sv/&f/g' \
176 -e 's/mv -v/&f/g' \
177 -e 's/mkdir -v/&p/g' -i ${script}
178 # Rename the scripts
179 mv ${script} ${script}$N
180 done
181 # Remove Bzip2 binaries before make install (LFS-6.2 compatibility)
182 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2$N
183 fi
184
185 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
186
187 for file in chapter06$N/* ; do
188 # Keep the script file name
189 this_script=`basename $file`
190
191 # We'll run the chroot commands differently than the others, so skip them in the
192 # dependencies and target creation.
193 # Skip also linux-headers in iterative builds.
194 case "${this_script}" in
195 *chroot) continue ;;
196 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
197 *linux-headers*) [[ -n "$N" ]] && continue ;;
198 esac
199
200 # Grab the name of the target.
201 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
202
203 # Find the version of the command files, if it corresponds with the building of
204 # a specific package. We need this here to can skip scripts not needed for
205 # iterations rebuilds
206 pkg_tarball=$(get_package_tarball_name $name)
207
208 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
209 case "${this_script}" in
210 *stripping*) ;;
211 *) continue ;;
212 esac
213 fi
214
215 # Append each name of the script files to a list (this will become
216 # the names of the targets in the Makefile)
217 # The kernfs script must be run as part of SUDO target.
218 case "${this_script}" in
219 *kernfs) runasroot="$runasroot ${this_script}" ;;
220 *) chapter6="$chapter6 ${this_script}" ;;
221 esac
222
223 #--------------------------------------------------------------------#
224 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
225 #--------------------------------------------------------------------#
226 #
227 # Drop in the name of the target on a new line, and the previous target
228 # as a dependency. Also call the echo_message function.
229 # In the mount of kernel filesystems we need to set LFS
230 # and not to use chroot.
231 case "${this_script}" in
232 *kernfs) LUSER_wrt_target "${this_script}" "$PREV" ;;
233 *) CHROOT_wrt_target "${this_script}" "$PREV" ;;
234 esac
235
236 # If $pkg_tarball isn't empty, we've got a package...
237 # Insert instructions for unpacking the package and changing directories
238 if [ "$pkg_tarball" != "" ] ; then
239 # Touch timestamp file if installed files logs will be created.
240 # But only for the firt build when running iterative builds.
241 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
242 CHROOT_wrt_TouchTimestamp
243 fi
244 CHROOT_Unpack "$pkg_tarball"
245 # If the testsuites must be run, initialize the log file
246 case $name in
247 binutils | gcc | glibc | gmp | mpfr )
248 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
249 ;;
250 * )
251 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
252 ;;
253 esac
254 # If using optimizations, write the instructions
255 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
256 fi
257
258 # In the mount of kernel filesystems we need to set LFS
259 # and not to use chroot.
260 case "${this_script}" in
261 *kernfs) wrt_RunAsRoot "$file" ;;
262 *) CHROOT_wrt_RunAsRoot "$file" ;;
263 esac
264
265 # Write installed files log and remove the build directory(ies)
266 # except if the package build fails.
267 if [ "$pkg_tarball" != "" ] ; then
268 case "${name}" in
269 *xz-utils) CHROOT_wrt_RemoveBuildDirs "xz" ;;
270 *) CHROOT_wrt_RemoveBuildDirs "$name" ;;
271 esac
272 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
273 CHROOT_wrt_LogNewFiles "$name"
274 fi
275 fi
276
277 # Include a touch of the target name so make can check
278 # if it's already been made.
279 wrt_touch
280 #
281 #--------------------------------------------------------------------#
282 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
283 #--------------------------------------------------------------------#
284
285 # Keep the script file name for Makefile dependencies.
286 PREV=${this_script}
287 # Set system_build envar for iteration targets
288 system_build=$chapter6
289 done # end for file in chapter06/*
290}
291
292#----------------------------#
293chapter78_Makefiles() {
294#----------------------------#
295 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
296
297 for file in chapter0{7,8}/* ; do
298 # Keep the script file name
299 this_script=`basename $file`
300
301 # Grub must be configured manually.
302 # Handle fstab creation.
303 # If no .config file is supplied, the kernel build is skipped
304 case ${this_script} in
305 *grub) continue ;;
306 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
307 *kernel) [[ -z ${CONFIG} ]] && continue
308 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
309 esac
310
311 # First append each name of the script files to a list (this will become
312 # the names of the targets in the Makefile
313 chapter78="$chapter78 ${this_script}"
314
315 #--------------------------------------------------------------------#
316 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
317 #--------------------------------------------------------------------#
318 #
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 CHROOT_wrt_target "${this_script}" "$PREV"
322
323 # Find the bootscripts and kernel package names
324 case "${this_script}" in
325 *bootscripts)
326 name="lfs-bootscripts"
327 pkg_tarball=$(get_package_tarball_name $name)
328 if [ "${INSTALL_LOG}" = "y" ] ; then
329 CHROOT_wrt_TouchTimestamp
330 fi
331 CHROOT_Unpack "$pkg_tarball"
332 ;;
333 *kernel)
334 name="linux"
335 pkg_tarball=$(get_package_tarball_name $name)
336 if [ "${INSTALL_LOG}" = "y" ] ; then
337 CHROOT_wrt_TouchTimestamp
338 fi
339 CHROOT_Unpack "$pkg_tarball"
340 ;;
341 esac
342
343 # Check if we have a real /etc/fstab file
344 case "${this_script}" in
345 *fstab) if [[ -n $FSTAB ]]; then
346 CHROOT_wrt_CopyFstab
347 else
348 CHROOT_wrt_RunAsRoot "$file"
349 fi
350 ;;
351 *) CHROOT_wrt_RunAsRoot "$file"
352 ;;
353 esac
354
355 case "${this_script}" in
356 *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy"
357 if [ "${INSTALL_LOG}" = "y" ] ; then
358 CHROOT_wrt_LogNewFiles "$name"
359 fi ;;
360 *kernel) CHROOT_wrt_RemoveBuildDirs "dummy"
361 if [ "${INSTALL_LOG}" = "y" ] ; then
362 CHROOT_wrt_LogNewFiles "$name"
363 fi ;;
364 esac
365
366 # Include a touch of the target name so make can check
367 # if it's already been made.
368 wrt_touch
369 #
370 #--------------------------------------------------------------------#
371 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
372 #--------------------------------------------------------------------#
373
374 # Keep the script file name for Makefile dependencies.
375 PREV=${this_script}
376 done # for file in chapter0{7,8}/*
377
378}
379
380
381
382#----------------------------#
383build_Makefile() { #
384#----------------------------#
385
386 echo "Creating Makefile... ${BOLD}START${OFF}"
387
388 cd $JHALFSDIR/${PROGNAME}-commands
389
390 # Start with a clean Makefile.tmp file
391 >$MKFILE
392
393 chapter4_Makefiles
394 chapter5_Makefiles
395 chapter6_Makefiles
396 # Add the iterations targets, if needed
397 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
398 chapter78_Makefiles
399 # Add the CUSTOM_TOOLS targets, if needed
400 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
401 # Add the BLFS_TOOL targets, if needed
402 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
403
404 # Add a header, some variables and include the function file
405 # to the top of the real Makefile.
406 wrt_Makefile_header
407
408 # Add chroot commands
409 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
410 i=1
411 for file in chapter06/*chroot* ; do
412 chroot=`cat $file | \
413 sed -e "s@chroot@$CHROOT_LOC@" \
414 -e '/#!\/bin\/bash/d' \
415 -e 's@ \\\@ @g' | \
416 tr -d '\n' | \
417 sed -e 's/ */ /g' \
418 -e 's|\\$|&&|g' \
419 -e 's|exit||g' \
420 -e 's|$| -c|' \
421 -e 's|"$$LFS"|$(MOUNT_PT)|' \
422 -e 's|set -e||' \
423 -e 's|set +h||'`
424 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
425 i=`expr $i + 1`
426 done
427
428 # Drop in the main target 'all:' and the chapter targets with each sub-target
429 # as a dependency.
430(
431 cat << EOF
432
433all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
434 @sudo make do_housekeeping
435 @echo "$VERSION - jhalfs build" > lfs-release && \\
436 sudo mv lfs-release \$(MOUNT_PT)/etc
437 @\$(call echo_finished,$VERSION)
438
439ck_UID:
440 @if [ \`id -u\` = "0" ]; then \\
441 echo "--------------------------------------------------"; \\
442 echo "You cannot run this makefile from the root account"; \\
443 echo "--------------------------------------------------"; \\
444 exit 1; \\
445 fi
446
447ck_LFS:
448 @if [ \`echo \$(LFS)\`x = "x" ]; then \\
449 echo "--------------------------------------------------"; \\
450 echo "Enviroment variable LFS must be set"; \\
451 echo "--------------------------------------------------"; \\
452 exit 1; \
453 fi
454
455mk_SETUP:
456 @\$(call echo_SU_request)
457 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
458 @touch \$@
459
460mk_LUSER: mk_SETUP
461 @\$(call echo_SULUSER_request)
462 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
463 @sudo make restore-luser-env
464 @touch \$@
465
466mk_SUDO: mk_LUSER
467 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
468 @touch \$@
469
470mk_CHROOT: mk_SUDO
471 @\$(call echo_CHROOT_request)
472 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
473 @touch \$@
474
475mk_BOOT: mk_CHROOT
476 @\$(call echo_CHROOT_request)
477 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
478 @touch \$@
479
480mk_CUSTOM_TOOLS: create-sbu_du-report
481 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
482 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
483 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
484 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
485 fi;
486 @touch \$@
487
488mk_BLFS_TOOL: mk_CUSTOM_TOOLS
489 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
490 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
491 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
492 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
493 fi;
494 @touch \$@
495
496devices: ck_LFS ck_UID
497 sudo mount -v --bind /dev \$(LFS)/dev
498 sudo mount -vt devpts devpts \$(LFS)/dev/pts
499 sudo mount -vt tmpfs shm \$(LFS)/dev/shm
500 sudo mount -vt proc proc \$(LFS)/proc
501 sudo mount -vt sysfs sysfs \$(LFS)/sys
502
503teardown: ck_LFS
504 sudo umount -v \$(LFS)/sys
505 sudo umount -v \$(LFS)/proc
506 sudo umount -v \$(LFS)/dev/shm
507 sudo umount -v \$(LFS)/dev/pts
508 sudo umount -v \$(LFS)/dev
509
510chroot: devices
511 sudo /usr/sbin/chroot \$(LFS) /tools/bin/env -i \\
512 HOME=/root TERM=\$(TERM) PS1='\\u:\\w\\\$\$ ' \\
513 PATH=/bin:/usr/bin:/sbin:/usr/sbin \\
514 /tools/bin/bash --login
515 \$(MAKE) teardown
516
517SETUP: $chapter4
518LUSER: $chapter5
519SUDO: $runasroot
520CHROOT: SHELL=/tools/bin/bash
521CHROOT: $chapter6
522BOOT: $chapter78
523CUSTOM_TOOLS: $custom_list
524BLFS_TOOL: $blfs_tool
525
526
527create-sbu_du-report: mk_BOOT
528 @\$(call echo_message, Building)
529 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
530 ./create-sbu_du-report.sh logs $VERSION; \\
531 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
532 fi;
533 @touch \$@
534
535restore-luser-env:
536 @\$(call echo_message, Building)
537 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
538 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
539 fi;
540 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
541 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
542 fi;
543 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
544 @\$(call housekeeping)
545
546do_housekeeping:
547 @-umount \$(MOUNT_PT)/sys
548 @-umount \$(MOUNT_PT)/proc
549 @-umount \$(MOUNT_PT)/dev/shm
550 @-umount \$(MOUNT_PT)/dev/pts
551 @-umount \$(MOUNT_PT)/dev
552 @-rm /tools
553 @-if [ ! -f luser-exist ]; then \\
554 userdel \$(LUSER); \\
555 rm -rf \$(LUSER_HOME); \\
556 fi;
557
558
559EOF
560) >> $MKFILE
561
562 # Bring over the items from the Makefile.tmp
563 cat $MKFILE.tmp >> $MKFILE
564 rm $MKFILE.tmp
565 echo "Creating Makefile... ${BOLD}DONE${OFF}"
566}
Note: See TracBrowser for help on using the repository browser.