source: CLFS2/master.sh@ 9bbf240

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

Ported CUSTOM_TOOLS support to all books.

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