1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | #=== MAKEFILE HEADER ===
|
---|
6 |
|
---|
7 | #----------------------------------#
|
---|
8 | wrt_Makefile_header() { #
|
---|
9 | #----------------------------------#
|
---|
10 | (
|
---|
11 | cat << EOF
|
---|
12 | # This file is automatically generated by jhalfs
|
---|
13 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
14 | #
|
---|
15 | # Generated on `date "+%F %X %Z"`
|
---|
16 |
|
---|
17 |
|
---|
18 | SHELL = /bin/bash
|
---|
19 |
|
---|
20 | SRC = /sources
|
---|
21 | MOUNT_PT = $BUILDDIR
|
---|
22 | PKG_LST = $PKG_LST
|
---|
23 | LUSER = $LUSER
|
---|
24 | LGROUP = $LGROUP
|
---|
25 | LHOME = $LHOME
|
---|
26 | SCRIPT_ROOT = $SCRIPT_ROOT
|
---|
27 |
|
---|
28 | BASEDIR = \$(MOUNT_PT)
|
---|
29 | SRCSDIR = \$(BASEDIR)/sources
|
---|
30 | CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
31 | LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$LOGDIRBASE
|
---|
32 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
|
---|
33 |
|
---|
34 | crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
35 | crLOGDIR = /\$(SCRIPT_ROOT)/$LOGDIRBASE
|
---|
36 | crTESTLOGDIR = /\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
|
---|
37 | crFILELOGDIR = /\$(SCRIPT_ROOT)/$FILELOGDIRBASE
|
---|
38 |
|
---|
39 | SU_LUSER = sudo -u \$(LUSER) -i sh -c
|
---|
40 | LUSER_HOME = \$(LHOME)/\$(LUSER)
|
---|
41 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
|
---|
42 | PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found --exclude /var/lib / \`\n"
|
---|
43 |
|
---|
44 | ADD_REPORT = $REPORT
|
---|
45 | ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
|
---|
46 | ADD_BLFS_TOOLS = $BLFS_TOOL
|
---|
47 | PKGMNGT = $PKGMNGT
|
---|
48 |
|
---|
49 |
|
---|
50 | export PATH := \${PATH}:/usr/sbin
|
---|
51 |
|
---|
52 | include makefile-functions
|
---|
53 |
|
---|
54 | EOF
|
---|
55 | ) > $MKFILE
|
---|
56 | }
|
---|
57 |
|
---|
58 | #=======================
|
---|
59 |
|
---|
60 |
|
---|
61 | #==== PACKAGES NAMES AND VERSIONS ====
|
---|
62 |
|
---|
63 | #----------------------------------#
|
---|
64 | get_package_tarball_name() { #
|
---|
65 | #----------------------------------#
|
---|
66 | local script_name=`echo ${1} | sed -e 's@^[0-9]\{1\}-@@'`
|
---|
67 |
|
---|
68 | # The use of 'head' is necessary to limit the return value to the FIRST match..
|
---|
69 | # hopefully this will not cause problems.
|
---|
70 | #
|
---|
71 | case $script_name in
|
---|
72 | tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
73 | ;;
|
---|
74 | iputils) echo $(grep "^iputils" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
75 | ;;
|
---|
76 | powerpc-utils) echo $(grep "^powerpc-utils" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
77 | ;;
|
---|
78 | uClibc)
|
---|
79 | if [[ "${PROGNAME}" = "clfs3" ]]; then
|
---|
80 | echo $(grep "^uClibc-" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
81 | else
|
---|
82 | echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
83 | fi
|
---|
84 | ;;
|
---|
85 | linux-headers)
|
---|
86 | if [[ "${PROGNAME}" = "lfs" ]] || [[ "${PROGNAME}" = "hlfs" ]] || [[ "${PROGNAME}" = "clfs" ]]; then
|
---|
87 | # Uses kernel headers directly
|
---|
88 | echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
89 | else
|
---|
90 | # CLFS{2,3} used to use massaged headers package
|
---|
91 | # echo $(grep "^linux-headers-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
92 | echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
93 | fi
|
---|
94 | ;;
|
---|
95 | expect) echo $(grep "^expect" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
96 | ;;
|
---|
97 | e2fsprogs-libs) echo $(grep "^e2fsprogs" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
98 | ;;
|
---|
99 | libcap) echo $(grep "^libcap" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
100 | ;;
|
---|
101 | util-linux-libs | util-linux-pass1) echo $(grep "^util-linux" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
102 | ;;
|
---|
103 | xz-utils) echo $(grep "^xz" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
104 | ;;
|
---|
105 | sqlite) echo $(grep "^sqlite" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
106 | ;;
|
---|
107 | udev) echo $(grep "^systemd" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
108 | ;;
|
---|
109 | xml-parser) echo $(grep "^XML" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
110 | ;;
|
---|
111 | libdbus) echo $(grep "^dbus" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
112 | ;;
|
---|
113 | glibc) echo $(grep "^glibc" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
114 | ;;
|
---|
115 | *) echo $(grep "^$script_name[_-][[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
116 | ;;
|
---|
117 | esac
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | #----------------------------------#
|
---|
122 | get_package_version() { #
|
---|
123 | #----------------------------------#
|
---|
124 | # Those hacks may change depending on the invention of devs for tarball names.
|
---|
125 | # Normally, we expect -digit to signal the beginning of the version field
|
---|
126 | # but it may happen that there is no '-' (tcl, expect), that the version
|
---|
127 | # field is ddd-d (pkg-config-lite-028-1, since sed is greedy, it finds only
|
---|
128 | # the second dash) or that the first character of the version is not a digit
|
---|
129 | # (iputils-s20121221)...
|
---|
130 | case ${1} in
|
---|
131 | tcl*|expect*|tzdata*|xmlts*|unzip*|lynx*)
|
---|
132 | echo ${1} | sed -e 's@^[^[:digit:]]*@@' \
|
---|
133 | -e 's@\(-src\)*\.tar.*@@'
|
---|
134 | ;;
|
---|
135 | iputils*) echo ${1} | sed -e 's@^.*-@@' \
|
---|
136 | -e 's@\.tar.*@@'
|
---|
137 | ;;
|
---|
138 | glibc*) echo ${1} | sed -e 's@^[^-]*-@@' \
|
---|
139 | -e 's@\.tar.*@@'
|
---|
140 | ;;
|
---|
141 | LVM*) echo ${1} | sed -e 's@^[^.]*\.@@' \
|
---|
142 | -e 's@\.tgz.*@@'
|
---|
143 | ;;
|
---|
144 | iproute*) echo ${1} | sed -e 's@^[^-]*-@@' \
|
---|
145 | -e 's@\.tar.*@@'
|
---|
146 | ;;
|
---|
147 | pkg*|udev*|Singular*|XML*)
|
---|
148 | echo ${1} | sed -e 's@^.*[a-z]-\([[:digit:]]\)@\1@' \
|
---|
149 | -e 's@\.tar.*@@' \
|
---|
150 | -e 's@\.zip.*@@'
|
---|
151 | ;;
|
---|
152 | *) echo ${1} | sed -e 's@^.*[-_]\([[:digit:]]\)@\1@' \
|
---|
153 | -e 's@\.tar.*@@' \
|
---|
154 | -e 's@\.zip.*@@'
|
---|
155 | ;;
|
---|
156 | esac
|
---|
157 |
|
---|
158 | }
|
---|
159 | #=======================
|
---|
160 |
|
---|
161 |
|
---|
162 | #==== TARGET HEADER ====
|
---|
163 |
|
---|
164 | #----------------------------------#
|
---|
165 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
166 | #----------------------------------#
|
---|
167 | local i=$1
|
---|
168 | local PREV=$2
|
---|
169 | local version
|
---|
170 | if [ "$3" != "" ]; then
|
---|
171 | version=-$3
|
---|
172 | fi
|
---|
173 | (
|
---|
174 | cat << EOF
|
---|
175 |
|
---|
176 | $i: $PREV
|
---|
177 | @\$(call echo_message, Building)
|
---|
178 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
179 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
|
---|
180 | @\$(PRT_DU) >>logs/\$@$version
|
---|
181 | EOF
|
---|
182 | ) >> $MKFILE.tmp
|
---|
183 | }
|
---|
184 |
|
---|
185 | #----------------------------------#
|
---|
186 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
187 | #----------------------------------#
|
---|
188 | local i=$1
|
---|
189 | local PREV=$2
|
---|
190 | local version
|
---|
191 | if [ "$3" != "" ]; then
|
---|
192 | version=-$3
|
---|
193 | fi
|
---|
194 | (
|
---|
195 | cat << EOF
|
---|
196 |
|
---|
197 | $i: $PREV
|
---|
198 | @\$(call echo_message, Building)
|
---|
199 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
200 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
|
---|
201 | @\$(PRT_DU_CR) >>logs/\$@$version
|
---|
202 | EOF
|
---|
203 | ) >> $MKFILE.tmp
|
---|
204 | }
|
---|
205 |
|
---|
206 | #=======================
|
---|
207 |
|
---|
208 |
|
---|
209 | #======== UNPACK =======
|
---|
210 |
|
---|
211 | #----------------------------------#
|
---|
212 | LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
213 | #----------------------------------#
|
---|
214 | local FILE=$1
|
---|
215 | local optSAVE_PREVIOUS=$2
|
---|
216 |
|
---|
217 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
218 | (
|
---|
219 | cat << EOF
|
---|
220 | @\$(call remove_existing_dirs,$FILE)
|
---|
221 | EOF
|
---|
222 | ) >> $MKFILE.tmp
|
---|
223 | fi
|
---|
224 |
|
---|
225 | (
|
---|
226 | cat << EOF
|
---|
227 | @\$(call unpack,$FILE)
|
---|
228 | @\$(call get_pkg_root_LUSER)
|
---|
229 | EOF
|
---|
230 | ) >> $MKFILE.tmp
|
---|
231 | }
|
---|
232 |
|
---|
233 | #----------------------------------#
|
---|
234 | CHROOT_Unpack() { #
|
---|
235 | #----------------------------------#
|
---|
236 | local FILE=$1
|
---|
237 | local optSAVE_PREVIOUS=$2
|
---|
238 |
|
---|
239 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
240 | (
|
---|
241 | cat << EOF
|
---|
242 | @\$(call remove_existing_dirs2,$FILE)
|
---|
243 | EOF
|
---|
244 | ) >> $MKFILE.tmp
|
---|
245 | fi
|
---|
246 | (
|
---|
247 | cat << EOF
|
---|
248 | @\$(call unpack2,$FILE)
|
---|
249 | @\$(call get_pkg_root2)
|
---|
250 | EOF
|
---|
251 | ) >> $MKFILE.tmp
|
---|
252 | }
|
---|
253 |
|
---|
254 | #=======================
|
---|
255 |
|
---|
256 |
|
---|
257 | #===== TESTS LOGS ======
|
---|
258 |
|
---|
259 | #----------------------------------#
|
---|
260 | LUSER_wrt_test_log() { # Initialize testsuite log file
|
---|
261 | #----------------------------------#
|
---|
262 | local version
|
---|
263 | if [ "$2" != "" ]; then
|
---|
264 | version=-$2
|
---|
265 | fi
|
---|
266 | local TESTLOGFILE=$1$version
|
---|
267 | (
|
---|
268 | cat << EOF
|
---|
269 | @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
270 | echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
|
---|
271 | EOF
|
---|
272 | ) >> $MKFILE.tmp
|
---|
273 | }
|
---|
274 |
|
---|
275 | #----------------------------------#
|
---|
276 | CHROOT_wrt_test_log() { #
|
---|
277 | #----------------------------------#
|
---|
278 | local version
|
---|
279 | if [ "$2" != "" ]; then
|
---|
280 | version=-$2
|
---|
281 | fi
|
---|
282 | local TESTLOGFILE=$1$version
|
---|
283 | (
|
---|
284 | cat << EOF
|
---|
285 | @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
286 | echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
|
---|
287 | EOF
|
---|
288 | ) >> $MKFILE.tmp
|
---|
289 | }
|
---|
290 |
|
---|
291 | #=======================
|
---|
292 |
|
---|
293 |
|
---|
294 | #======== RUN AS =======
|
---|
295 |
|
---|
296 | #----------------------------------#
|
---|
297 | wrt_RunAsRoot() { # Some scripts must be run as root..
|
---|
298 | #----------------------------------#
|
---|
299 | local MOUNT_ENV
|
---|
300 | local version
|
---|
301 | if [ "$2" != "" ]; then
|
---|
302 | version=-$2
|
---|
303 | fi
|
---|
304 | local file=$1
|
---|
305 |
|
---|
306 | case ${PROGNAME} in
|
---|
307 | lfs ) MOUNT_ENV="LFS" ;;
|
---|
308 | clfs ) MOUNT_ENV="CLFS" ;;
|
---|
309 | clfs2 ) MOUNT_ENV="CLFS" ;;
|
---|
310 | clfs3 ) MOUNT_ENV="CLFS" ;;
|
---|
311 | hlfs ) MOUNT_ENV="HLFS" ;;
|
---|
312 | *) echo "undefined progname $PROGNAME"; exit 1 ;;
|
---|
313 | esac
|
---|
314 |
|
---|
315 | (
|
---|
316 | cat << EOF
|
---|
317 | @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
|
---|
318 | ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
|
---|
319 | \$(PRT_DU) >>logs/\$@$version
|
---|
320 | EOF
|
---|
321 | ) >> $MKFILE.tmp
|
---|
322 | }
|
---|
323 |
|
---|
324 | #----------------------------------#
|
---|
325 | LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
|
---|
326 | #----------------------------------#
|
---|
327 | local file=$1
|
---|
328 | local version
|
---|
329 | if [ "$2" != "" ]; then
|
---|
330 | version=-$2
|
---|
331 | fi
|
---|
332 |
|
---|
333 | (
|
---|
334 | cat << EOF
|
---|
335 | @source ~/.bashrc && \\
|
---|
336 | \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
|
---|
337 | \$(PRT_DU) >>logs/\$@$version
|
---|
338 | EOF
|
---|
339 | ) >> $MKFILE.tmp
|
---|
340 | }
|
---|
341 |
|
---|
342 | #----------------------------------#
|
---|
343 | CHROOT_wrt_RunAsRoot() { #
|
---|
344 | #----------------------------------#
|
---|
345 | local file=$1
|
---|
346 | local version
|
---|
347 | if [ "$2" != "" ]; then
|
---|
348 | version=-$2
|
---|
349 | fi
|
---|
350 | (
|
---|
351 | cat << EOF
|
---|
352 | @source envars && \\
|
---|
353 | \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
|
---|
354 | \$(PRT_DU_CR) >>logs/\$@$version
|
---|
355 | EOF
|
---|
356 | ) >> $MKFILE.tmp
|
---|
357 |
|
---|
358 | }
|
---|
359 |
|
---|
360 | #=======================
|
---|
361 |
|
---|
362 |
|
---|
363 | #====== COPY FSTAB =====
|
---|
364 |
|
---|
365 | #----------------------------------#
|
---|
366 | LUSER_wrt_CopyFstab() { #
|
---|
367 | #----------------------------------#
|
---|
368 | (
|
---|
369 | cat << EOF
|
---|
370 | @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
371 | \$(PRT_DU) >>logs/\$@
|
---|
372 | EOF
|
---|
373 | ) >> $MKFILE.tmp
|
---|
374 | }
|
---|
375 |
|
---|
376 | #----------------------------------#
|
---|
377 | CHROOT_wrt_CopyFstab() { #
|
---|
378 | #----------------------------------#
|
---|
379 | (
|
---|
380 | cat << EOF
|
---|
381 | @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
382 | \$(PRT_DU_CR) >>logs/\$@
|
---|
383 | EOF
|
---|
384 | ) >> $MKFILE.tmp
|
---|
385 | }
|
---|
386 |
|
---|
387 | #=======================
|
---|
388 |
|
---|
389 |
|
---|
390 | #==== INSTALLED FILES LOGS ====
|
---|
391 |
|
---|
392 | #----------------------------------#
|
---|
393 | LUSER_wrt_TouchTimestamp() { #
|
---|
394 | #----------------------------------#
|
---|
395 | (
|
---|
396 | cat << EOF
|
---|
397 | @\$(call touch_timestamp_LUSER)
|
---|
398 | EOF
|
---|
399 | ) >> $MKFILE.tmp
|
---|
400 | }
|
---|
401 |
|
---|
402 | #----------------------------------#
|
---|
403 | CHROOT_wrt_TouchTimestamp() { #
|
---|
404 | #----------------------------------#
|
---|
405 | (
|
---|
406 | cat << EOF
|
---|
407 | @\$(call touch_timestamp)
|
---|
408 | EOF
|
---|
409 | ) >> $MKFILE.tmp
|
---|
410 | }
|
---|
411 |
|
---|
412 | #----------------------------------#
|
---|
413 | LUSER_wrt_LogNewFiles() { #
|
---|
414 | #----------------------------------#
|
---|
415 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
416 | (
|
---|
417 | cat << EOF
|
---|
418 | @\$(call log_new_files_LUSER,$name)
|
---|
419 | EOF
|
---|
420 | ) >> $MKFILE.tmp
|
---|
421 | }
|
---|
422 |
|
---|
423 | #----------------------------------#
|
---|
424 | CHROOT_wrt_LogNewFiles() { #
|
---|
425 | #----------------------------------#
|
---|
426 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
427 | (
|
---|
428 | cat << EOF
|
---|
429 | @\$(call log_new_files,$name)
|
---|
430 | EOF
|
---|
431 | ) >> $MKFILE.tmp
|
---|
432 | }
|
---|
433 |
|
---|
434 | #=======================
|
---|
435 |
|
---|
436 |
|
---|
437 | #==== RM BUILD DIRS ====
|
---|
438 |
|
---|
439 | #----------------------------------#
|
---|
440 | LUSER_RemoveBuildDirs() { #
|
---|
441 | #----------------------------------#
|
---|
442 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
443 | (
|
---|
444 | cat << EOF
|
---|
445 | @\$(call remove_build_dirs,$name)
|
---|
446 | EOF
|
---|
447 | ) >> $MKFILE.tmp
|
---|
448 | }
|
---|
449 |
|
---|
450 | #----------------------------------#
|
---|
451 | CHROOT_wrt_RemoveBuildDirs() { #
|
---|
452 | #----------------------------------#
|
---|
453 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
454 | (
|
---|
455 | cat << EOF
|
---|
456 | @\$(call remove_build_dirs2,$name)
|
---|
457 | EOF
|
---|
458 | ) >> $MKFILE.tmp
|
---|
459 | }
|
---|
460 |
|
---|
461 | #=======================
|
---|
462 |
|
---|
463 |
|
---|
464 | #======== TOUCH ========
|
---|
465 |
|
---|
466 | #----------------------------------#
|
---|
467 | wrt_touch() { #
|
---|
468 | #----------------------------------#
|
---|
469 | (
|
---|
470 | cat << EOF
|
---|
471 | @\$(call housekeeping)
|
---|
472 | EOF
|
---|
473 | ) >> $MKFILE.tmp
|
---|
474 | }
|
---|
475 |
|
---|
476 | #=======================
|
---|