source: CLFS2/master.sh@ 7cb8803

experimental
Last change on this file since 7cb8803 was 47fddc8, checked in by George Boudreau <georgeb@…>, 18 years ago

Change bool parameter definitions from 0/1 to y/n to match the new menu app

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