source: CLFS2/master.sh@ 056486c

experimental
Last change on this file since 056486c was 9485eba, checked in by George Boudreau <georgeb@…>, 18 years ago

Implement suggestion made byDan Nicholson for configurable user/group. Required many changes and allowed for the removal of user specific function calls. Tnx Dan

  • Property mode set to 100755
File size: 18.1 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 user-clfs-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
133#-----------------------------#
134cross_tools_Makefiles() { #
135#-----------------------------#
136 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools${R_arrow}"
137
138 for file in cross-tools/* ; do
139 # Keep the script file name
140 this_script=`basename $file`
141 #
142 # Skip this script...
143 case $this_script in
144 *cflags* | *variables* ) # work done in host_prep_Makefiles
145 continue; ;;
146 *) ;;
147 esac
148 #
149 # Set the dependency for the first target.
150 if [ -z $PREV ] ; then PREV=026-settingenvironment ; 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 wrt_target "${this_script}" "$PREV"
174 #
175 # If $pkg_tarball isn't empty, we've got a package...
176 if [ "$pkg_tarball" != "" ] ; then
177 wrt_unpack "$pkg_tarball"
178 # If using optimizations, write the instructions
179 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
180 fi
181 #
182 wrt_RunAsUser "${this_script}" "${file}"
183 #
184 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${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 # Set envars and scripts for iteration targets
205 LOGS="" # Start with an empty global LOGS envar
206 if [[ -z "$1" ]] ; then
207 local N=""
208 else
209 local N=-build_$1
210 local basicsystem=""
211 mkdir final-system$N
212 cp final-system/* final-system$N
213 for script in final-system$N/* ; do
214 # Overwrite existing symlinks, files, and dirs
215 sed -e 's/ln -sv/&f/g' \
216 -e 's/mv -v/&f/g' \
217 -e 's/mkdir -v/&p/g' -i ${script}
218 done
219 # Remove Bzip2 binaries before make install
220 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i final-system$N/*-bzip2
221 # Delete *old Readline libraries just after make install
222 sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i final-system$N/*-readline
223 fi
224
225 echo "${tab_}${GREEN}Processing... ${L_arrow}final system$N${R_arrow}"
226
227 for file in final-system$N/* ; do
228 # Keep the script file name
229 this_script=`basename $file`
230
231 # Test if the stripping phase must be skipped.
232 # Skip alsp temp-perl for iterative runs
233 case $this_script in
234 *stripping*) [[ "$STRIP" = "0" ]] && continue ;;
235 esac
236
237 # Grab the name of the target, strip id number, XXX-script
238 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
239 -e 's@temp-@@' \
240 -e 's@-64bit@@' \
241 -e 's@-64@@' \
242 -e 's@64@@' \
243 -e 's@n32@@'`
244
245 # Find the version of the command files, if it corresponds with the building of
246 # a specific package. We need this here to can skip scripts not needed for
247 # iterations rebuilds
248 pkg_tarball=$(get_package_tarball_name $name)
249
250 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
251 case "${this_script}" in
252 *stripping*) ;;
253 *) continue ;;
254 esac
255 fi
256
257 # Append each name of the script files to a list (this will become
258 # the names of the targets in the Makefile
259 basicsystem="$basicsystem ${this_script}${N}"
260
261 # Append each name of the script files to a list (this will become
262 # the names of the logs to be moved for each iteration)
263 LOGS="$LOGS ${this_script}"
264
265 #--------------------------------------------------------------------#
266 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
267 #--------------------------------------------------------------------#
268 #
269 # Drop in the name of the target on a new line, and the previous target
270 # as a dependency. Also call the echo_message function.
271 wrt_target "${this_script}${N}" "$PREV"
272 #
273 # If $pkg_tarball isn't empty, we've got a package...
274 if [ "$pkg_tarball" != "" ] ; then
275 wrt_unpack "$pkg_tarball"
276 # If using optimizations, write the instructions
277 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
278 fi
279 #
280 wrt_RunAsUser "${this_script}" "${file}"
281 #
282 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
283 #
284 # Include a touch of the target name so make can check if it's already been made.
285 wrt_touch
286 #
287 #--------------------------------------------------------------------#
288 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
289 #--------------------------------------------------------------------#
290 #
291 # Keep the script file name for Makefile dependencies.
292 PREV=${this_script}${N}
293 # Set system_build envar for iteration targets
294 system_build=$basicsystem
295 done # for file in final-system/* ...
296}
297
298
299
300#-----------------------------#
301bootscripts_Makefiles() { #
302#-----------------------------#
303 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts${R_arrow}"
304
305 for file in bootscripts/* ; do
306 # Keep the script file name
307 this_script=`basename $file`
308
309 case $this_script in
310 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
311 *console*) continue ;; # Use the files that came with the bootscripts
312 *) ;;
313 esac
314
315 # First append each name of the script files to a list (this will become
316 # the names of the targets in the Makefile
317 bootscripttools="$bootscripttools $this_script"
318
319 # Grab the name of the target, strip id number, XXX-script
320 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
321 -e 's@-64bit@@' \
322 -e 's@-64@@' \
323 -e 's@64@@' \
324 -e 's@n32@@'`
325 case $name in
326 *bootscripts*) name=bootscripts-cross-lfs ;;
327 *udev-rules) name=udev-cross-lfs ;;
328 esac
329
330 pkg_tarball=$(get_package_tarball_name $name)
331
332 #--------------------------------------------------------------------#
333 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
334 #--------------------------------------------------------------------#
335 #
336 # Drop in the name of the target on a new line, and the previous target
337 # as a dependency. Also call the echo_message function.
338 wrt_target "${this_script}" "$PREV"
339 #
340 # If $pkg_tarball isn't empty, we've got a package...
341 [[ "$pkg_tarball" != "" ]] && wrt_unpack "$pkg_tarball"
342 #
343 wrt_RunAsUser "${this_script}" "${file}"
344 #
345 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
346 #
347 # Include a touch of the target name so make can check if it's already been made.
348 wrt_touch
349 #
350 #--------------------------------------------------------------------#
351 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
352 #--------------------------------------------------------------------#
353 #
354 # Keep the script file name for Makefile dependencies.
355 PREV=$this_script
356
357 done # for file in bootscripts/* ...
358
359}
360
361
362#-----------------------------#
363bootable_Makefiles() { #
364#-----------------------------#
365 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable${R_arrow}"
366
367 for file in bootable/* ; do
368 # Keep the script file name
369 this_script=`basename $file`
370
371 # A little housekeeping on the scripts
372 case $this_script in
373 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
374 *kernel) # if there is no kernel config file do not build the kernel
375 [[ -z $CONFIG ]] && continue
376 # Copy the config file to /sources with a standardized name
377 cp $CONFIG $BUILDDIR/sources/kernel-config
378 ;;
379 esac
380 #
381 # First append each name of the script files to a list (this will become
382 # the names of the targets in the Makefile
383 bootable="$bootable $this_script"
384 #
385 # Grab the name of the target, strip id number and misc words.
386 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
387 case $this_script in
388 *kernel*) name=linux
389 ;;
390 esac
391
392 pkg_tarball=$(get_package_tarball_name $name)
393
394 #--------------------------------------------------------------------#
395 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
396 #--------------------------------------------------------------------#
397 #
398 # Drop in the name of the target on a new line, and the previous target
399 # as a dependency. Also call the echo_message function.
400 wrt_target "${this_script}" "$PREV"
401 #
402 # If $pkg_tarball isn't empty, we've got a package...
403 [[ "$pkg_tarball" != "" ]] && wrt_unpack "$pkg_tarball"
404 #
405 # Select a script execution method
406 case $this_script in
407 *fstab*) if [[ -n "$FSTAB" ]]; then
408 wrt_copy_fstab "${this_script}"
409 else
410 wrt_RunAsUser "${this_script}" "${file}"
411 fi
412 ;;
413 *chowning) wrt_RunAsRoot "${this_script}" "${file}"
414 ;;
415 *) wrt_RunAsUser "${this_script}" "${file}"
416 ;;
417 esac
418 #
419 # Housekeeping...remove any build directory(ies) except if the package build fails.
420 [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
421 #
422 # Include a touch of the target name so make can check if it's already been made.
423 wrt_touch
424 #
425 #--------------------------------------------------------------------#
426 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
427 #--------------------------------------------------------------------#
428 #
429 # Keep the script file name for Makefile dependencies.
430 PREV=$this_script
431
432 done
433
434 # Add SBU-disk_usage report target if required
435 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
436
437}
438
439
440#-----------------------------#
441build_Makefile() { # Construct a Makefile from the book scripts
442#-----------------------------#
443 echo "Creating Makefile... ${BOLD}START${OFF}"
444
445 cd $JHALFSDIR/${PROGNAME}-commands
446 # Start with a clean Makefile.tmp file
447 >$MKFILE.tmp
448
449 host_prep_Makefiles
450 cross_tools_Makefiles # $cross_tools
451 final_system_Makefiles # $basicsystem
452 bootscripts_Makefiles # $bootscripttools
453 bootable_Makefiles # $bootable
454
455 # Add a header, some variables and include the function file
456 # to the top of the real Makefile.
457(
458 cat << EOF
459$HEADER
460
461SRC= /sources
462MOUNT_PT= $BUILDDIR
463PKG_LST= $PKG_LST
464LUSER= $LUSER
465LGROUP= $LGROUP
466
467include makefile-functions
468
469EOF
470) > $MKFILE
471
472 # Drop in the main target 'all:' and the chapter targets with each sub-target
473 # as a dependency.
474(
475 cat << EOF
476all: chapter2 chapter3 chapter4 chapter5 chapter6 do-housekeeping
477 @\$(call echo_finished,$VERSION)
478
479chapter2: 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile
480
481chapter3: chapter2 $cross_tools
482
483chapter4: chapter3 $basicsystem
484
485chapter5: chapter4 $bootscripttools
486
487chapter6: chapter5 $bootable
488
489clean-all: clean
490 rm -rf ./{clfs2-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
491
492clean:
493
494restart:
495 @echo "This feature does not exist for the CLFS makefile. (yet)"
496
497restore-clfs-env:
498 @\$(call echo_message, Building)
499 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
500 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
501 fi;
502 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
503 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
504 fi;
505 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
506 touch \$@ && \\
507 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
508 echo --------------------------------------------------------------------------------\$(WHITE)
509
510do-housekeeping:
511 @-if [ ! -f user-clfs-exist ]; then \\
512 userdel \$(LUSER); \\
513 rm -rf /home/\$(LUSER); \\
514 fi;
515
516EOF
517) >> $MKFILE
518
519 # Bring over the items from the Makefile.tmp
520 cat $MKFILE.tmp >> $MKFILE
521 rm $MKFILE.tmp
522 echo "Creating Makefile... ${BOLD}DONE${OFF}"
523
524}
525
Note: See TracBrowser for help on using the repository browser.