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