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