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