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 | libelf) echo $(grep "^elfutils" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
116 | ;;
|
---|
117 | *) echo $(grep "^$script_name[_-][[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
118 | ;;
|
---|
119 | esac
|
---|
120 |
|
---|
121 | }
|
---|
122 |
|
---|
123 | #----------------------------------#
|
---|
124 | get_package_version() { #
|
---|
125 | #----------------------------------#
|
---|
126 | # Those hacks may change depending on the invention of devs for tarball names.
|
---|
127 | # Normally, we expect -digit to signal the beginning of the version field
|
---|
128 | # but it may happen that there is no '-' (tcl, expect), that the version
|
---|
129 | # field is ddd-d (pkg-config-lite-028-1, since sed is greedy, it finds only
|
---|
130 | # the second dash) or that the first character of the version is not a digit
|
---|
131 | # (iputils-s20121221)...
|
---|
132 | case ${1} in
|
---|
133 | tcl*|expect*|tzdata*|xmlts*|unzip*|lynx*)
|
---|
134 | echo ${1} | sed -e 's@^[^[:digit:]]*@@' \
|
---|
135 | -e 's@\(-src\)*\.tar.*@@'
|
---|
136 | ;;
|
---|
137 | iputils*) echo ${1} | sed -e 's@^.*-@@' \
|
---|
138 | -e 's@\.tar.*@@'
|
---|
139 | ;;
|
---|
140 | glibc*) echo ${1} | sed -e 's@^[^-]*-@@' \
|
---|
141 | -e 's@\.tar.*@@'
|
---|
142 | ;;
|
---|
143 | LVM*) echo ${1} | sed -e 's@^[^.]*\.@@' \
|
---|
144 | -e 's@\.tgz.*@@'
|
---|
145 | ;;
|
---|
146 | iproute*) echo ${1} | sed -e 's@^[^-]*-@@' \
|
---|
147 | -e 's@\.tar.*@@'
|
---|
148 | ;;
|
---|
149 | pkg*|udev*|Singular*|XML*)
|
---|
150 | echo ${1} | sed -e 's@^.*[a-z]-\([[:digit:]]\)@\1@' \
|
---|
151 | -e 's@\.tar.*@@' \
|
---|
152 | -e 's@\.zip.*@@'
|
---|
153 | ;;
|
---|
154 | *) echo ${1} | sed -e 's@^.*[-_]\([[:digit:]]\)@\1@' \
|
---|
155 | -e 's@\.tar.*@@' \
|
---|
156 | -e 's@\.zip.*@@'
|
---|
157 | ;;
|
---|
158 | esac
|
---|
159 |
|
---|
160 | }
|
---|
161 | #=======================
|
---|
162 |
|
---|
163 |
|
---|
164 | #==== TARGET HEADER ====
|
---|
165 |
|
---|
166 | #----------------------------------#
|
---|
167 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
168 | #----------------------------------#
|
---|
169 | local i=$1
|
---|
170 | local PREV=$2
|
---|
171 | local version
|
---|
172 | if [ "$3" != "" ]; then
|
---|
173 | version=-$3
|
---|
174 | fi
|
---|
175 | (
|
---|
176 | cat << EOF
|
---|
177 |
|
---|
178 | $i: $PREV
|
---|
179 | @\$(call echo_message, Building)
|
---|
180 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
181 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
|
---|
182 | @\$(PRT_DU) >>logs/\$@$version
|
---|
183 | EOF
|
---|
184 | ) >> $MKFILE.tmp
|
---|
185 | }
|
---|
186 |
|
---|
187 | #----------------------------------#
|
---|
188 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
189 | #----------------------------------#
|
---|
190 | local i=$1
|
---|
191 | local PREV=$2
|
---|
192 | local version
|
---|
193 | if [ "$3" != "" ]; then
|
---|
194 | version=-$3
|
---|
195 | fi
|
---|
196 | (
|
---|
197 | cat << EOF
|
---|
198 |
|
---|
199 | $i: $PREV
|
---|
200 | @\$(call echo_message, Building)
|
---|
201 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
202 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
|
---|
203 | @\$(PRT_DU_CR) >>logs/\$@$version
|
---|
204 | EOF
|
---|
205 | ) >> $MKFILE.tmp
|
---|
206 | }
|
---|
207 |
|
---|
208 | #=======================
|
---|
209 |
|
---|
210 |
|
---|
211 | #======== UNPACK =======
|
---|
212 |
|
---|
213 | #----------------------------------#
|
---|
214 | LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
215 | #----------------------------------#
|
---|
216 | local FILE=$1
|
---|
217 | local optSAVE_PREVIOUS=$2
|
---|
218 |
|
---|
219 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
220 | (
|
---|
221 | cat << EOF
|
---|
222 | @\$(call remove_existing_dirs,$FILE)
|
---|
223 | EOF
|
---|
224 | ) >> $MKFILE.tmp
|
---|
225 | fi
|
---|
226 |
|
---|
227 | (
|
---|
228 | cat << EOF
|
---|
229 | @\$(call unpack,$FILE)
|
---|
230 | @\$(call get_pkg_root_LUSER)
|
---|
231 | EOF
|
---|
232 | ) >> $MKFILE.tmp
|
---|
233 | }
|
---|
234 |
|
---|
235 | #----------------------------------#
|
---|
236 | CHROOT_Unpack() { #
|
---|
237 | #----------------------------------#
|
---|
238 | local FILE=$1
|
---|
239 | local optSAVE_PREVIOUS=$2
|
---|
240 |
|
---|
241 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
242 | (
|
---|
243 | cat << EOF
|
---|
244 | @\$(call remove_existing_dirs2,$FILE)
|
---|
245 | EOF
|
---|
246 | ) >> $MKFILE.tmp
|
---|
247 | fi
|
---|
248 | (
|
---|
249 | cat << EOF
|
---|
250 | @\$(call unpack2,$FILE)
|
---|
251 | @\$(call get_pkg_root2)
|
---|
252 | EOF
|
---|
253 | ) >> $MKFILE.tmp
|
---|
254 | }
|
---|
255 |
|
---|
256 | #=======================
|
---|
257 |
|
---|
258 |
|
---|
259 | #===== TESTS LOGS ======
|
---|
260 |
|
---|
261 | #----------------------------------#
|
---|
262 | LUSER_wrt_test_log() { # Initialize testsuite log file
|
---|
263 | #----------------------------------#
|
---|
264 | local version
|
---|
265 | if [ "$2" != "" ]; then
|
---|
266 | version=-$2
|
---|
267 | fi
|
---|
268 | local TESTLOGFILE=$1$version
|
---|
269 | (
|
---|
270 | cat << EOF
|
---|
271 | @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
272 | echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
|
---|
273 | EOF
|
---|
274 | ) >> $MKFILE.tmp
|
---|
275 | }
|
---|
276 |
|
---|
277 | #----------------------------------#
|
---|
278 | CHROOT_wrt_test_log() { #
|
---|
279 | #----------------------------------#
|
---|
280 | local version
|
---|
281 | if [ "$2" != "" ]; then
|
---|
282 | version=-$2
|
---|
283 | fi
|
---|
284 | local TESTLOGFILE=$1$version
|
---|
285 | (
|
---|
286 | cat << EOF
|
---|
287 | @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
288 | echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
|
---|
289 | EOF
|
---|
290 | ) >> $MKFILE.tmp
|
---|
291 | }
|
---|
292 |
|
---|
293 | #=======================
|
---|
294 |
|
---|
295 |
|
---|
296 | #======== RUN AS =======
|
---|
297 |
|
---|
298 | #----------------------------------#
|
---|
299 | wrt_RunAsRoot() { # Some scripts must be run as root..
|
---|
300 | #----------------------------------#
|
---|
301 | local MOUNT_ENV
|
---|
302 | local version
|
---|
303 | if [ "$2" != "" ]; then
|
---|
304 | version=-$2
|
---|
305 | fi
|
---|
306 | local file=$1
|
---|
307 |
|
---|
308 | case ${PROGNAME} in
|
---|
309 | lfs ) MOUNT_ENV="LFS" ;;
|
---|
310 | clfs ) MOUNT_ENV="CLFS" ;;
|
---|
311 | clfs2 ) MOUNT_ENV="CLFS" ;;
|
---|
312 | clfs3 ) MOUNT_ENV="CLFS" ;;
|
---|
313 | hlfs ) MOUNT_ENV="HLFS" ;;
|
---|
314 | *) echo "undefined progname $PROGNAME"; exit 1 ;;
|
---|
315 | esac
|
---|
316 |
|
---|
317 | (
|
---|
318 | cat << EOF
|
---|
319 | @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
|
---|
320 | ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
|
---|
321 | \$(PRT_DU) >>logs/\$@$version
|
---|
322 | EOF
|
---|
323 | ) >> $MKFILE.tmp
|
---|
324 | }
|
---|
325 |
|
---|
326 | #----------------------------------#
|
---|
327 | LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
|
---|
328 | #----------------------------------#
|
---|
329 | local file=$1
|
---|
330 | local version
|
---|
331 | if [ "$2" != "" ]; then
|
---|
332 | version=-$2
|
---|
333 | fi
|
---|
334 |
|
---|
335 | (
|
---|
336 | cat << EOF
|
---|
337 | @source ~/.bashrc && \\
|
---|
338 | \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
|
---|
339 | \$(PRT_DU) >>logs/\$@$version
|
---|
340 | EOF
|
---|
341 | ) >> $MKFILE.tmp
|
---|
342 | }
|
---|
343 |
|
---|
344 | #----------------------------------#
|
---|
345 | CHROOT_wrt_RunAsRoot() { #
|
---|
346 | #----------------------------------#
|
---|
347 | local file=$1
|
---|
348 | local version
|
---|
349 | if [ "$2" != "" ]; then
|
---|
350 | version=-$2
|
---|
351 | fi
|
---|
352 | (
|
---|
353 | cat << EOF
|
---|
354 | @source envars && \\
|
---|
355 | \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
|
---|
356 | \$(PRT_DU_CR) >>logs/\$@$version
|
---|
357 | EOF
|
---|
358 | ) >> $MKFILE.tmp
|
---|
359 |
|
---|
360 | }
|
---|
361 |
|
---|
362 | #=======================
|
---|
363 |
|
---|
364 |
|
---|
365 | #====== COPY FSTAB =====
|
---|
366 |
|
---|
367 | #----------------------------------#
|
---|
368 | LUSER_wrt_CopyFstab() { #
|
---|
369 | #----------------------------------#
|
---|
370 | (
|
---|
371 | cat << EOF
|
---|
372 | @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
373 | \$(PRT_DU) >>logs/\$@
|
---|
374 | EOF
|
---|
375 | ) >> $MKFILE.tmp
|
---|
376 | }
|
---|
377 |
|
---|
378 | #----------------------------------#
|
---|
379 | CHROOT_wrt_CopyFstab() { #
|
---|
380 | #----------------------------------#
|
---|
381 | (
|
---|
382 | cat << EOF
|
---|
383 | @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
384 | \$(PRT_DU_CR) >>logs/\$@
|
---|
385 | EOF
|
---|
386 | ) >> $MKFILE.tmp
|
---|
387 | }
|
---|
388 |
|
---|
389 | #=======================
|
---|
390 |
|
---|
391 |
|
---|
392 | #==== INSTALLED FILES LOGS ====
|
---|
393 |
|
---|
394 | #----------------------------------#
|
---|
395 | LUSER_wrt_TouchTimestamp() { #
|
---|
396 | #----------------------------------#
|
---|
397 | (
|
---|
398 | cat << EOF
|
---|
399 | @\$(call touch_timestamp_LUSER)
|
---|
400 | EOF
|
---|
401 | ) >> $MKFILE.tmp
|
---|
402 | }
|
---|
403 |
|
---|
404 | #----------------------------------#
|
---|
405 | CHROOT_wrt_TouchTimestamp() { #
|
---|
406 | #----------------------------------#
|
---|
407 | (
|
---|
408 | cat << EOF
|
---|
409 | @\$(call touch_timestamp)
|
---|
410 | EOF
|
---|
411 | ) >> $MKFILE.tmp
|
---|
412 | }
|
---|
413 |
|
---|
414 | #----------------------------------#
|
---|
415 | LUSER_wrt_LogNewFiles() { #
|
---|
416 | #----------------------------------#
|
---|
417 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
418 | (
|
---|
419 | cat << EOF
|
---|
420 | @\$(call log_new_files_LUSER,$name)
|
---|
421 | EOF
|
---|
422 | ) >> $MKFILE.tmp
|
---|
423 | }
|
---|
424 |
|
---|
425 | #----------------------------------#
|
---|
426 | CHROOT_wrt_LogNewFiles() { #
|
---|
427 | #----------------------------------#
|
---|
428 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
429 | (
|
---|
430 | cat << EOF
|
---|
431 | @\$(call log_new_files,$name)
|
---|
432 | EOF
|
---|
433 | ) >> $MKFILE.tmp
|
---|
434 | }
|
---|
435 |
|
---|
436 | #=======================
|
---|
437 |
|
---|
438 |
|
---|
439 | #==== RM BUILD DIRS ====
|
---|
440 |
|
---|
441 | #----------------------------------#
|
---|
442 | LUSER_RemoveBuildDirs() { #
|
---|
443 | #----------------------------------#
|
---|
444 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
445 | (
|
---|
446 | cat << EOF
|
---|
447 | @\$(call remove_build_dirs,$name)
|
---|
448 | EOF
|
---|
449 | ) >> $MKFILE.tmp
|
---|
450 | }
|
---|
451 |
|
---|
452 | #----------------------------------#
|
---|
453 | CHROOT_wrt_RemoveBuildDirs() { #
|
---|
454 | #----------------------------------#
|
---|
455 | local name=`echo ${1} | sed 's/[0-9]-//'`
|
---|
456 | (
|
---|
457 | cat << EOF
|
---|
458 | @\$(call remove_build_dirs2,$name)
|
---|
459 | EOF
|
---|
460 | ) >> $MKFILE.tmp
|
---|
461 | }
|
---|
462 |
|
---|
463 | #=======================
|
---|
464 |
|
---|
465 |
|
---|
466 | #======== TOUCH ========
|
---|
467 |
|
---|
468 | #----------------------------------#
|
---|
469 | wrt_touch() { #
|
---|
470 | #----------------------------------#
|
---|
471 | (
|
---|
472 | cat << EOF
|
---|
473 | @\$(call housekeeping)
|
---|
474 | EOF
|
---|
475 | ) >> $MKFILE.tmp
|
---|
476 | }
|
---|
477 |
|
---|
478 | #=======================
|
---|