1 | #!/bin/sh
|
---|
2 | set -e # Enable error trapping
|
---|
3 |
|
---|
4 |
|
---|
5 | ###################################
|
---|
6 | ### FUNCTIONS ###
|
---|
7 | ###################################
|
---|
8 |
|
---|
9 |
|
---|
10 | #----------------------------#
|
---|
11 | get_sources() { #
|
---|
12 | #----------------------------#
|
---|
13 | local IFS
|
---|
14 |
|
---|
15 | # Test if the packages must be downloaded
|
---|
16 | if [ ! "$HPKG" = "1" ] ; then
|
---|
17 | return
|
---|
18 | fi
|
---|
19 |
|
---|
20 | # Modify the 'internal field separator' to break on 'LF' only
|
---|
21 | IFS=$'\x0A'
|
---|
22 |
|
---|
23 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
24 | cd $BUILDDIR/sources
|
---|
25 |
|
---|
26 | > MISSING_FILES.DMP # Files not in md5sum end up here
|
---|
27 |
|
---|
28 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
29 | if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
|
---|
30 |
|
---|
31 | # Retrieve the master md5sum file
|
---|
32 | download "" MD5SUMS
|
---|
33 |
|
---|
34 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
35 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
36 | PKG=`echo $i | sed -e 's/-version.*//' \
|
---|
37 | -e 's/-file.*//' \
|
---|
38 | -e 's/uclibc/uClibc/' `
|
---|
39 |
|
---|
40 | # Needed for Groff patchlevel patch on UTF-8 branch
|
---|
41 | GROFFLEVEL=`grep "groff-patchlevel" $JHALFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
|
---|
42 |
|
---|
43 | #
|
---|
44 | # How to deal with orphan packages..??
|
---|
45 | #
|
---|
46 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
47 | case "$PKG" in
|
---|
48 | "expect-lib" ) continue ;; # not valid packages
|
---|
49 | "linux-dl" ) continue ;;
|
---|
50 | "groff-patchlevel" ) continue ;;
|
---|
51 | "uClibc-patch" ) continue ;;
|
---|
52 |
|
---|
53 | "tcl" ) FILE="$PKG$VRS-src.tar.bz2" ; download $PKG $FILE ;;
|
---|
54 | "vim-lang" ) FILE="vim-$VRS-lang.tar.bz2"; PKG="vim" ; download $PKG $FILE ;;
|
---|
55 | "udev-config" ) FILE="$VRS" ; PKG="udev" ; download $PKG $FILE ;;
|
---|
56 |
|
---|
57 | "uClibc-locale" ) FILE="$PKG-$VRS.tar.bz2" ; PKG="uClibc"
|
---|
58 | download $PKG $FILE
|
---|
59 | # There can be no patches for this file
|
---|
60 | continue ;;
|
---|
61 |
|
---|
62 | "gcc" ) download $PKG "gcc-core-$VRS.tar.bz2"
|
---|
63 | download $PKG "gcc-g++-$VRS.tar.bz2"
|
---|
64 | ;;
|
---|
65 | "glibc") download $PKG "$PKG-$VRS.tar.bz2"
|
---|
66 | download $PKG "$PKG-libidn-$VRS.tar.bz2"
|
---|
67 | ;;
|
---|
68 | * ) FILE="$PKG-$VRS.tar.bz2"
|
---|
69 | download $PKG $FILE
|
---|
70 | ;;
|
---|
71 | esac
|
---|
72 |
|
---|
73 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
74 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
75 | download $PKG $PATCH
|
---|
76 | done
|
---|
77 |
|
---|
78 | done
|
---|
79 |
|
---|
80 | # .... U G L Y .... what to do with the grsecurity patch to the kernel..
|
---|
81 | download grsecurity `grep grsecurity $JHALFSDIR/patches`
|
---|
82 |
|
---|
83 | # .... U G L Y .... deal with uClibc-locale-xxxxx.tar.bz2 format issue.
|
---|
84 | bzcat uClibc-locale-030818.tar.bz2 | gzip > uClibc-locale-030818.tgz
|
---|
85 |
|
---|
86 | if [[ -s $BUILDDIR/sources/MISSING_FILES.DMP ]]; then
|
---|
87 | echo -e "\n\n${tab_}${RED} One or more files were not retrieved.\n${tab_} Check <MISSING_FILES.DMP> for names ${OFF}\n\n"
|
---|
88 | fi
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | #----------------------------#
|
---|
93 | chapter4_Makefiles() { # Initialization of the system
|
---|
94 | #----------------------------#
|
---|
95 | local TARGET LOADER
|
---|
96 |
|
---|
97 | echo "${YELLOW} Processing Chapter-4 scripts ${OFF}"
|
---|
98 |
|
---|
99 | # Define a few model dependant variables
|
---|
100 | if [[ ${MODEL} = "uclibc" ]]; then
|
---|
101 | TARGET="tools-linux-uclibc"; LOADER="ld-uClibc.so.0"
|
---|
102 | else
|
---|
103 | TARGET="tools-linux-gnu"; LOADER="ld-linux.so.2"
|
---|
104 | fi
|
---|
105 |
|
---|
106 | # 022-
|
---|
107 | # If /home/hlfs is already present in the host, we asume that the
|
---|
108 | # hlfs user and group are also presents in the host, and a backup
|
---|
109 | # of their bash init files is made.
|
---|
110 | (
|
---|
111 | cat << EOF
|
---|
112 | 020-creatingtoolsdir:
|
---|
113 | @\$(call echo_message, Building)
|
---|
114 | @mkdir -v \$(MOUNT_PT)/tools && \\
|
---|
115 | rm -fv /tools && \\
|
---|
116 | ln -sv \$(MOUNT_PT)/tools /
|
---|
117 | @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
|
---|
118 | mkdir \$(MOUNT_PT)/sources; \\
|
---|
119 | fi;
|
---|
120 | @chmod a+wt \$(MOUNT_PT)/sources && \\
|
---|
121 | touch \$@
|
---|
122 |
|
---|
123 | 021-addinguser: 020-creatingtoolsdir
|
---|
124 | @\$(call echo_message, Building)
|
---|
125 | @if [ ! -d /home/lfs ]; then \\
|
---|
126 | groupadd lfs; \\
|
---|
127 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
|
---|
128 | else \\
|
---|
129 | touch user-lfs-exist; \\
|
---|
130 | fi;
|
---|
131 | @chown lfs \$(MOUNT_PT)/tools && \\
|
---|
132 | chown lfs \$(MOUNT_PT)/sources && \\
|
---|
133 | touch \$@
|
---|
134 |
|
---|
135 | 022-settingenvironment: 021-addinguser
|
---|
136 | @\$(call echo_message, Building)
|
---|
137 | @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
138 | mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
|
---|
139 | fi;
|
---|
140 | @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
141 | mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
|
---|
142 | fi;
|
---|
143 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
144 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
145 | echo "HLFS=\$(MOUNT_PT)" >> /home/lfs/.bashrc && \\
|
---|
146 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
147 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
148 | echo "export HLFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
149 | echo "" >> /home/lfs/.bashrc && \\
|
---|
150 | echo "target=$(uname -m)-${TARGET}" >> /home/lfs/.bashrc && \\
|
---|
151 | echo "ldso=/tools/lib/${LOADER}" >> /home/lfs/.bashrc && \\
|
---|
152 | echo "export target ldso" >> /home/lfs/.bashrc && \\
|
---|
153 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
154 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
155 | touch envars && \\
|
---|
156 | touch \$@
|
---|
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 "${YELLOW} Processing Chapter-5 scripts${OFF}"
|
---|
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 | # Test if the stripping phase must be skipped
|
---|
181 | *stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
|
---|
182 | # Select the appropriate library
|
---|
183 | *glibc*) [[ ${MODEL} = "uclibc" ]] && continue ;;
|
---|
184 | *uclibc*) [[ ${MODEL} = "glibc" ]] && 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 (minus the -headers or -cross in the case of gcc
|
---|
193 | # and binutils in chapter 5)
|
---|
194 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-cross@@' -e 's@-headers@@'`
|
---|
195 |
|
---|
196 | # >>>>>>>>>> U G L Y <<<<<<<<<
|
---|
197 | # Adjust 'name' and patch a few scripts on the fly..
|
---|
198 | case $name in
|
---|
199 | linux-libc) name=linux-libc-headers
|
---|
200 | ;;
|
---|
201 | uclibc) # this sucks as method to deal with gettext/libint inside uClibc
|
---|
202 | sed 's@^cd gettext-runtime@cd ../gettext-*/gettext-runtime@' -i chapter05/$this_script
|
---|
203 | ;;
|
---|
204 | gcc) # to compensate for the compiler test inside gcc (which fails), disable error trap
|
---|
205 | sed 's@^gcc -o test test.c@set +e; gcc -o test test.c@' -i chapter05/$this_script
|
---|
206 | ;;
|
---|
207 | esac
|
---|
208 |
|
---|
209 | # Set the dependency for the first target.
|
---|
210 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
211 |
|
---|
212 |
|
---|
213 | #--------------------------------------------------------------------#
|
---|
214 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
215 | #--------------------------------------------------------------------#
|
---|
216 | #
|
---|
217 | # Drop in the name of the target on a new line, and the previous target
|
---|
218 | # as a dependency. Also call the echo_message function.
|
---|
219 | wrt_target "$this_script" "$PREV"
|
---|
220 |
|
---|
221 | # Find the version of the command files, if it corresponds with the building of
|
---|
222 | # a specific package
|
---|
223 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
224 | # If $vrs isn't empty, we've got a package...
|
---|
225 | if [ "$vrs" != "" ] ; then
|
---|
226 | # Deal with non-standard names
|
---|
227 | case $name in
|
---|
228 | tcl) FILE="$name$vrs-src.tar" ;;
|
---|
229 | uclibc) FILE="uClibc-$vrs.tar" ;;
|
---|
230 | gcc) FILE="gcc-core-$vrs.tar" ;;
|
---|
231 | *) FILE="$name-$vrs.tar" ;;
|
---|
232 | esac
|
---|
233 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
234 | wrt_unpack "$FILE"
|
---|
235 | fi
|
---|
236 |
|
---|
237 | case $this_script in
|
---|
238 | *binutils* ) # Dump the path to sources directory for later removal
|
---|
239 | echo -e '\techo "$(MOUNT_PT)$(SRC)/$$ROOT" >> sources-dir' >> $MKFILE.tmp
|
---|
240 | ;;
|
---|
241 | *adjusting* ) # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
242 | echo -e '\t@echo "export PKGDIR=$(MOUNT_PT)$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
|
---|
243 | ;;
|
---|
244 | * ) # Everything else, add a true statment so we don't confuse make
|
---|
245 | echo -e '\ttrue' >> $MKFILE.tmp
|
---|
246 | ;;
|
---|
247 | esac
|
---|
248 |
|
---|
249 | # Insert date and disk usage at the top of the log file, the script run
|
---|
250 | # and date and disk usage again at the bottom of the log file.
|
---|
251 | wrt_run_as_su "${this_script}" "${file}"
|
---|
252 |
|
---|
253 | # Remove the build directory(ies) except if the package build fails
|
---|
254 | # (so we can review config.cache, config.log, etc.)
|
---|
255 | # For Binutils the sources must be retained for some time.
|
---|
256 | if [ "$vrs" != "" ] ; then
|
---|
257 | if [[ ! `_IS_ $this_script binutils` ]]; then
|
---|
258 | wrt_remove_build_dirs "$name"
|
---|
259 | fi
|
---|
260 | fi
|
---|
261 |
|
---|
262 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
263 | if [[ `_IS_ $this_script adjusting` ]] ; then
|
---|
264 | (
|
---|
265 | cat << EOF
|
---|
266 | @rm -r \`cat sources-dir\` && \\
|
---|
267 | rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
|
---|
268 | rm sources-dir
|
---|
269 | EOF
|
---|
270 | ) >> $MKFILE.tmp
|
---|
271 | fi
|
---|
272 |
|
---|
273 | # Include a touch of the target name so make can check if it's already been made.
|
---|
274 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
275 | #
|
---|
276 | #--------------------------------------------------------------------#
|
---|
277 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
278 | #--------------------------------------------------------------------#
|
---|
279 |
|
---|
280 | # Keep the script file name for Makefile dependencies.
|
---|
281 | PREV=$this_script
|
---|
282 | done # end for file in chapter05/*
|
---|
283 | }
|
---|
284 |
|
---|
285 |
|
---|
286 | #----------------------------#
|
---|
287 | chapter6_Makefiles() { # sysroot or chroot build phase
|
---|
288 | #----------------------------#
|
---|
289 | local TARGET LOADER
|
---|
290 | local file
|
---|
291 | local this_script
|
---|
292 |
|
---|
293 | #
|
---|
294 | # Set these definitions early and only once
|
---|
295 | #
|
---|
296 | if [[ ${MODEL} = "uclibc" ]]; then
|
---|
297 | TARGET="pc-linux-uclibc"; LOADER="ld-uClibc.so.0"
|
---|
298 | else
|
---|
299 | TARGET="pc-linux-gnu"; LOADER="ld-linux.so.2"
|
---|
300 | fi
|
---|
301 |
|
---|
302 | echo -e "${YELLOW} Processing Chapter-6 scripts ${OFF}"
|
---|
303 | for file in chapter06/* ; do
|
---|
304 | # Keep the script file name
|
---|
305 | this_script=`basename $file`
|
---|
306 |
|
---|
307 | # Skip this script depending on jhalfs.conf flags set.
|
---|
308 | case $this_script in
|
---|
309 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
310 | # dependencies and target creation.
|
---|
311 | *chroot* ) continue ;;
|
---|
312 | # Test if the stripping phase must be skipped
|
---|
313 | *-stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
|
---|
314 | # Select the appropriate library
|
---|
315 | *glibc*) [[ ${MODEL} = "uclibc" ]] && continue ;;
|
---|
316 | *uclibc*) [[ ${MODEL} = "glibc" ]] && continue ;;
|
---|
317 | *) ;;
|
---|
318 | esac
|
---|
319 |
|
---|
320 | # First append each name of the script files to a list (this will become
|
---|
321 | # the names of the targets in the Makefile
|
---|
322 | chapter6="$chapter6 $this_script"
|
---|
323 |
|
---|
324 | # Grab the name of the target
|
---|
325 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
|
---|
326 |
|
---|
327 | #
|
---|
328 | # Sed replacement for 'nodump' tag in xml scripts until Manuel has a chance to fix them
|
---|
329 | #
|
---|
330 | case $name in
|
---|
331 | kernfs)
|
---|
332 | # We are using LFS instead of HLFS..
|
---|
333 | sed 's/HLFS/LFS/' -i chapter06/$this_script
|
---|
334 | # Remove sysctl code if host does not have grsecurity enabled
|
---|
335 | if [[ "$GRSECURITY_HOST" = "0" ]]; then
|
---|
336 | sed '/sysctl/d' -i chapter06/$this_script
|
---|
337 | fi
|
---|
338 | ;;
|
---|
339 | module-init-tools)
|
---|
340 | if [[ "$TEST" = "0" ]]; then # This needs rework....
|
---|
341 | sed '/make distclean/d' -i chapter06/$this_script
|
---|
342 | fi
|
---|
343 | ;;
|
---|
344 | glibc) # PATCH.. Turn off error trapping for the remainder of the script.
|
---|
345 | sed 's|^make install|make install; set +e|' -i chapter06/$this_script
|
---|
346 | ;;
|
---|
347 | uclibc) # PATCH..
|
---|
348 | sed 's/EST5EDT/${TIMEZONE}/' -i chapter06/$this_script
|
---|
349 | # PATCH.. Cannot use interactive programs/scripts.
|
---|
350 | sed 's/make menuconfig/make oldconfig/' -i chapter06/$this_script
|
---|
351 | sed 's@^cd gettext-runtime@cd ../gettext-*/gettext-runtime@' -i chapter06/$this_script
|
---|
352 | ;;
|
---|
353 | gcc) # PATCH..
|
---|
354 | sed 's/rm /rm -f /' -i chapter06/$this_script
|
---|
355 | ;;
|
---|
356 | esac
|
---|
357 |
|
---|
358 | #--------------------------------------------------------------------#
|
---|
359 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
360 | #--------------------------------------------------------------------#
|
---|
361 | #
|
---|
362 | # Drop in the name of the target on a new line, and the previous target
|
---|
363 | # as a dependency. Also call the echo_message function.
|
---|
364 | wrt_target "$this_script" "$PREV"
|
---|
365 |
|
---|
366 | # Find the version of the command files, if it corresponds with the building of
|
---|
367 | # a specific package
|
---|
368 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
369 |
|
---|
370 | # If $vrs isn't empty, we've got a package...
|
---|
371 | # Insert instructions for unpacking the package and changing directories
|
---|
372 | if [ "$vrs" != "" ] ; then
|
---|
373 | # Deal with non-standard names
|
---|
374 | case $name in
|
---|
375 | tcl) FILE="$name$vrs-src.tar.*" ;;
|
---|
376 | uclibc) FILE="uClibc-$vrs.tar.*" ;;
|
---|
377 | gcc) FILE="gcc-core-$vrs.tar.*" ;;
|
---|
378 | *) FILE="$name-$vrs.tar.*" ;;
|
---|
379 | esac
|
---|
380 | wrt_unpack2 "$FILE"
|
---|
381 | wrt_target_vars
|
---|
382 | fi
|
---|
383 |
|
---|
384 | case $this_script in
|
---|
385 | *readjusting*) # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
386 | echo -e '\t@echo "export PKGDIR=$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
|
---|
387 | ;;
|
---|
388 | *glibc* | *uclibc* ) # For glibc and uClibc we need to set TIMEZONE envar.
|
---|
389 | wrt_export_timezone
|
---|
390 | ;;
|
---|
391 | *groff* ) # For Groff we need to set PAGE envar.
|
---|
392 | wrt_export_pagesize
|
---|
393 | ;;
|
---|
394 | esac
|
---|
395 |
|
---|
396 | # In the mount of kernel filesystems we need to set HLFS and not to use chroot.
|
---|
397 | if [[ `_IS_ $this_script kernfs` ]] ; then
|
---|
398 | wrt_run_as_root "${this_script}" "${file}"
|
---|
399 | #
|
---|
400 | # The rest of Chapter06
|
---|
401 | else
|
---|
402 | wrt_run_as_chroot1 "${this_script}" "${file}"
|
---|
403 | fi
|
---|
404 | #
|
---|
405 | # Remove the build directory(ies) except if the package build fails.
|
---|
406 | if [ "$vrs" != "" ] ; then
|
---|
407 | wrt_remove_build_dirs "$name"
|
---|
408 | fi
|
---|
409 | #
|
---|
410 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
411 | if [[ `_IS_ $this_script readjusting` ]] ; then
|
---|
412 | (
|
---|
413 | cat << EOF
|
---|
414 | @rm -r \`cat sources-dir\` && \\
|
---|
415 | rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
|
---|
416 | rm sources-dir
|
---|
417 | EOF
|
---|
418 | ) >> $MKFILE.tmp
|
---|
419 | fi
|
---|
420 |
|
---|
421 | # Include a touch of the target name so make can check if it's already been made.
|
---|
422 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
423 | #
|
---|
424 | #--------------------------------------------------------------------#
|
---|
425 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
426 | #--------------------------------------------------------------------#
|
---|
427 |
|
---|
428 | # Keep the script file name for Makefile dependencies.
|
---|
429 | PREV=$this_script
|
---|
430 | done # end for file in chapter06/*
|
---|
431 |
|
---|
432 | }
|
---|
433 |
|
---|
434 | #----------------------------#
|
---|
435 | chapter7_Makefiles() { # Create a bootable system.. kernel, bootscripts..etc
|
---|
436 | #----------------------------#
|
---|
437 | local file
|
---|
438 | local this_script
|
---|
439 |
|
---|
440 | echo "${YELLOW} Processing Chapter-7 scripts ${OFF}"
|
---|
441 | for file in chapter07/*; do
|
---|
442 | # Keep the script file name
|
---|
443 | this_script=`basename $file`
|
---|
444 |
|
---|
445 | # Grub must be configured manually.
|
---|
446 | # The filesystems can't be unmounted via Makefile and the user
|
---|
447 | # should enter the chroot environment to create the root
|
---|
448 | # password, edit several files and setup Grub.
|
---|
449 | case $this_script in
|
---|
450 | *grub) continue ;;
|
---|
451 | *reboot) continue ;;
|
---|
452 | *console) continue ;; # Use the file generated by lfs-bootscripts
|
---|
453 |
|
---|
454 | *kernel)
|
---|
455 | # If no .config file is supplied, the kernel build is skipped
|
---|
456 | [[ -z $CONFIG ]] && continue
|
---|
457 | # How does Manuel add this string to the file..
|
---|
458 | sed 's|cd \$PKGDIR.*||' -i chapter07/$this_script
|
---|
459 | # You cannot run menuconfig from within the makefile
|
---|
460 | sed 's|make menuconfig|make oldconfig|' -i chapter07/$this_script
|
---|
461 | # The files in the conglomeration dir are xxx.bz2
|
---|
462 | sed 's|.patch.gz|.patch.bz2|' -i chapter07/$this_script
|
---|
463 | sed 's|gunzip|bunzip2|' -i chapter07/$this_script
|
---|
464 | # If defined include the keymap in the kernel
|
---|
465 | if [[ -n "$KEYMAP" ]]; then
|
---|
466 | sed "s|^loadkeys -m.*>|loadkeys -m $KEYMAP >|" -i chapter07/$this_script
|
---|
467 | else
|
---|
468 | sed '/loadkeys -m/d' -i chapter07/$this_script
|
---|
469 | sed '/drivers\/char/d' -i chapter07/$this_script
|
---|
470 | fi
|
---|
471 | ;;
|
---|
472 | *usage) # The script bombs, disable error trapping
|
---|
473 | sed 's|set -e|set +e|' -i chapter07/$this_script
|
---|
474 | ;;
|
---|
475 | *profile) # Add the config values to the script
|
---|
476 | sed "s|LC_ALL=\*\*EDITME.*EDITME\*\*|LC_ALL=$LC_ALL|" -i chapter07/$this_script
|
---|
477 | sed "s|LANG=\*\*EDITME.*EDITME\*\*|LANG=$LANG|" -i chapter07/$this_script
|
---|
478 | ;;
|
---|
479 | esac
|
---|
480 |
|
---|
481 | # First append then name of the script file to a list (this will become
|
---|
482 | # the names of the targets in the Makefile
|
---|
483 | chapter7="$chapter7 $this_script"
|
---|
484 |
|
---|
485 | #--------------------------------------------------------------------#
|
---|
486 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
487 | #--------------------------------------------------------------------#
|
---|
488 | #
|
---|
489 | # Drop in the name of the target on a new line, and the previous target
|
---|
490 | # as a dependency. Also call the echo_message function.
|
---|
491 | wrt_target "$this_script" "$PREV"
|
---|
492 |
|
---|
493 | if [[ `_IS_ $this_script bootscripts` ]] ; then
|
---|
494 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
495 | FILE="lfs-bootscripts-$vrs.tar.*"
|
---|
496 | # The bootscript pkg references both lfs AND blfs bootscripts...
|
---|
497 | # see XML script for other additions to bootscripts file
|
---|
498 | # PATCH
|
---|
499 | vrs=`grep "^blfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
500 | sed "s|make install$|make install; cd ../blfs-bootscripts-$vrs|" -i chapter07/$this_script
|
---|
501 | wrt_unpack2 "$FILE"
|
---|
502 | (
|
---|
503 | cat << EOF
|
---|
504 | echo "\$(MOUNT_PT)\$(SRC)/blfs-bootscripts-$vrs" > sources-dir
|
---|
505 | EOF
|
---|
506 | ) >> $MKFILE.tmp
|
---|
507 | fi
|
---|
508 |
|
---|
509 | if [[ `_IS_ $this_script kernel` ]] ; then
|
---|
510 | # not much really, script does everything..
|
---|
511 | echo -e "\t@cp -f $CONFIG \$(MOUNT_PT)/sources/kernel-config" >> $MKFILE.tmp
|
---|
512 | fi
|
---|
513 |
|
---|
514 | # Check if we have a real /etc/fstab file
|
---|
515 | if [[ `_IS_ $this_script fstab` ]] && [[ -n "$FSTAB" ]] ; then
|
---|
516 | wrt_copy_fstab "$this_script"
|
---|
517 | else
|
---|
518 | # Initialize the log and run the script
|
---|
519 | wrt_run_as_chroot2 "${this_script}" "${file}"
|
---|
520 | fi
|
---|
521 |
|
---|
522 | # Remove the build directory except if the package build fails.
|
---|
523 | if [[ `_IS_ $this_script bootscripts` ]]; then
|
---|
524 | (
|
---|
525 | cat << EOF
|
---|
526 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
527 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT
|
---|
528 | @rm -r \`cat sources-dir\` && \\
|
---|
529 | rm sources-dir
|
---|
530 | EOF
|
---|
531 | ) >> $MKFILE.tmp
|
---|
532 | fi
|
---|
533 |
|
---|
534 | # Include a touch of the target name so make can check if it's already been made.
|
---|
535 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
536 | #
|
---|
537 | #--------------------------------------------------------------------#
|
---|
538 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
539 | #--------------------------------------------------------------------#
|
---|
540 |
|
---|
541 | # Keep the script file name for Makefile dependencies.
|
---|
542 | PREV=$this_script
|
---|
543 | done # for file in chapter07/*
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | #----------------------------#
|
---|
548 | build_Makefile() { # Construct a Makefile from the book scripts
|
---|
549 | #----------------------------#
|
---|
550 | echo -e "${GREEN}Creating Makefile... ${OFF}"
|
---|
551 |
|
---|
552 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
553 | # Start with a clean Makefile.tmp file
|
---|
554 | >$MKFILE.tmp
|
---|
555 |
|
---|
556 | chapter4_Makefiles
|
---|
557 | chapter5_Makefiles
|
---|
558 | chapter6_Makefiles
|
---|
559 | chapter7_Makefiles
|
---|
560 |
|
---|
561 | # Add a header, some variables and include the function file
|
---|
562 | # to the top of the real Makefile.
|
---|
563 | (
|
---|
564 | cat << EOF
|
---|
565 | $HEADER
|
---|
566 |
|
---|
567 | SRC= /sources
|
---|
568 | MOUNT_PT= $BUILDDIR
|
---|
569 | PAGE= $PAGE
|
---|
570 | TIMEZONE= $TIMEZONE
|
---|
571 |
|
---|
572 | include makefile-functions
|
---|
573 |
|
---|
574 | EOF
|
---|
575 | ) > $MKFILE
|
---|
576 |
|
---|
577 |
|
---|
578 | # Add chroot commands
|
---|
579 | i=1
|
---|
580 | for file in chapter06/*chroot* ; do
|
---|
581 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
|
---|
582 | -e '/^export/d' \
|
---|
583 | -e '/^logout/d' \
|
---|
584 | -e 's@ \\\@ @g' | tr -d '\n' | sed -e 's/ */ /g' \
|
---|
585 | -e 's|\\$|&&|g' \
|
---|
586 | -e 's|exit||g' \
|
---|
587 | -e 's|$| -c|' \
|
---|
588 | -e 's|"$$HLFS"|$(MOUNT_PT)|'\
|
---|
589 | -e 's|set -e||'`
|
---|
590 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
591 | i=`expr $i + 1`
|
---|
592 | done
|
---|
593 |
|
---|
594 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
595 | # as a dependency.
|
---|
596 | (
|
---|
597 | cat << EOF
|
---|
598 | all: chapter4 chapter5 chapter6 chapter7
|
---|
599 | @\$(call echo_finished,$VERSION)
|
---|
600 |
|
---|
601 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
602 |
|
---|
603 | chapter5: chapter4 $chapter5 restore-hlfs-env
|
---|
604 |
|
---|
605 | chapter6: chapter5 $chapter6
|
---|
606 |
|
---|
607 | chapter7: chapter6 $chapter7
|
---|
608 |
|
---|
609 | clean-all: clean
|
---|
610 | rm -rf ./{hlfs-commands,logs,Makefile,dump-hlfs-scripts.xsl,functions,packages,patches}
|
---|
611 |
|
---|
612 | clean: clean-chapter7 clean-chapter6 clean-chapter5 clean-chapter4
|
---|
613 |
|
---|
614 | clean-chapter4:
|
---|
615 | -if [ ! -f user-hlfs-exist ]; then \\
|
---|
616 | userdel hlfs; \\
|
---|
617 | rm -rf /home/hlfs; \\
|
---|
618 | fi;
|
---|
619 | rm -rf \$(MOUNT_PT)/tools
|
---|
620 | rm -f /tools
|
---|
621 | rm -f envars user-hlfs-exist
|
---|
622 | rm -f 02* logs/02*.log
|
---|
623 |
|
---|
624 | clean-chapter5:
|
---|
625 | rm -rf \$(MOUNT_PT)/tools/*
|
---|
626 | rm -f $chapter5 restore-hlfs-env sources-dir
|
---|
627 | cd logs && rm -f $chapter5 && cd ..
|
---|
628 |
|
---|
629 | clean-chapter6:
|
---|
630 | -umount \$(MOUNT_PT)/sys
|
---|
631 | -umount \$(MOUNT_PT)/proc
|
---|
632 | -umount \$(MOUNT_PT)/dev/shm
|
---|
633 | -umount \$(MOUNT_PT)/dev/pts
|
---|
634 | -umount \$(MOUNT_PT)/dev
|
---|
635 | rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
|
---|
636 | rm -f $chapter6
|
---|
637 | cd logs && rm -f $chapter6 && cd ..
|
---|
638 |
|
---|
639 | clean-chapter7:
|
---|
640 | rm -f $chapter7
|
---|
641 | cd logs && rm -f $chapter7 && cd ..
|
---|
642 |
|
---|
643 | restore-hlfs-env:
|
---|
644 | @\$(call echo_message, Building)
|
---|
645 | @if [ -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
646 | mv -fv /home/lfs/.bashrc.XXX /home/hlfs/.bashrc; \\
|
---|
647 | fi;
|
---|
648 | @if [ -f /home/hlfs/.bash_profile.XXX ]; then \\
|
---|
649 | mv -v /home/lfs/.bash_profile.XXX /home/hlfs/.bash_profile; \\
|
---|
650 | fi;
|
---|
651 | @chown lfs:lfs /home/lfs/.bash* && \\
|
---|
652 | touch \$@
|
---|
653 |
|
---|
654 | EOF
|
---|
655 | ) >> $MKFILE
|
---|
656 |
|
---|
657 | # Bring over the items from the Makefile.tmp
|
---|
658 | cat $MKFILE.tmp >> $MKFILE
|
---|
659 | rm $MKFILE.tmp
|
---|
660 | echo -ne "${GREEN}done\n${OFF}"
|
---|
661 | }
|
---|
662 |
|
---|
663 |
|
---|