source: common/libs/func_wrt_Makefile@ a1fcdea1

ablfs-more legacy trunk
Last change on this file since a1fcdea1 was 9bbb9c8, checked in by Pierre Labastie <pierre@…>, 7 years ago

Package management: compute times and sizes without packing times and sizes

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