source: common/libs/func_wrt_Makefile@ a690d42

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

Remove $Id$ comments, they are useless with git

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