source: CLFS2/master.sh@ 1ba5024

experimental
Last change on this file since 1ba5024 was 50fb011, checked in by George Boudreau <georgeb@…>, 18 years ago

First commit of changes to makefile generation. Makefile now does recursive calls to itself for the different phases..SETUP,LUSER,CHROOT,ROOT

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