1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | #=== MAKEFILE HEADER ===
|
---|
6 |
|
---|
7 | #----------------------------------#
|
---|
8 | wrt_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 |
|
---|
18 | SRC = /sources
|
---|
19 | MOUNT_PT = $BUILDDIR
|
---|
20 | PKG_LST = $PKG_LST
|
---|
21 | LUSER = $LUSER
|
---|
22 | LGROUP = $LGROUP
|
---|
23 | SCRIPT_ROOT = $SCRIPT_ROOT
|
---|
24 | ADD_BLFS_TOOLS = $BLFS_TOOL
|
---|
25 |
|
---|
26 | BASEDIR = \$(MOUNT_PT)
|
---|
27 | SRCSDIR = \$(BASEDIR)/sources
|
---|
28 | CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
29 | LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
|
---|
30 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
|
---|
31 |
|
---|
32 | crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
33 | crLOGDIR = /\$(SCRIPT_ROOT)/logs
|
---|
34 | crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
|
---|
35 |
|
---|
36 | SU_LUSER = su - \$(LUSER) -c
|
---|
37 | LUSER_HOME = /home/\$(LUSER)
|
---|
38 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
|
---|
39 | PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n"
|
---|
40 |
|
---|
41 | export PATH := \${PATH}:/usr/sbin
|
---|
42 |
|
---|
43 | include makefile-functions
|
---|
44 |
|
---|
45 | EOF
|
---|
46 | ) > $MKFILE
|
---|
47 | }
|
---|
48 |
|
---|
49 | #=======================
|
---|
50 |
|
---|
51 |
|
---|
52 | #==== PACKAGES NAMES ===
|
---|
53 |
|
---|
54 | #----------------------------------#
|
---|
55 | get_package_tarball_name() { #
|
---|
56 | #----------------------------------#
|
---|
57 | local script_name=`echo ${1} | sed -e 's@[0-9]\{1\}-@@'`
|
---|
58 |
|
---|
59 | # The use of 'head' is necessary to limit the return value to the FIRST match..
|
---|
60 | # hopefully this will not cause problems.
|
---|
61 | #
|
---|
62 | case $script_name in
|
---|
63 | tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
64 | ;;
|
---|
65 | linux-headers)
|
---|
66 | if [ "${PROGNAME}" = "lfs" ]; then
|
---|
67 | # Uses kernel headers directly
|
---|
68 | echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
69 | else
|
---|
70 | # CLFS/HLFS use massaged headers package
|
---|
71 | echo $(grep "^linux-headers-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
72 | fi
|
---|
73 | ;;
|
---|
74 | *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
75 | ;;
|
---|
76 | esac
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | #=======================
|
---|
81 |
|
---|
82 |
|
---|
83 | #==== TARGET HEADER ====
|
---|
84 |
|
---|
85 | #----------------------------------#
|
---|
86 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
87 | #----------------------------------#
|
---|
88 | local i=$1
|
---|
89 | local PREV=$2
|
---|
90 | (
|
---|
91 | cat << EOF
|
---|
92 |
|
---|
93 | $i: $PREV
|
---|
94 | @\$(call echo_message, Building)
|
---|
95 | @./progress_bar.sh \$@ \$\$PPID &
|
---|
96 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
97 | @\$(PRT_DU) >>logs/\$@
|
---|
98 | EOF
|
---|
99 | ) >> $MKFILE.tmp
|
---|
100 | }
|
---|
101 |
|
---|
102 | #----------------------------------#
|
---|
103 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
104 | #----------------------------------#
|
---|
105 | local i=$1
|
---|
106 | local PREV=$2
|
---|
107 | case $i in
|
---|
108 | iteration* ) local LOGFILE="${this_script}.log" ;;
|
---|
109 | * ) local LOGFILE="\$@" ;;
|
---|
110 | esac
|
---|
111 | (
|
---|
112 | cat << EOF
|
---|
113 |
|
---|
114 | $i: $PREV
|
---|
115 | @\$(call echo_message, Building)
|
---|
116 | @./progress_bar.sh \$@ \$\$PPID &
|
---|
117 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/$LOGFILE
|
---|
118 | @\$(PRT_DU_CR) >>logs/$LOGFILE
|
---|
119 | EOF
|
---|
120 | ) >> $MKFILE.tmp
|
---|
121 | }
|
---|
122 |
|
---|
123 | #=======================
|
---|
124 |
|
---|
125 |
|
---|
126 | #======== UNPACK =======
|
---|
127 |
|
---|
128 | #----------------------------------#
|
---|
129 | ROOT_Unpack() { # An alias, for clairity
|
---|
130 | #----------------------------------#
|
---|
131 | local FILE=$1
|
---|
132 | local optSAVE_PREVIOUS=$2
|
---|
133 |
|
---|
134 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
135 | (
|
---|
136 | cat << EOF
|
---|
137 | @\$(call remove_existing_dirs,$FILE)
|
---|
138 | EOF
|
---|
139 | ) >> $MKFILE.tmp
|
---|
140 | fi
|
---|
141 |
|
---|
142 | (
|
---|
143 | cat << EOF
|
---|
144 | @\$(call unpack,$FILE)
|
---|
145 | @\$(call get_pkg_root_LUSER)
|
---|
146 | EOF
|
---|
147 | ) >> $MKFILE.tmp
|
---|
148 | }
|
---|
149 |
|
---|
150 | #----------------------------------#
|
---|
151 | LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
152 | #----------------------------------#
|
---|
153 | local FILE=$1
|
---|
154 | local optSAVE_PREVIOUS=$2
|
---|
155 |
|
---|
156 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
157 | (
|
---|
158 | cat << EOF
|
---|
159 | @\$(call remove_existing_dirs,$FILE)
|
---|
160 | EOF
|
---|
161 | ) >> $MKFILE.tmp
|
---|
162 | fi
|
---|
163 |
|
---|
164 | (
|
---|
165 | cat << EOF
|
---|
166 | @\$(call unpack,$FILE)
|
---|
167 | @\$(call get_pkg_root_LUSER)
|
---|
168 | EOF
|
---|
169 | ) >> $MKFILE.tmp
|
---|
170 | }
|
---|
171 |
|
---|
172 | #----------------------------------#
|
---|
173 | CHROOT_Unpack() { #
|
---|
174 | #----------------------------------#
|
---|
175 | local FILE=$1
|
---|
176 | local optSAVE_PREVIOUS=$2
|
---|
177 |
|
---|
178 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
179 | (
|
---|
180 | cat << EOF
|
---|
181 | @\$(call remove_existing_dirs2,$FILE)
|
---|
182 | EOF
|
---|
183 | ) >> $MKFILE.tmp
|
---|
184 | fi
|
---|
185 | (
|
---|
186 | cat << EOF
|
---|
187 | @\$(call unpack3,$FILE)
|
---|
188 | @\$(call get_pkg_root2)
|
---|
189 | EOF
|
---|
190 | ) >> $MKFILE.tmp
|
---|
191 | }
|
---|
192 |
|
---|
193 | #=======================
|
---|
194 |
|
---|
195 |
|
---|
196 | #===== TESTS LOGS ======
|
---|
197 |
|
---|
198 | #----------------------------------#
|
---|
199 | LUSER_wrt_test_log() { # Initialize testsuite log file
|
---|
200 | #----------------------------------#
|
---|
201 | local TESTLOGFILE=$1
|
---|
202 | (
|
---|
203 | cat << EOF
|
---|
204 | @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
|
---|
205 | echo '\$(nl_)\`date\`\$(nl_)' >$TESTLOGDIR/$TESTLOGFILE
|
---|
206 | EOF
|
---|
207 | ) >> $MKFILE.tmp
|
---|
208 | }
|
---|
209 |
|
---|
210 | #----------------------------------#
|
---|
211 | CHROOT_wrt_test_log() { #
|
---|
212 | #----------------------------------#
|
---|
213 | local TESTLOGFILE=$1
|
---|
214 | (
|
---|
215 | cat << EOF
|
---|
216 | @echo "export TEST_LOG=/\$(SCRIPT_ROOT)/test-logs/$TESTLOGFILE" >> envars && \\
|
---|
217 | echo "\$(nl_)\`date\`\$(nl_)" >test-logs/$TESTLOGFILE
|
---|
218 | EOF
|
---|
219 | ) >> $MKFILE.tmp
|
---|
220 | }
|
---|
221 |
|
---|
222 | #=======================
|
---|
223 |
|
---|
224 |
|
---|
225 | #======== RUN AS =======
|
---|
226 |
|
---|
227 | #----------------------------------#
|
---|
228 | wrt_RunAsRoot() { # Some scripts must be run as root..
|
---|
229 | #----------------------------------#
|
---|
230 | local MOUNT_ENV
|
---|
231 | local this_script=$1
|
---|
232 | local file=$2
|
---|
233 |
|
---|
234 | case ${PROGNAME} in
|
---|
235 | lfs ) MOUNT_ENV="LFS" ;;
|
---|
236 | blfs ) MOUNT_ENV="BLFS" ;;
|
---|
237 | clfs ) MOUNT_ENV="CLFS" ;;
|
---|
238 | clfs2 ) MOUNT_ENV="CLFS" ;;
|
---|
239 | clfs3 ) MOUNT_ENV="CLFS" ;;
|
---|
240 | hlfs ) MOUNT_ENV="HLFS" ;;
|
---|
241 | *) echo "undefined progname $PROGNAME"; exit 1 ;;
|
---|
242 | esac
|
---|
243 |
|
---|
244 | (
|
---|
245 | cat << EOF
|
---|
246 | @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
|
---|
247 | \$(PRT_DU) >>logs/\$@
|
---|
248 | EOF
|
---|
249 | ) >> $MKFILE.tmp
|
---|
250 | }
|
---|
251 |
|
---|
252 | #----------------------------------#
|
---|
253 | ROOT_RunAsRoot() { #
|
---|
254 | #----------------------------------#
|
---|
255 | local file=$1
|
---|
256 | (
|
---|
257 | cat << EOF
|
---|
258 | @( time { source envars && \$(CMDSDIR)/$file >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
|
---|
259 | \$(PRT_DU_CR) >>logs/\$@
|
---|
260 | EOF
|
---|
261 | ) >> $MKFILE.tmp
|
---|
262 | }
|
---|
263 |
|
---|
264 | #----------------------------------#
|
---|
265 | LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
|
---|
266 | #----------------------------------#
|
---|
267 | local file=$1
|
---|
268 |
|
---|
269 | (
|
---|
270 | cat << EOF
|
---|
271 | @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
|
---|
272 | \$(PRT_DU) >> logs/\$@
|
---|
273 | EOF
|
---|
274 | ) >> $MKFILE.tmp
|
---|
275 | }
|
---|
276 |
|
---|
277 | #----------------------------------#
|
---|
278 | CHROOT_wrt_RunAsRoot() { #
|
---|
279 | #----------------------------------#
|
---|
280 | local file=$1
|
---|
281 | (
|
---|
282 | cat << EOF
|
---|
283 | @( time { source envars && \$(crCMDSDIR)/$file >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
|
---|
284 | \$(PRT_DU_CR) >>logs/\$@
|
---|
285 | EOF
|
---|
286 | ) >> $MKFILE.tmp
|
---|
287 |
|
---|
288 | }
|
---|
289 |
|
---|
290 | #=======================
|
---|
291 |
|
---|
292 |
|
---|
293 | #====== COPY FSTAB =====
|
---|
294 |
|
---|
295 | #----------------------------------#
|
---|
296 | LUSER_wrt_CopyFstab() { #
|
---|
297 | #----------------------------------#
|
---|
298 | (
|
---|
299 | cat << EOF
|
---|
300 | @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
|
---|
301 | EOF
|
---|
302 | ) >> $MKFILE.tmp
|
---|
303 | }
|
---|
304 |
|
---|
305 | #----------------------------------#
|
---|
306 | CHROOT_wrt_CopyFstab() { #
|
---|
307 | #----------------------------------#
|
---|
308 | (
|
---|
309 | cat << EOF
|
---|
310 | @( time { cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
|
---|
311 | EOF
|
---|
312 | ) >> $MKFILE.tmp
|
---|
313 | }
|
---|
314 |
|
---|
315 | #=======================
|
---|
316 |
|
---|
317 |
|
---|
318 | #==== RM BUILD DIRS ====
|
---|
319 |
|
---|
320 | #----------------------------------#
|
---|
321 | LUSER_RemoveBuildDirs() { #
|
---|
322 | #----------------------------------#
|
---|
323 | local name=$1
|
---|
324 | (
|
---|
325 | cat << EOF
|
---|
326 | @\$(call remove_build_dirs,$name)
|
---|
327 | EOF
|
---|
328 | ) >> $MKFILE.tmp
|
---|
329 | }
|
---|
330 |
|
---|
331 | #----------------------------------#
|
---|
332 | CHROOT_wrt_RemoveBuildDirs() { #
|
---|
333 | #----------------------------------#
|
---|
334 | local name=$1
|
---|
335 | (
|
---|
336 | cat << EOF
|
---|
337 | @\$(call remove_build_dirs2,$name)
|
---|
338 | EOF
|
---|
339 | ) >> $MKFILE.tmp
|
---|
340 | }
|
---|
341 |
|
---|
342 | #=======================
|
---|
343 |
|
---|
344 |
|
---|
345 | #======== TOUCH ========
|
---|
346 |
|
---|
347 | #----------------------------------#
|
---|
348 | wrt_touch() { #
|
---|
349 | #----------------------------------#
|
---|
350 | (
|
---|
351 | cat << EOF
|
---|
352 | @\$(call housekeeping)
|
---|
353 | EOF
|
---|
354 | ) >> $MKFILE.tmp
|
---|
355 | }
|
---|
356 |
|
---|
357 | #=======================
|
---|