source: common/libs/func_wrt_Makefile@ 4c32ca8

ablfs-more legacy trunk
Last change on this file since 4c32ca8 was 0722dde, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Do not use global $version when writing Makefile

In func_wrt_makefile, the two functions LUSER_wrt_unpack and
CHROOT_Unpack use the version variable without setting it.
This leads to the global version variable being used, which
writes garbage into the Makefile. Fix: just define version locally.

This bug does not occur often because those functions are only
used when using custom scripts for versioned packages (if building LFS).
It has been found by William Harrington.

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