source: CLFS2/master.sh@ 5c575e1

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

Ported INSTALL_LOG support to all books.

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