1 | #!/bin/sh
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | ###################################
|
---|
6 | ### FUNCTIONS ###
|
---|
7 | ###################################
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 | #----------------------------#
|
---|
12 | chapter4_Makefiles() {
|
---|
13 | #----------------------------#
|
---|
14 | echo -e "\n${tab_}${GREEN}Processing... ${L_arrow}Chapter4${R_arrow}"
|
---|
15 |
|
---|
16 | # If /home/lfs is already present in the host, we asume that the
|
---|
17 | # lfs user and group are also presents in the host, and a backup
|
---|
18 | # of their bash init files is made.
|
---|
19 | (
|
---|
20 | cat << EOF
|
---|
21 | 020-creatingtoolsdir:
|
---|
22 | @\$(call echo_message, Building)
|
---|
23 | @mkdir -v \$(MOUNT_PT)/tools && \\
|
---|
24 | rm -fv /tools && \\
|
---|
25 | ln -sv \$(MOUNT_PT)/tools / && \\
|
---|
26 | touch \$@
|
---|
27 |
|
---|
28 | 021-addinguser: 020-creatingtoolsdir
|
---|
29 | @\$(call echo_message, Building)
|
---|
30 | @if [ ! -d /home/lfs ]; then \\
|
---|
31 | groupadd lfs; \\
|
---|
32 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
|
---|
33 | else \\
|
---|
34 | touch user-lfs-exist; \\
|
---|
35 | fi;
|
---|
36 | @chown lfs \$(MOUNT_PT)/tools && \\
|
---|
37 | chown lfs \$(MOUNT_PT)/sources && \\
|
---|
38 | touch \$@
|
---|
39 |
|
---|
40 | 022-settingenvironment: 021-addinguser
|
---|
41 | @\$(call echo_message, Building)
|
---|
42 | @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
43 | mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
|
---|
44 | fi;
|
---|
45 | @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
46 | mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
|
---|
47 | fi;
|
---|
48 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
49 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
50 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
51 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
52 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
53 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
54 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
55 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
56 | touch envars && \\
|
---|
57 | touch \$@
|
---|
58 | EOF
|
---|
59 | ) >> $MKFILE.tmp
|
---|
60 | }
|
---|
61 |
|
---|
62 | #----------------------------#
|
---|
63 | chapter5_Makefiles() {
|
---|
64 | #----------------------------#
|
---|
65 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
|
---|
66 |
|
---|
67 | for file in chapter05/* ; do
|
---|
68 | # Keep the script file name
|
---|
69 | this_script=`basename $file`
|
---|
70 |
|
---|
71 | # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
|
---|
72 | if [ "$TEST" = "0" ]; then
|
---|
73 | if [[ `_IS_ ${this_script} tcl` ]] || [[ `_IS_ ${this_script} expect` ]] || [[ `_IS_ ${this_script} dejagnu` ]] ; then
|
---|
74 | continue
|
---|
75 | fi
|
---|
76 | fi
|
---|
77 |
|
---|
78 | # Test if the stripping phase must be skipped
|
---|
79 | if [ "$STRIP" = "0" ] && [[ `_IS_ ${this_script} stripping` ]] ; then
|
---|
80 | continue
|
---|
81 | fi
|
---|
82 |
|
---|
83 | # First append each name of the script files to a list (this will become
|
---|
84 | # the names of the targets in the Makefile
|
---|
85 | chapter5="$chapter5 ${this_script}"
|
---|
86 |
|
---|
87 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
88 | # and binutils in chapter 5)
|
---|
89 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
90 |
|
---|
91 | # Set the dependency for the first target.
|
---|
92 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
93 |
|
---|
94 | #--------------------------------------------------------------------#
|
---|
95 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
96 | #--------------------------------------------------------------------#
|
---|
97 | #
|
---|
98 | # Drop in the name of the target on a new line, and the previous target
|
---|
99 | # as a dependency. Also call the echo_message function.
|
---|
100 | wrt_target "${this_script}" "$PREV"
|
---|
101 |
|
---|
102 | # Find the version of the command files, if it corresponds with the building of
|
---|
103 | # a specific package
|
---|
104 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
105 |
|
---|
106 | # If $vrs isn't empty, we've got a package...
|
---|
107 | if [ "$vrs" != "" ] ; then
|
---|
108 | if [ "$name" = "tcl" ] ; then
|
---|
109 | FILE="$name$vrs-src.tar"
|
---|
110 | else
|
---|
111 | FILE="$name-$vrs.tar"
|
---|
112 | fi
|
---|
113 |
|
---|
114 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
115 | wrt_unpack "$FILE"
|
---|
116 | echo -e '\ttrue' >> $MKFILE.tmp
|
---|
117 | fi
|
---|
118 |
|
---|
119 | # Insert date and disk usage at the top of the log file, the script run
|
---|
120 | # and date and disk usage again at the bottom of the log file.
|
---|
121 | wrt_run_as_su "${this_script}" "$file"
|
---|
122 |
|
---|
123 | # Remove the build directory(ies) except if the package build fails
|
---|
124 | # (so we can review config.cache, config.log, etc.)
|
---|
125 | if [ "$vrs" != "" ] ; then
|
---|
126 | wrt_remove_build_dirs "$name"
|
---|
127 | fi
|
---|
128 |
|
---|
129 | # Include a touch of the target name so make can check
|
---|
130 | # if it's already been made.
|
---|
131 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
132 | #
|
---|
133 | #--------------------------------------------------------------------#
|
---|
134 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
135 | #--------------------------------------------------------------------#
|
---|
136 |
|
---|
137 | # Keep the script file name for Makefile dependencies.
|
---|
138 | PREV=${this_script}
|
---|
139 | done # end for file in chapter05/*
|
---|
140 | }
|
---|
141 |
|
---|
142 | #----------------------------#
|
---|
143 | chapter6_Makefiles() {
|
---|
144 | #----------------------------#
|
---|
145 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6${R_arrow}"
|
---|
146 | for file in chapter06/* ; do
|
---|
147 | # Keep the script file name
|
---|
148 | this_script=`basename $file`
|
---|
149 |
|
---|
150 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
151 | # dependencies and target creation.
|
---|
152 | if [[ `_IS_ ${this_script} chroot` ]] ; then
|
---|
153 | continue
|
---|
154 | fi
|
---|
155 |
|
---|
156 | # Test if the stripping phase must be skipped
|
---|
157 | if [ "$STRIP" = "0" ] && [[ `_IS_ ${this_script} stripping` ]] ; then
|
---|
158 | continue
|
---|
159 | fi
|
---|
160 |
|
---|
161 | # First append each name of the script files to a list (this will become
|
---|
162 | # the names of the targets in the Makefile
|
---|
163 | chapter6="$chapter6 ${this_script}"
|
---|
164 |
|
---|
165 | # Grab the name of the target
|
---|
166 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
|
---|
167 |
|
---|
168 | #--------------------------------------------------------------------#
|
---|
169 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
170 | #--------------------------------------------------------------------#
|
---|
171 | #
|
---|
172 | # Drop in the name of the target on a new line, and the previous target
|
---|
173 | # as a dependency. Also call the echo_message function.
|
---|
174 | wrt_target "${this_script}" "$PREV"
|
---|
175 |
|
---|
176 | # Find the version of the command files, if it corresponds with the building of
|
---|
177 | # a specific package
|
---|
178 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
179 |
|
---|
180 | # If $vrs isn't empty, we've got a package...
|
---|
181 | # Insert instructions for unpacking the package and changing directories
|
---|
182 | if [ "$vrs" != "" ] ; then
|
---|
183 | FILE="$name-$vrs.tar.*"
|
---|
184 | wrt_unpack2 "$FILE"
|
---|
185 | fi
|
---|
186 |
|
---|
187 | case "${this_script}" in
|
---|
188 | *glibc* ) wrt_export_timezone ;; # For Glibc we need to set TIMEZONE envar.
|
---|
189 | *groff* ) wrt_export_pagesize ;; # For Groff we need to set PAGE envar.
|
---|
190 | esac
|
---|
191 |
|
---|
192 | # In the mount of kernel filesystems we need to set LFS
|
---|
193 | # and not to use chroot.
|
---|
194 | if [[ `_IS_ ${this_script} kernfs` ]] ; then
|
---|
195 | wrt_run_as_root "${this_script}" "$file"
|
---|
196 | else # The rest of Chapter06
|
---|
197 | wrt_run_as_chroot1 "${this_script}" "$file"
|
---|
198 | fi
|
---|
199 |
|
---|
200 | # Remove the build directory(ies) except if the package build fails.
|
---|
201 | if [ "$vrs" != "" ] ; then
|
---|
202 | wrt_remove_build_dirs "$name"
|
---|
203 | fi
|
---|
204 |
|
---|
205 | # Include a touch of the target name so make can check
|
---|
206 | # if it's already been made.
|
---|
207 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
208 | #
|
---|
209 | #--------------------------------------------------------------------#
|
---|
210 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
211 | #--------------------------------------------------------------------#
|
---|
212 |
|
---|
213 | # Keep the script file name for Makefile dependencies.
|
---|
214 | PREV=${this_script}
|
---|
215 | done # end for file in chapter06/*
|
---|
216 | }
|
---|
217 |
|
---|
218 | #----------------------------#
|
---|
219 | chapter789_Makefiles() {
|
---|
220 | #----------------------------#
|
---|
221 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6/7/8${R_arrow}"
|
---|
222 | for file in chapter0{7,8,9}/* ; do
|
---|
223 | # Keep the script file name
|
---|
224 | this_script=`basename $file`
|
---|
225 |
|
---|
226 | # Grub must be configured manually.
|
---|
227 | # The filesystems can't be unmounted via Makefile and the user
|
---|
228 | # should enter the chroot environment to create the root
|
---|
229 | # password, edit several files and setup Grub.
|
---|
230 | if [[ `_IS_ ${this_script} grub` ]] || [[ `_IS_ ${this_script} reboot` ]] ; then
|
---|
231 | continue
|
---|
232 | fi
|
---|
233 |
|
---|
234 | # If no .config file is supplied, the kernel build is skipped
|
---|
235 | if [ -z $CONFIG ] && [[ `_IS_ ${this_script} kernel` ]] ; then
|
---|
236 | continue
|
---|
237 | fi
|
---|
238 |
|
---|
239 | # First append each name of the script files to a list (this will become
|
---|
240 | # the names of the targets in the Makefile
|
---|
241 | chapter789="$chapter789 ${this_script}"
|
---|
242 |
|
---|
243 | #--------------------------------------------------------------------#
|
---|
244 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
245 | #--------------------------------------------------------------------#
|
---|
246 | #
|
---|
247 | # Drop in the name of the target on a new line, and the previous target
|
---|
248 | # as a dependency. Also call the echo_message function.
|
---|
249 | wrt_target "${this_script}" "$PREV"
|
---|
250 |
|
---|
251 | # Find the bootscripts and kernel package names
|
---|
252 | if [[ `_IS_ ${this_script} bootscripts` ]] || [[ `_IS_ ${this_script} kernel` ]] ; then
|
---|
253 | if [[ `_IS_ ${this_script} bootscripts` ]] ; then
|
---|
254 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
255 | FILE="lfs-bootscripts-$vrs.tar.*"
|
---|
256 | elif [[ `_IS_ ${this_script} kernel` ]] ; then
|
---|
257 | vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
258 | FILE="linux-$vrs.tar.*"
|
---|
259 | fi
|
---|
260 | wrt_unpack2 "$FILE"
|
---|
261 | fi
|
---|
262 |
|
---|
263 | # Put in place the kernel .config file
|
---|
264 | if [[ `_IS_ ${this_script} kernel` ]] ; then
|
---|
265 | (
|
---|
266 | cat << EOF
|
---|
267 | @cp $CONFIG \$(MOUNT_PT)/sources/kernel-config
|
---|
268 | EOF
|
---|
269 | ) >> $MKFILE.tmp
|
---|
270 | fi
|
---|
271 |
|
---|
272 | # Check if we have a real /etc/fstab file
|
---|
273 | if [[ `_IS_ ${this_script} fstab` ]] && [[ -n "$FSTAB" ]] ; then
|
---|
274 | wrt_copy_fstab "${this_script}"
|
---|
275 | else
|
---|
276 | # Initialize the log and run the script
|
---|
277 | wrt_run_as_chroot2 "$this_script" "$file"
|
---|
278 | fi
|
---|
279 |
|
---|
280 | # Remove the build directory except if the package build fails.
|
---|
281 | if [[ `_IS_ ${this_script} bootscripts` ]] || [[ `_IS_ ${this_script} kernel` ]] ; then
|
---|
282 | wrt_remove_build_dirs "dummy"
|
---|
283 | fi
|
---|
284 |
|
---|
285 | # Include a touch of the target name so make can check
|
---|
286 | # if it's already been made.
|
---|
287 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
288 | #
|
---|
289 | #--------------------------------------------------------------------#
|
---|
290 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
291 | #--------------------------------------------------------------------#
|
---|
292 |
|
---|
293 | # Keep the script file name for Makefile dependencies.
|
---|
294 | PREV=${this_script}
|
---|
295 | done # for file in chapter0{7,8,9}/*
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | #----------------------------#
|
---|
300 | build_Makefile() {
|
---|
301 | #----------------------------#
|
---|
302 | echo -n "Creating Makefile... "
|
---|
303 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
304 |
|
---|
305 | # Start with a clean Makefile.tmp file
|
---|
306 | >$MKFILE.tmp
|
---|
307 |
|
---|
308 | chapter4_Makefiles
|
---|
309 | chapter5_Makefiles
|
---|
310 | chapter6_Makefiles
|
---|
311 | chapter789_Makefiles
|
---|
312 |
|
---|
313 |
|
---|
314 | # Add a header, some variables and include the function file
|
---|
315 | # to the top of the real Makefile.
|
---|
316 | (
|
---|
317 | cat << EOF
|
---|
318 | $HEADER
|
---|
319 |
|
---|
320 | SRC= /sources
|
---|
321 | MOUNT_PT= $BUILDDIR
|
---|
322 | PAGE= $PAGE
|
---|
323 | TIMEZONE= $TIMEZONE
|
---|
324 |
|
---|
325 | include makefile-functions
|
---|
326 |
|
---|
327 | EOF
|
---|
328 | ) > $MKFILE
|
---|
329 |
|
---|
330 |
|
---|
331 | # Add chroot commands
|
---|
332 | i=1
|
---|
333 | for file in chapter06/*chroot* ; do
|
---|
334 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
335 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
|
---|
336 | -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
|
---|
337 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
338 | i=`expr $i + 1`
|
---|
339 | done
|
---|
340 |
|
---|
341 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
342 | # as a dependency.
|
---|
343 | (
|
---|
344 | cat << EOF
|
---|
345 | all: chapter4 chapter5 chapter6 chapter789
|
---|
346 | @\$(call echo_finished,$VERSION)
|
---|
347 |
|
---|
348 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
349 |
|
---|
350 | chapter5: chapter4 $chapter5 restore-lfs-env
|
---|
351 |
|
---|
352 | chapter6: chapter5 $chapter6
|
---|
353 |
|
---|
354 | chapter789: chapter6 $chapter789
|
---|
355 |
|
---|
356 | clean-all: clean
|
---|
357 | rm -rf ./{lfs-commands,logs,Makefile,dump-lfs-scripts.xsl,functions,packages,patches}
|
---|
358 |
|
---|
359 | clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
|
---|
360 |
|
---|
361 | clean-chapter4:
|
---|
362 | -if [ ! -f user-lfs-exist ]; then \\
|
---|
363 | userdel lfs; \\
|
---|
364 | rm -rf /home/lfs; \\
|
---|
365 | fi;
|
---|
366 | rm -rf \$(MOUNT_PT)/tools
|
---|
367 | rm -f /tools
|
---|
368 | rm -f envars user-lfs-exist
|
---|
369 | rm -f 02* logs/02*.log
|
---|
370 |
|
---|
371 | clean-chapter5:
|
---|
372 | rm -rf \$(MOUNT_PT)/tools/*
|
---|
373 | rm -f $chapter5 restore-lfs-env sources-dir
|
---|
374 | cd logs && rm -f $chapter5 && cd ..
|
---|
375 |
|
---|
376 | clean-chapter6:
|
---|
377 | -umount \$(MOUNT_PT)/sys
|
---|
378 | -umount \$(MOUNT_PT)/proc
|
---|
379 | -umount \$(MOUNT_PT)/dev/shm
|
---|
380 | -umount \$(MOUNT_PT)/dev/pts
|
---|
381 | -umount \$(MOUNT_PT)/dev
|
---|
382 | rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
|
---|
383 | rm -f $chapter6
|
---|
384 | cd logs && rm -f $chapter6 && cd ..
|
---|
385 |
|
---|
386 | clean-chapter789:
|
---|
387 | rm -f $chapter789
|
---|
388 | cd logs && rm -f $chapter789 && cd ..
|
---|
389 |
|
---|
390 | restore-lfs-env:
|
---|
391 | @\$(call echo_message, Building)
|
---|
392 | @if [ -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
393 | mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
|
---|
394 | fi;
|
---|
395 | @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
396 | mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
|
---|
397 | fi;
|
---|
398 | @chown lfs:lfs /home/lfs/.bash* && \\
|
---|
399 | touch \$@
|
---|
400 |
|
---|
401 | EOF
|
---|
402 | ) >> $MKFILE
|
---|
403 |
|
---|
404 | # Bring over the items from the Makefile.tmp
|
---|
405 | cat $MKFILE.tmp >> $MKFILE
|
---|
406 | rm $MKFILE.tmp
|
---|
407 | echo -ne "done\n"
|
---|
408 | }
|
---|
409 |
|
---|
410 |
|
---|