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