source: LFS/master.sh@ dd529e9

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

Removed a remaining envars file reference.

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