1 | #!/bin/sh
|
---|
2 | # $Id$
|
---|
3 |
|
---|
4 | ###################################
|
---|
5 | ### FUNCTIONS ###
|
---|
6 | ###################################
|
---|
7 |
|
---|
8 |
|
---|
9 | #----------------------------#
|
---|
10 | host_prep_Makefiles() { # Initialization of the system
|
---|
11 | #----------------------------#
|
---|
12 | local CLFS_HOST
|
---|
13 |
|
---|
14 | echo "${tab_}${GREEN}Processing... ${L_arrow}host prep files ( SETUP ) ${R_arrow}"
|
---|
15 |
|
---|
16 | # defined here, only for ease of reading
|
---|
17 | CLFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
|
---|
18 | (
|
---|
19 | cat << EOF
|
---|
20 | 023-creatingtoolsdir:
|
---|
21 | @\$(call echo_message, Building)
|
---|
22 | @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
|
---|
23 | mkdir \$(MOUNT_PT)/sources; \\
|
---|
24 | fi;
|
---|
25 | @chmod a+wt \$(MOUNT_PT)/sources
|
---|
26 | @touch \$@ && \\
|
---|
27 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
28 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
29 |
|
---|
30 | 025-addinguser: 023-creatingtoolsdir
|
---|
31 | @\$(call echo_message, Building)
|
---|
32 | @if [ ! -d /home/\$(LUSER) ]; then \\
|
---|
33 | groupadd \$(LGROUP); \\
|
---|
34 | useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
|
---|
35 | else \\
|
---|
36 | touch luser-exist; \\
|
---|
37 | fi;
|
---|
38 | @chown -R \$(LUSER) \$(MOUNT_PT) && \\
|
---|
39 | chown \$(LUSER) \$(MOUNT_PT)/sources
|
---|
40 | @touch \$@ && \\
|
---|
41 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
42 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
43 |
|
---|
44 | 026-settingenvironment: 025-addinguser
|
---|
45 | @\$(call echo_message, Building)
|
---|
46 | @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
47 | mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
|
---|
48 | fi;
|
---|
49 | @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
50 | mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
|
---|
51 | fi;
|
---|
52 | @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
|
---|
53 | echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
|
---|
54 | echo "CLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
|
---|
55 | echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
|
---|
56 | echo "PATH=\$(MOUNT_PT)/cross-tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
|
---|
57 | echo "export CLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
|
---|
58 | echo "" >> /home/\$(LUSER)/.bashrc && \\
|
---|
59 | echo "unset CFLAGS" >> /home/\$(LUSER)/.bashrc && \\
|
---|
60 | echo "unset CXXFLAGS" >> /home/\$(LUSER)/.bashrc && \\
|
---|
61 | echo "" >> /home/\$(LUSER)/.bashrc && \\
|
---|
62 | echo "export CLFS_HOST=\"${CLFS_HOST}\"" >> /home/\$(LUSER)/.bashrc && \\
|
---|
63 | echo "export CLFS_TARGET=\"${TARGET}\"" >> /home/\$(LUSER)/.bashrc && \\
|
---|
64 | echo "export CLFS_TARGET32=\"${TARGET32}\"" >> /home/\$(LUSER)/.bashrc && \\
|
---|
65 | echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc
|
---|
66 | @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
|
---|
67 | touch envars && \\
|
---|
68 | chown \$(LUSER):\$(LGROUP) envars && \\
|
---|
69 | chmod -R a+wt \$(MOUNT_PT)
|
---|
70 | @touch \$@ && \\
|
---|
71 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
72 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
73 |
|
---|
74 | 027-create-directories: 026-settingenvironment
|
---|
75 | @\$(call echo_message, Building)
|
---|
76 |
|
---|
77 | @mkdir -p \$(MOUNT_PT)/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
|
---|
78 | @mkdir -p \$(MOUNT_PT)/{proc,media/{floppy,cdrom},sbin,srv,sys}
|
---|
79 | @mkdir -p \$(MOUNT_PT)/var/{lock,log,mail,run,spool}
|
---|
80 | @mkdir -p \$(MOUNT_PT)/var/{opt,cache,lib/{misc,locate},local}
|
---|
81 | @install -d -m 0750 \$(MOUNT_PT)/root
|
---|
82 | @install -d -m 1777 \$(MOUNT_PT){/var,}/tmp
|
---|
83 | @mkdir -p \$(MOUNT_PT)/usr/{,local/}{bin,include,lib,sbin,src}
|
---|
84 | @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{doc,info,locale,man}
|
---|
85 | @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/{misc,terminfo,zoneinfo}
|
---|
86 | @mkdir -p \$(MOUNT_PT)/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
|
---|
87 | @for dir in \$(MOUNT_PT)/usr{,/local}; do \\
|
---|
88 | ln -s share/{man,doc,info} \$\$dir ; \\
|
---|
89 | done
|
---|
90 |
|
---|
91 | @touch \$@ && \\
|
---|
92 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
93 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
94 |
|
---|
95 | 028-creating-sysfile: 027-create-directories
|
---|
96 | @\$(call echo_message, Building)
|
---|
97 |
|
---|
98 | @touch \$(MOUNT_PT)/etc/mtab
|
---|
99 | @echo "root::0:0:root:/root:/bin/bash" >> \$(MOUNT_PT)/etc/passwd
|
---|
100 | @echo "root:x:0:" >> \$(MOUNT_PT)/etc/group
|
---|
101 | @echo "bin:x:1:" >> \$(MOUNT_PT)/etc/group
|
---|
102 | @echo "sys:x:2:" >> \$(MOUNT_PT)/etc/group
|
---|
103 | @echo "kmem:x:3" >> \$(MOUNT_PT)/etc/group
|
---|
104 | @echo "tty:x:4:" >> \$(MOUNT_PT)/etc/group
|
---|
105 | @echo "tape:x:5:" >> \$(MOUNT_PT)/etc/group
|
---|
106 | @echo "daemon:x:6:" >> \$(MOUNT_PT)/etc/group
|
---|
107 | @echo "floppy:x:7:" >> \$(MOUNT_PT)/etc/group
|
---|
108 | @echo "disk:x:8:" >> \$(MOUNT_PT)/etc/group
|
---|
109 | @echo "lp:x:9:" >> \$(MOUNT_PT)/etc/group
|
---|
110 | @echo "dialout:x:10:" >> \$(MOUNT_PT)/etc/group
|
---|
111 | @echo "audio:x:11:" >> \$(MOUNT_PT)/etc/group
|
---|
112 | @echo "video:x:12:" >> \$(MOUNT_PT)/etc/group
|
---|
113 | @echo "utmp:x:13:" >> \$(MOUNT_PT)/etc/group
|
---|
114 | @echo "usb:x:14:" >> \$(MOUNT_PT)/etc/group
|
---|
115 | @echo "cdrom:x:15:" >> \$(MOUNT_PT)/etc/group
|
---|
116 |
|
---|
117 | @touch \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/{btmp,lastlog,wtmp}
|
---|
118 | @chmod 664 \$(MOUNT_PT)/var/run/utmp \$(MOUNT_PT)/var/log/lastlog
|
---|
119 | @chown -R \$(LUSER) \$(MOUNT_PT)
|
---|
120 |
|
---|
121 | @touch \$@ && \\
|
---|
122 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
123 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
124 |
|
---|
125 | EOF
|
---|
126 | ) >> $MKFILE.tmp
|
---|
127 |
|
---|
128 | host_prep=" 023-creatingtoolsdir 025-addinguser 026-settingenvironment 027-create-directories 028-creating-sysfile"
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | #-----------------------------#
|
---|
133 | cross_tools_Makefiles() { #
|
---|
134 | #-----------------------------#
|
---|
135 | echo "${tab_}${GREEN}Processing... ${L_arrow}cross tools ( LUSER ) ${R_arrow}"
|
---|
136 |
|
---|
137 | for file in cross-tools/* ; do
|
---|
138 | # Keep the script file name
|
---|
139 | this_script=`basename $file`
|
---|
140 | #
|
---|
141 | # Skip this script...
|
---|
142 | # NOTE.. the book indicated you only needed to install groff or file if the host
|
---|
143 | # had older versions. The packages would be installed in the target directory
|
---|
144 | # and not the host.
|
---|
145 | case $this_script in
|
---|
146 | *cflags* | *variables* ) # work done in host_prep_Makefiles
|
---|
147 | continue ;;
|
---|
148 | *) ;;
|
---|
149 | esac
|
---|
150 |
|
---|
151 | #
|
---|
152 | # Set the dependency for the first target.
|
---|
153 | if [ -z $PREV ] ; then PREV=028-creating-sysfile ; fi
|
---|
154 |
|
---|
155 | # First append each name of the script files to a list (this will become
|
---|
156 | # the names of the targets in the Makefile)
|
---|
157 | cross_tools="$cross_tools $this_script"
|
---|
158 |
|
---|
159 | # Grab the name of the target (minus the -headers or -cross in the case of gcc
|
---|
160 | # and binutils in chapter 5)
|
---|
161 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
|
---|
162 | -e 's@-static@@' \
|
---|
163 | -e 's@-final@@' \
|
---|
164 | -e 's@-64@@' \
|
---|
165 | -e 's@-n32@@'`
|
---|
166 | case $name in
|
---|
167 | uclibc*) name="uClibc" ;;
|
---|
168 | esac
|
---|
169 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
170 | #--------------------------------------------------------------------#
|
---|
171 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
172 | #--------------------------------------------------------------------#
|
---|
173 | #
|
---|
174 | # Drop in the name of the target on a new line, and the previous target
|
---|
175 | # as a dependency. Also call the echo_message function.
|
---|
176 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
177 | #
|
---|
178 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
179 | if [ "$pkg_tarball" != "" ] ; then
|
---|
180 | LUSER_wrt_unpack "$pkg_tarball"
|
---|
181 | # If using optimizations, write the instructions
|
---|
182 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
183 | fi
|
---|
184 | #
|
---|
185 | LUSER_wrt_RunAsUser "${file}"
|
---|
186 | #
|
---|
187 | [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
|
---|
188 | #
|
---|
189 | # Include a touch of the target name so make can check if it's already been made.
|
---|
190 | wrt_touch
|
---|
191 | #
|
---|
192 | #--------------------------------------------------------------------#
|
---|
193 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
194 | #--------------------------------------------------------------------#
|
---|
195 | #
|
---|
196 | # Keep the script file name for Makefile dependencies.
|
---|
197 | PREV=$this_script
|
---|
198 |
|
---|
199 | done # for file in ....
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | #-----------------------------#
|
---|
205 | final_system_Makefiles() { #
|
---|
206 | #-----------------------------#
|
---|
207 | echo "${tab_}${GREEN}Processing... ${L_arrow}final system ( LUSER ) ${R_arrow}"
|
---|
208 |
|
---|
209 | for file in final-system/* ; do
|
---|
210 | # Keep the script file name
|
---|
211 | this_script=`basename $file`
|
---|
212 |
|
---|
213 | # Test if the stripping phase must be skipped.
|
---|
214 | # Skip alsp temp-perl for iterative runs
|
---|
215 | case $this_script in
|
---|
216 | *stripping*) [[ "$STRIP" = "n" ]] && continue ;;
|
---|
217 | esac
|
---|
218 |
|
---|
219 | # Grab the name of the target, strip id number, XXX-script
|
---|
220 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
|
---|
221 | -e 's@temp-@@' \
|
---|
222 | -e 's@-64bit@@' \
|
---|
223 | -e 's@-64@@' \
|
---|
224 | -e 's@64@@' \
|
---|
225 | -e 's@n32@@'`
|
---|
226 |
|
---|
227 | # Find the version of the command files, if it corresponds with the building of
|
---|
228 | # a specific package.
|
---|
229 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
230 |
|
---|
231 | # Append each name of the script files to a list (this will become
|
---|
232 | # the names of the targets in the Makefile
|
---|
233 | basicsystem="$basicsystem ${this_script}"
|
---|
234 |
|
---|
235 | #--------------------------------------------------------------------#
|
---|
236 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
237 | #--------------------------------------------------------------------#
|
---|
238 | #
|
---|
239 | # Drop in the name of the target on a new line, and the previous target
|
---|
240 | # as a dependency. Also call the echo_message function.
|
---|
241 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
242 | #
|
---|
243 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
244 | if [ "$pkg_tarball" != "" ] ; then
|
---|
245 | LUSER_wrt_unpack "$pkg_tarball"
|
---|
246 | # If using optimizations, write the instructions
|
---|
247 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
248 | fi
|
---|
249 | #
|
---|
250 | LUSER_wrt_RunAsUser "${file}"
|
---|
251 | #
|
---|
252 | [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
|
---|
253 | #
|
---|
254 | # Include a touch of the target name so make can check if it's already been made.
|
---|
255 | wrt_touch
|
---|
256 | #
|
---|
257 | #--------------------------------------------------------------------#
|
---|
258 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
259 | #--------------------------------------------------------------------#
|
---|
260 | #
|
---|
261 | # Keep the script file name for Makefile dependencies.
|
---|
262 | PREV=${this_script}
|
---|
263 | done # for file in final-system/* ...
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 | #-----------------------------#
|
---|
269 | bootscripts_Makefiles() { #
|
---|
270 | #-----------------------------#
|
---|
271 | echo "${tab_}${GREEN}Processing... ${L_arrow}bootscripts ( LUSER ) ${R_arrow}"
|
---|
272 |
|
---|
273 | for file in bootscripts/* ; do
|
---|
274 | # Keep the script file name
|
---|
275 | this_script=`basename $file`
|
---|
276 |
|
---|
277 | case $this_script in
|
---|
278 | *udev) continue ;; # This is not a script but a commentary, we want udev-rules
|
---|
279 | *console*) continue ;; # Use the files that came with the bootscripts
|
---|
280 | *network*) continue ;; # Manually create these files
|
---|
281 | *) ;;
|
---|
282 | esac
|
---|
283 |
|
---|
284 | # First append each name of the script files to a list (this will become
|
---|
285 | # the names of the targets in the Makefile
|
---|
286 | bootscripttools="$bootscripttools $this_script"
|
---|
287 |
|
---|
288 | # Grab the name of the target, strip id number, XXX-script
|
---|
289 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'\
|
---|
290 | -e 's@-64bit@@' \
|
---|
291 | -e 's@-64@@' \
|
---|
292 | -e 's@64@@' \
|
---|
293 | -e 's@n32@@'`
|
---|
294 | case $name in
|
---|
295 | *bootscripts*) name=bootscripts-cross-lfs ;;
|
---|
296 | *udev-rules) name=udev-cross-lfs ;;
|
---|
297 | esac
|
---|
298 |
|
---|
299 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
300 |
|
---|
301 | #--------------------------------------------------------------------#
|
---|
302 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
303 | #--------------------------------------------------------------------#
|
---|
304 | #
|
---|
305 | # Drop in the name of the target on a new line, and the previous target
|
---|
306 | # as a dependency. Also call the echo_message function.
|
---|
307 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
308 | #
|
---|
309 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
310 | [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
|
---|
311 | #
|
---|
312 | LUSER_wrt_RunAsUser "${file}"
|
---|
313 | #
|
---|
314 | [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
|
---|
315 | #
|
---|
316 | # Include a touch of the target name so make can check if it's already been made.
|
---|
317 | wrt_touch
|
---|
318 | #
|
---|
319 | #--------------------------------------------------------------------#
|
---|
320 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
321 | #--------------------------------------------------------------------#
|
---|
322 | #
|
---|
323 | # Keep the script file name for Makefile dependencies.
|
---|
324 | PREV=$this_script
|
---|
325 |
|
---|
326 | done # for file in bootscripts/* ...
|
---|
327 |
|
---|
328 | }
|
---|
329 |
|
---|
330 |
|
---|
331 | #-----------------------------#
|
---|
332 | bootable_Makefiles() { #
|
---|
333 | #-----------------------------#
|
---|
334 | echo "${tab_}${GREEN}Processing... ${L_arrow}make bootable ( LUSER ) ${R_arrow}"
|
---|
335 |
|
---|
336 | for file in bootable/* ; do
|
---|
337 | # Keep the script file name
|
---|
338 | this_script=`basename $file`
|
---|
339 |
|
---|
340 | # A little housekeeping on the scripts
|
---|
341 | case $this_script in
|
---|
342 | *grub | *aboot | *colo | *silo | *arcload | *lilo | *reboot* ) continue ;;
|
---|
343 | *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
|
---|
344 | *kernel) # if there is no kernel config file do not build the kernel
|
---|
345 | [[ -z $CONFIG ]] && continue
|
---|
346 | # Copy the config file to /sources with a standardized name
|
---|
347 | cp $CONFIG $BUILDDIR/sources/kernel-config
|
---|
348 | ;;
|
---|
349 | esac
|
---|
350 | #
|
---|
351 | # First append each name of the script files to a list (this will become
|
---|
352 | # the names of the targets in the Makefile
|
---|
353 | # NOTE: new makfile format forces the last script, *chowning, into a separate
|
---|
354 | # phase.
|
---|
355 | case ${this_script} in
|
---|
356 | *chowning) chowning=${this_script} ;;
|
---|
357 | *) bootable="$bootable $this_script" ;;
|
---|
358 | esac
|
---|
359 | #
|
---|
360 | # Grab the name of the target, strip id number and misc words.
|
---|
361 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-build@@' `
|
---|
362 | case $this_script in
|
---|
363 | *kernel*) name=linux
|
---|
364 | ;;
|
---|
365 | esac
|
---|
366 |
|
---|
367 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
368 |
|
---|
369 | #--------------------------------------------------------------------#
|
---|
370 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
371 | #--------------------------------------------------------------------#
|
---|
372 | #
|
---|
373 | # Drop in the name of the target on a new line, and the previous target
|
---|
374 | # as a dependency. Also call the echo_message function.
|
---|
375 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
376 | #
|
---|
377 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
378 | [[ "$pkg_tarball" != "" ]] && LUSER_wrt_unpack "$pkg_tarball"
|
---|
379 | #
|
---|
380 | # Select a script execution method
|
---|
381 | case $this_script in
|
---|
382 | *fstab*) if [[ -n "$FSTAB" ]]; then
|
---|
383 | LUSER_wrt_CopyFstab
|
---|
384 | else
|
---|
385 | LUSER_wrt_RunAsUser "${file}"
|
---|
386 | fi
|
---|
387 | ;;
|
---|
388 | *chowning) wrt_RunAsRoot "${this_script}" "${file}"
|
---|
389 | ;;
|
---|
390 | *) LUSER_wrt_RunAsUser "${file}"
|
---|
391 | ;;
|
---|
392 | esac
|
---|
393 | #
|
---|
394 | # Housekeeping...remove any build directory(ies) except if the package build fails.
|
---|
395 | [[ "$pkg_tarball" != "" ]] && LUSER_RemoveBuildDirs "${name}"
|
---|
396 | #
|
---|
397 | # Include a touch of the target name so make can check if it's already been made.
|
---|
398 | wrt_touch
|
---|
399 | #
|
---|
400 | #--------------------------------------------------------------------#
|
---|
401 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
402 | #--------------------------------------------------------------------#
|
---|
403 | #
|
---|
404 | # Keep the script file name for Makefile dependencies.
|
---|
405 | PREV=$this_script
|
---|
406 |
|
---|
407 | done
|
---|
408 |
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | #-----------------------------#
|
---|
413 | build_Makefile() { # Construct a Makefile from the book scripts
|
---|
414 | #-----------------------------#
|
---|
415 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
416 |
|
---|
417 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
418 | # Start with a clean Makefile.tmp file
|
---|
419 | >$MKFILE.tmp
|
---|
420 |
|
---|
421 | host_prep_Makefiles
|
---|
422 | cross_tools_Makefiles # $cross_tools
|
---|
423 | final_system_Makefiles # $basicsystem
|
---|
424 | bootscripts_Makefiles # $bootscripttools
|
---|
425 | bootable_Makefiles # $bootable
|
---|
426 |
|
---|
427 | # Add a header, some variables and include the function file
|
---|
428 | # to the top of the real Makefile.
|
---|
429 | (
|
---|
430 | cat << EOF
|
---|
431 | $HEADER
|
---|
432 |
|
---|
433 | SRC = /sources
|
---|
434 | MOUNT_PT = $BUILDDIR
|
---|
435 | PKG_LST = $PKG_LST
|
---|
436 | LUSER = $LUSER
|
---|
437 | LGROUP = $LGROUP
|
---|
438 | SCRIPT_ROOT = $SCRIPT_ROOT
|
---|
439 |
|
---|
440 | BASEDIR = \$(MOUNT_PT)
|
---|
441 | SRCSDIR = \$(BASEDIR)/sources
|
---|
442 | CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
443 | LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
|
---|
444 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
|
---|
445 |
|
---|
446 | SU_LUSER = su - \$(LUSER) -c
|
---|
447 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=jhalfs --exclude=lost+found \$(MOUNT_PT)\`\n"
|
---|
448 | LUSER_HOME = /home/\$(LUSER)
|
---|
449 |
|
---|
450 | export PATH := \${PATH}:/usr/sbin
|
---|
451 |
|
---|
452 | include makefile-functions
|
---|
453 |
|
---|
454 | EOF
|
---|
455 | ) > $MKFILE
|
---|
456 |
|
---|
457 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
458 | # as a dependency.
|
---|
459 | (
|
---|
460 | cat << EOF
|
---|
461 |
|
---|
462 | all: ck_UID mk_SETUP mk_LUSER mk_ROOT create-sbu_du-report
|
---|
463 | @sudo make do-housekeeping
|
---|
464 | @\$(call echo_finished,$VERSION)
|
---|
465 |
|
---|
466 | ck_UID:
|
---|
467 | @if [ \`id -u\` = "0" ]; then \\
|
---|
468 | echo "--------------------------------------------------"; \\
|
---|
469 | echo "You cannot run this makefile from the root account"; \\
|
---|
470 | echo "--------------------------------------------------"; \\
|
---|
471 | exit 1; \\
|
---|
472 | fi
|
---|
473 |
|
---|
474 | mk_SETUP:
|
---|
475 | @\$(call echo_SU_request)
|
---|
476 | @sudo make SHELL=/bin/bash SETUP
|
---|
477 | @touch \$@
|
---|
478 |
|
---|
479 | mk_LUSER: mk_SETUP
|
---|
480 | @\$(call echo_SULUSER_request)
|
---|
481 | @(sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
|
---|
482 | @sudo make restore-luser-env
|
---|
483 | @touch \$@
|
---|
484 |
|
---|
485 | mk_ROOT:
|
---|
486 | @sudo make SHELL=/bin/bash ROOT
|
---|
487 | @touch \$@
|
---|
488 |
|
---|
489 | SETUP: $host_prep
|
---|
490 |
|
---|
491 | LUSER: $cross_tools $basicsystem $bootscripttools $bootable
|
---|
492 |
|
---|
493 | ROOT: $chowning
|
---|
494 |
|
---|
495 |
|
---|
496 | restore-luser-env:
|
---|
497 | @\$(call echo_message, Building)
|
---|
498 | @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
499 | mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
|
---|
500 | fi;
|
---|
501 | @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
502 | mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
|
---|
503 | fi;
|
---|
504 | @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
|
---|
505 | touch \$@ && \\
|
---|
506 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
507 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
508 |
|
---|
509 | do-housekeeping:
|
---|
510 | @-if [ ! -f luser-exist ]; then \\
|
---|
511 | userdel \$(LUSER); \\
|
---|
512 | rm -rf /home/\$(LUSER); \\
|
---|
513 | fi;
|
---|
514 |
|
---|
515 | EOF
|
---|
516 | ) >> $MKFILE
|
---|
517 |
|
---|
518 | # Add SBU-disk_usage report target
|
---|
519 | echo "create-sbu_du-report:" >> $MKFILE
|
---|
520 | if [[ "$REPORT" = "y" ]] ; then
|
---|
521 | (
|
---|
522 | cat << EOF
|
---|
523 | @\$(call echo_message, Building)
|
---|
524 | @./create-sbu_du-report.sh logs $VERSION
|
---|
525 | @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
|
---|
526 | @touch \$@
|
---|
527 |
|
---|
528 |
|
---|
529 | EOF
|
---|
530 | ) >> $MKFILE
|
---|
531 | else echo -e "\t@true\n\n" >> $MKFILE; fi
|
---|
532 |
|
---|
533 | # Bring over the items from the Makefile.tmp
|
---|
534 | cat $MKFILE.tmp >> $MKFILE
|
---|
535 | rm $MKFILE.tmp
|
---|
536 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
537 |
|
---|
538 | }
|
---|
539 |
|
---|