1 | #!/bin/bash
|
---|
2 | set -e # Enable error trapping
|
---|
3 |
|
---|
4 | # $Id$
|
---|
5 |
|
---|
6 | ###################################
|
---|
7 | ### FUNCTIONS ###
|
---|
8 | ###################################
|
---|
9 |
|
---|
10 |
|
---|
11 | #----------------------------#
|
---|
12 | process_toolchain() { # embryo,cocoon and butterfly need special handling
|
---|
13 | #----------------------------#
|
---|
14 | local toolchain=$1
|
---|
15 | local this_file=$2
|
---|
16 | local tc_phase
|
---|
17 | local binutil_tarball
|
---|
18 | local gcc_core_tarball
|
---|
19 | local TC_MountPT
|
---|
20 | local remove_existing
|
---|
21 |
|
---|
22 | tc_phase=`echo $toolchain | sed -e 's@[0-9]\{3\}-@@' -e 's@-toolchain@@'`
|
---|
23 | case $tc_phase in
|
---|
24 | embryo | \
|
---|
25 | cocoon) # Vars for LUSER phase
|
---|
26 | remove_existing="remove_existing_dirs"
|
---|
27 | TC_MountPT="\$(MOUNT_PT)\$(SRC)"
|
---|
28 | ;;
|
---|
29 | butterfly) # Vars for CHROOT phase
|
---|
30 | remove_existing="remove_existing_dirs2"
|
---|
31 | TC_MountPT="\$(SRC)"
|
---|
32 | ;;
|
---|
33 | esac
|
---|
34 |
|
---|
35 | #
|
---|
36 | # Safe method to remove existing toolchain dirs
|
---|
37 | binutil_tarball=$(get_package_tarball_name "binutils")
|
---|
38 | gcc_core_tarball=$(get_package_tarball_name "gcc-core")
|
---|
39 | (
|
---|
40 | cat << EOF
|
---|
41 | @\$(call ${remove_existing},$binutil_tarball)
|
---|
42 | @\$(call ${remove_existing},$gcc_core_tarball)
|
---|
43 | EOF
|
---|
44 | ) >> $MKFILE.tmp
|
---|
45 |
|
---|
46 | #
|
---|
47 | # Manually remove the toolchain directories..
|
---|
48 | (
|
---|
49 | cat << EOF
|
---|
50 | @rm -rf ${TC_MountPT}/${tc_phase}-toolchain && \\
|
---|
51 | rm -rf ${TC_MountPT}/${tc_phase}-build
|
---|
52 | EOF
|
---|
53 | ) >> $MKFILE.tmp
|
---|
54 |
|
---|
55 |
|
---|
56 | (
|
---|
57 | cat << EOF
|
---|
58 | @echo "export PKGDIR=${TC_MountPT}" > envars
|
---|
59 | EOF
|
---|
60 | ) >> $MKFILE.tmp
|
---|
61 |
|
---|
62 | case ${tc_phase} in
|
---|
63 | butterfly)
|
---|
64 | [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${toolchain}"
|
---|
65 | CHROOT_wrt_RunAsRoot "$this_file"
|
---|
66 | ;;
|
---|
67 | *) LUSER_wrt_RunAsUser "$this_file"
|
---|
68 | ;;
|
---|
69 | esac
|
---|
70 | #
|
---|
71 | (
|
---|
72 | cat << EOF
|
---|
73 | @\$(call ${remove_existing},$binutil_tarball)
|
---|
74 | @\$(call ${remove_existing},$gcc_core_tarball)
|
---|
75 | EOF
|
---|
76 | ) >> $MKFILE.tmp
|
---|
77 |
|
---|
78 | #
|
---|
79 | # Manually remove the toolchain directories..
|
---|
80 | (
|
---|
81 | cat << EOF
|
---|
82 | @rm -rf ${TC_MountPT}/${tc_phase}-toolchain && \\
|
---|
83 | rm -rf ${TC_MountPT}/${tc_phase}-build
|
---|
84 | EOF
|
---|
85 | ) >> $MKFILE.tmp
|
---|
86 |
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | #----------------------------#
|
---|
91 | chapter3_Makefiles() { # Initialization of the system
|
---|
92 | #----------------------------#
|
---|
93 |
|
---|
94 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter3 ( SETUP ) ${R_arrow}"
|
---|
95 |
|
---|
96 | # Define a few model dependant variables
|
---|
97 | if [[ ${MODEL} = "uclibc" ]]; then
|
---|
98 | TARGET="pc-linux-gnu"; LOADER="ld-uClibc.so.0"
|
---|
99 | else
|
---|
100 | TARGET="pc-linux-gnu"; LOADER="ld-linux.so.2"
|
---|
101 | fi
|
---|
102 |
|
---|
103 | # If /home/$LUSER is already present in the host, we asume that the
|
---|
104 | # hlfs user and group are also presents in the host, and a backup
|
---|
105 | # of their bash init files is made.
|
---|
106 | (
|
---|
107 | cat << EOF
|
---|
108 | 020-creatingtoolsdir:
|
---|
109 | @\$(call echo_message, Building)
|
---|
110 | @mkdir \$(MOUNT_PT)/tools && \\
|
---|
111 | rm -f /tools && \\
|
---|
112 | ln -s \$(MOUNT_PT)/tools / && \\
|
---|
113 | touch \$@ && \\
|
---|
114 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
115 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
116 |
|
---|
117 | 021-addinguser: 020-creatingtoolsdir
|
---|
118 | @\$(call echo_message, Building)
|
---|
119 | @if [ ! -d /home/\$(LUSER) ]; then \\
|
---|
120 | groupadd \$(LGROUP); \\
|
---|
121 | useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
|
---|
122 | else \\
|
---|
123 | touch luser-exist; \\
|
---|
124 | fi;
|
---|
125 | @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
|
---|
126 | chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
|
---|
127 | chmod a+wt \$(SRCSDIR) && \\
|
---|
128 | touch \$@ && \\
|
---|
129 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
130 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
131 |
|
---|
132 | 022-settingenvironment: 021-addinguser
|
---|
133 | @\$(call echo_message, Building)
|
---|
134 | @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
135 | mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
|
---|
136 | fi;
|
---|
137 | @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
138 | mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
|
---|
139 | fi;
|
---|
140 | @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
|
---|
141 | echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
|
---|
142 | echo "HLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
|
---|
143 | echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
|
---|
144 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
|
---|
145 | echo "export HLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
|
---|
146 | echo "" >> /home/\$(LUSER)/.bashrc && \\
|
---|
147 | echo "target=$(uname -m)-${TARGET}" >> /home/\$(LUSER)/.bashrc && \\
|
---|
148 | echo "ldso=/tools/lib/${LOADER}" >> /home/\$(LUSER)/.bashrc && \\
|
---|
149 | echo "export target ldso" >> /home/\$(LUSER)/.bashrc && \\
|
---|
150 | echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
|
---|
151 | chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
|
---|
152 | chmod -R a+wt \$(MOUNT_PT) && \\
|
---|
153 | touch envars && \\
|
---|
154 | chown \$(LUSER) envars && \\
|
---|
155 | touch \$@ && \\
|
---|
156 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
157 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
158 | EOF
|
---|
159 | ) >> $MKFILE.tmp
|
---|
160 | chapter3=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
|
---|
161 | }
|
---|
162 |
|
---|
163 | #----------------------------#
|
---|
164 | chapter5_Makefiles() { # Bootstrap or temptools phase
|
---|
165 | #----------------------------#
|
---|
166 | local file
|
---|
167 | local this_script
|
---|
168 |
|
---|
169 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
|
---|
170 |
|
---|
171 | for file in chapter05/* ; do
|
---|
172 | # Keep the script file name
|
---|
173 | this_script=`basename $file`
|
---|
174 |
|
---|
175 | # Skip this script depending on jhalfs.conf flags set.
|
---|
176 | case $this_script in
|
---|
177 | # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
|
---|
178 | *tcl* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
179 | *expect* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
180 | *dejagnu* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
181 | # Nothing interestin in this script
|
---|
182 | *introduction* ) continue ;;
|
---|
183 | # Test if the stripping phase must be skipped
|
---|
184 | *stripping* ) [[ "$STRIP" = "n" ]] && continue ;;
|
---|
185 | *) ;;
|
---|
186 | esac
|
---|
187 |
|
---|
188 | # First append each name of the script files to a list (this will become
|
---|
189 | # the names of the targets in the Makefile
|
---|
190 | chapter5="$chapter5 $this_script"
|
---|
191 |
|
---|
192 | # Grab the name of the target
|
---|
193 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
|
---|
194 |
|
---|
195 | # Adjust 'name'
|
---|
196 | case $name in
|
---|
197 | uclibc) name="uClibc" ;;
|
---|
198 | esac
|
---|
199 |
|
---|
200 | # Set the dependency for the first target.
|
---|
201 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
202 |
|
---|
203 | #--------------------------------------------------------------------#
|
---|
204 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
205 | #--------------------------------------------------------------------#
|
---|
206 | #
|
---|
207 | # Drop in the name of the target on a new line, and the previous target
|
---|
208 | # as a dependency. Also call the echo_message function.
|
---|
209 |
|
---|
210 | # This is a very special script and requires manual processing
|
---|
211 | # NO Optimization allowed
|
---|
212 | if [[ ${name} = "embryo-toolchain" ]] || \
|
---|
213 | [[ ${name} = "cocoon-toolchain" ]]; then
|
---|
214 | LUSER_wrt_target "$this_script" "$PREV"
|
---|
215 | process_toolchain "${this_script}" "${file}"
|
---|
216 | wrt_touch
|
---|
217 | PREV=$this_script
|
---|
218 | continue
|
---|
219 | fi
|
---|
220 | #
|
---|
221 | LUSER_wrt_target "$this_script" "$PREV"
|
---|
222 | # Find the version of the command files, if it corresponds with the building of
|
---|
223 | # a specific package
|
---|
224 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
225 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
226 | if [ "$pkg_tarball" != "" ] ; then
|
---|
227 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
228 | LUSER_wrt_unpack "$pkg_tarball"
|
---|
229 | # If using optimizations, write the instructions
|
---|
230 | [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
231 | fi
|
---|
232 | # Insert date and disk usage at the top of the log file, the script run
|
---|
233 | # and date and disk usage again at the bottom of the log file.
|
---|
234 | LUSER_wrt_RunAsUser "${file}"
|
---|
235 |
|
---|
236 | # Remove the build directory(ies) except if the package build fails
|
---|
237 | # (so we can review config.cache, config.log, etc.)
|
---|
238 | if [ "$pkg_tarball" != "" ] ; then
|
---|
239 | LUSER_RemoveBuildDirs "$name"
|
---|
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 # end for file in chapter05/*
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 | #----------------------------#
|
---|
256 | chapter6_Makefiles() { # sysroot or chroot build phase
|
---|
257 | #----------------------------#
|
---|
258 | local file
|
---|
259 | local this_script
|
---|
260 | # Set envars and scripts for iteration targets
|
---|
261 | if [[ -z "$1" ]] ; then
|
---|
262 | local N=""
|
---|
263 | else
|
---|
264 | local N=-build_$1
|
---|
265 | local chapter6=""
|
---|
266 | mkdir chapter06$N
|
---|
267 | cp chapter06/* chapter06$N
|
---|
268 | for script in chapter06$N/* ; do
|
---|
269 | # Overwrite existing symlinks, files, and dirs
|
---|
270 | sed -e 's/ln -s /ln -sf /g' \
|
---|
271 | -e 's/^mv /&-f/g' -i ${script}
|
---|
272 | done
|
---|
273 | # Remove Bzip2 binaries before make install
|
---|
274 | sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
|
---|
275 | # Fix how Module-Init-Tools do the install target
|
---|
276 | sed -e 's@make install@make INSTALL=install install@' -i chapter06$N/*-module-init-tools
|
---|
277 | # Delete *old Readline libraries just after make install
|
---|
278 | sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i chapter06$N/*-readline
|
---|
279 | # Don't readd already existing groups
|
---|
280 | sed -e '/groupadd/d' -i chapter06$N/*-udev
|
---|
281 | fi
|
---|
282 |
|
---|
283 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
|
---|
284 |
|
---|
285 | for file in chapter06$N/* ; do
|
---|
286 | # Keep the script file name
|
---|
287 | this_script=`basename $file`
|
---|
288 |
|
---|
289 | # Skip this script depending on jhalfs.conf flags set.
|
---|
290 | case $this_script in
|
---|
291 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
292 | # dependencies and target creation.
|
---|
293 | *chroot* ) continue ;;
|
---|
294 | # Test if the stripping phase must be skipped
|
---|
295 | *-stripping* ) [[ "$STRIP" = "n" ]] && continue ;;
|
---|
296 | esac
|
---|
297 |
|
---|
298 | # Grab the name of the target
|
---|
299 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
|
---|
300 |
|
---|
301 | case $name in
|
---|
302 | uclibc) name="uClibc" ;;
|
---|
303 | esac
|
---|
304 |
|
---|
305 | # Find the version of the command files, if it corresponds with the building of
|
---|
306 | # a specific package
|
---|
307 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
308 |
|
---|
309 | if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
|
---|
310 | case "${this_script}" in
|
---|
311 | *stripping*) ;;
|
---|
312 | *) continue ;;
|
---|
313 | esac
|
---|
314 | fi
|
---|
315 |
|
---|
316 | # Append each name of the script files to a list (this will become
|
---|
317 | # the names of the targets in the Makefile
|
---|
318 | chapter6="$chapter6 ${this_script}${N}"
|
---|
319 |
|
---|
320 |
|
---|
321 | #--------------------------------------------------------------------#
|
---|
322 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
323 | #--------------------------------------------------------------------#
|
---|
324 | #
|
---|
325 | # Drop in the name of the target on a new line, and the previous target
|
---|
326 | # as a dependency. Also call the echo_message function.
|
---|
327 | if [[ ${name} = "butterfly-toolchain" ]]; then
|
---|
328 | CHROOT_wrt_target "${this_script}${N}" "$PREV"
|
---|
329 | process_toolchain "${this_script}" "${file}"
|
---|
330 | wrt_touch
|
---|
331 | PREV=$this_script
|
---|
332 | continue
|
---|
333 | fi
|
---|
334 |
|
---|
335 | CHROOT_wrt_target "${this_script}${N}" "$PREV"
|
---|
336 |
|
---|
337 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
338 | # Insert instructions for unpacking the package and changing directories
|
---|
339 | if [ "$pkg_tarball" != "" ] ; then
|
---|
340 | CHROOT_Unpack "$pkg_tarball"
|
---|
341 | # If the testsuites must be run, initialize the log file
|
---|
342 | # butterfly-toolchain tests are enabled in 'process_tookchain' function
|
---|
343 | case $name in
|
---|
344 | glibc ) [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}${N}"
|
---|
345 | ;;
|
---|
346 | * ) [[ "$TEST" > "1" ]] && CHROOT_wrt_test_log "${this_script}${N}"
|
---|
347 | ;;
|
---|
348 | esac
|
---|
349 | # If using optimizations, write the instructions
|
---|
350 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
351 | fi
|
---|
352 |
|
---|
353 | # In the mount of kernel filesystems we need to set HLFS and not to use chroot.
|
---|
354 | case "${this_script}" in
|
---|
355 | *kernfs* | *changingowner*)
|
---|
356 | wrt_RunAsRoot "${file}"
|
---|
357 | ;;
|
---|
358 | *) # The rest of Chapter06
|
---|
359 | CHROOT_wrt_RunAsRoot "${file}"
|
---|
360 | ;;
|
---|
361 | esac
|
---|
362 | #
|
---|
363 | # Remove the build directory(ies) except if the package build fails.
|
---|
364 | if [ "$pkg_tarball" != "" ] ; then
|
---|
365 | CHROOT_wrt_RemoveBuildDirs "$name"
|
---|
366 | fi
|
---|
367 | #
|
---|
368 | # Include a touch of the target name so make can check if it's already been made.
|
---|
369 | wrt_touch
|
---|
370 | #
|
---|
371 | #--------------------------------------------------------------------#
|
---|
372 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
373 | #--------------------------------------------------------------------#
|
---|
374 |
|
---|
375 | # Keep the script file name for Makefile dependencies.
|
---|
376 | PREV=${this_script}${N}
|
---|
377 | # Set system_build envar for iteration targets
|
---|
378 | system_build=$chapter6
|
---|
379 | done # end for file in chapter06/*
|
---|
380 |
|
---|
381 | }
|
---|
382 |
|
---|
383 | #----------------------------#
|
---|
384 | chapter7_Makefiles() { # Create a bootable system.. kernel, bootscripts..etc
|
---|
385 | #----------------------------#
|
---|
386 | local file
|
---|
387 | local this_script
|
---|
388 |
|
---|
389 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7 ( BOOT ) ${R_arrow}"
|
---|
390 | for file in chapter07/*; do
|
---|
391 | # Keep the script file name
|
---|
392 | this_script=`basename $file`
|
---|
393 |
|
---|
394 | # Grub must be configured manually.
|
---|
395 | # The filesystems can't be unmounted via Makefile and the user
|
---|
396 | # should enter the chroot environment to create the root
|
---|
397 | # password, edit several files and setup Grub.
|
---|
398 | case $this_script in
|
---|
399 | *usage) continue ;; # Contains example commands
|
---|
400 | *grub) continue ;;
|
---|
401 | *console) continue ;; # Use the file generated by lfs-bootscripts
|
---|
402 | *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab
|
---|
403 | ;;
|
---|
404 | *kernel) # If no .config file is supplied, the kernel build is skipped
|
---|
405 | [[ -z $CONFIG ]] && continue
|
---|
406 | cp $CONFIG $BUILDDIR/sources/kernel-config
|
---|
407 | ;;
|
---|
408 | esac
|
---|
409 |
|
---|
410 | # First append then name of the script file to a list (this will become
|
---|
411 | # the names of the targets in the Makefile
|
---|
412 | chapter7="$chapter7 $this_script"
|
---|
413 |
|
---|
414 | #--------------------------------------------------------------------#
|
---|
415 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
416 | #--------------------------------------------------------------------#
|
---|
417 | #
|
---|
418 | # Drop in the name of the target on a new line, and the previous target
|
---|
419 | # as a dependency. Also call the echo_message function.
|
---|
420 | CHROOT_wrt_target "$this_script" "$PREV"
|
---|
421 |
|
---|
422 | case "${this_script}" in
|
---|
423 | *bootscripts*)
|
---|
424 | CHROOT_Unpack $(get_package_tarball_name "lfs-bootscripts")
|
---|
425 | blfs_bootscripts=$(get_package_tarball_name "blfs-bootscripts" | sed -e 's/.tar.*//' )
|
---|
426 | echo -e "\t@echo \"\$(MOUNT_PT)\$(SRC)/$blfs_bootscripts\" >> sources-dir" >> $MKFILE.tmp
|
---|
427 | ;;
|
---|
428 | esac
|
---|
429 |
|
---|
430 | case "${this_script}" in
|
---|
431 | *fstab*) # Check if we have a real /etc/fstab file
|
---|
432 | if [[ -n "$FSTAB" ]] ; then
|
---|
433 | CHROOT_wrt_CopyFstab
|
---|
434 | else
|
---|
435 | CHROOT_wrt_RunAsRoot "$file"
|
---|
436 | fi
|
---|
437 | ;;
|
---|
438 | *) # All other scripts
|
---|
439 | CHROOT_wrt_RunAsRoot "${file}"
|
---|
440 | ;;
|
---|
441 | esac
|
---|
442 |
|
---|
443 | # Remove the build directory except if the package build fails.
|
---|
444 | case "${this_script}" in
|
---|
445 | *bootscripts*)
|
---|
446 | (
|
---|
447 | cat << EOF
|
---|
448 | @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
449 | rm -r \$(SRC)/\$\$ROOT
|
---|
450 | @rm -r \`cat sources-dir\` && \\
|
---|
451 | rm sources-dir
|
---|
452 | EOF
|
---|
453 | ) >> $MKFILE.tmp
|
---|
454 | ;;
|
---|
455 | esac
|
---|
456 |
|
---|
457 | # Include a touch of the target name so make can check if it's already been made.
|
---|
458 | wrt_touch
|
---|
459 | #
|
---|
460 | #--------------------------------------------------------------------#
|
---|
461 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
462 | #--------------------------------------------------------------------#
|
---|
463 |
|
---|
464 | # Keep the script file name for Makefile dependencies.
|
---|
465 | PREV=$this_script
|
---|
466 | done # for file in chapter07/*
|
---|
467 | }
|
---|
468 |
|
---|
469 |
|
---|
470 | #----------------------------#
|
---|
471 | build_Makefile() { # Construct a Makefile from the book scripts
|
---|
472 | #----------------------------#
|
---|
473 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
474 |
|
---|
475 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
476 | # Start with a clean Makefile.tmp file
|
---|
477 | >$MKFILE.tmp
|
---|
478 |
|
---|
479 | chapter3_Makefiles
|
---|
480 | chapter5_Makefiles
|
---|
481 | chapter6_Makefiles
|
---|
482 | # Add the iterations targets, if needed
|
---|
483 | [[ "$COMPARE" = "y" ]] && wrt_compare_targets
|
---|
484 | chapter7_Makefiles
|
---|
485 |
|
---|
486 | # Add a header, some variables and include the function file
|
---|
487 | # to the top of the real Makefile.
|
---|
488 | wrt_Makefile_header
|
---|
489 |
|
---|
490 | # Add chroot commands
|
---|
491 | CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
|
---|
492 | i=1
|
---|
493 | for file in chapter06/*chroot* ; do
|
---|
494 | chroot=`cat $file | \
|
---|
495 | sed -e "s@chroot@$CHROOT_LOC@" \
|
---|
496 | -e '/#!\/bin\/bash/d' \
|
---|
497 | -e '/^export/d' \
|
---|
498 | -e '/^logout/d' \
|
---|
499 | -e 's@ \\\@ @g' | \
|
---|
500 | tr -d '\n' | \
|
---|
501 | sed -e 's/ */ /g' \
|
---|
502 | -e 's|\\$|&&|g' \
|
---|
503 | -e 's|exit||g' \
|
---|
504 | -e 's|$| -c|' \
|
---|
505 | -e 's|"$$HLFS"|$(MOUNT_PT)|'\
|
---|
506 | -e 's|set -e||' \
|
---|
507 | -e 's|set +h||'`
|
---|
508 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
509 | i=`expr $i + 1`
|
---|
510 | done
|
---|
511 |
|
---|
512 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
513 | # as a dependency.
|
---|
514 | (
|
---|
515 | cat << EOF
|
---|
516 |
|
---|
517 | all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL
|
---|
518 | @sudo make do-housekeeping
|
---|
519 | @\$(call echo_finished,$VERSION)
|
---|
520 |
|
---|
521 | ck_UID:
|
---|
522 | @if [ \`id -u\` = "0" ]; then \\
|
---|
523 | echo "--------------------------------------------------"; \\
|
---|
524 | echo "You cannot run this makefile from the root account"; \\
|
---|
525 | echo "--------------------------------------------------"; \\
|
---|
526 | exit 1; \\
|
---|
527 | fi
|
---|
528 |
|
---|
529 | mk_SETUP:
|
---|
530 | @\$(call echo_SU_request)
|
---|
531 | @sudo make SHELL=/bin/bash SETUP
|
---|
532 | @touch \$@
|
---|
533 |
|
---|
534 | mk_LUSER: mk_SETUP
|
---|
535 | @\$(call echo_SULUSER_request)
|
---|
536 | @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
|
---|
537 | @sudo make restore-luser-env
|
---|
538 | @touch \$@
|
---|
539 |
|
---|
540 | mk_SUDO: mk_LUSER
|
---|
541 | @sudo make SHELL=/bin/bash SUDO
|
---|
542 | @touch \$@
|
---|
543 |
|
---|
544 | mk_CHROOT: mk_SUDO
|
---|
545 | @if [ ! -e \$(MOUNT_PT)/bin ]; then \\
|
---|
546 | mkdir \$(MOUNT_PT)/bin; \\
|
---|
547 | cd \$(MOUNT_PT)/bin && \\
|
---|
548 | ln -sf /tools/bin/bash bash; ln -sf bash sh; \\
|
---|
549 | sudo chown -R 0:0 \$(MOUNT_PT)/bin; \\
|
---|
550 | fi;
|
---|
551 | @sudo sed -e 's|^ln -sv |ln -svf |' -i \$(CMDSDIR)/chapter06/064-createfiles
|
---|
552 | @\$(call echo_CHROOT_request)
|
---|
553 | @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT")
|
---|
554 | @touch \$@
|
---|
555 |
|
---|
556 | mk_BOOT: mk_CHROOT
|
---|
557 | @\$(call echo_CHROOT_request)
|
---|
558 | @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BOOT")
|
---|
559 | @touch \$@
|
---|
560 |
|
---|
561 | mk_BLFS_TOOL: create-sbu_du-report
|
---|
562 | @\$(call echo_PHASE,Building BLFS-TOOLS)
|
---|
563 | @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
|
---|
564 | sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
|
---|
565 | sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BLFS_TOOL"; \\
|
---|
566 | fi;
|
---|
567 | @touch \$@
|
---|
568 |
|
---|
569 |
|
---|
570 | SETUP: $chapter3
|
---|
571 | LUSER: $chapter5
|
---|
572 | SUDO: 060-kernfs 062-changingowner
|
---|
573 | CHROOT: $chapter6
|
---|
574 | BOOT: $chapter7
|
---|
575 | BLFS_TOOL: $blfs_tool
|
---|
576 |
|
---|
577 |
|
---|
578 | create-sbu_du-report: mk_BOOT
|
---|
579 | @\$(call echo_message, Building)
|
---|
580 | @if [ "\$(ADD_REPORT)" = "y" ]; then \\
|
---|
581 | ./create-sbu_du-report.sh logs $VERSION; \\
|
---|
582 | \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
|
---|
583 | fi;
|
---|
584 | @touch \$@
|
---|
585 |
|
---|
586 | restore-luser-env:
|
---|
587 | @\$(call echo_message, Building)
|
---|
588 | @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
589 | mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
|
---|
590 | fi;
|
---|
591 | @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
592 | mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
|
---|
593 | fi;
|
---|
594 | @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
|
---|
595 | touch \$@ && \\
|
---|
596 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
597 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
598 |
|
---|
599 | do-housekeeping:
|
---|
600 | @-umount \$(MOUNT_PT)/dev/pts
|
---|
601 | @-umount \$(MOUNT_PT)/dev/shm
|
---|
602 | @-umount \$(MOUNT_PT)/dev
|
---|
603 | @-umount \$(MOUNT_PT)/sys
|
---|
604 | @-umount \$(MOUNT_PT)/proc
|
---|
605 | @-rm /tools
|
---|
606 | @-if [ ! -f luser-exist ]; then \\
|
---|
607 | userdel \$(LUSER); \\
|
---|
608 | rm -rf /home/\$(LUSER); \\
|
---|
609 | fi;
|
---|
610 |
|
---|
611 |
|
---|
612 |
|
---|
613 | EOF
|
---|
614 | ) >> $MKFILE
|
---|
615 |
|
---|
616 | # Bring over the items from the Makefile.tmp
|
---|
617 | cat $MKFILE.tmp >> $MKFILE
|
---|
618 | rm $MKFILE.tmp
|
---|
619 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
620 |
|
---|
621 | }
|
---|