source: CLFS3/master.sh@ 486e9a7

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

Added support for host that place home dirs under a directory othen than /home.
Request and partial patch from Mario Lang.

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