source: LFS/master.sh@ c5ae20a

experimental
Last change on this file since c5ae20a was c5ae20a, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Fixed chapter04 targets dependencies.

  • Property mode set to 100644
File size: 14.4 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
2304_02-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
3004_03-addinguser: 04_02-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
4304_04-settingenvironment: 04_03-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 "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
56 echo "export LFS LC_ALL PATH" >> \$(LUSER_HOME)/.bashrc && \\
57 echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
58 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc
59 @\$(call housekeeping)
60EOF
61) > $MKFILE.tmp
62
63 chapter4=" 04_02-creatingtoolsdir 04_03-addinguser 04_04-settingenvironment"
64}
65
66
67
68#----------------------------#
69chapter5_Makefiles() {
70#----------------------------#
71 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
72
73 for file in chapter05/* ; do
74 # Keep the script file name
75 this_script=`basename $file`
76
77 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
78 case "${this_script}" in
79 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
80 *expect) [[ "${TEST}" = "0" ]] && continue ;;
81 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
82 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
83 esac
84
85 # First append each name of the script files to a list (this will become
86 # the names of the targets in the Makefile
87 # DO NOT append the changingowner script, it need be run as root.
88 # A hack is necessary: create script in chap5 BUT run as a dependency for
89 # SUDO target
90 case "${this_script}" in
91 *changingowner) runasroot="$runasroot ${this_script}" ;;
92 *) chapter5="$chapter5 ${this_script}" ;;
93 esac
94
95 # Set the dependency for the first target.
96 if [ -z $PREV ] ; then PREV=04_04-settingenvironment ; fi
97
98 #--------------------------------------------------------------------#
99 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
100 #--------------------------------------------------------------------#
101 #
102 # Drop in the name of the target on a new line, and the previous target
103 # as a dependency. Also call the echo_message function.
104 LUSER_wrt_target "${this_script}" "$PREV"
105
106 # Run the script.
107 # The changingowner script must be run as root.
108 case "${this_script}" in
109 *changingowner) wrt_RunAsRoot "$file" ;;
110 *) LUSER_wrt_RunAsUser "$file" ;;
111 esac
112
113 # Include a touch of the target name so make can check
114 # if it's already been made.
115 wrt_touch
116 #
117 #--------------------------------------------------------------------#
118 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
119 #--------------------------------------------------------------------#
120
121 # Keep the script file name for Makefile dependencies.
122 PREV=${this_script}
123 done # end for file in chapter05/*
124}
125
126
127#----------------------------#
128chapter6_Makefiles() {
129#----------------------------#
130
131 # Set envars and scripts for iteration targets
132 if [[ -z "$1" ]] ; then
133 local N=""
134 else
135 local N=-build_$1
136 local chapter6=""
137 mkdir chapter06$N
138 cp chapter06/* chapter06$N
139 for script in chapter06$N/* ; do
140 # Overwrite existing symlinks, files, and dirs
141 sed -e 's/ln -sv/&f/g' \
142 -e 's/mv -v/&f/g' \
143 -e 's/mkdir -v/&p/g' -i ${script}
144 # Rename the scripts
145 mv ${script} ${script}$N
146 done
147 fi
148
149 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
150
151 for file in chapter06$N/* ; do
152 # Keep the script file name
153 this_script=`basename $file`
154
155 # We'll run the chroot commands differently than the others, so skip them in the
156 # dependencies and target creation.
157 # Skip also linux-headers in iterative builds.
158 case "${this_script}" in
159 *chroot) continue ;;
160 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
161 *linux-headers*) [[ -n "$N" ]] && continue ;;
162 esac
163
164 # Grab the name of the package, if any.
165 name=`grep "^PACKAGE=" ${file} | sed -e 's@PACKAGE=@@'`
166
167 # Skip scripts not needed for iterations rebuilds
168 if [[ "$name" = "" ]] && [[ -n "$N" ]] ; then
169 case "${this_script}" in
170 *stripping*) ;;
171 *) continue ;;
172 esac
173 fi
174
175 # Append each name of the script files to a list (this will become
176 # the names of the targets in the Makefile)
177 # The kernfs script must be run as part of SUDO target.
178 case "${this_script}" in
179 *kernfs) runasroot="$runasroot ${this_script}" ;;
180 *) chapter6="$chapter6 ${this_script}" ;;
181 esac
182
183 #--------------------------------------------------------------------#
184 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
185 #--------------------------------------------------------------------#
186 #
187 # Drop in the name of the target on a new line, and the previous target
188 # as a dependency. Also call the echo_message function.
189 # In the mount of kernel filesystems we need to set LFS
190 # and not to use chroot.
191 case "${this_script}" in
192 *kernfs) LUSER_wrt_target "${this_script}" "$PREV" ;;
193 *) CHROOT_wrt_target "${this_script}" "$PREV" ;;
194 esac
195
196 # Touch timestamp file if installed files logs will be created.
197 # But only for the firt build when running iterative builds.
198 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
199 CHROOT_wrt_TouchTimestamp
200 fi
201
202 # In the mount of kernel filesystems we need to set LFS
203 # and not to use chroot.
204 case "${this_script}" in
205 *kernfs) wrt_RunAsRoot "$file" ;;
206 *) CHROOT_wrt_RunAsRoot "$file" ;;
207 esac
208
209 # Write installed files log
210 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
211 CHROOT_wrt_LogNewFiles "$name"
212 fi
213
214 # Include a touch of the target name so make can check
215 # if it's already been made.
216 wrt_touch
217 #
218 #--------------------------------------------------------------------#
219 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
220 #--------------------------------------------------------------------#
221
222 # Keep the script file name for Makefile dependencies.
223 PREV=${this_script}
224 # Set system_build envar for iteration targets
225 system_build=$chapter6
226 done # end for file in chapter06/*
227}
228
229#----------------------------#
230chapter78_Makefiles() {
231#----------------------------#
232 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
233
234 for file in chapter0{7,8}/* ; do
235 # Keep the script file name
236 this_script=`basename $file`
237
238 # Grub must be configured manually.
239 # Handle fstab creation.
240 # If no .config file is supplied, the kernel build is skipped
241 case ${this_script} in
242 *grub) continue ;;
243 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
244 *kernel) [[ -z ${CONFIG} ]] && continue
245 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
246 esac
247
248 # First append each name of the script files to a list (this will become
249 # the names of the targets in the Makefile
250 chapter78="$chapter78 ${this_script}"
251
252 #--------------------------------------------------------------------#
253 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
254 #--------------------------------------------------------------------#
255 #
256 # Drop in the name of the target on a new line, and the previous target
257 # as a dependency. Also call the echo_message function.
258 CHROOT_wrt_target "${this_script}" "$PREV"
259
260 # For bootscripts and kernel, start INSTALL_LOG if requested
261 case "${this_script}" in
262 *bootscripts | *kernel ) if [ "${INSTALL_LOG}" = "y" ] ; then
263 CHROOT_wrt_TouchTimestamp
264 fi ;;
265 esac
266
267 # Check if we have a real /etc/fstab file
268 case "${this_script}" in
269 *fstab) if [[ -n $FSTAB ]]; then
270 CHROOT_wrt_CopyFstab
271 else
272 CHROOT_wrt_RunAsRoot "$file"
273 fi
274 ;;
275 *) CHROOT_wrt_RunAsRoot "$file"
276 ;;
277 esac
278
279 case "${this_script}" in
280 *bootscripts) if [ "${INSTALL_LOG}" = "y" ] ; then
281 CHROOT_wrt_LogNewFiles "lfs-bootscripts"
282 fi ;;
283 *kernel) if [ "${INSTALL_LOG}" = "y" ] ; then
284 CHROOT_wrt_LogNewFiles "linux"
285 fi ;;
286 esac
287
288 # Include a touch of the target name so make can check
289 # if it's already been made.
290 wrt_touch
291 #
292 #--------------------------------------------------------------------#
293 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
294 #--------------------------------------------------------------------#
295
296 # Keep the script file name for Makefile dependencies.
297 PREV=${this_script}
298 done # for file in chapter0{7,8}/*
299
300}
301
302
303
304#----------------------------#
305build_Makefile() { #
306#----------------------------#
307
308 echo "Creating Makefile... ${BOLD}START${OFF}"
309
310 cd $JHALFSDIR/${PROGNAME}-commands
311
312 # Start with a clean Makefile.tmp file
313 >$MKFILE
314
315 chapter4_Makefiles
316 chapter5_Makefiles
317 chapter6_Makefiles
318 # Add the iterations targets, if needed
319 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
320 chapter78_Makefiles
321 # Add the CUSTOM_TOOLS targets, if needed
322 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
323 # Add the BLFS_TOOL targets, if needed
324 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
325
326 # Add a header, some variables and include the function file
327 # to the top of the real Makefile.
328 wrt_Makefile_header
329
330 # Add chroot commands
331 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
332 i=1
333 for file in chapter06/*chroot* ; do
334 chroot=`cat $file | tr -d '\n' | \
335 sed -e "s@chroot@$CHROOT_LOC@" \
336 -e 's@ \\\@ @g' \
337 -e 's/ */ /g' \
338 -e 's|\\$|&&|g' \
339 -e 's|"$$LFS"|$(MOUNT_PT)|' \
340 -e 's|$| -c|'`
341 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
342 i=`expr $i + 1`
343 done
344
345 # Drop in the main target 'all:' and the chapter targets with each sub-target
346 # as a dependency.
347(
348 cat << EOF
349
350all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
351 @sudo make do_housekeeping
352 @echo "$VERSION - jhalfs build" > lfs-release && \\
353 sudo mv lfs-release \$(MOUNT_PT)/etc
354 @\$(call echo_finished,$VERSION)
355
356ck_UID:
357 @if [ \`id -u\` = "0" ]; then \\
358 echo "--------------------------------------------------"; \\
359 echo "You cannot run this makefile from the root account"; \\
360 echo "--------------------------------------------------"; \\
361 exit 1; \\
362 fi
363
364mk_SETUP:
365 @\$(call echo_SU_request)
366 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
367 @touch \$@
368
369mk_LUSER: mk_SETUP
370 @\$(call echo_SULUSER_request)
371 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
372 @sudo make restore-luser-env
373 @touch \$@
374
375mk_SUDO: mk_LUSER
376 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
377 @touch \$@
378
379mk_CHROOT: mk_SUDO
380 @\$(call echo_CHROOT_request)
381 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
382 @touch \$@
383
384mk_BOOT: mk_CHROOT
385 @\$(call echo_CHROOT_request)
386 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
387 @touch \$@
388
389mk_CUSTOM_TOOLS: create-sbu_du-report
390 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
391 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
392 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
393 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
394 fi;
395 @touch \$@
396
397mk_BLFS_TOOL: mk_CUSTOM_TOOLS
398 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
399 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
400 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
401 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
402 fi;
403 @touch \$@
404
405
406SETUP: $chapter4
407LUSER: $chapter5
408SUDO: $runasroot
409CHROOT: SHELL=/tools/bin/bash
410CHROOT: $chapter6
411BOOT: $chapter78
412CUSTOM_TOOLS: $custom_list
413BLFS_TOOL: $blfs_tool
414
415
416create-sbu_du-report: mk_BOOT
417 @\$(call echo_message, Building)
418 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
419 ./create-sbu_du-report.sh logs $VERSION; \\
420 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
421 fi;
422 @touch \$@
423
424restore-luser-env:
425 @\$(call echo_message, Building)
426 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
427 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
428 fi;
429 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
430 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
431 fi;
432 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
433 @\$(call housekeeping)
434
435do_housekeeping:
436 @-umount \$(MOUNT_PT)/sys
437 @-umount \$(MOUNT_PT)/proc
438 @-umount \$(MOUNT_PT)/dev/shm
439 @-umount \$(MOUNT_PT)/dev/pts
440 @-umount \$(MOUNT_PT)/dev
441 @-rm /tools
442 @-if [ ! -f luser-exist ]; then \\
443 userdel \$(LUSER); \\
444 rm -rf \$(LUSER_HOME); \\
445 fi;
446
447
448EOF
449) >> $MKFILE
450
451 # Bring over the items from the Makefile.tmp
452 cat $MKFILE.tmp >> $MKFILE
453 rm $MKFILE.tmp
454 echo "Creating Makefile... ${BOLD}DONE${OFF}"
455}
Note: See TracBrowser for help on using the repository browser.