source: common/libs/func_wrt_Makefile@ 90f5b6d

ablfs-more legacy trunk
Last change on this file since 90f5b6d was 5637b53, checked in by Pierre Labastie <pierre@…>, 7 years ago

override libelf->elfutils for getting the tarball name

  • Property mode set to 100644
File size: 11.8 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 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 @\$(PRT_DU) >>logs/\$@$version
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 @\$(PRT_DU_CR) >>logs/\$@$version
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
220 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
221(
222cat << EOF
223 @\$(call remove_existing_dirs,$FILE)
224EOF
225) >> $MKFILE.tmp
226 fi
227
228(
229cat << EOF
230 @\$(call unpack,$FILE)
231 @\$(call get_pkg_root_LUSER)
232EOF
233) >> $MKFILE.tmp
234}
235
236#----------------------------------#
237CHROOT_Unpack() { #
238#----------------------------------#
239 local FILE=$1
240 local optSAVE_PREVIOUS=$2
241
242 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
243(
244cat << EOF
245 @\$(call remove_existing_dirs2,$FILE)
246EOF
247) >> $MKFILE.tmp
248 fi
249(
250cat << EOF
251 @\$(call unpack2,$FILE)
252 @\$(call get_pkg_root2)
253EOF
254) >> $MKFILE.tmp
255}
256
257#=======================
258
259
260#===== TESTS LOGS ======
261
262#----------------------------------#
263LUSER_wrt_test_log() { # Initialize testsuite log file
264#----------------------------------#
265 local version
266 if [ "$2" != "" ]; then
267 version=-$2
268 fi
269 local TESTLOGFILE=$1$version
270(
271cat << EOF
272 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
273 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
274EOF
275) >> $MKFILE.tmp
276}
277
278#----------------------------------#
279CHROOT_wrt_test_log() { #
280#----------------------------------#
281 local version
282 if [ "$2" != "" ]; then
283 version=-$2
284 fi
285 local TESTLOGFILE=$1$version
286(
287cat << EOF
288 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
289 echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
290EOF
291) >> $MKFILE.tmp
292}
293
294#=======================
295
296
297#======== RUN AS =======
298
299#----------------------------------#
300wrt_RunAsRoot() { # Some scripts must be run as root..
301#----------------------------------#
302 local MOUNT_ENV
303 local version
304 if [ "$2" != "" ]; then
305 version=-$2
306 fi
307 local file=$1
308
309 case ${PROGNAME} in
310 lfs ) MOUNT_ENV="LFS" ;;
311 clfs ) MOUNT_ENV="CLFS" ;;
312 clfs2 ) MOUNT_ENV="CLFS" ;;
313 clfs3 ) MOUNT_ENV="CLFS" ;;
314 hlfs ) MOUNT_ENV="HLFS" ;;
315 *) echo "undefined progname $PROGNAME"; exit 1 ;;
316 esac
317
318(
319cat << EOF
320 @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
321 ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
322 \$(PRT_DU) >>logs/\$@$version
323EOF
324) >> $MKFILE.tmp
325}
326
327#----------------------------------#
328LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
329#----------------------------------#
330 local file=$1
331 local version
332 if [ "$2" != "" ]; then
333 version=-$2
334 fi
335
336(
337cat << EOF
338 @source ~/.bashrc && \\
339 \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
340 \$(PRT_DU) >>logs/\$@$version
341EOF
342) >> $MKFILE.tmp
343}
344
345#----------------------------------#
346CHROOT_wrt_RunAsRoot() { #
347#----------------------------------#
348 local file=$1
349 local version
350 if [ "$2" != "" ]; then
351 version=-$2
352 fi
353(
354cat << EOF
355 @source envars && \\
356 \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
357 \$(PRT_DU_CR) >>logs/\$@$version
358EOF
359) >> $MKFILE.tmp
360
361}
362
363#=======================
364
365
366#====== COPY FSTAB =====
367
368#----------------------------------#
369LUSER_wrt_CopyFstab() { #
370#----------------------------------#
371(
372cat << EOF
373 @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
374 \$(PRT_DU) >>logs/\$@
375EOF
376) >> $MKFILE.tmp
377}
378
379#----------------------------------#
380CHROOT_wrt_CopyFstab() { #
381#----------------------------------#
382(
383cat << EOF
384 @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
385 \$(PRT_DU_CR) >>logs/\$@
386EOF
387) >> $MKFILE.tmp
388}
389
390#=======================
391
392
393#==== INSTALLED FILES LOGS ====
394
395#----------------------------------#
396LUSER_wrt_TouchTimestamp() { #
397#----------------------------------#
398(
399cat << EOF
400 @\$(call touch_timestamp_LUSER)
401EOF
402) >> $MKFILE.tmp
403}
404
405#----------------------------------#
406CHROOT_wrt_TouchTimestamp() { #
407#----------------------------------#
408(
409cat << EOF
410 @\$(call touch_timestamp)
411EOF
412) >> $MKFILE.tmp
413}
414
415#----------------------------------#
416LUSER_wrt_LogNewFiles() { #
417#----------------------------------#
418 local name=`echo ${1} | sed 's/[0-9]-//'`
419(
420cat << EOF
421 @\$(call log_new_files_LUSER,$name)
422EOF
423) >> $MKFILE.tmp
424}
425
426#----------------------------------#
427CHROOT_wrt_LogNewFiles() { #
428#----------------------------------#
429 local name=`echo ${1} | sed 's/[0-9]-//'`
430(
431cat << EOF
432 @\$(call log_new_files,$name)
433EOF
434) >> $MKFILE.tmp
435}
436
437#=======================
438
439
440#==== RM BUILD DIRS ====
441
442#----------------------------------#
443LUSER_RemoveBuildDirs() { #
444#----------------------------------#
445 local name=`echo ${1} | sed 's/[0-9]-//'`
446(
447cat << EOF
448 @\$(call remove_build_dirs,$name)
449EOF
450) >> $MKFILE.tmp
451}
452
453#----------------------------------#
454CHROOT_wrt_RemoveBuildDirs() { #
455#----------------------------------#
456 local name=`echo ${1} | sed 's/[0-9]-//'`
457(
458cat << EOF
459 @\$(call remove_build_dirs2,$name)
460EOF
461) >> $MKFILE.tmp
462}
463
464#=======================
465
466
467#======== TOUCH ========
468
469#----------------------------------#
470wrt_touch() { #
471#----------------------------------#
472(
473cat << EOF
474 @\$(call housekeeping)
475EOF
476) >> $MKFILE.tmp
477}
478
479#=======================
Note: See TracBrowser for help on using the repository browser.