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