source: CLFS2/master.sh@ 983db9f

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

Merged r2891:2893 from experimental.

  • Property mode set to 100755
File size: 17.8 KB
RevLine 
[7432834]1#!/bin/sh
2# $Id$
3
4###################################
5### FUNCTIONS ###
6###################################
7
8#----------------------------------#
9wrt_ExecuteAsUser() { # Execute the file ($3) under the users account ($1), log in $2
10#----------------------------------#
11 local this_user=$1
12 local this_script=$2
13 local file=$3
14(
15cat << EOF
16 @( time { su - ${this_user} -c "source /home/${this_user}/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
17 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
18EOF
19) >> $MKFILE.tmp
20}
21
22
23#----------------------------------#
24wrt_Unpack_SetOwner() { # Unpack and set owner. Assign 'ROOT' var
25#----------------------------------#
26 local USER_ACCT=$1
27 local FILE=$2
28 local optSAVE_PREVIOUS=$3
29
30 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
31 wrt_remove_existing_dirs "$FILE"
32 fi
33(
34cat << EOF
35 @\$(call unpack,$FILE)
36 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
37 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
38 chown -R ${USER_ACCT} \$(MOUNT_PT)\$(SRC)/\$\$ROOT
39EOF
40) >> $MKFILE.tmp
41}
42
43
44#----------------------------#
45host_prep_Makefiles() { # Initialization of the system
46#----------------------------#
47 local CLFS_HOST
48
49 echo "${tab_}${GREEN}Processing... ${L_arrow}host prep files${R_arrow}"
50
51 # defined here, only for ease of reading
52 CLFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
53(
54cat << EOF
55023-creatingtoolsdir:
56 @\$(call echo_message, Building)
57 @mkdir \$(MOUNT_PT)/tools && \\
58 rm -f /tools && \\
59 ln -s \$(MOUNT_PT)/tools /
60 @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
61 mkdir \$(MOUNT_PT)/sources; \\
62 fi;
63 @chmod a+wt \$(MOUNT_PT)/sources
64 @touch \$@ && \\
65 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
66 echo --------------------------------------------------------------------------------\$(WHITE)
67
68025-addinguser: 023-creatingtoolsdir
69 @\$(call echo_message, Building)
70 @if [ ! -d /home/clfs ]; then \\
71 groupadd clfs; \\
72 useradd -s /bin/bash -g clfs -m -k /dev/null clfs; \\
73 else \\
74 touch user-clfs-exist; \\
75 fi;
76 @chown clfs \$(MOUNT_PT) && \\
77 chown clfs \$(MOUNT_PT)/tools && \\
78 chown clfs \$(MOUNT_PT)/sources
79 @touch \$@ && \\
80 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
81 echo --------------------------------------------------------------------------------\$(WHITE)
82
83026-settingenvironment: 025-addinguser
84 @\$(call echo_message, Building)
85 @if [ -f /home/clfs/.bashrc -a ! -f /home/clfs/.bashrc.XXX ]; then \\
86 mv /home/clfs/.bashrc /home/clfs/.bashrc.XXX; \\
87 fi;
88 @if [ -f /home/clfs/.bash_profile -a ! -f /home/clfs/.bash_profile.XXX ]; then \\
89 mv /home/clfs/.bash_profile /home/clfs/.bash_profile.XXX; \\
90 fi;
91 @echo "set +h" > /home/clfs/.bashrc && \\
92 echo "umask 022" >> /home/clfs/.bashrc && \\
93 echo "CLFS=\$(MOUNT_PT)" >> /home/clfs/.bashrc && \\
94 echo "LC_ALL=POSIX" >> /home/clfs/.bashrc && \\
95 echo "PATH=\$(MOUNT_PT)/cross-tools/bin:/bin:/usr/bin" >> /home/clfs/.bashrc && \\
96 echo "export CLFS LC_ALL PATH" >> /home/clfs/.bashrc && \\
97 echo "" >> /home/clfs/.bashrc && \\
98 echo "unset CFLAGS" >> /home/clfs/.bashrc && \\
99 echo "unset CXXFLAGS" >> /home/clfs/.bashrc && \\
100 echo "" >> /home/clfs/.bashrc && \\
101 echo "export CLFS_HOST=\"${CLFS_HOST}\"" >> /home/clfs/.bashrc && \\
102 echo "export CLFS_TARGET=\"${TARGET}\"" >> /home/clfs/.bashrc && \\
103 echo "export CLFS_TARGET32=\"${TARGET32}\"" >> /home/clfs/.bashrc && \\
104 echo "source $JHALFSDIR/envars" >> /home/clfs/.bashrc
105 @chown clfs:clfs /home/clfs/.bashrc && \\
106 touch envars
107 @touch \$@ && \\
108 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
109 echo --------------------------------------------------------------------------------\$(WHITE)
110
111027-create-directories: 026-settingenvironment
112 @\$(call echo_message, Building)
113
114 @mkdir -p \$(MOUNT_PT)/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
115 @mkdir -p \$(MOUNT_PT)/{proc,media/{floppy,cdrom},sbin,srv,sys}
116 @mkdir -p \$(MOUNT_PT)/var/{lock,log,mail,run,spool}
117 @mkdir -p \$(MOUNT_PT)/var/{opt,cache,lib/{misc,locate},local}
118 @install -d -m 0750 \$(MOUNT_PT)/root
119 @install -d -m 1777 \$(MOUNT_PT){/var,}/tmp
120 @mkdir -p \$(MOUNT_PT)/usr/{,local/}{bin,include,lib,sbin,src}
121 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{doc,info,locale,man}
122 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{misc,terminfo,zoneinfo}
123 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
124 @for dir in \$(MOUNT_PT)/usr{,/local}; do \\
125 ln -s share/{man,doc,info} \$\$dir ; \\
126 done
127
128 @touch \$@ && \\
129 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
130 echo --------------------------------------------------------------------------------\$(WHITE)
131
132028-creating-sysfile: 027-create-directories
133 @\$(call echo_message, Building)
134
135 @touch \$(MOUNT_PT)/etc/mtab
136 @echo "root::0:0:root:/root:/bin/bash" >> \$(MOUNT_PT)/etc/passwd
137 @echo "root:x:0:" >> \$(MOUNT_PT)/etc/group
138 @echo "bin:x:1:" >> \$(MOUNT_PT)/etc/group
139 @echo "sys:x:2:" >> \$(MOUNT_PT)/etc/group
140 @echo "kmem:x:3" >> \$(MOUNT_PT)/etc/group
141 @echo "tty:x:4:" >> \$(MOUNT_PT)/etc/group
142 @echo "tape:x:5:" >> \$(MOUNT_PT)/etc/group
143 @echo "daemon:x:6:" >> \$(MOUNT_PT)/etc/group
144 @echo "floppy:x:7:" >> \$(MOUNT_PT)/etc/group
145 @echo "disk:x:8:" >> \$(MOUNT_PT)/etc/group
146 @echo "lp:x:9:" >> \$(MOUNT_PT)/etc/group
147 @echo "dialout:x:10:" >> \$(MOUNT_PT)/etc/group
148 @echo "audio:x:11:" >> \$(MOUNT_PT)/etc/group
149 @echo "video:x:12:" >> \$(MOUNT_PT)/etc/group
150 @echo "utmp:x:13:" >> \$(MOUNT_PT)/etc/group
151 @echo "usb:x:14:" >> \$(MOUNT_PT)/etc/group
152 @echo "cdrom:x:15:" >> \$(MOUNT_PT)/etc/group
153
154 @touch \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/{btmp,lastlog,wtmp}
155 @chmod 664 \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/lastlog
156 @chown -R clfs \$(MOUNT_PT)
157
158 @touch \$@ && \\
159 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
160 echo --------------------------------------------------------------------------------\$(WHITE)
161
162EOF
163) >> $MKFILE.tmp
164}
165
166
167
168#-----------------------------#
169cross_tools_Makefiles() { #
170#-----------------------------#
171 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools${R_arrow}"
172
173 for file in cross-tools/* ; do
174 # Keep the script file name
175 this_script=`basename $file`
176 #
177 # Skip this script...
178 case $this_script in
179 *cflags* | *variables* ) # work done in host_prep_Makefiles
180 continue; ;;
181 *) ;;
182 esac
183 #
184 # Set the dependency for the first target.
[f3fcecc]185 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
[7432834]186
187 # First append each name of the script files to a list (this will become
188 # the names of the targets in the Makefile
189 cross_tools="$cross_tools $this_script"
190
191 # Grab the name of the target (minus the -headers or -cross in the case of gcc
192 # and binutils in chapter 5)
193 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
194 -e 's@-static@@' \
195 -e 's@-final@@' \
196 -e 's@-64@@' \
197 -e 's@-n32@@'`
198 case $name in
199 glibc-headers) name="glibc" ;;
200 esac
201 pkg_tarball=$(get_package_tarball_name $name)
202
203 #--------------------------------------------------------------------#
204 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
205 #--------------------------------------------------------------------#
206 #
207 # Drop in the name of the target on a new line, and the previous target
208 # as a dependency. Also call the echo_message function.
209 wrt_target "${this_script}" "$PREV"
210 #
211 # If $pkg_tarball isn't empty, we've got a package...
212 if [ "$pkg_tarball" != "" ] ; then
213 wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
214 # If using optimizations, write the instructions
215 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
216 fi
217 #
218 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
219 #
220 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
221 #
222 # Include a touch of the target name so make can check if it's already been made.
223 wrt_touch
224 #
225 #--------------------------------------------------------------------#
226 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
227 #--------------------------------------------------------------------#
228 #
229 # Keep the script file name for Makefile dependencies.
230 PREV=$this_script
231
232 done # for file in ....
233}
234
235
236
237#-----------------------------#
238final_system_Makefiles() { #
239#-----------------------------#
[2dd88c4]240 echo "${tab_}${GREEN}Processing... ${L_arrow}final system${R_arrow}"
[7432834]241
[2dd88c4]242 for file in final-system/* ; do
[7432834]243 # Keep the script file name
244 this_script=`basename $file`
245
246 # Test if the stripping phase must be skipped.
247 # Skip alsp temp-perl for iterative runs
248 case $this_script in
249 *stripping*) [[ "$STRIP" = "0" ]] && continue ;;
250 esac
251
252 # Grab the name of the target, strip id number, XXX-script
253 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
254 -e 's@temp-@@' \
255 -e 's@-64bit@@' \
256 -e 's@-64@@' \
257 -e 's@64@@' \
258 -e 's@n32@@'`
259
260 # Find the version of the command files, if it corresponds with the building of
[2dd88c4]261 # a specific package.
[7432834]262 pkg_tarball=$(get_package_tarball_name $name)
263
264 # Append each name of the script files to a list (this will become
265 # the names of the targets in the Makefile
[2dd88c4]266 basicsystem="$basicsystem ${this_script}"
[7432834]267
268 #--------------------------------------------------------------------#
269 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
270 #--------------------------------------------------------------------#
271 #
272 # Drop in the name of the target on a new line, and the previous target
273 # as a dependency. Also call the echo_message function.
[2dd88c4]274 wrt_target "${this_script}" "$PREV"
[7432834]275 #
276 # If $pkg_tarball isn't empty, we've got a package...
277 if [ "$pkg_tarball" != "" ] ; then
278 wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
279 # If using optimizations, write the instructions
280 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
281 fi
282 #
283 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
284 #
285 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
286 #
287 # Include a touch of the target name so make can check if it's already been made.
288 wrt_touch
289 #
290 #--------------------------------------------------------------------#
291 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
292 #--------------------------------------------------------------------#
293 #
294 # Keep the script file name for Makefile dependencies.
[2dd88c4]295 PREV=${this_script}
[7432834]296 done # for file in final-system/* ...
297}
298
299
300
301#-----------------------------#
302bootscripts_Makefiles() { #
303#-----------------------------#
304 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts${R_arrow}"
305
306 for file in bootscripts/* ; do
307 # Keep the script file name
308 this_script=`basename $file`
309
310 case $this_script in
311 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
312 *console*) continue ;; # Use the files that came with the bootscripts
313 *) ;;
314 esac
315
316 # First append each name of the script files to a list (this will become
317 # the names of the targets in the Makefile
318 bootscripttools="$bootscripttools $this_script"
319
320 # Grab the name of the target, strip id number, XXX-script
321 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
322 -e 's@-64bit@@' \
323 -e 's@-64@@' \
324 -e 's@64@@' \
325 -e 's@n32@@'`
326 case $name in
327 *bootscripts*) name=bootscripts-cross-lfs ;;
328 *udev-rules) name=udev-cross-lfs ;;
329 esac
330
331 pkg_tarball=$(get_package_tarball_name $name)
332
333 #--------------------------------------------------------------------#
334 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
335 #--------------------------------------------------------------------#
336 #
337 # Drop in the name of the target on a new line, and the previous target
338 # as a dependency. Also call the echo_message function.
339 wrt_target "${this_script}" "$PREV"
340 #
341 # If $pkg_tarball isn't empty, we've got a package...
342 [[ "$pkg_tarball" != "" ]] && wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
343 #
344 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
345 #
346 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
347 #
348 # Include a touch of the target name so make can check if it's already been made.
349 wrt_touch
350 #
351 #--------------------------------------------------------------------#
352 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
353 #--------------------------------------------------------------------#
354 #
355 # Keep the script file name for Makefile dependencies.
356 PREV=$this_script
357
358 done # for file in bootscripts/* ...
359
360}
361
362
363#-----------------------------#
364bootable_Makefiles() { #
365#-----------------------------#
366 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable${R_arrow}"
367
368 for file in bootable/* ; do
369 # Keep the script file name
370 this_script=`basename $file`
371
372 # A little housekeeping on the scripts
373 case $this_script in
374 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
375 *kernel) # if there is no kernel config file do not build the kernel
376 [[ -z $CONFIG ]] && continue
377 # Copy the config file to /sources with a standardized name
378 cp $CONFIG $BUILDDIR/sources/kernel-config
379 ;;
380 esac
381 #
382 # First append each name of the script files to a list (this will become
383 # the names of the targets in the Makefile
384 bootable="$bootable $this_script"
385 #
386 # Grab the name of the target, strip id number and misc words.
387 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
388 case $this_script in
389 *kernel*) name=linux
390 ;;
391 esac
392
393 pkg_tarball=$(get_package_tarball_name $name)
394
395 #--------------------------------------------------------------------#
396 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
397 #--------------------------------------------------------------------#
398 #
399 # Drop in the name of the target on a new line, and the previous target
400 # as a dependency. Also call the echo_message function.
401 wrt_target "${this_script}" "$PREV"
402 #
403 # If $pkg_tarball isn't empty, we've got a package...
404 [[ "$pkg_tarball" != "" ]] && wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
405 #
406 # Select a script execution method
407 case $this_script in
408 *fstab*) if [[ -n "$FSTAB" ]]; then
409 wrt_copy_fstab "${this_script}"
410 else
411 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
412 fi
413 ;;
[2dd88c4]414 *) wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
[7432834]415 ;;
416 esac
417 #
418 # Housekeeping...remove any build directory(ies) except if the package build fails.
419 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
420 #
421 # Include a touch of the target name so make can check if it's already been made.
422 wrt_touch
423 #
424 #--------------------------------------------------------------------#
425 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
426 #--------------------------------------------------------------------#
427 #
428 # Keep the script file name for Makefile dependencies.
429 PREV=$this_script
430
431 done
432
433 # Add SBU-disk_usage report target if required
434 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
435
436}
437
438
439#-----------------------------#
440build_Makefile() { # Construct a Makefile from the book scripts
441#-----------------------------#
442 echo "Creating Makefile... ${BOLD}START${OFF}"
443
444 cd $JHALFSDIR/${PROGNAME}-commands
445 # Start with a clean Makefile.tmp file
446 >$MKFILE.tmp
447
448 host_prep_Makefiles
449 cross_tools_Makefiles # $cross_tools
450 final_system_Makefiles # $basicsystem
451 bootscripts_Makefiles # $bootscripttools
452 bootable_Makefiles # $bootable
453
454 # Add a header, some variables and include the function file
455 # to the top of the real Makefile.
456(
457 cat << EOF
458$HEADER
459
460SRC= /sources
461MOUNT_PT= $BUILDDIR
462PKG_LST= $PKG_LST
463
464include makefile-functions
465
466EOF
467) > $MKFILE
468
469 # Drop in the main target 'all:' and the chapter targets with each sub-target
470 # as a dependency.
471(
472 cat << EOF
473all: chapter2 chapter3 chapter4 chapter5 chapter6 do-housekeeping
474 @\$(call echo_finished,$VERSION)
475
476chapter2: 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile
477
478chapter3: chapter2 $cross_tools
479
480chapter4: chapter3 $basicsystem
481
482chapter5: chapter4 $bootscripttools
483
484chapter6: chapter5 $bootable
485
486clean-all: clean
487 rm -rf ./{clfs2-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
488
[2dd88c4]489clean:
[7432834]490
491restart:
492 @echo "This feature does not exist for the CLFS makefile. (yet)"
493
494restore-clfs-env:
495 @\$(call echo_message, Building)
496 @if [ -f /home/clfs/.bashrc.XXX ]; then \\
497 mv -f /home/clfs/.bashrc.XXX /home/clfs/.bashrc; \\
498 fi;
499 @if [ -f /home/clfs/.bash_profile.XXX ]; then \\
500 mv /home/clfs/.bash_profile.XXX /home/clfs/.bash_profile; \\
501 fi;
502 @chown clfs:clfs /home/clfs/.bash* && \\
503 touch \$@ && \\
504 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
505 echo --------------------------------------------------------------------------------\$(WHITE)
506
507do-housekeeping:
508 @-if [ ! -f user-clfs-exist ]; then \\
509 userdel clfs; \\
510 rm -rf /home/clfs; \\
511 fi;
512
513EOF
514) >> $MKFILE
515
516 # Bring over the items from the Makefile.tmp
517 cat $MKFILE.tmp >> $MKFILE
518 rm $MKFILE.tmp
519 echo "Creating Makefile... ${BOLD}DONE${OFF}"
520
521}
522
Note: See TracBrowser for help on using the repository browser.