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