source: CLFS2/master.sh@ 982ae7c

experimental
Last change on this file since 982ae7c was 3b63c8c, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Updated experimental branch to current trunk code.

  • Property mode set to 100755
File size: 19.0 KB
Line 
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.
185 if [ -z $PREV ] ; then PREV=026-settingenvironment ; fi
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#-----------------------------#
240 # Set envars and scripts for iteration targets
241 LOGS="" # Start with an empty global LOGS envar
242 if [[ -z "$1" ]] ; then
243 local N=""
244 else
245 local N=-build_$1
246 local basicsystem=""
247 mkdir final-system$N
248 cp final-system/* final-system$N
249 for script in final-system$N/* ; do
250 # Overwrite existing symlinks, files, and dirs
251 sed -e 's/ln -sv/&f/g' \
252 -e 's/mv -v/&f/g' \
253 -e 's/mkdir -v/&p/g' -i ${script}
254 done
255 # Remove Bzip2 binaries before make install
256 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i final-system$N/*-bzip2
257 # Delete *old Readline libraries just after make install
258 sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i final-system$N/*-readline
259 fi
260
261 echo "${tab_}${GREEN}Processing... ${L_arrow}final system$N${R_arrow}"
262
263 for file in final-system$N/* ; do
264 # Keep the script file name
265 this_script=`basename $file`
266
267 # Test if the stripping phase must be skipped.
268 # Skip alsp temp-perl for iterative runs
269 case $this_script in
270 *stripping*) [[ "$STRIP" = "0" ]] && continue ;;
271 esac
272
273 # Grab the name of the target, strip id number, XXX-script
274 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
275 -e 's@temp-@@' \
276 -e 's@-64bit@@' \
277 -e 's@-64@@' \
278 -e 's@64@@' \
279 -e 's@n32@@'`
280
281 # Find the version of the command files, if it corresponds with the building of
282 # a specific package. We need this here to can skip scripts not needed for
283 # iterations rebuilds
284 pkg_tarball=$(get_package_tarball_name $name)
285
286 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
287 case "${this_script}" in
288 *stripping*) ;;
289 *) continue ;;
290 esac
291 fi
292
293 # Append each name of the script files to a list (this will become
294 # the names of the targets in the Makefile
295 basicsystem="$basicsystem ${this_script}${N}"
296
297 # Append each name of the script files to a list (this will become
298 # the names of the logs to be moved for each iteration)
299 LOGS="$LOGS ${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 wrt_target "${this_script}${N}" "$PREV"
308 #
309 # If $pkg_tarball isn't empty, we've got a package...
310 if [ "$pkg_tarball" != "" ] ; then
311 wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
312 # If using optimizations, write the instructions
313 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
314 fi
315 #
316 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
317 #
318 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
319 #
320 # Include a touch of the target name so make can check if it's already been made.
321 wrt_touch
322 #
323 #--------------------------------------------------------------------#
324 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
325 #--------------------------------------------------------------------#
326 #
327 # Keep the script file name for Makefile dependencies.
328 PREV=${this_script}${N}
329 # Set system_build envar for iteration targets
330 system_build=$basicsystem
331 done # for file in final-system/* ...
332}
333
334
335
336#-----------------------------#
337bootscripts_Makefiles() { #
338#-----------------------------#
339 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts${R_arrow}"
340
341 for file in bootscripts/* ; do
342 # Keep the script file name
343 this_script=`basename $file`
344
345 case $this_script in
346 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
347 *console*) continue ;; # Use the files that came with the bootscripts
348 *) ;;
349 esac
350
351 # First append each name of the script files to a list (this will become
352 # the names of the targets in the Makefile
353 bootscripttools="$bootscripttools $this_script"
354
355 # Grab the name of the target, strip id number, XXX-script
356 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
357 -e 's@-64bit@@' \
358 -e 's@-64@@' \
359 -e 's@64@@' \
360 -e 's@n32@@'`
361 case $name in
362 *bootscripts*) name=bootscripts-cross-lfs ;;
363 *udev-rules) name=udev-cross-lfs ;;
364 esac
365
366 pkg_tarball=$(get_package_tarball_name $name)
367
368 #--------------------------------------------------------------------#
369 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
370 #--------------------------------------------------------------------#
371 #
372 # Drop in the name of the target on a new line, and the previous target
373 # as a dependency. Also call the echo_message function.
374 wrt_target "${this_script}" "$PREV"
375 #
376 # If $pkg_tarball isn't empty, we've got a package...
377 [[ "$pkg_tarball" != "" ]] && wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
378 #
379 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
380 #
381 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
382 #
383 # Include a touch of the target name so make can check if it's already been made.
384 wrt_touch
385 #
386 #--------------------------------------------------------------------#
387 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
388 #--------------------------------------------------------------------#
389 #
390 # Keep the script file name for Makefile dependencies.
391 PREV=$this_script
392
393 done # for file in bootscripts/* ...
394
395}
396
397
398#-----------------------------#
399bootable_Makefiles() { #
400#-----------------------------#
401 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable${R_arrow}"
402
403 for file in bootable/* ; do
404 # Keep the script file name
405 this_script=`basename $file`
406
407 # A little housekeeping on the scripts
408 case $this_script in
409 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
410 *kernel) # if there is no kernel config file do not build the kernel
411 [[ -z $CONFIG ]] && continue
412 # Copy the config file to /sources with a standardized name
413 cp $CONFIG $BUILDDIR/sources/kernel-config
414 ;;
415 esac
416 #
417 # First append each name of the script files to a list (this will become
418 # the names of the targets in the Makefile
419 bootable="$bootable $this_script"
420 #
421 # Grab the name of the target, strip id number and misc words.
422 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
423 case $this_script in
424 *kernel*) name=linux
425 ;;
426 esac
427
428 pkg_tarball=$(get_package_tarball_name $name)
429
430 #--------------------------------------------------------------------#
431 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
432 #--------------------------------------------------------------------#
433 #
434 # Drop in the name of the target on a new line, and the previous target
435 # as a dependency. Also call the echo_message function.
436 wrt_target "${this_script}" "$PREV"
437 #
438 # If $pkg_tarball isn't empty, we've got a package...
439 [[ "$pkg_tarball" != "" ]] && wrt_Unpack_SetOwner "clfs" "$pkg_tarball"
440 #
441 # Select a script execution method
442 case $this_script in
443 *fstab*) if [[ -n "$FSTAB" ]]; then
444 wrt_copy_fstab "${this_script}"
445 else
446 wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
447 fi
448 ;;
449 *) wrt_ExecuteAsUser "clfs" "${this_script}" "${file}"
450 ;;
451 esac
452 #
453 # Housekeeping...remove any build directory(ies) except if the package build fails.
454 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
455 #
456 # Include a touch of the target name so make can check if it's already been made.
457 wrt_touch
458 #
459 #--------------------------------------------------------------------#
460 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
461 #--------------------------------------------------------------------#
462 #
463 # Keep the script file name for Makefile dependencies.
464 PREV=$this_script
465
466 done
467
468 # Add SBU-disk_usage report target if required
469 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
470
471}
472
473
474#-----------------------------#
475build_Makefile() { # Construct a Makefile from the book scripts
476#-----------------------------#
477 echo "Creating Makefile... ${BOLD}START${OFF}"
478
479 cd $JHALFSDIR/${PROGNAME}-commands
480 # Start with a clean Makefile.tmp file
481 >$MKFILE.tmp
482
483 host_prep_Makefiles
484 cross_tools_Makefiles # $cross_tools
485 final_system_Makefiles # $basicsystem
486 bootscripts_Makefiles # $bootscripttools
487 bootable_Makefiles # $bootable
488
489 # Add a header, some variables and include the function file
490 # to the top of the real Makefile.
491(
492 cat << EOF
493$HEADER
494
495SRC= /sources
496MOUNT_PT= $BUILDDIR
497PKG_LST= $PKG_LST
498
499include makefile-functions
500
501EOF
502) > $MKFILE
503
504 # Drop in the main target 'all:' and the chapter targets with each sub-target
505 # as a dependency.
506(
507 cat << EOF
508all: chapter2 chapter3 chapter4 chapter5 chapter6 do-housekeeping
509 @\$(call echo_finished,$VERSION)
510
511chapter2: 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile
512
513chapter3: chapter2 $cross_tools
514
515chapter4: chapter3 $basicsystem
516
517chapter5: chapter4 $bootscripttools
518
519chapter6: chapter5 $bootable
520
521clean-all: clean
522 rm -rf ./{clfs2-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
523
524clean:
525
526restart:
527 @echo "This feature does not exist for the CLFS makefile. (yet)"
528
529restore-clfs-env:
530 @\$(call echo_message, Building)
531 @if [ -f /home/clfs/.bashrc.XXX ]; then \\
532 mv -f /home/clfs/.bashrc.XXX /home/clfs/.bashrc; \\
533 fi;
534 @if [ -f /home/clfs/.bash_profile.XXX ]; then \\
535 mv /home/clfs/.bash_profile.XXX /home/clfs/.bash_profile; \\
536 fi;
537 @chown clfs:clfs /home/clfs/.bash* && \\
538 touch \$@ && \\
539 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
540 echo --------------------------------------------------------------------------------\$(WHITE)
541
542do-housekeeping:
543 @-if [ ! -f user-clfs-exist ]; then \\
544 userdel clfs; \\
545 rm -rf /home/clfs; \\
546 fi;
547
548EOF
549) >> $MKFILE
550
551 # Bring over the items from the Makefile.tmp
552 cat $MKFILE.tmp >> $MKFILE
553 rm $MKFILE.tmp
554 echo "Creating Makefile... ${BOLD}DONE${OFF}"
555
556}
557
Note: See TracBrowser for help on using the repository browser.