source: common/libs/func_wrt_Makefile@ 56a5508

2.4
Last change on this file since 56a5508 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
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"
[f7d1386]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
[1838bc7]48
49
[195ed9f]50export PATH := \${PATH}:/usr/sbin
51
52include makefile-functions
53
54EOF
55) > $MKFILE
56}
[fe30c61]57
58#=======================
59
60
[3cb4ef5b]61#==== PACKAGES NAMES AND VERSIONS ====
[fe30c61]62
63#----------------------------------#
64get_package_tarball_name() { #
65#----------------------------------#
[659be15]66 local script_name=`echo ${1} | sed -e 's@^[0-9]\{1\}-@@'`
[fe30c61]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 ;;
[608fbe1]74 iputils) echo $(grep "^iputils" $JHALFSDIR/pkg_tarball_list | head -n1 )
75 ;;
[7214dad]76 powerpc-utils) echo $(grep "^powerpc-utils" $JHALFSDIR/pkg_tarball_list | head -n1 )
77 ;;
[3c38ab0]78 uClibc)
79 if [[ "${PROGNAME}" = "clfs3" ]]; then
80 echo $(grep "^uClibc-" $JHALFSDIR/pkg_tarball_list | head -n1 )
[7214dad]81 else
[3c38ab0]82 echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
[7214dad]83 fi
84 ;;
[fe30c61]85 linux-headers)
[31a37db]86 if [[ "${PROGNAME}" = "lfs" ]] || [[ "${PROGNAME}" = "hlfs" ]] || [[ "${PROGNAME}" = "clfs" ]]; then
[fe30c61]87 # Uses kernel headers directly
88 echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
89 else
[608fbe1]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 )
[fe30c61]93 fi
94 ;;
[d8006a00]95 expect) echo $(grep "^expect" $JHALFSDIR/pkg_tarball_list | head -n1 )
96 ;;
[608fbe1]97 e2fsprogs-libs) echo $(grep "^e2fsprogs" $JHALFSDIR/pkg_tarball_list | head -n1 )
98 ;;
[f0a31de]99 libcap) echo $(grep "^libcap" $JHALFSDIR/pkg_tarball_list | head -n1 )
100 ;;
[82808d1]101 util-linux-libs | util-linux-pass1) echo $(grep "^util-linux" $JHALFSDIR/pkg_tarball_list | head -n1 )
[608fbe1]102 ;;
[4b54394]103 xz-utils) echo $(grep "^xz" $JHALFSDIR/pkg_tarball_list | head -n1 )
[083e2fd]104 ;;
[7072e1f]105 sqlite) echo $(grep "^sqlite" $JHALFSDIR/pkg_tarball_list | head -n1 )
[083e2fd]106 ;;
107 udev) echo $(grep "^systemd" $JHALFSDIR/pkg_tarball_list | head -n1 )
108 ;;
[8099885]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 ;;
[3917eca]113 glibc) echo $(grep "^glibc" $JHALFSDIR/pkg_tarball_list | head -n1 )
[0313634]114 ;;
115 libelf) echo $(grep "^elfutils" $JHALFSDIR/pkg_tarball_list | head -n1 )
[3917eca]116 ;;
[7072e1f]117 *) echo $(grep "^$script_name[_-][[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
[fe30c61]118 ;;
119 esac
120
121}
122
[3cb4ef5b]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 ;;
[3917eca]140 glibc*) echo ${1} | sed -e 's@^[^-]*-@@' \
141 -e 's@\.tar.*@@'
142 ;;
[3cb4ef5b]143 LVM*) echo ${1} | sed -e 's@^[^.]*\.@@' \
144 -e 's@\.tgz.*@@'
145 ;;
146 iproute*) echo ${1} | sed -e 's@^[^-]*-@@' \
147 -e 's@\.tar.*@@'
148 ;;
[3d96a65]149 pkg*|udev*|Singular*|XML*)
[3cb4ef5b]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}
[fe30c61]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
[3cb4ef5b]171 local version
172 if [ "$3" != "" ]; then
173 version=-$3
174 fi
[fe30c61]175(
176cat << EOF
177
178$i: $PREV
179 @\$(call echo_message, Building)
[75d6d1c]180${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
[3cb4ef5b]181 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
182 @\$(PRT_DU) >>logs/\$@$version
[fe30c61]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
[3cb4ef5b]192 local version
193 if [ "$3" != "" ]; then
194 version=-$3
195 fi
[fe30c61]196(
197cat << EOF
198
199$i: $PREV
200 @\$(call echo_message, Building)
[75d6d1c]201${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
[3cb4ef5b]202 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
203 @\$(PRT_DU_CR) >>logs/\$@$version
[fe30c61]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
[1f81129]250 @\$(call unpack2,$FILE)
[fe30c61]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#----------------------------------#
[3cb4ef5b]264 local version
265 if [ "$2" != "" ]; then
266 version=-$2
267 fi
268 local TESTLOGFILE=$1$version
[fe30c61]269(
270cat << EOF
[6bb080e]271 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
[3cb4ef5b]272 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
[fe30c61]273EOF
274) >> $MKFILE.tmp
275}
276
277#----------------------------------#
278CHROOT_wrt_test_log() { #
279#----------------------------------#
[3cb4ef5b]280 local version
281 if [ "$2" != "" ]; then
282 version=-$2
283 fi
284 local TESTLOGFILE=$1$version
[fe30c61]285(
286cat << EOF
[8f2c086]287 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
[3cb4ef5b]288 echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
[fe30c61]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
[3cb4ef5b]302 local version
303 if [ "$2" != "" ]; then
304 version=-$2
305 fi
[8f2c086]306 local file=$1
[fe30c61]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
[68713c9]319 @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
[3cb4ef5b]320 ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
321 \$(PRT_DU) >>logs/\$@$version
[fe30c61]322EOF
323) >> $MKFILE.tmp
324}
325
326#----------------------------------#
[0210014]327LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
[fe30c61]328#----------------------------------#
329 local file=$1
[3cb4ef5b]330 local version
331 if [ "$2" != "" ]; then
332 version=-$2
333 fi
[fe30c61]334
335(
336cat << EOF
[68713c9]337 @source ~/.bashrc && \\
[3cb4ef5b]338 \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@$version 2>&1 && \\
339 \$(PRT_DU) >>logs/\$@$version
[fe30c61]340EOF
341) >> $MKFILE.tmp
342}
343
344#----------------------------------#
345CHROOT_wrt_RunAsRoot() { #
346#----------------------------------#
347 local file=$1
[3cb4ef5b]348 local version
349 if [ "$2" != "" ]; then
350 version=-$2
351 fi
[fe30c61]352(
353cat << EOF
[68713c9]354 @source envars && \\
[3cb4ef5b]355 \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@$version 2>&1 && \\
356 \$(PRT_DU_CR) >>logs/\$@$version
[fe30c61]357EOF
358) >> $MKFILE.tmp
359
360}
361
362#=======================
363
364
365#====== COPY FSTAB =====
366
367#----------------------------------#
368LUSER_wrt_CopyFstab() { #
369#----------------------------------#
370(
371cat << EOF
[68713c9]372 @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
[0210014]373 \$(PRT_DU) >>logs/\$@
[fe30c61]374EOF
375) >> $MKFILE.tmp
376}
377
378#----------------------------------#
379CHROOT_wrt_CopyFstab() { #
380#----------------------------------#
381(
382cat << EOF
[68713c9]383 @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
[0210014]384 \$(PRT_DU_CR) >>logs/\$@
[fe30c61]385EOF
386) >> $MKFILE.tmp
387}
388
389#=======================
390
391
[93346ee]392#==== INSTALLED FILES LOGS ====
393
[f546320]394#----------------------------------#
395LUSER_wrt_TouchTimestamp() { #
396#----------------------------------#
397(
398cat << EOF
399 @\$(call touch_timestamp_LUSER)
400EOF
401) >> $MKFILE.tmp
402}
403
[93346ee]404#----------------------------------#
405CHROOT_wrt_TouchTimestamp() { #
406#----------------------------------#
407(
408cat << EOF
409 @\$(call touch_timestamp)
410EOF
411) >> $MKFILE.tmp
412}
413
[f546320]414#----------------------------------#
415LUSER_wrt_LogNewFiles() { #
416#----------------------------------#
[e639536]417 local name=`echo ${1} | sed 's/[0-9]-//'`
[f546320]418(
419cat << EOF
420 @\$(call log_new_files_LUSER,$name)
421EOF
422) >> $MKFILE.tmp
423}
424
[93346ee]425#----------------------------------#
426CHROOT_wrt_LogNewFiles() { #
427#----------------------------------#
[e639536]428 local name=`echo ${1} | sed 's/[0-9]-//'`
[93346ee]429(
430cat << EOF
431 @\$(call log_new_files,$name)
432EOF
433) >> $MKFILE.tmp
434}
435
436#=======================
437
438
[fe30c61]439#==== RM BUILD DIRS ====
440
441#----------------------------------#
442LUSER_RemoveBuildDirs() { #
443#----------------------------------#
[e639536]444 local name=`echo ${1} | sed 's/[0-9]-//'`
[fe30c61]445(
446cat << EOF
447 @\$(call remove_build_dirs,$name)
448EOF
449) >> $MKFILE.tmp
450}
451
452#----------------------------------#
453CHROOT_wrt_RemoveBuildDirs() { #
454#----------------------------------#
[e639536]455 local name=`echo ${1} | sed 's/[0-9]-//'`
[fe30c61]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.