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