source: common/libs/func_wrt_Makefile@ 195ed9f

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

Moved Makefile header creation to a common function.

  • Property mode set to 100644
File size: 7.6 KB
RevLine 
[fe30c61]1#!/bin/bash
2
3# $Id$
4
5#=== MAKEFILE HEADER ===
6
[195ed9f]7#----------------------------------#
8wrt_Makefile_header() { #
9#----------------------------------#
10(
11 cat << EOF
12# This file is automatically generated by jhalfs
[fe30c61]13# DO NOT EDIT THIS FILE MANUALLY
14#
[195ed9f]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}
[fe30c61]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#----------------------------------#
129ROOT_Unpack() { # An alias, for clairity
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#----------------------------------#
151LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
152#----------------------------------#
153 local FILE=$1
154 local optSAVE_PREVIOUS=$2
155
156 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
157(
158cat << EOF
159 @\$(call remove_existing_dirs,$FILE)
160EOF
161) >> $MKFILE.tmp
162 fi
163
164(
165cat << EOF
166 @\$(call unpack,$FILE)
167 @\$(call get_pkg_root_LUSER)
168EOF
169) >> $MKFILE.tmp
170}
171
172#----------------------------------#
173CHROOT_Unpack() { #
174#----------------------------------#
175 local FILE=$1
176 local optSAVE_PREVIOUS=$2
177
178 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
179(
180cat << EOF
181 @\$(call remove_existing_dirs2,$FILE)
182EOF
183) >> $MKFILE.tmp
184 fi
185(
186cat << EOF
187 @\$(call unpack3,$FILE)
188 @\$(call get_pkg_root2)
189EOF
190) >> $MKFILE.tmp
191}
192
193#=======================
194
195
196#===== TESTS LOGS ======
197
198#----------------------------------#
199LUSER_wrt_test_log() { # Initialize testsuite log file
200#----------------------------------#
201 local TESTLOGFILE=$1
202(
203cat << EOF
204 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
205 echo '\$(nl_)\`date\`\$(nl_)' >$TESTLOGDIR/$TESTLOGFILE
206EOF
207) >> $MKFILE.tmp
208}
209
210#----------------------------------#
211CHROOT_wrt_test_log() { #
212#----------------------------------#
213 local TESTLOGFILE=$1
214(
215cat << EOF
216 @echo "export TEST_LOG=/\$(SCRIPT_ROOT)/test-logs/$TESTLOGFILE" >> envars && \\
217 echo "\$(nl_)\`date\`\$(nl_)" >test-logs/$TESTLOGFILE
218EOF
219) >> $MKFILE.tmp
220}
221
222#=======================
223
224
225#======== RUN AS =======
226
227#----------------------------------#
228wrt_RunAsRoot() { # Some scripts must be run as root..
229#----------------------------------#
230 local MOUNT_ENV
231 local this_script=$1
232 local file=$2
233
234 case ${PROGNAME} in
235 lfs ) MOUNT_ENV="LFS" ;;
236 blfs ) MOUNT_ENV="BLFS" ;;
237 clfs ) MOUNT_ENV="CLFS" ;;
238 clfs2 ) MOUNT_ENV="CLFS" ;;
239 clfs3 ) MOUNT_ENV="CLFS" ;;
240 hlfs ) MOUNT_ENV="HLFS" ;;
241 *) echo "undefined progname $PROGNAME"; exit 1 ;;
242 esac
243
244(
245cat << EOF
246 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
247 \$(PRT_DU) >>logs/\$@
248EOF
249) >> $MKFILE.tmp
250}
251
252#----------------------------------#
253ROOT_RunAsRoot() { #
254#----------------------------------#
255 local file=$1
256(
257cat << EOF
258 @( time { source envars && \$(CMDSDIR)/$file >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
259 \$(PRT_DU_CR) >>logs/\$@
260EOF
261) >> $MKFILE.tmp
262}
263
264#----------------------------------#
265LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
266#----------------------------------#
267 local file=$1
268
269(
270cat << EOF
271 @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
272 \$(PRT_DU) >> logs/\$@
273EOF
274) >> $MKFILE.tmp
275}
276
277#----------------------------------#
278CHROOT_wrt_RunAsRoot() { #
279#----------------------------------#
280 local file=$1
281(
282cat << EOF
283 @( time { source envars && \$(crCMDSDIR)/$file >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
284 \$(PRT_DU_CR) >>logs/\$@
285EOF
286) >> $MKFILE.tmp
287
288}
289
290#=======================
291
292
293#====== COPY FSTAB =====
294
295#----------------------------------#
296LUSER_wrt_CopyFstab() { #
297#----------------------------------#
298(
299cat << EOF
300 @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
301EOF
302) >> $MKFILE.tmp
303}
304
305#----------------------------------#
306CHROOT_wrt_CopyFstab() { #
307#----------------------------------#
308(
309cat << EOF
310 @( time { cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
311EOF
312) >> $MKFILE.tmp
313}
314
315#=======================
316
317
318#==== RM BUILD DIRS ====
319
320#----------------------------------#
321LUSER_RemoveBuildDirs() { #
322#----------------------------------#
323 local name=$1
324(
325cat << EOF
326 @\$(call remove_build_dirs,$name)
327EOF
328) >> $MKFILE.tmp
329}
330
331#----------------------------------#
332CHROOT_wrt_RemoveBuildDirs() { #
333#----------------------------------#
334 local name=$1
335(
336cat << EOF
337 @\$(call remove_build_dirs2,$name)
338EOF
339) >> $MKFILE.tmp
340}
341
342#=======================
343
344
345#======== TOUCH ========
346
347#----------------------------------#
348wrt_touch() { #
349#----------------------------------#
350(
351cat << EOF
352 @\$(call housekeeping)
353EOF
354) >> $MKFILE.tmp
355}
356
357#=======================
Note: See TracBrowser for help on using the repository browser.