source: common/libs/func_wrt_Makefile@ 532ede6

2.4 ablfs-more legacy new_features trunk
Last change on this file since 532ede6 was ef32ce5, checked in by Pierre Labastie <pierre@…>, 11 years ago

Getting mad because you cannot interrupt the build once started?
The present set of commands seems to allow interrupting during the chapter
5 phase. No changes to chroot phase yet.

  • Property mode set to 100644
File size: 11.5 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5#=== MAKEFILE HEADER ===
6
7#----------------------------------#
8wrt_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
18SHELL = /bin/bash
19
20SRC = /sources
21MOUNT_PT = $BUILDDIR
22PKG_LST = $PKG_LST
23LUSER = $LUSER
24LGROUP = $LGROUP
25LHOME = $LHOME
26SCRIPT_ROOT = $SCRIPT_ROOT
27
28BASEDIR = \$(MOUNT_PT)
29SRCSDIR = \$(BASEDIR)/sources
30CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
31LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$LOGDIRBASE
32TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
33
34crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
35crLOGDIR = /\$(SCRIPT_ROOT)/$LOGDIRBASE
36crTESTLOGDIR = /\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
37crFILELOGDIR = /\$(SCRIPT_ROOT)/$FILELOGDIRBASE
38
39SU_LUSER = sudo -u \$(LUSER) -i sh -c
40LUSER_HOME = \$(LHOME)/\$(LUSER)
41PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
42PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n"
43
44ADD_REPORT = $REPORT
45ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
46ADD_BLFS_TOOLS = $BLFS_TOOL
47PKGMNGT = $PKGMNGT
48
49
50export PATH := \${PATH}:/usr/sbin
51
52include makefile-functions
53
54EOF
55) > $MKFILE
56}
57
58#=======================
59
60
61#==== PACKAGES NAMES AND VERSIONS ====
62
63#----------------------------------#
64get_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) 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#----------------------------------#
120get_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*)
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#----------------------------------#
160LUSER_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(
169cat << 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
176EOF
177) >> $MKFILE.tmp
178}
179
180#----------------------------------#
181CHROOT_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(
190cat << 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
197EOF
198) >> $MKFILE.tmp
199}
200
201#=======================
202
203
204#======== UNPACK =======
205
206#----------------------------------#
207LUSER_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(
214cat << EOF
215 @\$(call remove_existing_dirs,$FILE)
216EOF
217) >> $MKFILE.tmp
218 fi
219
220(
221cat << EOF
222 @\$(call unpack,$FILE)
223 @\$(call get_pkg_root_LUSER)
224EOF
225) >> $MKFILE.tmp
226}
227
228#----------------------------------#
229CHROOT_Unpack() { #
230#----------------------------------#
231 local FILE=$1
232 local optSAVE_PREVIOUS=$2
233
234 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
235(
236cat << EOF
237 @\$(call remove_existing_dirs2,$FILE)
238EOF
239) >> $MKFILE.tmp
240 fi
241(
242cat << EOF
243 @\$(call unpack2,$FILE)
244 @\$(call get_pkg_root2)
245EOF
246) >> $MKFILE.tmp
247}
248
249#=======================
250
251
252#===== TESTS LOGS ======
253
254#----------------------------------#
255LUSER_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(
263cat << EOF
264 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
265 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
266EOF
267) >> $MKFILE.tmp
268}
269
270#----------------------------------#
271CHROOT_wrt_test_log() { #
272#----------------------------------#
273 local version
274 if [ "$2" != "" ]; then
275 version=-$2
276 fi
277 local TESTLOGFILE=$1$version
278(
279cat << EOF
280 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
281 echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
282EOF
283) >> $MKFILE.tmp
284}
285
286#=======================
287
288
289#======== RUN AS =======
290
291#----------------------------------#
292wrt_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(
311cat << EOF
312 @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
313 ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
314 \$(PRT_DU) >>logs/\$@$version
315EOF
316) >> $MKFILE.tmp
317}
318
319#----------------------------------#
320LUSER_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(
329cat << EOF
330 @source ~/.bashrc && \\
331 \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
332 \$(PRT_DU) >>logs/\$@$version
333EOF
334) >> $MKFILE.tmp
335}
336
337#----------------------------------#
338CHROOT_wrt_RunAsRoot() { #
339#----------------------------------#
340 local file=$1
341 local version
342 if [ "$2" != "" ]; then
343 version=-$2
344 fi
345(
346cat << EOF
347 @source envars && \\
348 \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
349 \$(PRT_DU_CR) >>logs/\$@$version
350EOF
351) >> $MKFILE.tmp
352
353}
354
355#=======================
356
357
358#====== COPY FSTAB =====
359
360#----------------------------------#
361LUSER_wrt_CopyFstab() { #
362#----------------------------------#
363(
364cat << EOF
365 @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
366 \$(PRT_DU) >>logs/\$@
367EOF
368) >> $MKFILE.tmp
369}
370
371#----------------------------------#
372CHROOT_wrt_CopyFstab() { #
373#----------------------------------#
374(
375cat << EOF
376 @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
377 \$(PRT_DU_CR) >>logs/\$@
378EOF
379) >> $MKFILE.tmp
380}
381
382#=======================
383
384
385#==== INSTALLED FILES LOGS ====
386
387#----------------------------------#
388LUSER_wrt_TouchTimestamp() { #
389#----------------------------------#
390(
391cat << EOF
392 @\$(call touch_timestamp_LUSER)
393EOF
394) >> $MKFILE.tmp
395}
396
397#----------------------------------#
398CHROOT_wrt_TouchTimestamp() { #
399#----------------------------------#
400(
401cat << EOF
402 @\$(call touch_timestamp)
403EOF
404) >> $MKFILE.tmp
405}
406
407#----------------------------------#
408LUSER_wrt_LogNewFiles() { #
409#----------------------------------#
410 local name=`echo ${1} | sed 's/[0-9]-//'`
411(
412cat << EOF
413 @\$(call log_new_files_LUSER,$name)
414EOF
415) >> $MKFILE.tmp
416}
417
418#----------------------------------#
419CHROOT_wrt_LogNewFiles() { #
420#----------------------------------#
421 local name=`echo ${1} | sed 's/[0-9]-//'`
422(
423cat << EOF
424 @\$(call log_new_files,$name)
425EOF
426) >> $MKFILE.tmp
427}
428
429#=======================
430
431
432#==== RM BUILD DIRS ====
433
434#----------------------------------#
435LUSER_RemoveBuildDirs() { #
436#----------------------------------#
437 local name=`echo ${1} | sed 's/[0-9]-//'`
438(
439cat << EOF
440 @\$(call remove_build_dirs,$name)
441EOF
442) >> $MKFILE.tmp
443}
444
445#----------------------------------#
446CHROOT_wrt_RemoveBuildDirs() { #
447#----------------------------------#
448 local name=`echo ${1} | sed 's/[0-9]-//'`
449(
450cat << EOF
451 @\$(call remove_build_dirs2,$name)
452EOF
453) >> $MKFILE.tmp
454}
455
456#=======================
457
458
459#======== TOUCH ========
460
461#----------------------------------#
462wrt_touch() { #
463#----------------------------------#
464(
465cat << EOF
466 @\$(call housekeeping)
467EOF
468) >> $MKFILE.tmp
469}
470
471#=======================
Note: See TracBrowser for help on using the repository browser.