source: CLFS2/master.sh@ 38d2de6

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

Added support for host that place home dirs under a directory othen than /home.
Request and partial patch from Mario Lang.

  • Property mode set to 100644
File size: 17.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 "" >> \$(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 LUSER_wrt_unpack "$pkg_tarball"
221 # If using optimizations, write the instructions
222 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
223 fi
224 #
225 LUSER_wrt_RunAsUser "${file}"
226 #
227 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
228 #
229 # Include a touch of the target name so make can check if it's already been made.
230 wrt_touch
231 #
232 #--------------------------------------------------------------------#
233 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
234 #--------------------------------------------------------------------#
235 #
236 # Keep the script file name for Makefile dependencies.
237 PREV=${this_script}
238 done # for file in final-system/* ...
239}
240
241
242
243#-----------------------------#
244bootscripts_Makefiles() { #
245#-----------------------------#
246 echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
247
248 for file in bootscripts/* ; do
249 # Keep the script file name
250 this_script=`basename $file`
251
252 case $this_script in
253 *udev) continue ;; # This is not a script but a commentary, we want udev-rules
254 *console*) continue ;; # Use the files that came with the bootscripts
255 *network*) continue ;; # Manually create these files
256 *) ;;
257 esac
258
259 # First append each name of the script files to a list (this will become
260 # the names of the targets in the Makefile
261 bootscripttools="$bootscripttools $this_script"
262
263 # Grab the name of the target, strip id number, XXX-script
264 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
265 -e 's@-64bit@@' \
266 -e 's@-64@@' \
267 -e 's@64@@' \
268 -e 's@n32@@'`
269 case $name in
270 *bootscripts*) name=bootscripts-cross-lfs ;;
271 *udev-rules) name=udev-cross-lfs ;;
272 esac
273
274 pkg_tarball=$(get_package_tarball_name $name)
275
276 #--------------------------------------------------------------------#
277 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
278 #--------------------------------------------------------------------#
279 #
280 # Drop in the name of the target on a new line, and the previous target
281 # as a dependency. Also call the echo_message function.
282 LUSER_wrt_target "${this_script}" "$PREV"
283 #
284 # If $pkg_tarball isn't empty, we've got a package...
285 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
286 #
287 LUSER_wrt_RunAsUser "${file}"
288 #
289 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
290 #
291 # Include a touch of the target name so make can check if it's already been made.
292 wrt_touch
293 #
294 #--------------------------------------------------------------------#
295 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
296 #--------------------------------------------------------------------#
297 #
298 # Keep the script file name for Makefile dependencies.
299 PREV=$this_script
300
301 done # for file in bootscripts/* ...
302
303}
304
305
306#-----------------------------#
307bootable_Makefiles() { #
308#-----------------------------#
309 echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
310
311 for file in bootable/* ; do
312 # Keep the script file name
313 this_script=`basename $file`
314
315 # A little housekeeping on the scripts
316 case $this_script in
317 *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
318 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
319 *kernel) # if there is no kernel config file do not build the kernel
320 [[ -z $CONFIG ]] && continue
321 # Copy the config file to /sources with a standardized name
322 cp $CONFIG $BUILDDIR/sources/kernel-config
323 ;;
324 esac
325 #
326 # First append each name of the script files to a list (this will become
327 # the names of the targets in the Makefile
328 # NOTE: new makfile format forces the last script, *chowning, into a separate
329 # phase.
330 case ${this_script} in
331 *chowning) chowning=" ${this_script}" ;;
332 *) bootable="$bootable $this_script" ;;
333 esac
334 #
335 # Grab the name of the target, strip id number and misc words.
336 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
337 case $this_script in
338 *kernel*) name=linux
339 ;;
340 esac
341
342 pkg_tarball=$(get_package_tarball_name $name)
343
344 #--------------------------------------------------------------------#
345 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
346 #--------------------------------------------------------------------#
347 #
348 # Drop in the name of the target on a new line, and the previous target
349 # as a dependency. Also call the echo_message function.
350 LUSER_wrt_target "${this_script}" "$PREV"
351 #
352 # If $pkg_tarball isn't empty, we've got a package...
353 [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
354 #
355 # Select a script execution method
356 case $this_script in
357 *fstab*) if [[ -n "$FSTAB" ]]; then
358 LUSER_wrt_CopyFstab
359 else
360 LUSER_wrt_RunAsUser "${file}"
361 fi
362 ;;
363 *chowning) wrt_RunAsRoot "${file}"
364 ;;
365 *) LUSER_wrt_RunAsUser "${file}"
366 ;;
367 esac
368 #
369 # Housekeeping...remove any build directory(ies) except if the package build fails.
370 [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
371 #
372 # Include a touch of the target name so make can check if it's already been made.
373 wrt_touch
374 #
375 #--------------------------------------------------------------------#
376 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
377 #--------------------------------------------------------------------#
378 #
379 # Keep the script file name for Makefile dependencies.
380 PREV=$this_script
381
382 done
383
384}
385
386
387#-----------------------------#
388build_Makefile() { # Construct a Makefile from the book scripts
389#-----------------------------#
390 echo "Creating Makefile... ${BOLD}START${OFF}"
391
392 cd $JHALFSDIR/${PROGNAME}-commands
393 # Start with a clean Makefile.tmp file
394 >$MKFILE.tmp
395
396 host_prep_Makefiles
397 cross_tools_Makefiles # $cross_tools
398 final_system_Makefiles # $basicsystem
399 bootscripts_Makefiles # $bootscripttools
400 bootable_Makefiles # $bootable
401 # Add the CUSTOM_TOOLS targets, if needed
402 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
403 # Add the BLFS_TOOL targets, if needed.
404 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
405
406 # Add a header, some variables and include the function file
407 # to the top of the real Makefile.
408 wrt_Makefile_header
409
410 # Drop in the main target 'all:' and the chapter targets with each sub-target
411 # as a dependency.
412(
413cat << EOF
414
415all: ck_UID mk_SETUP mk_LUSER create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL mk_ROOT
416 @sudo make restore-luser-env
417 @sudo make do-housekeeping
418 @\$(call echo_finished,$VERSION)
419
420ck_UID:
421 @if [ \`id -u\` = "0" ]; then \\
422 echo "--------------------------------------------------"; \\
423 echo "You cannot run this makefile from the root account"; \\
424 echo "--------------------------------------------------"; \\
425 exit 1; \\
426 fi
427
428mk_SETUP:
429 @\$(call echo_SU_request)
430 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
431 @touch \$@
432
433mk_LUSER: mk_SETUP
434 @\$(call echo_SULUSER_request)
435 @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
436 @touch \$@
437
438mk_CUSTOM_TOOLS: create-sbu_du-report
439 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
440 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
441 (sudo \$(SU_LUSER) "mkdir -p $BUILDDIR$TRACKING_DIR"); \\
442 (sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
443 fi;
444 @touch \$@
445
446mk_BLFS_TOOL: mk_CUSTOM_TOOLS
447 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
448 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
449 (sudo \$(SU_LUSER) "mkdir -p $BUILDDIR$TRACKING_DIR"); \\
450 (sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
451 fi;
452 @touch \$@
453
454mk_ROOT: create-sbu_du-report
455 @\$(call echo_SU_request)
456 @echo "$VERSION-sysroot - jhalfs build" > clfs-release && \\
457 sudo mv clfs-release \$(MOUNT_PT)/etc
458 @sudo make BREAKPOINT=\$(BREAKPOINT) ROOT
459 @touch \$@
460
461SETUP: $host_prep
462LUSER: $cross_tools $basicsystem $bootscripttools $bootable
463CUSTOM_TOOLS: $custom_list
464BLFS_TOOL: $blfs_tool
465ROOT: $chowning
466
467
468create-sbu_du-report: mk_LUSER
469 @\$(call echo_message, Building)
470 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
471 ./create-sbu_du-report.sh logs $VERSION; \\
472 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
473 fi;
474 @touch \$@
475
476restore-luser-env:
477 @\$(call echo_message, Building)
478 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
479 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
480 fi;
481 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
482 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
483 fi;
484 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash* && \\
485 touch \$@ && \\
486 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
487 echo --------------------------------------------------------------------------------\$(WHITE)
488
489do-housekeeping:
490 @-if [ ! -f luser-exist ]; then \\
491 userdel \$(LUSER); \\
492 rm -rf \$(LUSER_HOME); \\
493 fi;
494
495EOF
496) >> $MKFILE
497
498 # Bring over the items from the Makefile.tmp
499 cat $MKFILE.tmp >> $MKFILE
500 rm $MKFILE.tmp
501 echo "Creating Makefile... ${BOLD}DONE${OFF}"
502
503}
Note: See TracBrowser for help on using the repository browser.