source: LFS/master.sh@ 6bb080e

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 6bb080e was 6bb080e, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Revised compare code. Test build in progres.

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