source: CLFS2/master.sh@ 398a037

experimental
Last change on this file since 398a037 was 398a037, checked in by George Boudreau <georgeb@…>, 18 years ago

Mods to most files to allow for reduction of internal functions and reduction in the size of the generated makefile

  • Property mode set to 100755
File size: 17.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${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 @mkdir \$(MOUNT_PT)/tools && \\
23 rm -f /tools && \\
24 ln -s \$(MOUNT_PT)/tools /
25 @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
26 mkdir \$(MOUNT_PT)/sources; \\
27 fi;
28 @chmod a+wt \$(MOUNT_PT)/sources
29 @touch \$@ && \\
30 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
31 echo --------------------------------------------------------------------------------\$(WHITE)
32
33025-addinguser: 023-creatingtoolsdir
34 @\$(call echo_message, Building)
35 @if [ ! -d /home/\$(LUSER) ]; then \\
36 groupadd \$(LGROUP); \\
37 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
38 else \\
39 touch luser-exist; \\
40 fi;
41 @chown \$(LUSER) \$(MOUNT_PT) && \\
42 chown \$(LUSER) \$(MOUNT_PT)/tools && \\
43 chown \$(LUSER) \$(MOUNT_PT)/sources
44 @touch \$@ && \\
45 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
46 echo --------------------------------------------------------------------------------\$(WHITE)
47
48026-settingenvironment: 025-addinguser
49 @\$(call echo_message, Building)
50 @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
51 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
52 fi;
53 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
54 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
55 fi;
56 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
57 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
58 echo "CLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
59 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
60 echo "PATH=\$(MOUNT_PT)/cross-tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
61 echo "export CLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
62 echo "" >> /home/\$(LUSER)/.bashrc && \\
63 echo "unset CFLAGS" >> /home/\$(LUSER)/.bashrc && \\
64 echo "unset CXXFLAGS" >> /home/\$(LUSER)/.bashrc && \\
65 echo "" >> /home/\$(LUSER)/.bashrc && \\
66 echo "export CLFS_HOST=\"${CLFS_HOST}\"" >> /home/\$(LUSER)/.bashrc && \\
67 echo "export CLFS_TARGET=\"${TARGET}\"" >> /home/\$(LUSER)/.bashrc && \\
68 echo "export CLFS_TARGET32=\"${TARGET32}\"" >> /home/\$(LUSER)/.bashrc && \\
69 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc
70 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
71 touch envars
72 @touch \$@ && \\
73 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
74 echo --------------------------------------------------------------------------------\$(WHITE)
75
76027-create-directories: 026-settingenvironment
77 @\$(call echo_message, Building)
78
79 @mkdir -p \$(MOUNT_PT)/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
80 @mkdir -p \$(MOUNT_PT)/{proc,media/{floppy,cdrom},sbin,srv,sys}
81 @mkdir -p \$(MOUNT_PT)/var/{lock,log,mail,run,spool}
82 @mkdir -p \$(MOUNT_PT)/var/{opt,cache,lib/{misc,locate},local}
83 @install -d -m 0750 \$(MOUNT_PT)/root
84 @install -d -m 1777 \$(MOUNT_PT){/var,}/tmp
85 @mkdir -p \$(MOUNT_PT)/usr/{,local/}{bin,include,lib,sbin,src}
86 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{doc,info,locale,man}
87 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{misc,terminfo,zoneinfo}
88 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
89 @for dir in \$(MOUNT_PT)/usr{,/local}; do \\
90 ln -s share/{man,doc,info} \$\$dir ; \\
91 done
92
93 @touch \$@ && \\
94 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
95 echo --------------------------------------------------------------------------------\$(WHITE)
96
97028-creating-sysfile: 027-create-directories
98 @\$(call echo_message, Building)
99
100 @touch \$(MOUNT_PT)/etc/mtab
101 @echo "root::0:0:root:/root:/bin/bash" >> \$(MOUNT_PT)/etc/passwd
102 @echo "root:x:0:" >> \$(MOUNT_PT)/etc/group
103 @echo "bin:x:1:" >> \$(MOUNT_PT)/etc/group
104 @echo "sys:x:2:" >> \$(MOUNT_PT)/etc/group
105 @echo "kmem:x:3" >> \$(MOUNT_PT)/etc/group
106 @echo "tty:x:4:" >> \$(MOUNT_PT)/etc/group
107 @echo "tape:x:5:" >> \$(MOUNT_PT)/etc/group
108 @echo "daemon:x:6:" >> \$(MOUNT_PT)/etc/group
109 @echo "floppy:x:7:" >> \$(MOUNT_PT)/etc/group
110 @echo "disk:x:8:" >> \$(MOUNT_PT)/etc/group
111 @echo "lp:x:9:" >> \$(MOUNT_PT)/etc/group
112 @echo "dialout:x:10:" >> \$(MOUNT_PT)/etc/group
113 @echo "audio:x:11:" >> \$(MOUNT_PT)/etc/group
114 @echo "video:x:12:" >> \$(MOUNT_PT)/etc/group
115 @echo "utmp:x:13:" >> \$(MOUNT_PT)/etc/group
116 @echo "usb:x:14:" >> \$(MOUNT_PT)/etc/group
117 @echo "cdrom:x:15:" >> \$(MOUNT_PT)/etc/group
118
119 @touch \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/{btmp,lastlog,wtmp}
120 @chmod 664 \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/lastlog
121 @chown -R \$(LUSER) \$(MOUNT_PT)
122
123 @touch \$@ && \\
124 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
125 echo --------------------------------------------------------------------------------\$(WHITE)
126
127EOF
128) >> $MKFILE.tmp
129}
130
131
132#-----------------------------#
133cross_tools_Makefiles() { #
134#-----------------------------#
135 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools${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 wrt_target "${this_script}" "$PREV"
183 #
184 # If $pkg_tarball isn't empty, we've got a package...
185 if [ "$pkg_tarball" != "" ] ; then
186 wrt_unpack "$pkg_tarball"
187 # If using optimizations, write the instructions
188 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
189 fi
190 #
191 wrt_RunAsUser "${this_script}" "${file}"
192 #
193 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${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${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" = "0" ]] && 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 wrt_target "${this_script}" "$PREV"
248 #
249 # If $pkg_tarball isn't empty, we've got a package...
250 if [ "$pkg_tarball" != "" ] ; then
251 wrt_unpack "$pkg_tarball"
252 # If using optimizations, write the instructions
253 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
254 fi
255 #
256 wrt_RunAsUser "${this_script}" "${file}"
257 #
258 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${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${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 wrt_target "${this_script}" "$PREV"
314 #
315 # If $pkg_tarball isn't empty, we've got a package...
316 [[ "$pkg_tarball" != "" ]] && wrt_unpack "$pkg_tarball"
317 #
318 wrt_RunAsUser "${this_script}" "${file}"
319 #
320 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${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${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 *kernel) # if there is no kernel config file do not build the kernel
350 [[ -z $CONFIG ]] && continue
351 # Copy the config file to /sources with a standardized name
352 cp $CONFIG $BUILDDIR/sources/kernel-config
353 ;;
354 esac
355 #
356 # First append each name of the script files to a list (this will become
357 # the names of the targets in the Makefile
358 bootable="$bootable $this_script"
359 #
360 # Grab the name of the target, strip id number and misc words.
361 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
362 case $this_script in
363 *kernel*) name=linux
364 ;;
365 esac
366
367 pkg_tarball=$(get_package_tarball_name $name)
368
369 #--------------------------------------------------------------------#
370 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
371 #--------------------------------------------------------------------#
372 #
373 # Drop in the name of the target on a new line, and the previous target
374 # as a dependency. Also call the echo_message function.
375 wrt_target "${this_script}" "$PREV"
376 #
377 # If $pkg_tarball isn't empty, we've got a package...
378 [[ "$pkg_tarball" != "" ]] && wrt_unpack "$pkg_tarball"
379 #
380 # Select a script execution method
381 case $this_script in
382 *fstab*) if [[ -n "$FSTAB" ]]; then
383 wrt_copy_fstab "${this_script}"
384 else
385 wrt_RunAsUser "${this_script}" "${file}"
386 fi
387 ;;
388 *chowning) wrt_RunAsRoot "${this_script}" "${file}"
389 ;;
390 *) wrt_RunAsUser "${this_script}" "${file}"
391 ;;
392 esac
393 #
394 # Housekeeping...remove any build directory(ies) except if the package build fails.
395 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
396 #
397 # Include a touch of the target name so make can check if it's already been made.
398 wrt_touch
399 #
400 #--------------------------------------------------------------------#
401 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
402 #--------------------------------------------------------------------#
403 #
404 # Keep the script file name for Makefile dependencies.
405 PREV=$this_script
406
407 done
408
409 # Add SBU-disk_usage report target if required
410 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
411
412}
413
414
415#-----------------------------#
416build_Makefile() { # Construct a Makefile from the book scripts
417#-----------------------------#
418 echo "Creating Makefile... ${BOLD}START${OFF}"
419
420 cd $JHALFSDIR/${PROGNAME}-commands
421 # Start with a clean Makefile.tmp file
422 >$MKFILE.tmp
423
424 host_prep_Makefiles
425 cross_tools_Makefiles # $cross_tools
426 final_system_Makefiles # $basicsystem
427 bootscripts_Makefiles # $bootscripttools
428 bootable_Makefiles # $bootable
429
430 # Add a header, some variables and include the function file
431 # to the top of the real Makefile.
432(
433 cat << EOF
434$HEADER
435
436SRC = /sources
437MOUNT_PT = $BUILDDIR
438PKG_LST = $PKG_LST
439LUSER = $LUSER
440LGROUP = $LGROUP
441SCRIPT_ROOT = $SCRIPT_ROOT
442
443BASEDIR = \$(MOUNT_PT)
444SRCSDIR = \$(BASEDIR)/sources
445CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
446LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
447TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
448
449SU_LUSER = su - \$(LUSER) -c
450PRT_DU = echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n"
451LUSER_HOME = /home/\$(LUSER)
452
453include makefile-functions
454
455EOF
456) > $MKFILE
457
458 # Drop in the main target 'all:' and the chapter targets with each sub-target
459 # as a dependency.
460(
461 cat << EOF
462all: chapter2 chapter3 chapter4 chapter5 chapter6 restore-luser-env do-housekeeping
463 @\$(call echo_finished,$VERSION)
464
465chapter2: 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile
466
467chapter3: chapter2 $cross_tools
468
469chapter4: chapter3 $basicsystem
470
471chapter5: chapter4 $bootscripttools
472
473chapter6: chapter5 $bootable
474
475clean-all: clean
476 rm -rf ./{clfs2-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
477
478clean:
479
480restart:
481 @echo "This feature does not exist for the CLFS makefile. (yet)"
482
483restore-luser-env:
484 @\$(call echo_message, Building)
485 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
486 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
487 fi;
488 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
489 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
490 fi;
491 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
492 touch \$@ && \\
493 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
494 echo --------------------------------------------------------------------------------\$(WHITE)
495
496do-housekeeping:
497 @-if [ ! -f luser-exist ]; then \\
498 userdel \$(LUSER); \\
499 rm -rf /home/\$(LUSER); \\
500 fi;
501
502EOF
503) >> $MKFILE
504
505 # Bring over the items from the Makefile.tmp
506 cat $MKFILE.tmp >> $MKFILE
507 rm $MKFILE.tmp
508 echo "Creating Makefile... ${BOLD}DONE${OFF}"
509
510}
511
Note: See TracBrowser for help on using the repository browser.