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