source: common/libs/func_wrt_Makefile@ 8f2c086

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

Functions clean-up.

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