source: CLFS2/master.sh@ 045b2dc

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

Merged r3043:3145 from experimental:
New Makefile code and other improvements.

  • Property mode set to 100755
File size: 18.8 KB
Line 
1#!/bin/sh
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 # NOTE.. the book indicated you only needed to install groff or file if the host
143 # had older versions. The packages would be installed in the target directory
144 # and not the host.
145 case $this_script in
146 *cflags* | *variables* ) # work done in host_prep_Makefiles
147 continue ;;
148 *file ) FileVer=`file --version | head -n1 | cut -d " " -f1`
149 [[ "$FileVer" = "file-4.17" ]] && continue
150 ;;
151 *groff) GroffVer=`groff --version | head -n1 | cut -d " " -f4`
152 [[ "$GroffVer" = "1.19.2" ]] && continue
153 ;;
154 *) ;;
155 esac
156
157 #
158 # Set the dependency for the first target.
159 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
160
161 # First append each name of the script files to a list (this will become
162 # the names of the targets in the Makefile
163 cross_tools="$cross_tools $this_script"
164
165 # Grab the name of the target (minus the -headers or -cross in the case of gcc
166 # and binutils in chapter 5)
167 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
168 -e 's@-static@@' \
169 -e 's@-final@@' \
170 -e 's@-64@@' \
171 -e 's@-n32@@'`
172 case $name in
173 glibc-headers) name="glibc" ;;
174 esac
175 pkg_tarball=$(get_package_tarball_name $name)
176 #--------------------------------------------------------------------#
177 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
178 #--------------------------------------------------------------------#
179 #
180 # Drop in the name of the target on a new line, and the previous target
181 # as a dependency. Also call the echo_message function.
182 LUSER_wrt_target "${this_script}" "$PREV"
183 #
184 # If $pkg_tarball isn't empty, we've got a package...
185 if [ "$pkg_tarball" != "" ] ; then
186 LUSER_wrt_unpack "$pkg_tarball"
187 # If using optimizations, write the instructions
188 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
189 fi
190 #
191 LUSER_wrt_RunAsUser "${file}"
192 #
193 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
194 #
195 # Include a touch of the target name so make can check if it's already been made.
196 wrt_touch
197 #
198 #--------------------------------------------------------------------#
199 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
200 #--------------------------------------------------------------------#
201 #
202 # Keep the script file name for Makefile dependencies.
203 PREV=$this_script
204
205 done # for file in ....
206}
207
208
209
210#-----------------------------#
211final_system_Makefiles() { #
212#-----------------------------#
213 echo "${tab_}${GREEN}Processing... ${L_arrow}final system ( LUSER ) ${R_arrow}"
214
215 for file in final-system/* ; do
216 # Keep the script file name
217 this_script=`basename $file`
218
219 # Test if the stripping phase must be skipped.
220 # Skip alsp temp-perl for iterative runs
221 case $this_script in
222 *stripping*) [[ "$STRIP" = "n" ]] && continue ;;
223 esac
224
225 # Grab the name of the target, strip id number, XXX-script
226 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
227 -e 's@temp-@@' \
228 -e 's@-64bit@@' \
229 -e 's@-64@@' \
230 -e 's@64@@' \
231 -e 's@n32@@'`
232
233 # Find the version of the command files, if it corresponds with the building of
234 # a specific package.
235 pkg_tarball=$(get_package_tarball_name $name)
236
237 # Append each name of the script files to a list (this will become
238 # the names of the targets in the Makefile
239 basicsystem="$basicsystem ${this_script}"
240
241 #--------------------------------------------------------------------#
242 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
243 #--------------------------------------------------------------------#
244 #
245 # Drop in the name of the target on a new line, and the previous target
246 # as a dependency. Also call the echo_message function.
247 LUSER_wrt_target "${this_script}" "$PREV"
248 #
249 # If $pkg_tarball isn't empty, we've got a package...
250 if [ "$pkg_tarball" != "" ] ; then
251 LUSER_wrt_unpack "$pkg_tarball"
252 # If using optimizations, write the instructions
253 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
254 fi
255 #
256 LUSER_wrt_RunAsUser "${file}"
257 #
258 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
259 #
260 # Include a touch of the target name so make can check if it's already been made.
261 wrt_touch
262 #
263 #--------------------------------------------------------------------#
264 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
265 #--------------------------------------------------------------------#
266 #
267 # Keep the script file name for Makefile dependencies.
268 PREV=${this_script}
269 done # for file in final-system/* ...
270}
271
272
273
274#-----------------------------#
275bootscripts_Makefiles() { #
276#-----------------------------#
277 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
278
279 for file in bootscripts/* ; do
280 # Keep the script file name
281 this_script=`basename $file`
282
283 case $this_script in
284 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
285 *console*) continue ;; # Use the files that came with the bootscripts
286 *network*) continue ;; # Manually create these files
287 *) ;;
288 esac
289
290 # First append each name of the script files to a list (this will become
291 # the names of the targets in the Makefile
292 bootscripttools="$bootscripttools $this_script"
293
294 # Grab the name of the target, strip id number, XXX-script
295 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
296 -e 's@-64bit@@' \
297 -e 's@-64@@' \
298 -e 's@64@@' \
299 -e 's@n32@@'`
300 case $name in
301 *bootscripts*) name=bootscripts-cross-lfs ;;
302 *udev-rules) name=udev-cross-lfs ;;
303 esac
304
305 pkg_tarball=$(get_package_tarball_name $name)
306
307 #--------------------------------------------------------------------#
308 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
309 #--------------------------------------------------------------------#
310 #
311 # Drop in the name of the target on a new line, and the previous target
312 # as a dependency. Also call the echo_message function.
313 LUSER_wrt_target "${this_script}" "$PREV"
314 #
315 # If $pkg_tarball isn't empty, we've got a package...
316 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
317 #
318 LUSER_wrt_RunAsUser "${file}"
319 #
320 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
321 #
322 # Include a touch of the target name so make can check if it's already been made.
323 wrt_touch
324 #
325 #--------------------------------------------------------------------#
326 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
327 #--------------------------------------------------------------------#
328 #
329 # Keep the script file name for Makefile dependencies.
330 PREV=$this_script
331
332 done # for file in bootscripts/* ...
333
334}
335
336
337#-----------------------------#
338bootable_Makefiles() { #
339#-----------------------------#
340 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
341
342 for file in bootable/* ; do
343 # Keep the script file name
344 this_script=`basename $file`
345
346 # A little housekeeping on the scripts
347 case $this_script in
348 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
349 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
350 *kernel) # if there is no kernel config file do not build the kernel
351 [[ -z $CONFIG ]] && continue
352 # Copy the config file to /sources with a standardized name
353 cp $CONFIG $BUILDDIR/sources/kernel-config
354 ;;
355 esac
356 #
357 # First append each name of the script files to a list (this will become
358 # the names of the targets in the Makefile
359 # NOTE: new makfile format forces the last script, *chowning, into a separate
360 # phase.
361 case ${this_script} in
362 *chowning) chowning=${this_script} ;;
363 *) bootable="$bootable $this_script" ;;
364 esac
365 #
366 # Grab the name of the target, strip id number and misc words.
367 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
368 case $this_script in
369 *kernel*) name=linux
370 ;;
371 esac
372
373 pkg_tarball=$(get_package_tarball_name $name)
374
375 #--------------------------------------------------------------------#
376 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
377 #--------------------------------------------------------------------#
378 #
379 # Drop in the name of the target on a new line, and the previous target
380 # as a dependency. Also call the echo_message function.
381 LUSER_wrt_target "${this_script}" "$PREV"
382 #
383 # If $pkg_tarball isn't empty, we've got a package...
384 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
385 #
386 # Select a script execution method
387 case $this_script in
388 *fstab*) if [[ -n "$FSTAB" ]]; then
389 LUSER_wrt_CopyFstab
390 else
391 LUSER_wrt_RunAsUser "${file}"
392 fi
393 ;;
394 *chowning) wrt_RunAsRoot "${this_script}" "${file}"
395 ;;
396 *) LUSER_wrt_RunAsUser "${file}"
397 ;;
398 esac
399 #
400 # Housekeeping...remove any build directory(ies) except if the package build fails.
401 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
402 #
403 # Include a touch of the target name so make can check if it's already been made.
404 wrt_touch
405 #
406 #--------------------------------------------------------------------#
407 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
408 #--------------------------------------------------------------------#
409 #
410 # Keep the script file name for Makefile dependencies.
411 PREV=$this_script
412
413 done
414
415}
416
417
418#-----------------------------#
419build_Makefile() { # Construct a Makefile from the book scripts
420#-----------------------------#
421 echo "Creating Makefile... ${BOLD}START${OFF}"
422
423 cd $JHALFSDIR/${PROGNAME}-commands
424 # Start with a clean Makefile.tmp file
425 >$MKFILE.tmp
426
427 host_prep_Makefiles
428 cross_tools_Makefiles # $cross_tools
429 final_system_Makefiles # $basicsystem
430 bootscripts_Makefiles # $bootscripttools
431 bootable_Makefiles # $bootable
432
433 # Add a header, some variables and include the function file
434 # to the top of the real Makefile.
435(
436 cat << EOF
437$HEADER
438
439SRC = /sources
440MOUNT_PT = $BUILDDIR
441PKG_LST = $PKG_LST
442LUSER = $LUSER
443LGROUP = $LGROUP
444SCRIPT_ROOT = $SCRIPT_ROOT
445
446BASEDIR = \$(MOUNT_PT)
447SRCSDIR = \$(BASEDIR)/sources
448CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
449LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
450TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
451
452SU_LUSER = su - \$(LUSER) -c
453PRT_DU = echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n"
454LUSER_HOME = /home/\$(LUSER)
455
456export PATH := \${PATH}:/usr/sbin
457
458include makefile-functions
459
460EOF
461) > $MKFILE
462
463 # Drop in the main target 'all:' and the chapter targets with each sub-target
464 # as a dependency.
465(
466cat << EOF
467
468all: ck_UID mk_SETUP mk_LUSER mk_ROOT create-sbu_du-report
469 @sudo make do-housekeeping
470 @\$(call echo_finished,$VERSION)
471
472ck_UID:
473 @if [ \`id -u\` = "0" ]; then \\
474 echo "--------------------------------------------------"; \\
475 echo "You cannot run this makefile from the root account"; \\
476 echo "--------------------------------------------------"; \\
477 exit 1; \\
478 fi
479
480mk_SETUP:
481 @\$(call echo_SU_request)
482 @sudo make SETUP
483 @touch \$@
484
485mk_LUSER: mk_SETUP
486 @\$(call echo_SULUSER_request)
487 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make LUSER" )
488 @sudo make restore-luser-env
489 @touch \$@
490
491mk_ROOT:
492 @sudo make ROOT
493 @touch \$@
494
495SETUP: $host_prep
496
497LUSER: $cross_tools $basicsystem $bootscripttools $bootable
498
499ROOT: $chowning
500
501
502restart:
503 @echo "This feature does not exist for the CLFS-2 makefile. (yet)"
504
505restore-luser-env:
506 @\$(call echo_message, Building)
507 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
508 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
509 fi;
510 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
511 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
512 fi;
513 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
514 touch \$@ && \\
515 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
516 echo --------------------------------------------------------------------------------\$(WHITE)
517
518do-housekeeping:
519 @-if [ ! -f luser-exist ]; then \\
520 userdel \$(LUSER); \\
521 rm -rf /home/\$(LUSER); \\
522 fi;
523
524EOF
525) >> $MKFILE
526
527 # Add SBU-disk_usage report target
528 echo "create-sbu_du-report:" >> $MKFILE
529 if [[ "$REPORT" = "y" ]] ; then
530(
531 cat << EOF
532 @\$(call echo_message, Building)
533 @./create-sbu_du-report.sh logs $VERSION
534 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
535 @touch \$@
536
537
538EOF
539) >> $MKFILE
540 else echo -e "\t@true\n\n" >> $MKFILE; fi
541
542 # Bring over the items from the Makefile.tmp
543 cat $MKFILE.tmp >> $MKFILE
544 rm $MKFILE.tmp
545 echo "Creating Makefile... ${BOLD}DONE${OFF}"
546
547}
548
Note: See TracBrowser for help on using the repository browser.