source: CLFS3/master.sh@ 4eba1ea

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 4eba1ea was 3c38ab0, checked in by George Boudreau <georgeb@…>, 18 years ago

Adapted to clfs bootscript naming convention

  • Property mode set to 100644
File size: 17.7 KB
RevLine 
[91ff6a9]1#!/bin/bash
[837797e]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 && \\
[f56e662]64 echo "export CLFS_MIPS_LEVEL=\"${MIPS_LEVEL}\"" >> /home/\$(LUSER)/.bashrc && \\
[6af630c]65 echo "export BUILD=\"${ABI}\"" >> /home/\$(LUSER)/.bashrc && \\
[837797e]66 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc
67 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
68 touch envars && \\
69 chown \$(LUSER):\$(LGROUP) envars && \\
70 chmod -R a+wt \$(MOUNT_PT)
71 @touch \$@ && \\
72 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
73 echo --------------------------------------------------------------------------------\$(WHITE)
74
75027-create-directories: 026-settingenvironment
76 @\$(call echo_message, Building)
77
78 @mkdir -p \$(MOUNT_PT)/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
79 @mkdir -p \$(MOUNT_PT)/{proc,media/{floppy,cdrom},sbin,srv,sys}
80 @mkdir -p \$(MOUNT_PT)/var/{lock,log,mail,run,spool}
81 @mkdir -p \$(MOUNT_PT)/var/{opt,cache,lib/{misc,locate},local}
82 @install -d -m 0750 \$(MOUNT_PT)/root
83 @install -d -m 1777 \$(MOUNT_PT){/var,}/tmp
84 @mkdir -p \$(MOUNT_PT)/usr/{,local/}{bin,include,lib,sbin,src}
85 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{doc,info,locale,man}
86 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{misc,terminfo,zoneinfo}
87 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
88 @for dir in \$(MOUNT_PT)/usr{,/local}; do \\
89 ln -s share/{man,doc,info} \$\$dir ; \\
90 done
91
92 @touch \$@ && \\
93 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
94 echo --------------------------------------------------------------------------------\$(WHITE)
95
96028-creating-sysfile: 027-create-directories
97 @\$(call echo_message, Building)
98
99 @touch \$(MOUNT_PT)/etc/mtab
[8b23a0e]100 @echo "root::0:0:root:/root:/bin/ash" >> \$(MOUNT_PT)/etc/passwd
[837797e]101 @echo "root:x:0:" >> \$(MOUNT_PT)/etc/group
102 @echo "bin:x:1:" >> \$(MOUNT_PT)/etc/group
103 @echo "sys:x:2:" >> \$(MOUNT_PT)/etc/group
104 @echo "kmem:x:3" >> \$(MOUNT_PT)/etc/group
105 @echo "tty:x:4:" >> \$(MOUNT_PT)/etc/group
106 @echo "tape:x:5:" >> \$(MOUNT_PT)/etc/group
107 @echo "daemon:x:6:" >> \$(MOUNT_PT)/etc/group
108 @echo "floppy:x:7:" >> \$(MOUNT_PT)/etc/group
109 @echo "disk:x:8:" >> \$(MOUNT_PT)/etc/group
110 @echo "lp:x:9:" >> \$(MOUNT_PT)/etc/group
111 @echo "dialout:x:10:" >> \$(MOUNT_PT)/etc/group
112 @echo "audio:x:11:" >> \$(MOUNT_PT)/etc/group
113 @echo "video:x:12:" >> \$(MOUNT_PT)/etc/group
114 @echo "utmp:x:13:" >> \$(MOUNT_PT)/etc/group
115 @echo "usb:x:14:" >> \$(MOUNT_PT)/etc/group
116 @echo "cdrom:x:15:" >> \$(MOUNT_PT)/etc/group
117
118 @touch \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/{btmp,lastlog,wtmp}
119 @chmod 664 \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/lastlog
120 @chown -R \$(LUSER) \$(MOUNT_PT)
121
122 @touch \$@ && \\
123 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
124 echo --------------------------------------------------------------------------------\$(WHITE)
125
126EOF
127) >> $MKFILE.tmp
128
129 host_prep=" 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile"
130}
131
132
133#-----------------------------#
134cross_tools_Makefiles() { #
135#-----------------------------#
136 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools ( LUSER ) ${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 # NOTE.. the book indicated you only needed to install groff or file if the host
144 # had older versions. The packages would be installed in the target directory
145 # and not the host.
146 case $this_script in
[b1607e2]147 *cflags* | *variables* | *abi ) # work done in host_prep_Makefiles
[837797e]148 continue ;;
149 *) ;;
150 esac
151
152 #
153 # Set the dependency for the first target.
154 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
155
156 # First append each name of the script files to a list (this will become
157 # the names of the targets in the Makefile)
158 cross_tools="$cross_tools $this_script"
159
160 # Grab the name of the target (minus the -headers or -cross in the case of gcc
161 # and binutils in chapter 5)
162 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
163 -e 's@-static@@' \
164 -e 's@-final@@' \
165 -e 's@-64@@' \
166 -e 's@-n32@@'`
167 case $name in
168 uclibc*) name="uClibc" ;;
169 esac
170 pkg_tarball=$(get_package_tarball_name $name)
171 #--------------------------------------------------------------------#
172 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
173 #--------------------------------------------------------------------#
174 #
175 # Drop in the name of the target on a new line, and the previous target
176 # as a dependency. Also call the echo_message function.
177 LUSER_wrt_target "${this_script}" "$PREV"
178 #
179 # If $pkg_tarball isn't empty, we've got a package...
180 if [ "$pkg_tarball" != "" ] ; then
181 LUSER_wrt_unpack "$pkg_tarball"
182 # If using optimizations, write the instructions
183 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
184 fi
185 #
186 LUSER_wrt_RunAsUser "${file}"
187 #
188 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
189 #
190 # Include a touch of the target name so make can check if it's already been made.
191 wrt_touch
192 #
193 #--------------------------------------------------------------------#
194 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
195 #--------------------------------------------------------------------#
196 #
197 # Keep the script file name for Makefile dependencies.
198 PREV=$this_script
199
200 done # for file in ....
201}
202
203
204
205#-----------------------------#
206final_system_Makefiles() { #
207#-----------------------------#
208 echo "${tab_}${GREEN}Processing... ${L_arrow}final system ( LUSER ) ${R_arrow}"
209
210 for file in final-system/* ; do
211 # Keep the script file name
212 this_script=`basename $file`
213
214 # Test if the stripping phase must be skipped.
215 # Skip alsp temp-perl for iterative runs
216 case $this_script in
217 *stripping*) [[ "$STRIP" = "n" ]] && continue ;;
218 esac
219
220 # Grab the name of the target, strip id number, XXX-script
221 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
222 -e 's@temp-@@' \
223 -e 's@-64bit@@' \
224 -e 's@-64@@' \
225 -e 's@64@@' \
226 -e 's@n32@@'`
227
228 # Find the version of the command files, if it corresponds with the building of
229 # a specific package.
230 pkg_tarball=$(get_package_tarball_name $name)
231
232 # Append each name of the script files to a list (this will become
233 # the names of the targets in the Makefile
234 basicsystem="$basicsystem ${this_script}"
235
236 #--------------------------------------------------------------------#
237 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
238 #--------------------------------------------------------------------#
239 #
240 # Drop in the name of the target on a new line, and the previous target
241 # as a dependency. Also call the echo_message function.
242 LUSER_wrt_target "${this_script}" "$PREV"
243 #
244 # If $pkg_tarball isn't empty, we've got a package...
245 if [ "$pkg_tarball" != "" ] ; then
246 LUSER_wrt_unpack "$pkg_tarball"
247 # If using optimizations, write the instructions
248 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
249 fi
250 #
251 LUSER_wrt_RunAsUser "${file}"
252 #
253 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
254 #
255 # Include a touch of the target name so make can check if it's already been made.
256 wrt_touch
257 #
258 #--------------------------------------------------------------------#
259 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
260 #--------------------------------------------------------------------#
261 #
262 # Keep the script file name for Makefile dependencies.
263 PREV=${this_script}
264 done # for file in final-system/* ...
265}
266
267
268
269#-----------------------------#
270bootscripts_Makefiles() { #
271#-----------------------------#
272 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
273
274 for file in bootscripts/* ; do
275 # Keep the script file name
276 this_script=`basename $file`
277
278 case $this_script in
279 *console*) continue ;; # Use the files that came with the bootscripts
280 *network*) continue ;; # Manually create these files
281 *) ;;
282 esac
283
284 # First append each name of the script files to a list (this will become
285 # the names of the targets in the Makefile
286 bootscripttools="$bootscripttools $this_script"
287
288 # Grab the name of the target, strip id number, XXX-script
289 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
290 -e 's@-64bit@@' \
291 -e 's@-64@@' \
292 -e 's@64@@' \
293 -e 's@n32@@'`
294 case $name in
[3c38ab0]295 *bootscripts*) name=clfs-embedded-bootscripts ;;
[837797e]296 esac
297
298 pkg_tarball=$(get_package_tarball_name $name)
299
300 #--------------------------------------------------------------------#
301 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
302 #--------------------------------------------------------------------#
303 #
304 # Drop in the name of the target on a new line, and the previous target
305 # as a dependency. Also call the echo_message function.
306 LUSER_wrt_target "${this_script}" "$PREV"
307 #
308 # If $pkg_tarball isn't empty, we've got a package...
309 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
310 #
311 LUSER_wrt_RunAsUser "${file}"
312 #
313 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
314 #
315 # Include a touch of the target name so make can check if it's already been made.
316 wrt_touch
317 #
318 #--------------------------------------------------------------------#
319 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
320 #--------------------------------------------------------------------#
321 #
322 # Keep the script file name for Makefile dependencies.
323 PREV=$this_script
324
325 done # for file in bootscripts/* ...
326
327}
328
329
330#-----------------------------#
331bootable_Makefiles() { #
332#-----------------------------#
333 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
334
335 for file in bootable/* ; do
336 # Keep the script file name
337 this_script=`basename $file`
338
339 # A little housekeeping on the scripts
340 case $this_script in
341 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
342 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
343 *kernel) # if there is no kernel config file do not build the kernel
344 [[ -z $CONFIG ]] && continue
345 # Copy the config file to /sources with a standardized name
346 cp $CONFIG $BUILDDIR/sources/kernel-config
347 ;;
348 esac
349 #
350 # First append each name of the script files to a list (this will become
351 # the names of the targets in the Makefile
352 # NOTE: new makfile format forces the last script, *chowning, into a separate
353 # phase.
354 case ${this_script} in
355 *chowning) chowning=${this_script} ;;
356 *) bootable="$bootable $this_script" ;;
357 esac
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 LUSER_wrt_target "${this_script}" "$PREV"
375 #
376 # If $pkg_tarball isn't empty, we've got a package...
377 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
378 #
379 # Select a script execution method
380 case $this_script in
381 *fstab*) if [[ -n "$FSTAB" ]]; then
382 LUSER_wrt_CopyFstab
383 else
384 LUSER_wrt_RunAsUser "${file}"
385 fi
386 ;;
[8f2c086]387 *chowning) wrt_RunAsRoot "${file}"
[837797e]388 ;;
389 *) LUSER_wrt_RunAsUser "${file}"
390 ;;
391 esac
392 #
393 # Housekeeping...remove any build directory(ies) except if the package build fails.
394 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${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}
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.
[195ed9f]428 wrt_Makefile_header
[837797e]429
430 # Drop in the main target 'all:' and the chapter targets with each sub-target
431 # as a dependency.
432(
433cat << EOF
434
435all: ck_UID mk_SETUP mk_LUSER mk_ROOT create-sbu_du-report
436 @sudo make do-housekeeping
437 @\$(call echo_finished,$VERSION)
438
439ck_UID:
440 @if [ \`id -u\` = "0" ]; then \\
441 echo "--------------------------------------------------"; \\
442 echo "You cannot run this makefile from the root account"; \\
443 echo "--------------------------------------------------"; \\
444 exit 1; \\
445 fi
446
447mk_SETUP:
448 @\$(call echo_SU_request)
449 @sudo make SHELL=/bin/bash SETUP
450 @touch \$@
451
452mk_LUSER: mk_SETUP
453 @\$(call echo_SULUSER_request)
454 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
455 @sudo make restore-luser-env
456 @touch \$@
457
458mk_ROOT:
459 @sudo make SHELL=/bin/bash ROOT
460 @touch \$@
461
462
[1838bc7]463SETUP: $host_prep
[837797e]464LUSER: $cross_tools $basicsystem $bootscripttools $bootable
465ROOT: $chowning
466
467
[1838bc7]468create-sbu_du-report: ROOT
469 @\$(call echo_message, Building)
470 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
471 ./create-sbu_du-report.sh logs $VERSION; \\
472 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
473 fi;
474 @touch \$@
475
[837797e]476restore-luser-env:
477 @\$(call echo_message, Building)
478 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
479 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
480 fi;
481 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
482 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
483 fi;
484 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
485 touch \$@ && \\
486 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
487 echo --------------------------------------------------------------------------------\$(WHITE)
488
489do-housekeeping:
490 @-if [ ! -f luser-exist ]; then \\
491 userdel \$(LUSER); \\
492 rm -rf /home/\$(LUSER); \\
493 fi;
494
495EOF
496) >> $MKFILE
497
498 # Bring over the items from the Makefile.tmp
499 cat $MKFILE.tmp >> $MKFILE
500 rm $MKFILE.tmp
501 echo "Creating Makefile... ${BOLD}DONE${OFF}"
502
503}
504
Note: See TracBrowser for help on using the repository browser.