source: common/libs/func_wrt_Makefile@ e967368

2.4
Last change on this file since e967368 was 0313634, checked in by Pierre Labastie <pierre@…>, 7 years ago

Merge trunk r4024 and r4039, fixing generation of Makefile and of
DESTDIR install for libelf

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