source: common/libs/func_wrt_Makefile@ 7fe73c8

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 7fe73c8 was 6d73498, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Fixed progress_bar.sh run inside chroot jail.

  • Property mode set to 100644
File size: 7.3 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
17ifeq (\$(shell [ -x /bin/bash ] && echo /bin/bash),/bin/bash)
18 SHELL = /bin/bash
19else
20 SHELL = /tools/bin/bash
21endif
22
23SRC = /sources
24MOUNT_PT = $BUILDDIR
25PKG_LST = $PKG_LST
26LUSER = $LUSER
27LGROUP = $LGROUP
28SCRIPT_ROOT = $SCRIPT_ROOT
29
30BASEDIR = \$(MOUNT_PT)
31SRCSDIR = \$(BASEDIR)/sources
32CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
33LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
34TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
35
36crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
37crLOGDIR = /\$(SCRIPT_ROOT)/logs
38crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
39
40SU_LUSER = su - \$(LUSER) -c
41LUSER_HOME = /home/\$(LUSER)
42PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
43PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n"
44
45ADD_REPORT = $REPORT
46ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
47ADD_BLFS_TOOLS = $BLFS_TOOL
48
49
50export PATH := \${PATH}:/usr/sbin
51
52include makefile-functions
53
54EOF
55) > $MKFILE
56}
57
58#=======================
59
60
61#==== PACKAGES NAMES ===
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 uClibc)
75 if [[ "${PROGNAME}" = "clfs3" ]]; then
76 echo $(grep "^uClibc-" $JHALFSDIR/pkg_tarball_list | head -n1 )
77 else
78 echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
79 fi
80 ;;
81 linux-headers)
82 if [[ "${PROGNAME}" = "lfs" ]] || [[ "${PROGNAME}" = "hlfs" ]] ; then
83 # Uses kernel headers directly
84 echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
85 else
86 # CLFS{,2,3} use massaged headers package
87 echo $(grep "^linux-headers-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
88 fi
89 ;;
90 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
91 ;;
92 esac
93
94}
95
96#=======================
97
98
99#==== TARGET HEADER ====
100
101#----------------------------------#
102LUSER_wrt_target() { # Create target and initialize log file
103#----------------------------------#
104 local i=$1
105 local PREV=$2
106(
107cat << EOF
108
109$i: $PREV
110 @\$(call echo_message, Building)
111 @\$(SHELL) progress_bar.sh \$@ \$\$PPID &
112 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
113 @\$(PRT_DU) >>logs/\$@
114EOF
115) >> $MKFILE.tmp
116}
117
118#----------------------------------#
119CHROOT_wrt_target() { # Create target and initialize log file
120#----------------------------------#
121 local i=$1
122 local PREV=$2
123(
124cat << EOF
125
126$i: $PREV
127 @\$(call echo_message, Building)
128 @\$(SHELL) progress_bar.sh \$@ \$\$PPID &
129 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
130 @\$(PRT_DU_CR) >>logs/\$@
131EOF
132) >> $MKFILE.tmp
133}
134
135#=======================
136
137
138#======== UNPACK =======
139
140#----------------------------------#
141LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
142#----------------------------------#
143 local FILE=$1
144 local optSAVE_PREVIOUS=$2
145
146 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
147(
148cat << EOF
149 @\$(call remove_existing_dirs,$FILE)
150EOF
151) >> $MKFILE.tmp
152 fi
153
154(
155cat << EOF
156 @\$(call unpack,$FILE)
157 @\$(call get_pkg_root_LUSER)
158EOF
159) >> $MKFILE.tmp
160}
161
162#----------------------------------#
163CHROOT_Unpack() { #
164#----------------------------------#
165 local FILE=$1
166 local optSAVE_PREVIOUS=$2
167
168 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
169(
170cat << EOF
171 @\$(call remove_existing_dirs2,$FILE)
172EOF
173) >> $MKFILE.tmp
174 fi
175(
176cat << EOF
177 @\$(call unpack2,$FILE)
178 @\$(call get_pkg_root2)
179EOF
180) >> $MKFILE.tmp
181}
182
183#=======================
184
185
186#===== TESTS LOGS ======
187
188#----------------------------------#
189LUSER_wrt_test_log() { # Initialize testsuite log file
190#----------------------------------#
191 local TESTLOGFILE=$1
192(
193cat << EOF
194 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
195 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/\$@
196EOF
197) >> $MKFILE.tmp
198}
199
200#----------------------------------#
201CHROOT_wrt_test_log() { #
202#----------------------------------#
203 local TESTLOGFILE=$1
204(
205cat << EOF
206 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
207 echo "\$(nl_)\`date\`\$(nl_)" >test-logs/\$@
208EOF
209) >> $MKFILE.tmp
210}
211
212#=======================
213
214
215#======== RUN AS =======
216
217#----------------------------------#
218wrt_RunAsRoot() { # Some scripts must be run as root..
219#----------------------------------#
220 local MOUNT_ENV
221 local file=$1
222
223 case ${PROGNAME} in
224 lfs ) MOUNT_ENV="LFS" ;;
225 clfs ) MOUNT_ENV="CLFS" ;;
226 clfs2 ) MOUNT_ENV="CLFS" ;;
227 clfs3 ) MOUNT_ENV="CLFS" ;;
228 hlfs ) MOUNT_ENV="HLFS" ;;
229 *) echo "undefined progname $PROGNAME"; exit 1 ;;
230 esac
231
232(
233cat << EOF
234 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
235 \$(PRT_DU) >>logs/\$@
236EOF
237) >> $MKFILE.tmp
238}
239
240#----------------------------------#
241LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
242#----------------------------------#
243 local file=$1
244
245(
246cat << EOF
247 @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
248 \$(PRT_DU) >> logs/\$@
249EOF
250) >> $MKFILE.tmp
251}
252
253#----------------------------------#
254CHROOT_wrt_RunAsRoot() { #
255#----------------------------------#
256 local file=$1
257(
258cat << EOF
259 @( time { source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
260 \$(PRT_DU_CR) >>logs/\$@
261EOF
262) >> $MKFILE.tmp
263
264}
265
266#=======================
267
268
269#====== COPY FSTAB =====
270
271#----------------------------------#
272LUSER_wrt_CopyFstab() { #
273#----------------------------------#
274(
275cat << EOF
276 @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
277EOF
278) >> $MKFILE.tmp
279}
280
281#----------------------------------#
282CHROOT_wrt_CopyFstab() { #
283#----------------------------------#
284(
285cat << EOF
286 @( time { cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
287EOF
288) >> $MKFILE.tmp
289}
290
291#=======================
292
293
294#==== RM BUILD DIRS ====
295
296#----------------------------------#
297LUSER_RemoveBuildDirs() { #
298#----------------------------------#
299 local name=$1
300(
301cat << EOF
302 @\$(call remove_build_dirs,$name)
303EOF
304) >> $MKFILE.tmp
305}
306
307#----------------------------------#
308CHROOT_wrt_RemoveBuildDirs() { #
309#----------------------------------#
310 local name=$1
311(
312cat << EOF
313 @\$(call remove_build_dirs2,$name)
314EOF
315) >> $MKFILE.tmp
316}
317
318#=======================
319
320
321#======== TOUCH ========
322
323#----------------------------------#
324wrt_touch() { #
325#----------------------------------#
326(
327cat << EOF
328 @\$(call housekeeping)
329EOF
330) >> $MKFILE.tmp
331}
332
333#=======================
Note: See TracBrowser for help on using the repository browser.