source: CLFS/master.sh@ fcb540b

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since fcb540b was fcb540b, checked in by George Boudreau <georgeb@…>, 18 years ago

CLFS:: Correct extraction of data from chroot file

  • Property mode set to 100644
File size: 34.4 KB
Line 
1#!/bin/bash
2# $Id$
3
4
5orphan_scripts="" # 2 scripts do not fit BOOT_Makefiles LUSER environment
6
7
8#--------------------------------------#
9host_prep_Makefiles() { #
10#--------------------------------------#
11 local CLFS_HOST
12
13 echo "${tab_}${GREEN}Processing... ${L_arrow}host prep files ( SETUP ) ${R_arrow}"
14
15 # defined here, only for ease of reading
16 CLFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
17(
18cat << EOF
19023-creatingtoolsdir:
20 @\$(call echo_message, Building)
21 @mkdir \$(MOUNT_PT)/tools && \\
22 rm -f /tools && \\
23 ln -s \$(MOUNT_PT)/tools / && \\
24 touch \$@ && \\
25 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
26 echo --------------------------------------------------------------------------------\$(WHITE)
27
28024-creatingcrossdir: 023-creatingtoolsdir
29 @\$(call echo_message, Building)
30 @mkdir -v \$(MOUNT_PT)/cross-tools && \\
31 rm -f /cross-tools && \\
32 ln -s \$(MOUNT_PT)/cross-tools / && \\
33 touch \$@ && \\
34 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
35 echo --------------------------------------------------------------------------------\$(WHITE)
36
37025-addinguser: 024-creatingcrossdir
38 @\$(call echo_message, Building)
39 @if [ ! -d /home/\$(LUSER) ]; then \\
40 groupadd \$(LGROUP); \\
41 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
42 else \\
43 touch luser-exist; \\
44 fi;
45 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
46 chown \$(LUSER) \$(MOUNT_PT)/cross-tools && \\
47 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
48 chmod a+wt \$(SRCSDIR) && \\
49 touch \$@ && \\
50 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
51 echo --------------------------------------------------------------------------------\$(WHITE)
52
53026-settingenvironment: 025-addinguser
54 @\$(call echo_message, Building)
55 @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
56 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
57 fi;
58 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
59 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
60 fi;
61 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
62 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
63 echo "CLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
64 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
65 echo "PATH=/cross-tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
66 echo "export CLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
67 echo "" >> /home/\$(LUSER)/.bashrc && \\
68 echo "unset CFLAGS" >> /home/\$(LUSER)/.bashrc && \\
69 echo "unset CXXFLAGS" >> /home/\$(LUSER)/.bashrc && \\
70 echo "" >> /home/\$(LUSER)/.bashrc && \\
71 echo "export CLFS_HOST=\"${CLFS_HOST}\"" >> /home/\$(LUSER)/.bashrc && \\
72 echo "export CLFS_TARGET=\"${TARGET}\"" >> /home/\$(LUSER)/.bashrc && \\
73 echo "export CLFS_TARGET32=\"${TARGET32}\"" >> /home/\$(LUSER)/.bashrc && \\
74 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc
75 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
76 touch envars && \\
77 chmod -R a+wt \$(MOUNT_PT) && \\
78 chown -R \$(LUSER) \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
79 touch \$@ && \\
80 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
81 echo --------------------------------------------------------------------------------\$(WHITE)
82EOF
83) >> $MKFILE.tmp
84 host_prep=" 023-creatingtoolsdir 024-creatingcrossdir 026-settingenvironment"
85
86}
87
88#--------------------------------------#
89cross_tools_Makefiles() { #
90#--------------------------------------#
91 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools ( LUSER ) ${R_arrow}"
92
93 for file in cross-tools/* ; do
94 # Keep the script file name
95 this_script=`basename $file`
96 #
97 # Skip this script...
98 case $this_script in
99 *cflags* | *variables* ) # work done in host_prep_Makefiles
100 continue; ;;
101 *) ;;
102 esac
103 #
104 # Set the dependency for the first target.
105 if [ -z $PREV ] ; then PREV=026-settingenvironment ; fi
106
107 # First append each name of the script files to a list (this will become
108 # the names of the targets in the Makefile
109 cross_tools="$cross_tools $this_script"
110
111 # Grab the name of the target (minus the -headers or -cross in the case of gcc
112 # and binutils in chapter 5)
113 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
114 -e 's@-static@@' \
115 -e 's@-final@@' \
116 -e 's@-64@@' \
117 -e 's@-n32@@'`
118 pkg_tarball=$(get_package_tarball_name $name)
119
120 #--------------------------------------------------------------------#
121 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
122 #--------------------------------------------------------------------#
123 #
124 # Drop in the name of the target on a new line, and the previous target
125 # as a dependency. Also call the echo_message function.
126 LUSER_wrt_target "${this_script}" "$PREV"
127 #
128 # If $pkg_tarball isn't empty, we've got a package...
129 #
130 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
131 #
132 LUSER_wrt_RunAsUser "${file}"
133 #
134 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
135 #
136 # Include a touch of the target name so make can check if it's already been made.
137 wrt_touch
138 #
139 #--------------------------------------------------------------------#
140 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
141 #--------------------------------------------------------------------#
142 #
143 # Keep the script file name for Makefile dependencies.
144 PREV=$this_script
145
146 done # for file in ....
147}
148
149#--------------------------------------#
150temptools_Makefiles() { #
151#--------------------------------------#
152 echo "${tab_}${GREEN}Processing... ${L_arrow}temp system ( LUSER ) ${R_arrow}"
153
154 for file in temp-system/* ; do
155 # Keep the script file name
156 this_script=`basename $file`
157 #
158 # Deal with any odd scripts..
159 case $this_script in
160 *choose) # The choose script will fail if you cannot enter the new environment
161 # If the 'boot' build method was chosen don't run the script
162 [[ $METHOD = "boot" ]] && continue; ;;
163 *) ;;
164 esac
165
166 #
167 # First append each name of the script files to a list (this will become
168 # the names of the targets in the Makefile
169 temptools="$temptools $this_script"
170
171 #
172 # Grab the name of the target, strip id number, XXX-script
173 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
174 #
175 pkg_tarball=$(get_package_tarball_name $name)
176
177 #--------------------------------------------------------------------#
178 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
179 #--------------------------------------------------------------------#
180 #
181 # Drop in the name of the target on a new line, and the previous target
182 # as a dependency. Also call the echo_message function.
183 LUSER_wrt_target "${this_script}" "$PREV"
184 #
185 # If $pkg_tarball isn't empty, we've got a package...
186 # Insert instructions for unpacking the package and to set the PKGDIR variable.
187 #
188 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
189 [[ "$pkg_tarball" != "" ]] && [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
190 #
191 LUSER_wrt_RunAsUser "${file}"
192 #
193 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
194 #
195 # Include a touch of the target name so make can check if it's already been made.
196 wrt_touch
197 #
198 #--------------------------------------------------------------------#
199 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
200 #--------------------------------------------------------------------#
201 #
202 # Keep the script file name for Makefile dependencies.
203 PREV=$this_script
204 done # for file in ....
205}
206
207
208#--------------------------------------#
209chroot_Makefiles() { #
210#--------------------------------------#
211 echo "${tab_}${GREEN}Processing... ${L_arrow}tmptools CHROOT ( CHROOT ) ${R_arrow}"
212
213 for file in chroot/* ; do
214 # Keep the script file name
215 this_script=`basename $file`
216 #
217 # Skipping scripts is done now and not included in the build tree.
218 case $this_script in
219 *chroot*) continue ;;
220 esac
221
222 #
223 # First append each name of the script files to a list (this will become
224 # the names of the targets in the Makefile
225 case "${this_script}" in
226 *util-linux) orphan_scripts="${orphan_scripts} ${this_script}" ;;
227 *kernfs) orphan_scripts="${orphan_scripts} ${this_script}" ;;
228 *) chroottools="$chroottools $this_script" ;;
229 esac
230
231 # Grab the name of the target, strip id number, XXX-script
232 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
233
234 pkg_tarball=$(get_package_tarball_name $name)
235
236 # This is very ugly:: util-linux is in /chroot but must be run under LUSER
237 # .. Customized makefile entry
238 case "${this_script}" in
239 *util-linux)
240 LUSER_wrt_target "${this_script}" "$PREV"
241 LUSER_wrt_unpack "$pkg_tarball"
242 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
243 LUSER_wrt_RunAsUser "${file}"
244 LUSER_RemoveBuildDirs "${name}"
245 wrt_touch
246 temptools="$temptools $this_script"
247 continue ;;
248 esac
249
250
251 #--------------------------------------------------------------------#
252 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
253 #--------------------------------------------------------------------#
254 #
255 # Drop in the name of the target on a new line, and the previous target
256 # as a dependency. Also call the echo_message function.
257 CHROOT_wrt_target "${this_script}" "$PREV"
258 #
259 # If $pkg_tarball isn't empty, we've got a package...
260 # Insert instructions for unpacking the package and changing directories
261 #
262 if [ "$pkg_tarball" != "" ] ; then
263 CHROOT_Unpack "$pkg_tarball"
264 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
265 fi
266 #
267 # Select a script execution method
268 case $this_script in
269 *kernfs) wrt_RunAsRoot "${file}" ;;
270 *) CHROOT_wrt_RunAsRoot "${file}" ;;
271 esac
272 #
273 # Housekeeping...remove the build directory(ies), except if the package build fails.
274 [[ "$pkg_tarball" != "" ]] && CHROOT_wrt_RemoveBuildDirs "${name}"
275 #
276 # Include a touch of the target name so make can check if it's already been made.
277 wrt_touch
278 #
279 #--------------------------------------------------------------------#
280 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
281 #--------------------------------------------------------------------#
282 #
283 # Keep the script file name for Makefile dependencies.
284 PREV=$this_script
285
286 done # for file in...
287}
288
289
290#--------------------------------------#
291boot_Makefiles() { #
292#--------------------------------------#
293
294 echo "${tab_}${GREEN}Processing... ${L_arrow}tmptools BOOT ( LUSER ) ${R_arrow}"
295 #
296 # Create a target bootable partition containing a compile environment. Later
297 # on we boot into this environment and contine the build.
298 #
299 for file in boot/* ; do
300 # Keep the script file name
301 this_script=`basename $file`
302
303 # A little housekeeping on the scripts
304 case $this_script in
305 *grub | *aboot | *colo | *silo | *arcload | *lilo ) continue ;;
306 *whatnext*) continue ;;
307 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
308 *kernel) # if there is no kernel config file do not build the kernel
309 [[ -z $CONFIG ]] && continue
310 # Copy the config file to /sources with a standardized name
311 cp $BOOT_CONFIG $BUILDDIR/sources/bootkernel-config
312 ;;
313 esac
314 #
315 # First append each name of the script files to a list (this will become
316 # the names of the targets in the Makefile
317 case "${this_script}" in
318 *changingowner) orphan_scripts="${orphan_scripts} ${this_script}" ;;
319 *devices) orphan_scripts="${orphan_scripts} ${this_script}" ;;
320 *) boottools="$boottools $this_script" ;;
321 esac
322 #
323 # Grab the name of the target, strip id number and misc words.
324 case $this_script in
325 *kernel) name=linux ;;
326 *bootscripts) name="bootscripts-cross-lfs" ;;
327 *udev-rules) name="udev-cross-lfs" ;;
328 *grub-build) name=grub ;;
329 *-aboot-build) name=aboot ;;
330 *yaboot-build) name=yaboot ;;
331 *colo-build) name=colo ;;
332 *silo-build) name=silo ;;
333 *arcload-build) name=arcload ;;
334 *lilo-build) name=lilo ;;
335 *) name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' ` ;;
336 esac
337 # Identify the unique version naming scheme for the clfs bootscripts..(bad boys)
338 pkg_tarball=$(get_package_tarball_name $name)
339
340 #--------------------------------------------------------------------#
341 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
342 #--------------------------------------------------------------------#
343 #
344 # Drop in the name of the target on a new line, and the previous target
345 # as a dependency. Also call the echo_message function.
346 LUSER_wrt_target "${this_script}" "$PREV"
347 #
348 # If $pkg_tarball isn't empty, we've got a package...
349 # Insert instructions for unpacking the package and changing directories
350 #
351 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
352 [[ "$pkg_tarball" != "" ]] && [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
353 #
354 # Select a script execution method
355 case $this_script in
356 # The following 2 scripts are defined in the /boot directory but need
357 # to be run as a root user. Set them up here but run them in another phase
358 *changingowner*) wrt_RunAsRoot "${file}" ;;
359 *devices*) wrt_RunAsRoot "${file}" ;;
360 *fstab*) if [[ -n "$FSTAB" ]]; then
361 LUSER_wrt_CopyFstab
362 else
363 LUSER_wrt_RunAsUser "${file}"
364 fi
365 ;;
366 *) LUSER_wrt_RunAsUser "${file}" ;;
367 esac
368 #
369 # Housekeeping...remove any build directory(ies) except if the package build fails.
370 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
371 #
372 # Include a touch of the target name so make can check if it's already been made.
373 wrt_touch
374 #
375 #--------------------------------------------------------------------#
376 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
377 #--------------------------------------------------------------------#
378 #
379 # Keep the script file name for Makefile dependencies.
380 PREV=$this_script
381
382 done
383}
384
385
386#--------------------------------------#
387testsuite_tools_Makefiles() { #
388#--------------------------------------#
389
390 if [[ "${METHOD}" = "chroot" ]]; then
391 echo "${tab_}${GREEN}Processing... ${L_arrow}(chroot) testsuite tools ( CHROOT ) ${R_arrow}"
392 else
393 echo "${tab_}${GREEN}Processing... ${L_arrow}(boot) testsuite tools ( ROOT ) ${R_arrow}"
394 PREV=""
395 fi
396
397 for file in testsuite-tools/* ; do
398 # Keep the script file name
399 this_script=`basename $file`
400
401 # First append each name of the script files to a list (this will become
402 # the names of the targets in the Makefile
403 testsuitetools="$testsuitetools $this_script"
404
405 # Grab the name of the target, strip id number, XXX-script
406 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
407 -e 's@-64bit@@' \
408 -e 's@-64@@' \
409 -e 's@64@@' \
410 -e 's@n32@@'`
411
412 pkg_tarball=$(get_package_tarball_name $name)
413
414 #--------------------------------------------------------------------#
415 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
416 #--------------------------------------------------------------------#
417 #
418 # Drop in the name of the target on a new line, and the previous target
419 # as a dependency. Also call the echo_message function.
420 CHROOT_wrt_target "${this_script}" "$PREV"
421 #
422 CHROOT_Unpack "$pkg_tarball"
423 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
424 #
425 CHROOT_wrt_RunAsRoot "${file}"
426 #
427 CHROOT_wrt_RemoveBuildDirs "${name}"
428 #
429 # Include a touch of the target name so make can check if it's already been made.
430 wrt_touch
431 #
432 #--------------------------------------------------------------------#
433 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
434 #--------------------------------------------------------------------#
435 #
436 # Keep the script file name for Makefile dependencies.
437 PREV=$this_script
438
439 done
440}
441
442
443#--------------------------------------#
444final_system_Makefiles() { #
445#--------------------------------------#
446 # Set envars and scripts for iteration targets
447 if [[ -z "$1" ]] ; then
448 local N=""
449 # In boot method the makesys phase was initiated in testsuite_tools_makefile
450 [[ "${METHOD}" = "boot" ]] && [[ "$TEST" = 0 ]] && PREV=""
451 else
452 local N=-build_$1
453 local basicsystem=""
454 mkdir final-system$N
455 cp final-system/* final-system$N
456 for script in final-system$N/* ; do
457 # Overwrite existing symlinks, files, and dirs
458 sed -e 's/ln -sv/&f/g' \
459 -e 's/mv -v/&f/g' \
460 -e 's/mkdir -v/&p/g' -i ${script}
461 # Rename the scripts
462 mv ${script} ${script}$N
463 done
464 # Remove Bzip2 binaries before make install
465 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i final-system$N/*-bzip2$N
466 # Delete *old Readline libraries just after make install
467 sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i final-system$N/*-readline$N
468 fi
469
470 if [[ "${METHOD}" = "chroot" ]]; then
471 echo "${tab_}${GREEN}Processing... ${L_arrow}(chroot) final system$N ( CHROOT ) ${R_arrow}"
472 else
473 echo "${tab_}${GREEN}Processing... ${L_arrow}(boot) final system$N ( ROOT ) ${R_arrow}"
474 fi
475
476 for file in final-system$N/* ; do
477 # Keep the script file name
478 this_script=`basename $file`
479
480 # Test if the stripping phase must be skipped.
481 # Skip alsp temp-perl for iterative runs
482 case $this_script in
483 *stripping*) [[ "$STRIP" = "n" ]] && continue ;;
484 *temp-perl*) [[ -n "$N" ]] && continue ;;
485 esac
486
487 # Grab the name of the target, strip id number, XXX-script
488 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
489 -e 's@temp-@@' \
490 -e 's@-64bit@@' \
491 -e 's@-64@@' \
492 -e 's@64@@' \
493 -e 's@n32@@' \
494 -e 's,'$N',,'`
495
496 # Find the version of the command files, if it corresponds with the building of
497 # a specific package. We need this here to can skip scripts not needed for
498 # iterations rebuilds
499 pkg_tarball=$(get_package_tarball_name $name)
500
501 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
502 case "${this_script}" in
503 *stripping*) ;;
504 *) continue ;;
505 esac
506 fi
507
508 # Append each name of the script files to a list (this will become
509 # the names of the targets in the Makefile
510 basicsystem="$basicsystem ${this_script}"
511
512 #--------------------------------------------------------------------#
513 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
514 #--------------------------------------------------------------------#
515 #
516 # Drop in the name of the target on a new line, and the previous target
517 # as a dependency. Also call the echo_message function.
518 CHROOT_wrt_target "${this_script}" "$PREV"
519
520 # If $pkg_tarball isn't empty, we've got a package...
521 if [ "$pkg_tarball" != "" ] ; then
522 CHROOT_Unpack "$pkg_tarball"
523 # If the testsuites must be run, initialize the log file
524 case $name in
525 binutils | gcc | glibc )
526 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
527 ;;
528 * )
529 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
530 ;;
531 esac
532 # If using optimizations, write the instructions
533 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
534 fi
535 #
536 CHROOT_wrt_RunAsRoot "${file}"
537 #
538 [[ "$pkg_tarball" != "" ]] && CHROOT_wrt_RemoveBuildDirs "${name}"
539 #
540 # Include a touch of the target name so make can check if it's already been made.
541 wrt_touch
542 #
543 #--------------------------------------------------------------------#
544 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
545 #--------------------------------------------------------------------#
546 #
547 # Keep the script file name for Makefile dependencies.
548 PREV=${this_script}
549 # Set system_build envar for iteration targets
550 system_build=$basicsystem
551 done # for file in final-system/* ...
552}
553
554#--------------------------------------#
555bootscripts_Makefiles() { #
556#--------------------------------------#
557
558 if [[ "${METHOD}" = "chroot" ]]; then
559 echo "${tab_}${GREEN}Processing... ${L_arrow}(chroot) bootscripts ( CHROOT ) ${R_arrow}"
560 else
561 echo "${tab_}${GREEN}Processing... ${L_arrow}(boot) bootscripts ( ROOT ) ${R_arrow}"
562 fi
563
564 for file in bootscripts/* ; do
565 # Keep the script file name
566 this_script=`basename $file`
567
568 case $this_script in
569 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
570 *console*) continue ;; # Use the files that came with the bootscripts
571 *) ;;
572 esac
573
574 # First append each name of the script files to a list (this will become
575 # the names of the targets in the Makefile
576 bootscripttools="$bootscripttools $this_script"
577
578 # Grab the name of the target, strip id number, XXX-script
579 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
580 -e 's@-64bit@@' \
581 -e 's@-64@@' \
582 -e 's@64@@' \
583 -e 's@n32@@'`
584 case $name in
585 *bootscripts*) name=bootscripts-cross-lfs ;;
586 *udev-rules) name=udev-cross-lfs ;;
587 esac
588
589 pkg_tarball=$(get_package_tarball_name $name)
590
591 #--------------------------------------------------------------------#
592 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
593 #--------------------------------------------------------------------#
594 #
595 # Drop in the name of the target on a new line, and the previous target
596 # as a dependency. Also call the echo_message function.
597 CHROOT_wrt_target "${this_script}" "$PREV"
598 #
599 # If $pkg_tarball isn't empty, we've got a package...
600 #
601 [[ "$pkg_tarball" != "" ]] && CHROOT_Unpack "$pkg_tarball"
602 #
603 CHROOT_wrt_RunAsRoot "${file}"
604 #
605 [[ "$pkg_tarball" != "" ]] && CHROOT_wrt_RemoveBuildDirs "${name}"
606 #
607 # Include a touch of the target name so make can check if it's already been made.
608 wrt_touch
609 #
610 #--------------------------------------------------------------------#
611 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
612 #--------------------------------------------------------------------#
613 #
614 # Keep the script file name for Makefile dependencies.
615 PREV=$this_script
616
617 done # for file in bootscripts/* ...
618}
619
620#--------------------------------------#
621bootable_Makefiles() { #
622#--------------------------------------#
623
624 if [[ "${METHOD}" = "chroot" ]]; then
625 echo "${tab_}${GREEN}Processing... ${L_arrow}(chroot) make bootable ( CHROOT ) ${R_arrow}"
626 else
627 echo "${tab_}${GREEN}Processing... ${L_arrow}(boot) make bootable ( ROOT ) ${R_arrow}"
628 fi
629
630
631 for file in bootable/* ; do
632 # Keep the script file name
633 this_script=`basename $file`
634
635 # A little housekeeping on the scripts
636 case $this_script in
637 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
638 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
639 *kernel) # if there is no kernel config file do not build the kernel
640 [[ -z $CONFIG ]] && continue
641 # Copy the config file to /sources with a standardized name
642 cp $CONFIG $BUILDDIR/sources/kernel-config
643 ;;
644 esac
645 #
646 # First append each name of the script files to a list (this will become
647 # the names of the targets in the Makefile
648 bootabletools="$bootabletools $this_script"
649 #
650 # Grab the name of the target, strip id number and misc words.
651 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
652 case $this_script in
653 *kernel*) name=linux
654 ;;
655 esac
656
657 pkg_tarball=$(get_package_tarball_name $name)
658
659 #--------------------------------------------------------------------#
660 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
661 #--------------------------------------------------------------------#
662 #
663 # Drop in the name of the target on a new line, and the previous target
664 # as a dependency. Also call the echo_message function.
665 CHROOT_wrt_target "${this_script}" "$PREV"
666 #
667 # If $pkg_tarball isn't empty, we've got a package...
668 # Insert instructions for unpacking the package and changing directories
669 #
670 [[ "$pkg_tarball" != "" ]] && CHROOT_Unpack "$pkg_tarball"
671 #
672 # Select a script execution method
673 case $this_script in
674 *fstab*) if [[ -n "$FSTAB" ]]; then
675 CHROOT_wrt_CopyFstab
676 else
677 CHROOT_wrt_RunAsRoot "${file}"
678 fi
679 ;;
680 *) CHROOT_wrt_RunAsRoot "${file}"
681 ;;
682 esac
683 #
684 # Housekeeping...remove any build directory(ies) except if the package build fails.
685 [[ "$pkg_tarball" != "" ]] && CHROOT_wrt_RemoveBuildDirs "${name}"
686 #
687 # Include a touch of the target name so make can check if it's already been made.
688 wrt_touch
689 #
690 #--------------------------------------------------------------------#
691 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
692 #--------------------------------------------------------------------#
693 #
694 # Keep the script file name for Makefile dependencies.
695 PREV=$this_script
696
697 done
698
699}
700
701
702#--------------------------------------#
703build_Makefile() { # Construct a Makefile from the book scripts
704#--------------------------------------#
705 #
706 # Script crashes if error trapping is on
707 #
708set +e
709 declare -f method_cmds
710set -e
711
712 echo "...Creating Makefile... ${BOLD}START${OFF}"
713
714 cd $JHALFSDIR/${PROGNAME}-commands
715 # Start with a clean files
716 >$MKFILE
717 >$MKFILE.tmp
718
719 method_cmds=${METHOD}_Makefiles
720
721 host_prep_Makefiles # mk_SETUP (SETUP) $host_prep
722 cross_tools_Makefiles # mk_CROSS (LUSER) $cross_tools
723 temptools_Makefiles # mk_TEMP (LUSER) $temptools
724 $method_cmds # mk_SYSTOOLS (CHROOT) $chroottools/$boottools
725 if [[ ! $TEST = "0" ]]; then
726 testsuite_tools_Makefiles # mk_SYSTOOLS (CHROOT) $testsuitetools
727 fi
728 final_system_Makefiles # mk_FINAL (CHROOT) $basicsystem
729 # Add the iterations targets, if needed
730 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
731 bootscripts_Makefiles # mk_BOOTSCRIPT (CHROOT) $bootscripttools
732 bootable_Makefiles # mk_BOOTABLE (CHROOT) $bootabletools
733
734 # Add the CUSTOM_TOOLS targets, if needed
735 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
736 # Add the BLFS_TOOL targets, if needed
737 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
738
739 # Add a header, some variables and include the function file
740 # to the top of the real Makefile.
741 wrt_Makefile_header
742
743 # Add chroot commands
744 if [ "$METHOD" = "chroot" ] ; then
745 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
746 chroot=`cat chroot/*chroot* | \
747 sed -e "s@chroot@$CHROOT_LOC@" \
748 -e '/#!\/bin\/bash/d' \
749 -e '/^export/d' \
750 -e '/^logout/d' \
751 -e 's@ \\\@ @g' | \
752 tr -d '\n' | \
753 sed -e 's/ */ /g' \
754 -e 's|\\$|&&|g' \
755 -e 's|exit||g' \
756 -e 's|$| -c|' \
757 -e 's|"$${CLFS}"|$(MOUNT_PT)|'\
758 -e 's|set -e||' \
759 -e 's|set +h||'`
760 echo -e "CHROOT1= $chroot\n" >> $MKFILE
761 fi
762
763################## CHROOT ####################
764
765if [[ "${METHOD}" = "chroot" ]]; then
766(
767cat << EOF
768
769all: ck_UID mk_SETUP mk_CROSS mk_SUDO mk_SYSTOOLS create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
770 @sudo make do-housekeeping
771 @echo "$VERSION - jhalfs build" > clfs-release && \\
772 sudo mv clfs-release \$(MOUNT_PT)/etc
773 @\$(call echo_finished,$VERSION)
774
775ck_UID:
776 @if [ \`id -u\` = "0" ]; then \\
777 echo "+--------------------------------------------------+"; \\
778 echo "|You cannot run this makefile from the root account|"; \\
779 echo "+--------------------------------------------------+"; \\
780 exit 1; \\
781 fi
782
783#---------------AS ROOT
784mk_SETUP:
785 @\$(call echo_SU_request)
786 @sudo make SHELL=/bin/bash SETUP
787 @touch \$@
788
789#---------------AS LUSER
790mk_CROSS: mk_SETUP
791 @\$(call echo_PHASE,Cross and Temporary Tools)
792 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash AS_LUSER" )
793 @sudo make restore-luser-env
794 @touch \$@
795
796mk_SUDO: mk_CROSS
797 @sudo make SHELL=/bin/bash SUDO
798 @touch \$@
799#
800# The convoluted piece of code below is necessary to provide 'make' with a valid shell in the
801# chroot environment. (Unless someone knows a different way)
802# Manually create the /bin directory and provide link to the /tools dir.
803# Also change the original symlink creation to include (f)orce to prevent failure due to
804# pre-existing links.
805
806#---------------CHROOT JAIL
807mk_SYSTOOLS: mk_SUDO
808 @if [ ! -e \$(MOUNT_PT)/bin ]; then \\
809 mkdir \$(MOUNT_PT)/bin; \\
810 cd \$(MOUNT_PT)/bin && \\
811 ln -svf /tools/bin/bash bash; ln -sf bash sh; \\
812 sudo chown -R 0:0 \$(MOUNT_PT)/bin; \\
813 fi;
814 @sudo sed -e 's|^ln -sv |ln -svf |' -i \$(CMDSDIR)/chroot/*-createfiles
815 @\$(call echo_CHROOT_request)
816 @\$(call echo_PHASE, CHROOT JAIL )
817 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT_JAIL")
818 @touch \$@
819
820mk_CUSTOM_TOOLS: create-sbu_du-report
821 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
822 \$(call echo_PHASE,Building CUSTOM_TOOLS); \\
823 \$(call echo_CHROOT_request); \\
824 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
825 (sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CUSTOM_TOOLS"); \\
826 fi;
827 @touch \$@
828
829mk_BLFS_TOOL: mk_CUSTOM_TOOLS
830 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
831 \$(call echo_PHASE,Building BLFS_TOOL); \\
832 \$(call echo_CHROOT_request); \\
833 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
834 sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BLFS_TOOL"; \\
835 fi;
836 @touch \$@
837
838SETUP: $host_prep
839AS_LUSER: $cross_tools $temptools
840SUDO: $orphan_scripts
841CHROOT_JAIL: ${chroottools} $testsuitetools $basicsystem $bootscripttools $bootabletools
842CUSTOM_TOOLS: $custom_list
843BLFS_TOOL: $blfs_tool
844
845
846create-sbu_du-report: mk_SYSTOOLS
847 @\$(call echo_message, Building)
848 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
849 ./create-sbu_du-report.sh logs $VERSION; \\
850 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
851 fi;
852 @touch \$@
853
854do-housekeeping:
855 @-umount \$(MOUNT_PT)/dev/pts
856 @-umount \$(MOUNT_PT)/dev/shm
857 @-umount \$(MOUNT_PT)/dev
858 @-umount \$(MOUNT_PT)/sys
859 @-umount \$(MOUNT_PT)/proc
860 @-rm /tools /cross-tools
861 @-if [ ! -f luser-exist ]; then \\
862 userdel \$(LUSER); \\
863 rm -rf /home/\$(LUSER); \\
864 fi;
865
866EOF
867) >> $MKFILE
868
869fi
870
871################### BOOT #####################
872
873if [[ "${METHOD}" = "boot" ]]; then
874(
875cat << EOF
876
877all: ck_UID mk_SETUP mk_CROSS mk_SUDO
878 @sudo make restore-luser-env
879 @sudo make do-housekeeping
880 @\$(call echo_boot_finished,$VERSION)
881
882makesys: mk_FINAL mk_CUSTOM_TOOLS mk_BLFS_TOOL
883 @echo "$VERSION - jhalfs build" > /etc/clfs-release
884 @\$(call echo_finished,$VERSION)
885
886
887ck_UID:
888 @if [ \`id -u\` = "0" ]; then \\
889 echo "+--------------------------------------------------+"; \\
890 echo "|You cannot run this makefile from the root account|"; \\
891 echo "|However, if this is the boot environment |"; \\
892 echo "| the command you are looking for is |"; \\
893 echo "| make makesys |"; \\
894 echo "| to finish off the build |"; \\
895 echo "+--------------------------------------------------+"; \\
896 exit 1; \\
897 fi
898
899#---------------AS ROOT
900
901mk_SETUP:
902 @\$(call echo_SU_request)
903 @sudo make SHELL=/bin/bash SETUP
904 @touch \$@
905
906#---------------AS LUSER
907
908mk_CROSS: mk_SETUP
909 @\$(call echo_PHASE,Cross Tool)
910 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash AS_LUSER" )
911 @touch \$@
912
913mk_SUDO: mk_CROSS
914 @sudo make SHELL=/bin/bash SUDO
915 @touch \$@
916
917#---------------AS ROOT
918
919mk_FINAL:
920 @\$(call echo_PHASE,Final System)
921 @( source /root/.bash_profile && make AS_ROOT )
922 @touch \$@
923
924mk_CUSTOM_TOOLS: mk_FINAL
925 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
926 mkdir -p ${TRACKING_DIR}; \\
927 \$(call echo_PHASE,Building CUSTOM_TOOLS); \\
928 ( source /root/.bash_profile && make CUSTOM_TOOLS"); \\
929 fi;
930 @touch \$@
931
932mk_BLFS_TOOL: mk_CUSTOM_TOOLS
933 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
934 mkdir -p $TRACKING_DIR; \\
935 \$(call echo_PHASE,Building BLFS_TOOL); \\
936 ( source /root/.bash_profile && make BLFS_TOOL ); \\
937 fi
938 @touch \$@
939
940SETUP: $host_prep
941AS_LUSER: $cross_tools $temptools ${boottools}
942SUDO: $orphan_scripts
943AS_ROOT: $testsuitetools $basicsystem $bootscripttools $bootabletools
944CUSTOM_TOOLS: $custom_list
945BLFS_TOOL: $blfs_tool
946
947do-housekeeping:
948 @-rm /tools /cross-tools
949 @-if [ ! -f luser-exist ]; then \\
950 userdel \$(LUSER); \\
951 rm -rf /home/\$(LUSER); \\
952 fi;
953
954EOF
955) >> $MKFILE
956fi
957
958(
959 cat << EOF
960
961restore-luser-env:
962 @\$(call echo_message, Building)
963 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
964 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
965 fi;
966 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
967 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
968 fi;
969 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
970 touch \$@ && \\
971 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
972 echo --------------------------------------------------------------------------------\$(WHITE)
973
974########################################################
975
976
977EOF
978) >> $MKFILE
979
980 # Bring over the items from the Makefile.tmp
981 cat $MKFILE.tmp >> $MKFILE
982 rm $MKFILE.tmp
983
984 echo "Creating Makefile... ${BOLD}DONE${OFF}"
985}
Note: See TracBrowser for help on using the repository browser.