source: CLFS3/master.sh@ 5932971

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

CLFS{2,3}: the user that launch the Makefile need write priviledges on MOUNT_PT/jhalfs dir and can't write on MOUNT_PT/etc.

  • Property mode set to 100644
File size: 17.4 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
122#-----------------------------#
123cross_tools_Makefiles() { #
124#-----------------------------#
125 echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools ( LUSER ) ${R_arrow}"
126
127 for file in cross-tools/* ; do
128 # Keep the script file name
129 this_script=`basename $file`
130 #
131 # Skip this script...
132 # NOTE.. the book indicated you only needed to install groff or file if the host
133 # had older versions. The packages would be installed in the target directory
134 # and not the host.
135 case $this_script in
136 *cflags* | *variables* | *abi | *toolchain*) # work done in host_prep_Makefiles
137 continue ;;
138 *) ;;
139 esac
140
141 #
142 # Set the dependency for the first target.
143 if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
144
145 # First append each name of the script files to a list (this will become
146 # the names of the targets in the Makefile)
147 cross_tools="$cross_tools $this_script"
148
149 # Grab the name of the target (minus the -headers or -cross in the case of gcc
150 # and binutils in chapter 5)
151 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
152 -e 's@-static@@' \
153 -e 's@-final@@' \
154 -e 's@-64@@' \
155 -e 's@-n32@@'`
156 case $name in
157 uclibc*) name="uClibc" ;;
158 esac
159 pkg_tarball=$(get_package_tarball_name $name)
160 #--------------------------------------------------------------------#
161 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
162 #--------------------------------------------------------------------#
163 #
164 # Drop in the name of the target on a new line, and the previous target
165 # as a dependency. Also call the echo_message function.
166 LUSER_wrt_target "${this_script}" "$PREV"
167 #
168 # If $pkg_tarball isn't empty, we've got a package...
169 if [ "$pkg_tarball" != "" ] ; then
170 LUSER_wrt_unpack "$pkg_tarball"
171 # If using optimizations, write the instructions
172 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
173 fi
174 #
175 LUSER_wrt_RunAsUser "${file}"
176 #
177 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
178 #
179 # Include a touch of the target name so make can check if it's already been made.
180 wrt_touch
181 #
182 #--------------------------------------------------------------------#
183 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
184 #--------------------------------------------------------------------#
185 #
186 # Keep the script file name for Makefile dependencies.
187 PREV=$this_script
188
189 done # for file in ....
190}
191
192
193
194#-----------------------------#
195final_system_Makefiles() { #
196#-----------------------------#
197 echo "${tab_}${GREEN}Processing... ${L_arrow}final system ( LUSER ) ${R_arrow}"
198
199 for file in final-system/* ; do
200 # Keep the script file name
201 this_script=`basename $file`
202
203 # Test if the stripping phase must be skipped.
204 # Skip alsp temp-perl for iterative runs
205 case $this_script in
206 *stripping*) [[ "$STRIP" = "n" ]] && continue ;;
207 esac
208
209 # Grab the name of the target, strip id number, XXX-script
210 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
211 -e 's@temp-@@' \
212 -e 's@-64bit@@' \
213 -e 's@-64@@' \
214 -e 's@64@@' \
215 -e 's@n32@@'`
216
217 # Find the version of the command files, if it corresponds with the building of
218 # a specific package.
219 pkg_tarball=$(get_package_tarball_name $name)
220
221 # Append each name of the script files to a list (this will become
222 # the names of the targets in the Makefile
223 basicsystem="$basicsystem ${this_script}"
224
225 #--------------------------------------------------------------------#
226 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
227 #--------------------------------------------------------------------#
228 #
229 # Drop in the name of the target on a new line, and the previous target
230 # as a dependency. Also call the echo_message function.
231 LUSER_wrt_target "${this_script}" "$PREV"
232 #
233 # If $pkg_tarball isn't empty, we've got a package...
234 if [ "$pkg_tarball" != "" ] ; then
235 LUSER_wrt_unpack "$pkg_tarball"
236 # If using optimizations, write the instructions
237 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
238 fi
239 #
240 LUSER_wrt_RunAsUser "${file}"
241 #
242 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
243 #
244 # Include a touch of the target name so make can check if it's already been made.
245 wrt_touch
246 #
247 #--------------------------------------------------------------------#
248 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
249 #--------------------------------------------------------------------#
250 #
251 # Keep the script file name for Makefile dependencies.
252 PREV=${this_script}
253 done # for file in final-system/* ...
254}
255
256
257
258#-----------------------------#
259bootscripts_Makefiles() { #
260#-----------------------------#
261 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
262
263 for file in bootscripts/* ; do
264 # Keep the script file name
265 this_script=`basename $file`
266
267 case $this_script in
268 *console*) continue ;; # Use the files that came with the bootscripts
269 *network*) continue ;; # Manually create these files
270 *) ;;
271 esac
272
273 # First append each name of the script files to a list (this will become
274 # the names of the targets in the Makefile
275 bootscripttools="$bootscripttools $this_script"
276
277 # Grab the name of the target, strip id number, XXX-script
278 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
279 -e 's@-64bit@@' \
280 -e 's@-64@@' \
281 -e 's@64@@' \
282 -e 's@n32@@'`
283 case $name in
284 *bootscripts*) name=clfs-embedded-bootscripts ;;
285 esac
286
287 pkg_tarball=$(get_package_tarball_name $name)
288
289 #--------------------------------------------------------------------#
290 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
291 #--------------------------------------------------------------------#
292 #
293 # Drop in the name of the target on a new line, and the previous target
294 # as a dependency. Also call the echo_message function.
295 LUSER_wrt_target "${this_script}" "$PREV"
296 #
297 # If $pkg_tarball isn't empty, we've got a package...
298 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
299 #
300 LUSER_wrt_RunAsUser "${file}"
301 #
302 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
303 #
304 # Include a touch of the target name so make can check if it's already been made.
305 wrt_touch
306 #
307 #--------------------------------------------------------------------#
308 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
309 #--------------------------------------------------------------------#
310 #
311 # Keep the script file name for Makefile dependencies.
312 PREV=$this_script
313
314 done # for file in bootscripts/* ...
315
316}
317
318
319#-----------------------------#
320bootable_Makefiles() { #
321#-----------------------------#
322 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
323
324 for file in bootable/* ; do
325 # Keep the script file name
326 this_script=`basename $file`
327
328 # A little housekeeping on the scripts
329 case $this_script in
330 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
331 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
332 *kernel) # if there is no kernel config file do not build the kernel
333 [[ -z $CONFIG ]] && continue
334 # Copy the config file to /sources with a standardized name
335 cp $CONFIG $BUILDDIR/sources/kernel-config
336 ;;
337 esac
338 #
339 # First append each name of the script files to a list (this will become
340 # the names of the targets in the Makefile
341 # NOTE: new makfile format forces the last script, *chowning, into a separate
342 # phase.
343 case ${this_script} in
344 *chowning) chowning=${this_script} ;;
345 *) bootable="$bootable $this_script" ;;
346 esac
347 #
348 # Grab the name of the target, strip id number and misc words.
349 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
350 case $this_script in
351 *kernel*) name=linux
352 ;;
353 esac
354
355 pkg_tarball=$(get_package_tarball_name $name)
356
357 #--------------------------------------------------------------------#
358 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
359 #--------------------------------------------------------------------#
360 #
361 # Drop in the name of the target on a new line, and the previous target
362 # as a dependency. Also call the echo_message function.
363 LUSER_wrt_target "${this_script}" "$PREV"
364 #
365 # If $pkg_tarball isn't empty, we've got a package...
366 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
367 #
368 # Select a script execution method
369 case $this_script in
370 *fstab*) if [[ -n "$FSTAB" ]]; then
371 LUSER_wrt_CopyFstab
372 else
373 LUSER_wrt_RunAsUser "${file}"
374 fi
375 ;;
376 *chowning) wrt_RunAsRoot "${file}"
377 ;;
378 *) LUSER_wrt_RunAsUser "${file}"
379 ;;
380 esac
381 #
382 # Housekeeping...remove any build directory(ies) except if the package build fails.
383 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
384 #
385 # Include a touch of the target name so make can check if it's already been made.
386 wrt_touch
387 #
388 #--------------------------------------------------------------------#
389 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
390 #--------------------------------------------------------------------#
391 #
392 # Keep the script file name for Makefile dependencies.
393 PREV=$this_script
394
395 done
396
397}
398
399
400#-----------------------------#
401build_Makefile() { # Construct a Makefile from the book scripts
402#-----------------------------#
403 echo "Creating Makefile... ${BOLD}START${OFF}"
404
405 cd $JHALFSDIR/${PROGNAME}-commands
406 # Start with a clean Makefile.tmp file
407 >$MKFILE.tmp
408
409 host_prep_Makefiles
410 cross_tools_Makefiles # $cross_tools
411 final_system_Makefiles # $basicsystem
412 bootscripts_Makefiles # $bootscripttools
413 bootable_Makefiles # $bootable
414
415 # Add a header, some variables and include the function file
416 # to the top of the real Makefile.
417 wrt_Makefile_header
418
419 # Drop in the main target 'all:' and the chapter targets with each sub-target
420 # as a dependency.
421(
422cat << EOF
423
424all: ck_UID mk_SETUP mk_LUSER mk_ROOT create-sbu_du-report
425 @sudo make do-housekeeping
426 @\$(call echo_finished,$VERSION)
427
428ck_UID:
429 @if [ \`id -u\` = "0" ]; then \\
430 echo "--------------------------------------------------"; \\
431 echo "You cannot run this makefile from the root account"; \\
432 echo "--------------------------------------------------"; \\
433 exit 1; \\
434 fi
435
436mk_SETUP:
437 @\$(call echo_SU_request)
438 @sudo make SHELL=/bin/bash SETUP
439 @touch \$@
440
441mk_LUSER: mk_SETUP
442 @\$(call echo_SULUSER_request)
443 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
444 @sudo make restore-luser-env
445 @touch \$@
446
447mk_ROOT:
448 @echo "$VERSION-embedded - jhalfs build" > clfs-release && \\
449 sudo mv clfs-release \$(MOUNT_PT)/etc
450 @sudo make SHELL=/bin/bash ROOT
451 @touch \$@
452
453
454SETUP: $host_prep
455LUSER: $cross_tools $basicsystem $bootscripttools $bootable
456ROOT: $chowning
457
458
459create-sbu_du-report: ROOT
460 @\$(call echo_message, Building)
461 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
462 ./create-sbu_du-report.sh logs $VERSION; \\
463 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
464 fi;
465 @touch \$@
466
467restore-luser-env:
468 @\$(call echo_message, Building)
469 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
470 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
471 fi;
472 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
473 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
474 fi;
475 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
476 touch \$@ && \\
477 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
478 echo --------------------------------------------------------------------------------\$(WHITE)
479
480do-housekeeping:
481 @-if [ ! -f luser-exist ]; then \\
482 userdel \$(LUSER); \\
483 rm -rf /home/\$(LUSER); \\
484 fi;
485
486EOF
487) >> $MKFILE
488
489 # Bring over the items from the Makefile.tmp
490 cat $MKFILE.tmp >> $MKFILE
491 rm $MKFILE.tmp
492 echo "Creating Makefile... ${BOLD}DONE${OFF}"
493
494}
495
Note: See TracBrowser for help on using the repository browser.