source: CLFS2/master.sh@ 608fbe1

2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 608fbe1 was 535fd45, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Fixed SCRIPT_ROOT and SRCSDIR permissions in CLFS2 and CLFS3 to don't break jhalfs run when using CLEAN feature.

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