source: common/libs/func_wrt_Makefile

trunk
Last change on this file was cacc6c5, checked in by Pierre Labastie <pierre.labastie@…>, 13 months ago

Allow users to pass a cpuset

If using a new book, MAKEFLAGS is set to -j$(nproc), so that if
we want to easure timings with 4 processors and our computer has
more than that, we need to restrict the number of processors.
Jhalfs allows to do that using th cpuset cgroup controller, so that
it only restrits the make job and not the whole machine. For that
use a small scripts written by Xi Ruoyao that restarts make this
the cpuset set.

  • Property mode set to 100644
File size: 7.3 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)/$COMMANDS
29LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$LOGDIRBASE
30TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$TESTLOGDIRBASE
31
32crCMDSDIR = /\$(SCRIPT_ROOT)/$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
47CPUSET = $CPUSET
48
49
50export PATH := \${PATH}:/usr/sbin
51
52include makefile-functions
53
54EOF
55) > $MKFILE
56}
57
58#=======================
59
60
61#==== TARGET HEADER ====
62
63#----------------------------------#
64LUSER_wrt_target() { # Create target and initialize log file
65#----------------------------------#
66 local i=$1
67 local PREV=$2
68 local version
69 if [ "$3" != "" ]; then
70 version=-$3
71 fi
72(
73cat << EOF
74
75$i: $PREV
76 @\$(call echo_message, Building)
77${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
78 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
79 @ : > envars
80EOF
81) >> $MKFILE.tmp
82}
83
84#----------------------------------#
85CHROOT_wrt_target() { # Create target and initialize log file
86#----------------------------------#
87 local i=$1
88 local PREV=$2
89 local version
90 if [ "$3" != "" ]; then
91 version=-$3
92 fi
93(
94cat << EOF
95
96$i: $PREV
97 @\$(call echo_message, Building)
98${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
99 @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@$version
100 @ : > envars
101EOF
102) >> $MKFILE.tmp
103}
104
105#=======================
106
107
108#======== UNPACK =======
109
110#----------------------------------#
111LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
112#----------------------------------#
113 local FILE="$1"
114 local optSAVE_PREVIOUS="$2"
115 local version
116 if [ "$3" != "" ]; then
117 version=-"$3"
118 fi
119
120 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
121(
122cat << EOF
123 @\$(call remove_existing_dirs,$FILE)
124EOF
125) >> $MKFILE.tmp
126 fi
127
128(
129cat << EOF
130 @\$(PRT_DU) >>logs/\$@$version
131 @\$(call unpack,$FILE)
132 @\$(call get_pkg_root_LUSER)
133EOF
134) >> $MKFILE.tmp
135}
136
137#----------------------------------#
138CHROOT_Unpack() { #
139#----------------------------------#
140 local FILE=$1
141 local optSAVE_PREVIOUS=$2
142 local version
143 if [ "$3" != "" ]; then
144 version=-"$3"
145 fi
146
147 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
148(
149cat << EOF
150 @\$(call remove_existing_dirs2,$FILE)
151EOF
152) >> $MKFILE.tmp
153 fi
154
155(
156cat << EOF
157 @\$(PRT_DU_CR) >>logs/\$@$version
158 @\$(call unpack2,$FILE)
159 @\$(call get_pkg_root2)
160EOF
161) >> $MKFILE.tmp
162}
163
164#=======================
165
166
167#===== TESTS LOGS ======
168
169#----------------------------------#
170LUSER_wrt_test_log() { # Initialize testsuite log file
171#----------------------------------#
172 local version
173 if [ "$2" != "" ]; then
174 version=-$2
175 fi
176 local TESTLOGFILE=$1$version
177(
178cat << EOF
179 @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
180 echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/$TESTLOGFILE
181EOF
182) >> $MKFILE.tmp
183}
184
185#----------------------------------#
186CHROOT_wrt_test_log() { #
187#----------------------------------#
188 local version
189 if [ "$2" != "" ]; then
190 version=-$2
191 fi
192 local TESTLOGFILE=$1$version
193(
194cat << EOF
195 @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
196 echo "\$(nl_)\`date\`\$(nl_)" >\$(crTESTLOGDIR)/$TESTLOGFILE
197EOF
198) >> $MKFILE.tmp
199}
200
201#=======================
202
203
204#======== RUN AS =======
205
206#----------------------------------#
207wrt_RunAsRoot() { # Some scripts must be run as root..
208#----------------------------------#
209 local MOUNT_ENV
210 local version
211 if [ "$2" != "" ]; then
212 version=-$2
213 fi
214 local file=$1
215
216(
217cat << EOF
218 @export LFS=\$(MOUNT_PT) && \\
219 $COMMANDS/`dirname $file`/\$@ >>logs/\$@$version 2>&1
220EOF
221) >> $MKFILE.tmp
222}
223
224#----------------------------------#
225LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
226#----------------------------------#
227 local file=$1
228 local version
229 if [ "$2" != "" ]; then
230 version=-$2
231 fi
232
233(
234cat << EOF
235 @source ~/.bashrc && \\
236 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@$version 2>&1
237EOF
238) >> $MKFILE.tmp
239}
240
241#----------------------------------#
242CHROOT_wrt_RunAsRoot() { #
243#----------------------------------#
244 local file=$1
245 local version
246 if [ "$2" != "" ]; then
247 version=-$2
248 fi
249(
250cat << EOF
251 @source envars && \\
252 \$(crCMDSDIR)/`dirname $file`/\$@ >>\$(crLOGDIR)/\$@$version 2>&1
253EOF
254) >> $MKFILE.tmp
255
256}
257
258#=======================
259
260
261#====== COPY FSTAB =====
262
263#----------------------------------#
264LUSER_wrt_CopyFstab() { #
265#----------------------------------#
266(
267cat << EOF
268 @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
269 \$(PRT_DU) >>logs/\$@
270EOF
271) >> $MKFILE.tmp
272}
273
274#----------------------------------#
275CHROOT_wrt_CopyFstab() { #
276#----------------------------------#
277(
278cat << EOF
279 @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
280 \$(PRT_DU_CR) >>logs/\$@
281EOF
282) >> $MKFILE.tmp
283}
284
285#=======================
286
287
288#==== INSTALLED FILES LOGS ====
289
290#----------------------------------#
291LUSER_wrt_TouchTimestamp() { #
292#----------------------------------#
293(
294cat << EOF
295 @\$(call touch_timestamp_LUSER)
296EOF
297) >> $MKFILE.tmp
298}
299
300#----------------------------------#
301CHROOT_wrt_TouchTimestamp() { #
302#----------------------------------#
303(
304cat << EOF
305 @\$(call touch_timestamp)
306EOF
307) >> $MKFILE.tmp
308}
309
310#----------------------------------#
311LUSER_wrt_LogNewFiles() { #
312#----------------------------------#
313(
314cat << EOF
315 @\$(call log_new_files_LUSER,$1)
316EOF
317) >> $MKFILE.tmp
318}
319
320#----------------------------------#
321CHROOT_wrt_LogNewFiles() { #
322#----------------------------------#
323(
324cat << EOF
325 @\$(call log_new_files,$1)
326EOF
327) >> $MKFILE.tmp
328}
329
330#=======================
331
332
333#==== RM BUILD DIRS ====
334
335#----------------------------------#
336LUSER_RemoveBuildDirs() { #
337#----------------------------------#
338 local name=`echo ${1} | sed 's/[0-9]-//'`
339(
340cat << EOF
341 @\$(call remove_build_dirs,$name)
342EOF
343) >> $MKFILE.tmp
344}
345
346#----------------------------------#
347CHROOT_wrt_RemoveBuildDirs() { #
348#----------------------------------#
349 local name=`echo ${1} | sed 's/[0-9]-//'`
350(
351cat << EOF
352 @\$(call remove_build_dirs2,$name)
353EOF
354) >> $MKFILE.tmp
355}
356
357#=======================
358
359
360#======== TOUCH ========
361
362#----------------------------------#
363wrt_touch() { #
364#----------------------------------#
365(
366cat << EOF
367 @\$(call housekeeping)
368EOF
369) >> $MKFILE.tmp
370}
371
372#=======================
Note: See TracBrowser for help on using the repository browser.