source: CLFS2/master.sh@ 8426d1f

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 8426d1f was 3673dc1, checked in by George Boudreau <georgeb@…>, 18 years ago

Minor corrections to CLFS-sysroot. Removed existance test for file and groff

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