source: common/libs/func_wrt_Makefile@ 9bbb9c8

ablfs-more legacy trunk
Last change on this file since 9bbb9c8 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
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
[aec4483]17
18SHELL = /bin/bash
[195ed9f]19
20SRC = /sources
21MOUNT_PT = $BUILDDIR
22PKG_LST = $PKG_LST
23LUSER = $LUSER
24LGROUP = $LGROUP
[962793a]25LHOME = $LHOME
[195ed9f]26SCRIPT_ROOT = $SCRIPT_ROOT
27
28BASEDIR = \$(MOUNT_PT)
29SRCSDIR = \$(BASEDIR)/sources
30CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
[93346ee]31LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$LOGDIRBASE
32TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
[195ed9f]33
34crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
[93346ee]35crLOGDIR = /\$(SCRIPT_ROOT)/$LOGDIRBASE
36crTESTLOGDIR = /\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
37crFILELOGDIR = /\$(SCRIPT_ROOT)/$FILELOGDIRBASE
[195ed9f]38
[ef32ce5]39SU_LUSER = sudo -u \$(LUSER) -i sh -c
[962793a]40LUSER_HOME = \$(LHOME)/\$(LUSER)
[195ed9f]41PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
[9bbb9c8]42PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found --exclude /var/lib / \`\n"
[195ed9f]43
[3e7ceed]44ADD_REPORT = $REPORT
45ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
46ADD_BLFS_TOOLS = $BLFS_TOOL
[7072e1f]47PKGMNGT = $PKGMNGT
[322226d]48WRAP_INSTALL = $WRAP_INSTALL
[1838bc7]49
50
[195ed9f]51export PATH := \${PATH}:/usr/sbin
52
53include makefile-functions
54
55EOF
56) > $MKFILE
57}
[fe30c61]58
59#=======================
60
61
[3cb4ef5b]62#==== PACKAGES NAMES AND VERSIONS ====
[fe30c61]63
64#----------------------------------#
65get_package_tarball_name() { #
66#----------------------------------#
[659be15]67 local script_name=`echo ${1} | sed -e 's@^[0-9]\{1\}-@@'`
[fe30c61]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 ;;
[608fbe1]75 iputils) echo $(grep "^iputils" $JHALFSDIR/pkg_tarball_list | head -n1 )
76 ;;
[7214dad]77 powerpc-utils) echo $(grep "^powerpc-utils" $JHALFSDIR/pkg_tarball_list | head -n1 )
78 ;;
[3c38ab0]79 uClibc)
80 if [[ "${PROGNAME}" = "clfs3" ]]; then
81 echo $(grep "^uClibc-" $JHALFSDIR/pkg_tarball_list | head -n1 )
[7214dad]82 else
[3c38ab0]83 echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
[7214dad]84 fi
85 ;;
[fe30c61]86 linux-headers)
[31a37db]87 if [[ "${PROGNAME}" = "lfs" ]] || [[ "${PROGNAME}" = "hlfs" ]] || [[ "${PROGNAME}" = "clfs" ]]; then
[fe30c61]88 # Uses kernel headers directly
89 echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
90 else
[608fbe1]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 )
[fe30c61]94 fi
95 ;;
[d8006a00]96 expect) echo $(grep "^expect" $JHALFSDIR/pkg_tarball_list | head -n1 )
97 ;;
[608fbe1]98 e2fsprogs-libs) echo $(grep "^e2fsprogs" $JHALFSDIR/pkg_tarball_list | head -n1 )
99 ;;
[f0a31de]100 libcap) echo $(grep "^libcap" $JHALFSDIR/pkg_tarball_list | head -n1 )
101 ;;
[82808d1]102 util-linux-libs | util-linux-pass1) echo $(grep "^util-linux" $JHALFSDIR/pkg_tarball_list | head -n1 )
[608fbe1]103 ;;
[4b54394]104 xz-utils) echo $(grep "^xz" $JHALFSDIR/pkg_tarball_list | head -n1 )
[083e2fd]105 ;;
[7072e1f]106 sqlite) echo $(grep "^sqlite" $JHALFSDIR/pkg_tarball_list | head -n1 )
[083e2fd]107 ;;
108 udev) echo $(grep "^systemd" $JHALFSDIR/pkg_tarball_list | head -n1 )
109 ;;
[8099885]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 ;;
[7072e1f]114 *) echo $(grep "^$script_name[_-][[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
[fe30c61]115 ;;
116 esac
117
118}
119
[3cb4ef5b]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 ;;
[3d96a65]143 pkg*|udev*|Singular*|XML*)
[3cb4ef5b]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}
[fe30c61]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
[3cb4ef5b]165 local version
166 if [ "$3" != "" ]; then
167 version=-$3
168 fi
[fe30c61]169(
170cat << EOF
171
172$i: $PREV
173 @\$(call echo_message, Building)
[75d6d1c]174${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
[3cb4ef5b]175 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
176 @\$(PRT_DU) >>logs/\$@$version
[fe30c61]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
[3cb4ef5b]186 local version
187 if [ "$3" != "" ]; then
188 version=-$3
189 fi
[fe30c61]190(
191cat << EOF
192
193$i: $PREV
194 @\$(call echo_message, Building)
[75d6d1c]195${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
[3cb4ef5b]196 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
197 @\$(PRT_DU_CR) >>logs/\$@$version
[fe30c61]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
[1f81129]244 @\$(call unpack2,$FILE)
[fe30c61]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#----------------------------------#
[3cb4ef5b]258 local version
259 if [ "$2" != "" ]; then
260 version=-$2
261 fi
262 local TESTLOGFILE=$1$version
[fe30c61]263(
264cat << EOF
[6bb080e]265 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
[3cb4ef5b]266 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
[fe30c61]267EOF
268) >> $MKFILE.tmp
269}
270
271#----------------------------------#
272CHROOT_wrt_test_log() { #
273#----------------------------------#
[3cb4ef5b]274 local version
275 if [ "$2" != "" ]; then
276 version=-$2
277 fi
278 local TESTLOGFILE=$1$version
[fe30c61]279(
280cat << EOF
[8f2c086]281 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
[3cb4ef5b]282 echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
[fe30c61]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
[3cb4ef5b]296 local version
297 if [ "$2" != "" ]; then
298 version=-$2
299 fi
[8f2c086]300 local file=$1
[fe30c61]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
[68713c9]313 @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
[3cb4ef5b]314 ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
315 \$(PRT_DU) >>logs/\$@$version
[fe30c61]316EOF
317) >> $MKFILE.tmp
318}
319
320#----------------------------------#
[0210014]321LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
[fe30c61]322#----------------------------------#
323 local file=$1
[3cb4ef5b]324 local version
325 if [ "$2" != "" ]; then
326 version=-$2
327 fi
[fe30c61]328
329(
330cat << EOF
[68713c9]331 @source ~/.bashrc && \\
[3cb4ef5b]332 \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
333 \$(PRT_DU) >>logs/\$@$version
[fe30c61]334EOF
335) >> $MKFILE.tmp
336}
337
338#----------------------------------#
339CHROOT_wrt_RunAsRoot() { #
340#----------------------------------#
341 local file=$1
[3cb4ef5b]342 local version
343 if [ "$2" != "" ]; then
344 version=-$2
345 fi
[fe30c61]346(
347cat << EOF
[68713c9]348 @source envars && \\
[3cb4ef5b]349 \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
350 \$(PRT_DU_CR) >>logs/\$@$version
[fe30c61]351EOF
352) >> $MKFILE.tmp
353
354}
355
356#=======================
357
358
359#====== COPY FSTAB =====
360
361#----------------------------------#
362LUSER_wrt_CopyFstab() { #
363#----------------------------------#
364(
365cat << EOF
[68713c9]366 @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
[0210014]367 \$(PRT_DU) >>logs/\$@
[fe30c61]368EOF
369) >> $MKFILE.tmp
370}
371
372#----------------------------------#
373CHROOT_wrt_CopyFstab() { #
374#----------------------------------#
375(
376cat << EOF
[68713c9]377 @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
[0210014]378 \$(PRT_DU_CR) >>logs/\$@
[fe30c61]379EOF
380) >> $MKFILE.tmp
381}
382
383#=======================
384
385
[93346ee]386#==== INSTALLED FILES LOGS ====
387
[f546320]388#----------------------------------#
389LUSER_wrt_TouchTimestamp() { #
390#----------------------------------#
391(
392cat << EOF
393 @\$(call touch_timestamp_LUSER)
394EOF
395) >> $MKFILE.tmp
396}
397
[93346ee]398#----------------------------------#
399CHROOT_wrt_TouchTimestamp() { #
400#----------------------------------#
401(
402cat << EOF
403 @\$(call touch_timestamp)
404EOF
405) >> $MKFILE.tmp
406}
407
[f546320]408#----------------------------------#
409LUSER_wrt_LogNewFiles() { #
410#----------------------------------#
[e639536]411 local name=`echo ${1} | sed 's/[0-9]-//'`
[f546320]412(
413cat << EOF
414 @\$(call log_new_files_LUSER,$name)
415EOF
416) >> $MKFILE.tmp
417}
418
[93346ee]419#----------------------------------#
420CHROOT_wrt_LogNewFiles() { #
421#----------------------------------#
[e639536]422 local name=`echo ${1} | sed 's/[0-9]-//'`
[93346ee]423(
424cat << EOF
425 @\$(call log_new_files,$name)
426EOF
427) >> $MKFILE.tmp
428}
429
430#=======================
431
432
[fe30c61]433#==== RM BUILD DIRS ====
434
435#----------------------------------#
436LUSER_RemoveBuildDirs() { #
437#----------------------------------#
[e639536]438 local name=`echo ${1} | sed 's/[0-9]-//'`
[fe30c61]439(
440cat << EOF
441 @\$(call remove_build_dirs,$name)
442EOF
443) >> $MKFILE.tmp
444}
445
446#----------------------------------#
447CHROOT_wrt_RemoveBuildDirs() { #
448#----------------------------------#
[e639536]449 local name=`echo ${1} | sed 's/[0-9]-//'`
[fe30c61]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.