source: CLFS2/master.sh@ d9daa95

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

Ported LUSER code and last CLFS2 fix from experimental.

  • Property mode set to 100755
File size: 17.4 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 *) ;;
287 esac
288
289 # First append each name of the script files to a list (this will become
290 # the names of the targets in the Makefile
291 bootscripttools="$bootscripttools $this_script"
292
293 # Grab the name of the target, strip id number, XXX-script
294 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
295 -e 's@-64bit@@' \
296 -e 's@-64@@' \
297 -e 's@64@@' \
298 -e 's@n32@@'`
299 case $name in
300 *bootscripts*) name=bootscripts-cross-lfs ;;
301 *udev-rules) name=udev-cross-lfs ;;
302 esac
303
304 pkg_tarball=$(get_package_tarball_name $name)
305
306 #--------------------------------------------------------------------#
307 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
308 #--------------------------------------------------------------------#
309 #
310 # Drop in the name of the target on a new line, and the previous target
311 # as a dependency. Also call the echo_message function.
312 wrt_target "${this_script}" "$PREV"
313 #
314 # If $pkg_tarball isn't empty, we've got a package...
315 [[ "$pkg_tarball" != "" ]] && wrt_unpack "$pkg_tarball"
316 #
317 wrt_RunAsUser "${this_script}" "${file}"
318 #
319 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
320 #
321 # Include a touch of the target name so make can check if it's already been made.
322 wrt_touch
323 #
324 #--------------------------------------------------------------------#
325 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
326 #--------------------------------------------------------------------#
327 #
328 # Keep the script file name for Makefile dependencies.
329 PREV=$this_script
330
331 done # for file in bootscripts/* ...
332
333}
334
335
336#-----------------------------#
337bootable_Makefiles() { #
338#-----------------------------#
339 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable${R_arrow}"
340
341 for file in bootable/* ; do
342 # Keep the script file name
343 this_script=`basename $file`
344
345 # A little housekeeping on the scripts
346 case $this_script in
347 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
348 *kernel) # if there is no kernel config file do not build the kernel
349 [[ -z $CONFIG ]] && continue
350 # Copy the config file to /sources with a standardized name
351 cp $CONFIG $BUILDDIR/sources/kernel-config
352 ;;
353 esac
354 #
355 # First append each name of the script files to a list (this will become
356 # the names of the targets in the Makefile
357 bootable="$bootable $this_script"
358 #
359 # Grab the name of the target, strip id number and misc words.
360 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
361 case $this_script in
362 *kernel*) name=linux
363 ;;
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 "$pkg_tarball"
378 #
379 # Select a script execution method
380 case $this_script in
381 *fstab*) if [[ -n "$FSTAB" ]]; then
382 wrt_copy_fstab "${this_script}"
383 else
384 wrt_RunAsUser "${this_script}" "${file}"
385 fi
386 ;;
387 *chowning) wrt_RunAsRoot "${this_script}" "${file}"
388 ;;
389 *) wrt_RunAsUser "${this_script}" "${file}"
390 ;;
391 esac
392 #
393 # Housekeeping...remove any build directory(ies) except if the package build fails.
394 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
395 #
396 # Include a touch of the target name so make can check if it's already been made.
397 wrt_touch
398 #
399 #--------------------------------------------------------------------#
400 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
401 #--------------------------------------------------------------------#
402 #
403 # Keep the script file name for Makefile dependencies.
404 PREV=$this_script
405
406 done
407
408 # Add SBU-disk_usage report target if required
409 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
410
411}
412
413
414#-----------------------------#
415build_Makefile() { # Construct a Makefile from the book scripts
416#-----------------------------#
417 echo "Creating Makefile... ${BOLD}START${OFF}"
418
419 cd $JHALFSDIR/${PROGNAME}-commands
420 # Start with a clean Makefile.tmp file
421 >$MKFILE.tmp
422
423 host_prep_Makefiles
424 cross_tools_Makefiles # $cross_tools
425 final_system_Makefiles # $basicsystem
426 bootscripts_Makefiles # $bootscripttools
427 bootable_Makefiles # $bootable
428
429 # Add a header, some variables and include the function file
430 # to the top of the real Makefile.
431(
432 cat << EOF
433$HEADER
434
435SRC= /sources
436MOUNT_PT= $BUILDDIR
437PKG_LST= $PKG_LST
438LUSER= $LUSER
439LGROUP= $LGROUP
440
441include makefile-functions
442
443EOF
444) > $MKFILE
445
446 # Drop in the main target 'all:' and the chapter targets with each sub-target
447 # as a dependency.
448(
449 cat << EOF
450all: chapter2 chapter3 chapter4 chapter5 chapter6 restore-luser-env do-housekeeping
451 @\$(call echo_finished,$VERSION)
452
453chapter2: 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile
454
455chapter3: chapter2 $cross_tools
456
457chapter4: chapter3 $basicsystem
458
459chapter5: chapter4 $bootscripttools
460
461chapter6: chapter5 $bootable
462
463clean-all: clean
464 rm -rf ./{clfs2-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
465
466clean:
467
468restart:
469 @echo "This feature does not exist for the CLFS makefile. (yet)"
470
471restore-luser-env:
472 @\$(call echo_message, Building)
473 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
474 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
475 fi;
476 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
477 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
478 fi;
479 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
480 touch \$@ && \\
481 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
482 echo --------------------------------------------------------------------------------\$(WHITE)
483
484do-housekeeping:
485 @-if [ ! -f luser-exist ]; then \\
486 userdel \$(LUSER); \\
487 rm -rf /home/\$(LUSER); \\
488 fi;
489
490EOF
491) >> $MKFILE
492
493 # Bring over the items from the Makefile.tmp
494 cat $MKFILE.tmp >> $MKFILE
495 rm $MKFILE.tmp
496 echo "Creating Makefile... ${BOLD}DONE${OFF}"
497
498}
499
Note: See TracBrowser for help on using the repository browser.