source: LFS/master.sh@ 41d8577

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

Makefile envars and fuctions revised.

  • Property mode set to 100644
File size: 14.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 $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 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 *) wrt_RunScript "$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 wrt_target "${this_script}" "$PREV"
189
190 # Touch timestamp file if installed files logs will be created.
191 # But only for the firt build when running iterative builds.
192 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
193 wrt_TouchTimestamp
194 fi
195
196 # In the mount of kernel filesystems we need to set LFS
197 # and not to use chroot.
198 case "${this_script}" in
199 *kernfs) wrt_RunAsRoot "$file" ;;
200 *) wrt_RunScript "$file" ;;
201 esac
202
203 # Write installed files log
204 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
205 wrt_LogNewFiles "$name"
206 fi
207
208 # Include a touch of the target name so make can check
209 # if it's already been made.
210 wrt_touch
211 #
212 #--------------------------------------------------------------------#
213 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
214 #--------------------------------------------------------------------#
215
216 # Keep the script file name for Makefile dependencies.
217 PREV=${this_script}
218 # Set system_build envar for iteration targets
219 system_build=$chapter6
220 done # end for file in chapter06/*
221}
222
223#----------------------------#
224chapter78_Makefiles() {
225#----------------------------#
226 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
227
228 for file in chapter0{7,8}/* ; do
229 # Keep the script file name
230 this_script=`basename $file`
231
232 # Grub must be configured manually.
233 # Handle fstab creation.
234 # If no .config file is supplied, the kernel build is skipped
235 case ${this_script} in
236 *grub) continue ;;
237 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
238 *kernel) [[ -z ${CONFIG} ]] && continue
239 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
240 esac
241
242 # First append each name of the script files to a list (this will become
243 # the names of the targets in the Makefile
244 chapter78="$chapter78 ${this_script}"
245
246 #--------------------------------------------------------------------#
247 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
248 #--------------------------------------------------------------------#
249 #
250 # Drop in the name of the target on a new line, and the previous target
251 # as a dependency. Also call the echo_message function.
252 wrt_target "${this_script}" "$PREV"
253
254 # For bootscripts and kernel, start INSTALL_LOG if requested
255 case "${this_script}" in
256 *bootscripts | *kernel ) if [ "${INSTALL_LOG}" = "y" ] ; then
257 wrt_TouchTimestamp
258 fi ;;
259 esac
260
261 # Check if we have a real /etc/fstab file
262 case "${this_script}" in
263 *fstab) if [[ -n $FSTAB ]]; then
264 wrt_CopyFstab
265 else
266 wrt_RunScript "$file"
267 fi ;;
268 *) wrt_RunScript "$file" ;;
269 esac
270
271 case "${this_script}" in
272 *bootscripts) if [ "${INSTALL_LOG}" = "y" ] ; then
273 wrt_LogNewFiles "lfs-bootscripts"
274 fi ;;
275 *kernel) if [ "${INSTALL_LOG}" = "y" ] ; then
276 wrt_LogNewFiles "linux"
277 fi ;;
278 esac
279
280 # Include a touch of the target name so make can check
281 # if it's already been made.
282 wrt_touch
283 #
284 #--------------------------------------------------------------------#
285 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
286 #--------------------------------------------------------------------#
287
288 # Keep the script file name for Makefile dependencies.
289 PREV=${this_script}
290 done # for file in chapter0{7,8}/*
291
292}
293
294
295
296#----------------------------#
297build_Makefile() { #
298#----------------------------#
299
300 echo "Creating Makefile... ${BOLD}START${OFF}"
301
302 cd $JHALFSDIR/${PROGNAME}-commands
303
304 # Start with a clean Makefile.tmp file
305 >$MKFILE
306
307 chapter4_Makefiles
308 chapter5_Makefiles
309 chapter6_Makefiles
310 # Add the iterations targets, if needed
311 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
312 chapter78_Makefiles
313 # Add the CUSTOM_TOOLS targets, if needed
314 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
315 # Add the BLFS_TOOL targets, if needed
316 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
317
318 # Add a header, some variables and include the function file
319 # to the top of the real Makefile.
320 wrt_Makefile_header
321
322 # Add chroot commands
323 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
324 i=1
325 for file in chapter06/*chroot* ; do
326 chroot=`cat $file | tr -d '\n' | \
327 sed -e "s@chroot@$CHROOT_LOC@" \
328 -e 's@ \\\@ @g' \
329 -e 's/ */ /g' \
330 -e 's|\\$|&&|g' \
331 -e 's|"$$LFS"|$(MOUNT_PT)|' \
332 -e 's|$| -c|'`
333 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
334 i=`expr $i + 1`
335 done
336
337 # Drop in the main target 'all:' and the chapter targets with each sub-target
338 # as a dependency.
339(
340 cat << EOF
341
342all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
343 @sudo make do_housekeeping
344 @echo "$VERSION - jhalfs build" > lfs-release && \\
345 sudo mv lfs-release \$(MOUNT_PT)/etc
346 @\$(call echo_finished,$VERSION)
347
348ck_UID:
349 @if [ \`id -u\` = "0" ]; then \\
350 echo "--------------------------------------------------"; \\
351 echo "You cannot run this makefile from the root account"; \\
352 echo "--------------------------------------------------"; \\
353 exit 1; \\
354 fi
355
356mk_SETUP:
357 @\$(call echo_SU_request)
358 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
359 @touch \$@
360
361mk_LUSER: mk_SETUP
362 @\$(call echo_SULUSER_request)
363 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
364 @sudo make restore-luser-env
365 @touch \$@
366
367mk_SUDO: mk_LUSER
368 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
369 @touch \$@
370
371mk_CHROOT: mk_SUDO
372 @\$(call echo_CHROOT_request)
373 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
374 @touch \$@
375
376mk_BOOT: mk_CHROOT
377 @\$(call echo_CHROOT_request)
378 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
379 @touch \$@
380
381mk_CUSTOM_TOOLS: create-sbu_du-report
382 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
383 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
384 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
385 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
386 fi;
387 @touch \$@
388
389mk_BLFS_TOOL: mk_CUSTOM_TOOLS
390 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
391 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
392 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
393 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
394 fi;
395 @touch \$@
396
397
398SETUP: $chapter4
399LUSER: $chapter5
400SUDO: $runasroot
401CHROOT: SHELL=/tools/bin/bash
402CHROOT: $chapter6
403BOOT: $chapter78
404CUSTOM_TOOLS: $custom_list
405BLFS_TOOL: $blfs_tool
406
407
408create-sbu_du-report: mk_BOOT
409 @\$(call echo_message, Building)
410 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
411 ./create-sbu_du-report.sh logs $VERSION; \\
412 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
413 fi;
414 @touch \$@
415
416restore-luser-env:
417 @\$(call echo_message, Building)
418 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
419 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
420 fi;
421 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
422 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
423 fi;
424 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
425 @\$(call housekeeping)
426
427do_housekeeping:
428 @-umount \$(MOUNT_PT)/sys
429 @-umount \$(MOUNT_PT)/proc
430 @-umount \$(MOUNT_PT)/dev/shm
431 @-umount \$(MOUNT_PT)/dev/pts
432 @-umount \$(MOUNT_PT)/dev
433 @-rm /tools
434 @-if [ ! -f luser-exist ]; then \\
435 userdel \$(LUSER); \\
436 rm -rf \$(LUSER_HOME); \\
437 fi;
438
439
440EOF
441) >> $MKFILE
442
443 # Bring over the items from the Makefile.tmp
444 cat $MKFILE.tmp >> $MKFILE
445 rm $MKFILE.tmp
446 echo "Creating Makefile... ${BOLD}DONE${OFF}"
447}
Note: See TracBrowser for help on using the repository browser.