1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | ###################################
|
---|
6 | ### FUNCTIONS ###
|
---|
7 | ###################################
|
---|
8 |
|
---|
9 |
|
---|
10 | #############################################################
|
---|
11 |
|
---|
12 |
|
---|
13 | #----------------------------#
|
---|
14 | chapter4_Makefiles() { #
|
---|
15 | #----------------------------#
|
---|
16 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
|
---|
17 | # Ensure the first dependency is empty
|
---|
18 | unset PREV
|
---|
19 |
|
---|
20 | for file in chapter04/* ; do
|
---|
21 | # Keep the script file name
|
---|
22 | this_script=`basename $file`
|
---|
23 |
|
---|
24 | # First append each name of the script files to a list (this will become
|
---|
25 | # the names of the targets in the Makefile
|
---|
26 | # DO NOT append the settingenvironment script, it need be run as luser.
|
---|
27 | # A hack is necessary: create script in chap4 BUT run as a dependency for
|
---|
28 | # LUSER target
|
---|
29 | case "${this_script}" in
|
---|
30 | *settingenvironment) chapter5="$chapter5 ${this_script}" ;;
|
---|
31 | *) chapter4="$chapter4 ${this_script}" ;;
|
---|
32 | esac
|
---|
33 |
|
---|
34 | # Grab the name of the target
|
---|
35 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
|
---|
36 |
|
---|
37 | #--------------------------------------------------------------------#
|
---|
38 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
39 | #--------------------------------------------------------------------#
|
---|
40 | #
|
---|
41 |
|
---|
42 | # Drop in the name of the target on a new line, and the previous target
|
---|
43 | # as a dependency. Also call the echo_message function.
|
---|
44 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
45 |
|
---|
46 | case "${this_script}" in
|
---|
47 | *settingenvironment)
|
---|
48 | (
|
---|
49 | cat << EOF
|
---|
50 | @cd && \\
|
---|
51 | function source() { true; } && \\
|
---|
52 | export -f source && \\
|
---|
53 | \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
|
---|
54 | sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
|
---|
55 | echo source $JHALFSDIR/envars >> .bashrc
|
---|
56 | @\$(PRT_DU) >>logs/\$@
|
---|
57 | EOF
|
---|
58 | ) >> $MKFILE.tmp
|
---|
59 | ;;
|
---|
60 | *addinguser)
|
---|
61 | (
|
---|
62 | cat << EOF
|
---|
63 | @if [ -f luser-id ]; then \\
|
---|
64 | function useradd() { true; }; \\
|
---|
65 | function groupadd() { true; }; \\
|
---|
66 | export -f useradd groupadd; \\
|
---|
67 | fi; \\
|
---|
68 | export LFS=\$(MOUNT_PT) && \\
|
---|
69 | \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
|
---|
70 | \$(PRT_DU) >>logs/\$@
|
---|
71 | @chown \$(LUSER):\$(LGROUP) envars
|
---|
72 | @chmod -R a+wt $JHALFSDIR
|
---|
73 | @chmod a+wt \$(SRCSDIR)
|
---|
74 | EOF
|
---|
75 | ) >> $MKFILE.tmp
|
---|
76 | ;;
|
---|
77 | *) wrt_RunAsRoot "$file" ;;
|
---|
78 | esac
|
---|
79 |
|
---|
80 | # Include a touch of the target name so make can check
|
---|
81 | # if it's already been made.
|
---|
82 | wrt_touch
|
---|
83 | #
|
---|
84 | #--------------------------------------------------------------------#
|
---|
85 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
86 | #--------------------------------------------------------------------#
|
---|
87 |
|
---|
88 | # Keep the script file name for Makefile dependencies.
|
---|
89 | PREV=${this_script}
|
---|
90 | done # end for file in chapter04/*
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | #----------------------------#
|
---|
96 | chapter5_Makefiles() {
|
---|
97 | #----------------------------#
|
---|
98 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
|
---|
99 |
|
---|
100 | # Initialize the Makefile target: it'll change during chapter
|
---|
101 | # For vanilla lfs, the "changingowner" script should be run as root. So
|
---|
102 | # it belongs to the "SUDO" target, with list in the "runasroot" variable.
|
---|
103 | # For new lfs, changingowner and kernfs are in "runsaroot", then the following,
|
---|
104 | # starting at creatingdirs, are in the "CHROOT" target, in variable "chapter6".
|
---|
105 | # Makefile_target records the variable, not really the target!
|
---|
106 | # We use a case statement on that variable, because instructions in the
|
---|
107 | # Makefile change according to the phase of the build (LUSER, SUDO, CHROOT).
|
---|
108 | Makefile_target=chapter5
|
---|
109 |
|
---|
110 | # Start loop
|
---|
111 | for file in chapter05/* ; do
|
---|
112 | # Keep the script file name
|
---|
113 | this_script=`basename $file`
|
---|
114 |
|
---|
115 | # Fix locales creation when running chapter05 testsuites (ugly)
|
---|
116 | case "${this_script}" in
|
---|
117 | *glibc) [[ "${TEST}" = "3" ]] && \
|
---|
118 | sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
|
---|
119 | esac
|
---|
120 |
|
---|
121 | # Append each name of the script files to a list that Makefile_target
|
---|
122 | # points to. But before that, change Makefile_target at the first script
|
---|
123 | # of each target.
|
---|
124 | case "${this_script}" in
|
---|
125 | *changingowner) Makefile_target=runasroot ;;
|
---|
126 | *creatingdirs ) Makefile_target=chapter6 ;; # only run for new lfs
|
---|
127 | esac
|
---|
128 | eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
|
---|
129 |
|
---|
130 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
131 | # and binutils in chapter 5)
|
---|
132 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' \
|
---|
133 | -e 's@-pass[0-9]\{1\}@@' \
|
---|
134 | -e 's@-libstdc++@@'`
|
---|
135 |
|
---|
136 | #--------------------------------------------------------------------#
|
---|
137 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
138 | #--------------------------------------------------------------------#
|
---|
139 | #
|
---|
140 | # Find the name of the tarball and the version of the package
|
---|
141 | pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
|
---|
142 | pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
|
---|
143 |
|
---|
144 | # Drop in the name of the target on a new line, and the previous target
|
---|
145 | # as a dependency. Also call the echo_message function.
|
---|
146 | case $Makefile_target in
|
---|
147 | chapter6) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
|
---|
148 | *) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
|
---|
149 | esac
|
---|
150 |
|
---|
151 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
152 | if [ "$pkg_tarball" != "" ] ; then
|
---|
153 | # Always initialize the log file, since the test instructions may be
|
---|
154 | # "uncommented" by the user
|
---|
155 | case $Makefile_target in
|
---|
156 | chapter6) CHROOT_wrt_test_log "${this_script}" "$pkg_version" ;;
|
---|
157 | *) LUSER_wrt_test_log "${this_script}" "$pkg_version" ;;
|
---|
158 | esac
|
---|
159 |
|
---|
160 | # If using optimizations, write the instructions
|
---|
161 | case "${OPTIMIZE}${this_script}${REALSBU}" in
|
---|
162 | *binutils-pass1y) ;;
|
---|
163 | 2*) wrt_optimize "$name" && wrt_makeflags "$name" ;;
|
---|
164 | *) ;;
|
---|
165 | esac
|
---|
166 | fi
|
---|
167 |
|
---|
168 | # Insert date and disk usage at the top of the log file, the script run
|
---|
169 | # and date and disk usage again at the bottom of the log file.
|
---|
170 | # The changingowner script must be run as root.
|
---|
171 | case "${Makefile_target}" in
|
---|
172 | runasroot) wrt_RunAsRoot "$file" "$pkg_version" ;;
|
---|
173 | chapter5) LUSER_wrt_RunAsUser "$file" "$pkg_version" ;;
|
---|
174 | chapter6) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
|
---|
175 | esac
|
---|
176 |
|
---|
177 | # Include a touch of the target name so make can check
|
---|
178 | # 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 | done # end for file in chapter05/*
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | #----------------------------#
|
---|
192 | chapter6_Makefiles() {
|
---|
193 | #----------------------------#
|
---|
194 |
|
---|
195 | # Set envars and scripts for iteration targets
|
---|
196 | if [[ -z "$1" ]] ; then
|
---|
197 | local N=""
|
---|
198 | else
|
---|
199 | local N=-build_$1
|
---|
200 | local chapter6=""
|
---|
201 | mkdir chapter06$N
|
---|
202 | cp chapter06/* chapter06$N
|
---|
203 | for script in chapter06$N/* ; do
|
---|
204 | # Overwrite existing symlinks, files, and dirs
|
---|
205 | sed -e 's/ln *-sv/&f/g' \
|
---|
206 | -e 's/mv *-v/&f/g' \
|
---|
207 | -e 's/mkdir *-v/&p/g' -i ${script}
|
---|
208 | # Suppress the mod of "test-installation.pl" because now
|
---|
209 | # the library path points to /usr/lib
|
---|
210 | if [[ ${script} =~ glibc ]]; then
|
---|
211 | sed '/DL=/,/unset DL/d' -i ${script}
|
---|
212 | fi
|
---|
213 | # Rename the scripts
|
---|
214 | mv ${script} ${script}$N
|
---|
215 | done
|
---|
216 | # Remove Bzip2 binaries before make install (LFS-6.2 compatibility)
|
---|
217 | sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2$N
|
---|
218 | fi
|
---|
219 |
|
---|
220 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
|
---|
221 |
|
---|
222 | # Initialize the Makefile target. In vanilla lfs, kernfs should be run as root,
|
---|
223 | # then the others are run in chroot. If in new lfs, we should start in chroot.
|
---|
224 | # this will be changed later because man-pages is the first script in
|
---|
225 | # chapter 6. Note that this Makefile_target business is not really needed here
|
---|
226 | # but we do it to have a similar structure to chapter 5 (we may merge all
|
---|
227 | # those functions at some point).
|
---|
228 | case "$N" in
|
---|
229 | -build*) Makefile_target=chapter6 ;;
|
---|
230 | *) Makefile_target=runasroot ;;
|
---|
231 | esac
|
---|
232 |
|
---|
233 | # Start loop
|
---|
234 | for file in chapter06$N/* ; do
|
---|
235 | # Keep the script file name
|
---|
236 | this_script=`basename $file`
|
---|
237 |
|
---|
238 | # Skip the "stripping" scripts if the user does not want to strip.
|
---|
239 | # Skip also linux-headers in iterative builds.
|
---|
240 | case "${this_script}" in
|
---|
241 | *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
|
---|
242 | *linux-headers*) [[ -n "$N" ]] && continue ;;
|
---|
243 | esac
|
---|
244 |
|
---|
245 | # Grab the name of the target.
|
---|
246 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
|
---|
247 |
|
---|
248 | # Find the tarball corresponding to our script.
|
---|
249 | # If it doesn't exist, we skip it in iterations rebuilds (except stripping).
|
---|
250 | pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
|
---|
251 | pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
|
---|
252 |
|
---|
253 | if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
|
---|
254 | case "${this_script}" in
|
---|
255 | *stripping*) ;;
|
---|
256 | *) continue ;;
|
---|
257 | esac
|
---|
258 | fi
|
---|
259 |
|
---|
260 | # Append each name of the script files to a list (this will become
|
---|
261 | # the names of the targets in the Makefile)
|
---|
262 | # The kernfs script must be run as part of SUDO target.
|
---|
263 | case "${this_script}" in
|
---|
264 | *creatingdirs) Makefile_target=chapter6 ;;
|
---|
265 | *man-pages ) Makefile_target=chapter6 ;;
|
---|
266 | esac
|
---|
267 | eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
|
---|
268 |
|
---|
269 | #--------------------------------------------------------------------#
|
---|
270 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
271 | #--------------------------------------------------------------------#
|
---|
272 | #
|
---|
273 | # Drop in the name of the target on a new line, and the previous target
|
---|
274 | # as a dependency. Also call the echo_message function.
|
---|
275 | # In the mount of kernel filesystems we need to set LFS
|
---|
276 | # and not to use chroot.
|
---|
277 | case "${Makefile_target}" in
|
---|
278 | runasroot) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
|
---|
279 | *) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
|
---|
280 | esac
|
---|
281 |
|
---|
282 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
283 | # Insert instructions for unpacking the package and changing directories
|
---|
284 | if [ "$pkg_tarball" != "" ] ; then
|
---|
285 | # Touch timestamp file if installed files logs will be created.
|
---|
286 | # But only for the firt build when running iterative builds.
|
---|
287 | if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
|
---|
288 | CHROOT_wrt_TouchTimestamp
|
---|
289 | fi
|
---|
290 | # Always initialize the log file, so that the user may reinstate a
|
---|
291 | # commented out test
|
---|
292 | CHROOT_wrt_test_log "${this_script}" "$pkg_version"
|
---|
293 | # If using optimizations, write the instructions
|
---|
294 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
295 | fi
|
---|
296 |
|
---|
297 | # In the mount of kernel filesystems we need to set LFS
|
---|
298 | # and not to use chroot.
|
---|
299 | case "${Makefile_target}" in
|
---|
300 | runasroot) wrt_RunAsRoot "$file" "$pkg_version" ;;
|
---|
301 | *) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
|
---|
302 | esac
|
---|
303 |
|
---|
304 | # Write installed files log and remove the build directory(ies)
|
---|
305 | # except if the package build fails.
|
---|
306 | if [ "$pkg_tarball" != "" ] ; then
|
---|
307 | if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
|
---|
308 | CHROOT_wrt_LogNewFiles "$name"
|
---|
309 | fi
|
---|
310 | fi
|
---|
311 |
|
---|
312 | # Include a touch of the target name so make can check
|
---|
313 | # if it's already been made.
|
---|
314 | wrt_touch
|
---|
315 | #
|
---|
316 | #--------------------------------------------------------------------#
|
---|
317 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
318 | #--------------------------------------------------------------------#
|
---|
319 |
|
---|
320 | # Keep the script file name for Makefile dependencies.
|
---|
321 | PREV=${this_script}
|
---|
322 | # Set system_build envar for iteration targets
|
---|
323 | if [ -z "$N" ]; then
|
---|
324 | system_build="$system_build $this_script"
|
---|
325 | fi
|
---|
326 | done # end for file in chapter06/*
|
---|
327 | if [ -n "$N" ]; then
|
---|
328 | system_build="$chapter6"
|
---|
329 | fi
|
---|
330 | }
|
---|
331 |
|
---|
332 | #----------------------------#
|
---|
333 | chapter78_Makefiles() {
|
---|
334 | #----------------------------#
|
---|
335 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
|
---|
336 |
|
---|
337 | for file in chapter0{7,8}/* ; do
|
---|
338 | # Keep the script file name
|
---|
339 | this_script=`basename $file`
|
---|
340 |
|
---|
341 | # Grub must be configured manually.
|
---|
342 | # Handle fstab creation.
|
---|
343 | # If no .config file is supplied, the kernel build is skipped
|
---|
344 | case ${this_script} in
|
---|
345 | *grub) continue ;;
|
---|
346 | *fstab) [[ -z "${FSTAB}" ]] ||
|
---|
347 | [[ ${FSTAB} == $BUILDDIR/sources/fstab ]] ||
|
---|
348 | cp ${FSTAB} $BUILDDIR/sources/fstab ;;
|
---|
349 | *kernel) [[ -z ${CONFIG} ]] && continue
|
---|
350 | [[ ${CONFIG} == $BUILDDIR/sources/kernel-config ]] ||
|
---|
351 | cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
|
---|
352 | esac
|
---|
353 |
|
---|
354 | # First append each name of the script files to a list (this will become
|
---|
355 | # the names of the targets in the Makefile
|
---|
356 | chapter78="$chapter78 ${this_script}"
|
---|
357 |
|
---|
358 | #--------------------------------------------------------------------#
|
---|
359 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
360 | #--------------------------------------------------------------------#
|
---|
361 | #
|
---|
362 | # Drop in the name of the target on a new line, and the previous target
|
---|
363 | # as a dependency. Also call the echo_message function.
|
---|
364 | CHROOT_wrt_target "${this_script}" "$PREV"
|
---|
365 |
|
---|
366 | # Find the bootscripts or networkscripts (for systemd)
|
---|
367 | # and kernel package names
|
---|
368 | case "${this_script}" in
|
---|
369 | *bootscripts)
|
---|
370 | name="lfs-bootscripts"
|
---|
371 | if [ "${INSTALL_LOG}" = "y" ] ; then
|
---|
372 | CHROOT_wrt_TouchTimestamp
|
---|
373 | fi
|
---|
374 | ;;
|
---|
375 | *network-scripts)
|
---|
376 | name="lfs-network-scripts"
|
---|
377 | if [ "${INSTALL_LOG}" = "y" ] ; then
|
---|
378 | CHROOT_wrt_TouchTimestamp
|
---|
379 | fi
|
---|
380 | ;;
|
---|
381 | *kernel)
|
---|
382 | name="linux"
|
---|
383 | if [ "${INSTALL_LOG}" = "y" ] ; then
|
---|
384 | CHROOT_wrt_TouchTimestamp
|
---|
385 | fi
|
---|
386 | # If using optimizations, use MAKEFLAGS (unless blacklisted)
|
---|
387 | # no setting of CFLAGS and friends.
|
---|
388 | [[ "$OPTIMIZE" != "0" ]] && wrt_makeflags "$name"
|
---|
389 | ;;
|
---|
390 | esac
|
---|
391 |
|
---|
392 | # Check if we have a real /etc/fstab file
|
---|
393 | case "${this_script}" in
|
---|
394 | *fstab) if [[ -n "$FSTAB" ]]; then
|
---|
395 | CHROOT_wrt_CopyFstab
|
---|
396 | else
|
---|
397 | CHROOT_wrt_RunAsRoot "$file"
|
---|
398 | fi
|
---|
399 | ;;
|
---|
400 | *) CHROOT_wrt_RunAsRoot "$file"
|
---|
401 | ;;
|
---|
402 | esac
|
---|
403 |
|
---|
404 | case "${this_script}" in
|
---|
405 | *bootscripts|*network-scripts|*kernel)
|
---|
406 | if [ "${INSTALL_LOG}" = "y" ] ; then
|
---|
407 | CHROOT_wrt_LogNewFiles "$name"
|
---|
408 | fi ;;
|
---|
409 | esac
|
---|
410 | # Include a touch of the target name so make can check
|
---|
411 | # if it's already been made.
|
---|
412 | wrt_touch
|
---|
413 | #
|
---|
414 | #--------------------------------------------------------------------#
|
---|
415 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
416 | #--------------------------------------------------------------------#
|
---|
417 |
|
---|
418 | # Keep the script file name for Makefile dependencies.
|
---|
419 | PREV=${this_script}
|
---|
420 | done # for file in chapter0{7,8}/*
|
---|
421 |
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 | #----------------------------#
|
---|
427 | build_Makefile() { #
|
---|
428 | #----------------------------#
|
---|
429 |
|
---|
430 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
431 |
|
---|
432 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
433 |
|
---|
434 | # Start with a clean Makefile.tmp file
|
---|
435 | >$MKFILE
|
---|
436 |
|
---|
437 | chapter4_Makefiles
|
---|
438 | chapter5_Makefiles
|
---|
439 | chapter6_Makefiles
|
---|
440 | # Add the iterations targets, if needed
|
---|
441 | [[ "$COMPARE" = "y" ]] && wrt_compare_targets
|
---|
442 | chapter78_Makefiles
|
---|
443 | # Add the CUSTOM_TOOLS targets, if needed
|
---|
444 | [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
|
---|
445 |
|
---|
446 | # Add a header, some variables and include the function file
|
---|
447 | # to the top of the real Makefile.
|
---|
448 | wrt_Makefile_header
|
---|
449 |
|
---|
450 | # Add chroot commands
|
---|
451 | CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
|
---|
452 | i=1
|
---|
453 | for file in ../chroot-scripts/*chroot* ; do
|
---|
454 | chroot=`cat $file | \
|
---|
455 | perl -pe 's|\\\\\n||g' | \
|
---|
456 | tr -s [:space:] | \
|
---|
457 | grep chroot | \
|
---|
458 | sed -e "s|chroot|$CHROOT_LOC|" \
|
---|
459 | -e 's|\\$|&&|g' \
|
---|
460 | -e 's|"$$LFS"|$(MOUNT_PT)|'`
|
---|
461 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
462 | i=`expr $i + 1`
|
---|
463 | done
|
---|
464 |
|
---|
465 | # Store virtual kernel file systems commands:
|
---|
466 | devices=`cat ../kernfs-scripts/devices.sh | \
|
---|
467 | sed -e 's|^| |' \
|
---|
468 | -e 's|mount|sudo &|' \
|
---|
469 | -e 's|mkdir|sudo &|' \
|
---|
470 | -e 's|\\$|&&|g' \
|
---|
471 | -e 's|\$|; \\\\|' \
|
---|
472 | -e 's|then|& :|' \
|
---|
473 | -e 's|\$\$LFS|$(MOUNT_PT)|g'`
|
---|
474 | teardown=`cat ../kernfs-scripts/teardown.sh | \
|
---|
475 | sed -e 's|^| |' \
|
---|
476 | -e 's|umount|sudo &|' \
|
---|
477 | -e 's|\$LFS|$(MOUNT_PT)|'`
|
---|
478 | teardownat=`cat ../kernfs-scripts/teardown.sh | \
|
---|
479 | sed -e 's|^| |' \
|
---|
480 | -e 's|umount|@-sudo &|' \
|
---|
481 | -e 's|\$LFS|$(MOUNT_PT)|'`
|
---|
482 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
483 | # as a dependency.
|
---|
484 | (
|
---|
485 | cat << EOF
|
---|
486 |
|
---|
487 | all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS
|
---|
488 | $teardownat
|
---|
489 | @sudo make do_housekeeping
|
---|
490 | EOF
|
---|
491 | ) >> $MKFILE
|
---|
492 | if [ "$INITSYS" = systemd ]; then
|
---|
493 | (
|
---|
494 | cat << EOF
|
---|
495 | @/bin/echo -e -n \\
|
---|
496 | NAME=\\"Linux From Scratch\\"\\\\n\\
|
---|
497 | VERSION=\\"$VERSION\\"\\\\n\\
|
---|
498 | ID=lfs\\\\n\\
|
---|
499 | PRETTY_NAME=\\"Linux From Scratch $VERSION\\"\\\\n\\
|
---|
500 | VERSION_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
|
---|
501 | > os-release && \\
|
---|
502 | sudo mv os-release \$(MOUNT_PT)/etc && \\
|
---|
503 | sudo chown root:root \$(MOUNT_PT)/etc/os-release
|
---|
504 | EOF
|
---|
505 | ) >> $MKFILE
|
---|
506 | fi
|
---|
507 | (
|
---|
508 | cat << EOF
|
---|
509 | @echo $VERSION > lfs-release && \\
|
---|
510 | sudo mv lfs-release \$(MOUNT_PT)/etc && \\
|
---|
511 | sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
|
---|
512 | @/bin/echo -e -n \\
|
---|
513 | DISTRIB_ID=\\"Linux From Scratch\\"\\\\n\\
|
---|
514 | DISTRIB_RELEASE=\\"$VERSION\\"\\\\n\\
|
---|
515 | DISTRIB_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
|
---|
516 | DISTRIB_DESCRIPTION=\\"Linux From Scratch\\"\\\\n\\
|
---|
517 | > lsb-release && \\
|
---|
518 | sudo mv lsb-release \$(MOUNT_PT)/etc && \\
|
---|
519 | sudo chown root:root \$(MOUNT_PT)/etc/lsb-release
|
---|
520 | @\$(call echo_finished,$VERSION)
|
---|
521 |
|
---|
522 | ck_UID:
|
---|
523 | @if [ \`id -u\` = "0" ]; then \\
|
---|
524 | echo "--------------------------------------------------"; \\
|
---|
525 | echo "You cannot run this makefile from the root account"; \\
|
---|
526 | echo "--------------------------------------------------"; \\
|
---|
527 | exit 1; \\
|
---|
528 | fi
|
---|
529 |
|
---|
530 | mk_SETUP:
|
---|
531 | @\$(call echo_SU_request)
|
---|
532 | @sudo make save-luser
|
---|
533 | @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
|
---|
534 | @touch \$@
|
---|
535 |
|
---|
536 | mk_LUSER: mk_SETUP
|
---|
537 | @\$(call echo_SULUSER_request)
|
---|
538 | @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
|
---|
539 | @sudo make restore-luser
|
---|
540 | @touch \$@
|
---|
541 |
|
---|
542 | mk_SUDO: mk_LUSER
|
---|
543 | @sudo rm -f envars
|
---|
544 | @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
|
---|
545 | @touch \$@
|
---|
546 |
|
---|
547 | mk_CHROOT: mk_SUDO
|
---|
548 | @\$(call echo_CHROOT_request)
|
---|
549 | @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
|
---|
550 | @touch \$@
|
---|
551 |
|
---|
552 | mk_BOOT: mk_CHROOT
|
---|
553 | @\$(call echo_CHROOT_request)
|
---|
554 | @( sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
|
---|
555 | @touch \$@
|
---|
556 |
|
---|
557 | mk_BLFS_TOOL: create-sbu_du-report
|
---|
558 | @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
|
---|
559 | \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
|
---|
560 | (sudo \$(CHROOT2) -c "make -C $BLFS_ROOT/work"); \\
|
---|
561 | fi;
|
---|
562 | @touch \$@
|
---|
563 |
|
---|
564 | mk_CUSTOM_TOOLS: mk_BLFS_TOOL
|
---|
565 | @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
|
---|
566 | \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
|
---|
567 | sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
|
---|
568 | (sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
|
---|
569 | fi;
|
---|
570 | @touch \$@
|
---|
571 |
|
---|
572 | devices: ck_UID
|
---|
573 | $devices
|
---|
574 | EOF
|
---|
575 | ) >> $MKFILE
|
---|
576 | if [ "$INITSYS" = systemd ]; then
|
---|
577 | (
|
---|
578 | cat << EOF
|
---|
579 | sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
|
---|
580 | sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
|
---|
581 | EOF
|
---|
582 | ) >> $MKFILE
|
---|
583 | fi
|
---|
584 | (
|
---|
585 | cat << EOF
|
---|
586 |
|
---|
587 | teardown:
|
---|
588 | $teardown
|
---|
589 |
|
---|
590 | chroot1: devices
|
---|
591 | sudo \$(CHROOT1)
|
---|
592 | \$(MAKE) teardown
|
---|
593 |
|
---|
594 | chroot: devices
|
---|
595 | sudo \$(CHROOT2)
|
---|
596 | \$(MAKE) teardown
|
---|
597 |
|
---|
598 | SETUP: $chapter4
|
---|
599 | LUSER: $chapter5
|
---|
600 | SUDO: $runasroot
|
---|
601 | EOF
|
---|
602 | ) >> $MKFILE
|
---|
603 | if [ "$INITSYS" = systemd ]; then
|
---|
604 | (
|
---|
605 | cat << EOF
|
---|
606 | mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
|
---|
607 | cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
|
---|
608 |
|
---|
609 | EOF
|
---|
610 | ) >> $MKFILE
|
---|
611 | fi
|
---|
612 | (
|
---|
613 | cat << EOF
|
---|
614 | CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
|
---|
615 | CHROOT: $chapter6
|
---|
616 | BOOT: $chapter78
|
---|
617 | CUSTOM_TOOLS: $custom_list
|
---|
618 |
|
---|
619 |
|
---|
620 | create-sbu_du-report: mk_BOOT
|
---|
621 | @\$(call echo_message, Building)
|
---|
622 | @if [ "\$(ADD_REPORT)" = "y" ]; then \\
|
---|
623 | sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
|
---|
624 | \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
|
---|
625 | fi
|
---|
626 | @touch \$@
|
---|
627 |
|
---|
628 | save-luser:
|
---|
629 | @\$(call echo_message, Building)
|
---|
630 | @LUSER_ID=\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
|
---|
631 | if [ -n "\$\$LUSER_ID" ]; then \\
|
---|
632 | if [ ! -d \$(LUSER_HOME).XXX ]; then \\
|
---|
633 | mv \$(LUSER_HOME){,.XXX}; \\
|
---|
634 | mkdir \$(LUSER_HOME); \\
|
---|
635 | chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
|
---|
636 | fi; \\
|
---|
637 | echo "\$\$LUSER_ID" > luser-id; \\
|
---|
638 | echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
|
---|
639 | else \\
|
---|
640 | rm luser-id; \\
|
---|
641 | echo User \$(LUSER) does not exist; \\
|
---|
642 | echo It will be created with book instructions.; \\
|
---|
643 | fi
|
---|
644 | @\$(call housekeeping)
|
---|
645 |
|
---|
646 | restore-luser:
|
---|
647 | @\$(call echo_message, Building)
|
---|
648 | @if [ -f luser-id ]; then \\
|
---|
649 | rm -rf \$(LUSER_HOME); \\
|
---|
650 | mv \$(LUSER_HOME){.XXX,}; \\
|
---|
651 | rm luser-id; \\
|
---|
652 | else \\
|
---|
653 | userdel \$(LUSER); \\
|
---|
654 | groupdel \$(LGROUP); \\
|
---|
655 | rm -rf \$(LUSER_HOME); \\
|
---|
656 | fi
|
---|
657 | @\$(call housekeeping)
|
---|
658 |
|
---|
659 | do_housekeeping:
|
---|
660 | @-rm /tools
|
---|
661 |
|
---|
662 | EOF
|
---|
663 | ) >> $MKFILE
|
---|
664 |
|
---|
665 | # Bring over the items from the Makefile.tmp
|
---|
666 | cat $MKFILE.tmp >> $MKFILE
|
---|
667 | rm $MKFILE.tmp
|
---|
668 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
669 | }
|
---|