source: common/libs/func_wrt_Makefile@ 9f6ceb0

2.4
Last change on this file since 9f6ceb0 was 3917eca, checked in by Pierre Labastie <pierre@…>, 7 years ago

Allow non-numeric version in glibc

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