source: CLFS3/master.sh@ 936efa8

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

CLFSx: Create a custom /etc/clfs-release file.

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