source: CLFS2/master.sh@ 6f74ca1

ablfs-more legacy trunk
Last change on this file since 6f74ca1 was c57747d, checked in by Pierre Labastie <pierre@…>, 7 years ago

Make the date of the SBU_DU file the same as the one reported at the end of
the jhalfs run. Note that date is the one when the run is started

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