source: CLFS3/master.sh@ b230bd6

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

CLFS3 don't have a stripping page.

  • Property mode set to 100644
File size: 19.6 KB
Line 
1#!/bin/bash
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
20
21025-addinguser:
22 @\$(call echo_message, Building)
23 @if [ ! -d /home/\$(LUSER) ]; then \\
24 groupadd \$(LGROUP); \\
25 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
26 else \\
27 touch luser-exist; \\
28 fi;
29 @touch \$@ && \\
30 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
31 echo --------------------------------------------------------------------------------\$(WHITE)
32
33026-settingenvironment: 025-addinguser
34 @\$(call echo_message, Building)
35 @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
36 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
37 fi;
38 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
39 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
40 fi;
41 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
42 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
43 echo "CLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
44 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
45 echo "PATH=\$(MOUNT_PT)/cross-tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
46 echo "export CLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
47 echo "" >> /home/\$(LUSER)/.bashrc && \\
48 echo "unset CFLAGS" >> /home/\$(LUSER)/.bashrc && \\
49 echo "unset CXXFLAGS" >> /home/\$(LUSER)/.bashrc && \\
50 echo "" >> /home/\$(LUSER)/.bashrc && \\
51 echo "export CLFS_HOST=\"${CLFS_HOST}\"" >> /home/\$(LUSER)/.bashrc && \\
52 echo "export CLFS_TARGET=\"${TARGET}\"" >> /home/\$(LUSER)/.bashrc && \\
53 echo "export CLFS_MIPS_LEVEL=\"${MIPS_LEVEL}\"" >> /home/\$(LUSER)/.bashrc && \\
54 echo "export BUILD=\"${ABI}\"" >> /home/\$(LUSER)/.bashrc && \\
55 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc
56 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
57 touch envars && \\
58 chown \$(LUSER):\$(LGROUP) envars
59 @touch \$@ && \\
60 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
61 echo --------------------------------------------------------------------------------\$(WHITE)
62
63027-create-directories: 026-settingenvironment
64 @\$(call echo_message, Building)
65
66 @mkdir -p \$(MOUNT_PT)/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
67 @mkdir -p \$(MOUNT_PT)/{proc,media/{floppy,cdrom},sbin,srv,sys}
68 @mkdir -p \$(MOUNT_PT)/var/{lock,log,mail,run,spool}
69 @mkdir -p \$(MOUNT_PT)/var/{opt,cache,lib/{misc,locate},local}
70 @install -d -m 0750 \$(MOUNT_PT)/root
71 @install -d -m 1777 \$(MOUNT_PT){/var,}/tmp
72 @mkdir -p \$(MOUNT_PT)/usr/{,local/}{bin,include,lib,sbin,src}
73 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{doc,info,locale,man}
74 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{misc,terminfo,zoneinfo}
75 @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
76 @for dir in \$(MOUNT_PT)/usr{,/local}; do \\
77 ln -s share/{man,doc,info} \$\$dir ; \\
78 done
79
80 @touch \$@ && \\
81 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
82 echo --------------------------------------------------------------------------------\$(WHITE)
83
84028-creating-sysfile: 027-create-directories
85 @\$(call echo_message, Building)
86
87 @touch \$(MOUNT_PT)/etc/mtab
88 @echo "root::0:0:root:/root:/bin/ash" >> \$(MOUNT_PT)/etc/passwd
89 @echo "root:x:0:" >> \$(MOUNT_PT)/etc/group
90 @echo "bin:x:1:" >> \$(MOUNT_PT)/etc/group
91 @echo "sys:x:2:" >> \$(MOUNT_PT)/etc/group
92 @echo "kmem:x:3" >> \$(MOUNT_PT)/etc/group
93 @echo "tty:x:4:" >> \$(MOUNT_PT)/etc/group
94 @echo "tape:x:5:" >> \$(MOUNT_PT)/etc/group
95 @echo "daemon:x:6:" >> \$(MOUNT_PT)/etc/group
96 @echo "floppy:x:7:" >> \$(MOUNT_PT)/etc/group
97 @echo "disk:x:8:" >> \$(MOUNT_PT)/etc/group
98 @echo "lp:x:9:" >> \$(MOUNT_PT)/etc/group
99 @echo "dialout:x:10:" >> \$(MOUNT_PT)/etc/group
100 @echo "audio:x:11:" >> \$(MOUNT_PT)/etc/group
101 @echo "video:x:12:" >> \$(MOUNT_PT)/etc/group
102 @echo "utmp:x:13:" >> \$(MOUNT_PT)/etc/group
103 @echo "usb:x:14:" >> \$(MOUNT_PT)/etc/group
104 @echo "cdrom:x:15:" >> \$(MOUNT_PT)/etc/group
105
106 @touch \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/{btmp,lastlog,wtmp}
107 @chmod 664 \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/lastlog
108 @chown -R \$(LUSER) \$(MOUNT_PT) && \\
109 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT)
110
111 @touch \$@ && \\
112 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
113 echo --------------------------------------------------------------------------------\$(WHITE)
114
115EOF
116) >> $MKFILE.tmp
117
118 host_prep=" 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile"
119}
120
121#-----------------------------#
122systemprep_Makefiles() { #
123#-----------------------------#
124 echo "${tab_}${GREEN}Processing... ${L_arrow}system prep tools ( LUSER ) ${R_arrow}"
125
126 for file in systemprep/* ; do
127 # Keep the script file name
128 this_script=`basename $file`
129
130 # Set the dependency for the first target.
131 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
132
133 # First append each name of the script files to a list (this will become
134 # the names of the targets in the Makefile)
135 cross_tools="$cross_tools $this_script"
136
137 # Grab the name of the target (minus the -headers or -cross in the case of gcc
138 # and binutils in chapter 5)
139 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
140
141 pkg_tarball=$(get_package_tarball_name $name)
142 #--------------------------------------------------------------------#
143 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
144 #--------------------------------------------------------------------#
145 #
146 # Drop in the name of the target on a new line, and the previous target
147 # as a dependency. Also call the echo_message function.
148 LUSER_wrt_target "${this_script}" "$PREV"
149 #
150 # If $pkg_tarball isn't empty, we've got a package...
151 if [ "$pkg_tarball" != "" ] ; then
152 LUSER_wrt_unpack "$pkg_tarball"
153 fi
154 #
155 LUSER_wrt_RunAsUser "${file}"
156 #
157 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
158 #
159 # Include a touch of the target name so make can check if it's already been made.
160 wrt_touch
161 #
162 #--------------------------------------------------------------------#
163 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
164 #--------------------------------------------------------------------#
165 #
166 # Keep the script file name for Makefile dependencies.
167 PREV=$this_script
168
169 done # for file in ....
170}
171
172
173#-----------------------------#
174cross_tools_Makefiles() { #
175#-----------------------------#
176 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools ( LUSER ) ${R_arrow}"
177
178 for file in cross-tools/* ; do
179 # Keep the script file name
180 this_script=`basename $file`
181 #
182 # Skip this script...
183 # NOTE.. the book indicated you only needed to install groff or file if the host
184 # had older versions. The packages would be installed in the target directory
185 # and not the host.
186 case $this_script in
187 *cflags* | *variables* | *abi | *toolchain*) # work done in host_prep_Makefiles
188 continue ;;
189 *) ;;
190 esac
191
192 #
193 # Set the dependency for the first target.
194 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
195
196 # First append each name of the script files to a list (this will become
197 # the names of the targets in the Makefile)
198 cross_tools="$cross_tools $this_script"
199
200 # Grab the name of the target (minus the -headers or -cross in the case of gcc
201 # and binutils in chapter 5)
202 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
203 -e 's@-static@@' \
204 -e 's@-final@@' \
205 -e 's@-64@@' \
206 -e 's@-n32@@'`
207 case $name in
208 uclibc*) name="uClibc" ;;
209 esac
210 pkg_tarball=$(get_package_tarball_name $name)
211 #--------------------------------------------------------------------#
212 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
213 #--------------------------------------------------------------------#
214 #
215 # Drop in the name of the target on a new line, and the previous target
216 # as a dependency. Also call the echo_message function.
217 LUSER_wrt_target "${this_script}" "$PREV"
218 #
219 # If $pkg_tarball isn't empty, we've got a package...
220 if [ "$pkg_tarball" != "" ] ; then
221 LUSER_wrt_unpack "$pkg_tarball"
222 # If using optimizations, write the instructions
223 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
224 fi
225 #
226 LUSER_wrt_RunAsUser "${file}"
227 #
228 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
229 #
230 # Include a touch of the target name so make can check if it's already been made.
231 wrt_touch
232 #
233 #--------------------------------------------------------------------#
234 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
235 #--------------------------------------------------------------------#
236 #
237 # Keep the script file name for Makefile dependencies.
238 PREV=$this_script
239
240 done # for file in ....
241}
242
243
244
245#-----------------------------#
246final_system_Makefiles() { #
247#-----------------------------#
248 echo "${tab_}${GREEN}Processing... ${L_arrow}final system ( LUSER ) ${R_arrow}"
249
250 for file in final-system/* ; do
251 # Keep the script file name
252 this_script=`basename $file`
253
254 # Grab the name of the target, strip id number, XXX-script
255 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
256 -e 's@temp-@@' \
257 -e 's@-64bit@@' \
258 -e 's@-64@@' \
259 -e 's@64@@' \
260 -e 's@n32@@'`
261
262 # Find the version of the command files, if it corresponds with the building of
263 # a specific package.
264 pkg_tarball=$(get_package_tarball_name $name)
265
266 # Append each name of the script files to a list (this will become
267 # the names of the targets in the Makefile
268 basicsystem="$basicsystem ${this_script}"
269
270 #--------------------------------------------------------------------#
271 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
272 #--------------------------------------------------------------------#
273 #
274 # Drop in the name of the target on a new line, and the previous target
275 # as a dependency. Also call the echo_message function.
276 LUSER_wrt_target "${this_script}" "$PREV"
277 #
278 # If $pkg_tarball isn't empty, we've got a package...
279 if [ "$pkg_tarball" != "" ] ; then
280 LUSER_wrt_unpack "$pkg_tarball"
281 # If using optimizations, write the instructions
282 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
283 fi
284 #
285 LUSER_wrt_RunAsUser "${file}"
286 #
287 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
288 #
289 # Include a touch of the target name so make can check if it's already been made.
290 wrt_touch
291 #
292 #--------------------------------------------------------------------#
293 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
294 #--------------------------------------------------------------------#
295 #
296 # Keep the script file name for Makefile dependencies.
297 PREV=${this_script}
298 done # for file in final-system/* ...
299}
300
301
302
303#-----------------------------#
304bootscripts_Makefiles() { #
305#-----------------------------#
306 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
307
308 for file in bootscripts/* ; do
309 # Keep the script file name
310 this_script=`basename $file`
311
312 case $this_script in
313 *console*) continue ;; # Use the files that came with the bootscripts
314 *network*) continue ;; # Manually create these files
315 *) ;;
316 esac
317
318 # First append each name of the script files to a list (this will become
319 # the names of the targets in the Makefile
320 bootscripttools="$bootscripttools $this_script"
321
322 # Grab the name of the target, strip id number, XXX-script
323 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
324 -e 's@-64bit@@' \
325 -e 's@-64@@' \
326 -e 's@64@@' \
327 -e 's@n32@@'`
328 case $name in
329 *bootscripts*) name=clfs-embedded-bootscripts ;;
330 esac
331
332 pkg_tarball=$(get_package_tarball_name $name)
333
334 #--------------------------------------------------------------------#
335 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
336 #--------------------------------------------------------------------#
337 #
338 # Drop in the name of the target on a new line, and the previous target
339 # as a dependency. Also call the echo_message function.
340 LUSER_wrt_target "${this_script}" "$PREV"
341 #
342 # If $pkg_tarball isn't empty, we've got a package...
343 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
344 #
345 LUSER_wrt_RunAsUser "${file}"
346 #
347 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
348 #
349 # Include a touch of the target name so make can check if it's already been made.
350 wrt_touch
351 #
352 #--------------------------------------------------------------------#
353 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
354 #--------------------------------------------------------------------#
355 #
356 # Keep the script file name for Makefile dependencies.
357 PREV=$this_script
358
359 done # for file in bootscripts/* ...
360
361}
362
363
364#-----------------------------#
365bootable_Makefiles() { #
366#-----------------------------#
367 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
368
369 for file in bootable/* ; do
370 # Keep the script file name
371 this_script=`basename $file`
372
373 # A little housekeeping on the scripts
374 case $this_script in
375 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
376 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
377 *kernel) # if there is no kernel config file do not build the kernel
378 [[ -z $CONFIG ]] && continue
379 # Copy the config file to /sources with a standardized name
380 cp $CONFIG $BUILDDIR/sources/kernel-config
381 ;;
382 esac
383 #
384 # First append each name of the script files to a list (this will become
385 # the names of the targets in the Makefile
386 # NOTE: new makfile format forces the last script, *chowning, into a separate
387 # phase.
388 case ${this_script} in
389 *chowning) chowning=${this_script} ;;
390 *) bootable="$bootable $this_script" ;;
391 esac
392 #
393 # Grab the name of the target, strip id number and misc words.
394 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
395 case $this_script in
396 *kernel*) name=linux
397 ;;
398 esac
399
400 pkg_tarball=$(get_package_tarball_name $name)
401
402 #--------------------------------------------------------------------#
403 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
404 #--------------------------------------------------------------------#
405 #
406 # Drop in the name of the target on a new line, and the previous target
407 # as a dependency. Also call the echo_message function.
408 LUSER_wrt_target "${this_script}" "$PREV"
409 #
410 # If $pkg_tarball isn't empty, we've got a package...
411 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
412 #
413 # Select a script execution method
414 case $this_script in
415 *fstab*) if [[ -n "$FSTAB" ]]; then
416 LUSER_wrt_CopyFstab
417 else
418 LUSER_wrt_RunAsUser "${file}"
419 fi
420 ;;
421 *chowning) wrt_RunAsRoot "${file}"
422 ;;
423 *) LUSER_wrt_RunAsUser "${file}"
424 ;;
425 esac
426 #
427 # Housekeeping...remove any build directory(ies) except if the package build fails.
428 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
429 #
430 # Include a touch of the target name so make can check if it's already been made.
431 wrt_touch
432 #
433 #--------------------------------------------------------------------#
434 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
435 #--------------------------------------------------------------------#
436 #
437 # Keep the script file name for Makefile dependencies.
438 PREV=$this_script
439
440 done
441
442}
443
444
445#-----------------------------#
446build_Makefile() { # Construct a Makefile from the book scripts
447#-----------------------------#
448 echo "Creating Makefile... ${BOLD}START${OFF}"
449
450 cd $JHALFSDIR/${PROGNAME}-commands
451 # Start with a clean Makefile.tmp file
452 >$MKFILE.tmp
453
454 host_prep_Makefiles
455 [[ "${PLATFORM% -*}" = "WRT" ]] && systemprep_Makefiles # $cross_tools
456 cross_tools_Makefiles # $cross_tools
457 final_system_Makefiles # $basicsystem
458 bootscripts_Makefiles # $bootscripttools
459 bootable_Makefiles # $bootable
460 # Add the CUSTOM_TOOLS targets, if needed
461 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
462
463 # Add a header, some variables and include the function file
464 # to the top of the real Makefile.
465 wrt_Makefile_header
466
467 # Drop in the main target 'all:' and the chapter targets with each sub-target
468 # as a dependency.
469(
470cat << EOF
471
472all: ck_UID mk_SETUP mk_LUSER create-sbu_du-report mk_CUSTOM_TOOLS mk_ROOT
473 @sudo make restore-luser-env
474 @sudo make do-housekeeping
475 @\$(call echo_finished,$VERSION)
476
477ck_UID:
478 @if [ \`id -u\` = "0" ]; then \\
479 echo "--------------------------------------------------"; \\
480 echo "You cannot run this makefile from the root account"; \\
481 echo "--------------------------------------------------"; \\
482 exit 1; \\
483 fi
484
485mk_SETUP:
486 @\$(call echo_SU_request)
487 @sudo make SETUP
488 @touch \$@
489
490mk_LUSER: mk_SETUP
491 @\$(call echo_SULUSER_request)
492 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make LUSER" )
493 @touch \$@
494
495mk_CUSTOM_TOOLS: create-sbu_du-report
496 \$(call echo_PHASE,Building CUSTOM_TOOLS);
497 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
498 (sudo \$(SU_LUSER) "mkdir -p $BUILDDIR$TRACKING_DIR"); \\
499 (sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make CUSTOM_TOOLS"); \\
500 fi;
501 @touch \$@
502
503mk_ROOT:
504 @\$(call echo_SU_request)
505 @echo "$VERSION-embedded - jhalfs build" > clfs-release && \\
506 sudo mv clfs-release \$(MOUNT_PT)/etc
507 @sudo make ROOT
508 @touch \$@
509
510
511SETUP: $host_prep
512LUSER: $cross_tools $basicsystem $bootscripttools $bootable
513CUSTOM_TOOLS: $custom_list
514ROOT: $chowning
515
516
517create-sbu_du-report: mk_LUSER
518 @\$(call echo_message, Building)
519 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
520 ./create-sbu_du-report.sh logs $VERSION; \\
521 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
522 fi;
523 @touch \$@
524
525restore-luser-env:
526 @\$(call echo_message, Building)
527 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
528 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
529 fi;
530 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
531 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
532 fi;
533 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
534 touch \$@ && \\
535 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
536 echo --------------------------------------------------------------------------------\$(WHITE)
537
538do-housekeeping:
539 @-if [ ! -f luser-exist ]; then \\
540 userdel \$(LUSER); \\
541 rm -rf /home/\$(LUSER); \\
542 fi;
543
544EOF
545) >> $MKFILE
546
547 # Bring over the items from the Makefile.tmp
548 cat $MKFILE.tmp >> $MKFILE
549 rm $MKFILE.tmp
550 echo "Creating Makefile... ${BOLD}DONE${OFF}"
551
552}
553
Note: See TracBrowser for help on using the repository browser.