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 | PKGMNGT = $PKGMNGT
|
---|
48 |
|
---|
49 |
|
---|
50 | export PATH := \${PATH}:/usr/sbin
|
---|
51 |
|
---|
52 | include makefile-functions
|
---|
53 |
|
---|
54 | EOF
|
---|
55 | ) > $MKFILE
|
---|
56 | }
|
---|
57 |
|
---|
58 | #=======================
|
---|
59 |
|
---|
60 |
|
---|
61 | #==== PACKAGES NAMES ===
|
---|
62 |
|
---|
63 | #----------------------------------#
|
---|
64 | get_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 | util-linux-libs) echo $(grep "^util-linux" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
100 | ;;
|
---|
101 | xz-utils) echo $(grep "^xz" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
102 | ;;
|
---|
103 | sqlite) echo $(grep "^sqlite" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
104 | ;;
|
---|
105 | *) echo $(grep "^$script_name[_-][[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
106 | ;;
|
---|
107 | esac
|
---|
108 |
|
---|
109 | }
|
---|
110 |
|
---|
111 | #=======================
|
---|
112 |
|
---|
113 |
|
---|
114 | #==== TARGET HEADER ====
|
---|
115 |
|
---|
116 | #----------------------------------#
|
---|
117 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
118 | #----------------------------------#
|
---|
119 | local i=$1
|
---|
120 | local PREV=$2
|
---|
121 | (
|
---|
122 | cat << EOF
|
---|
123 |
|
---|
124 | $i: $PREV
|
---|
125 | @\$(call echo_message, Building)
|
---|
126 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
127 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
128 | @\$(PRT_DU) >>logs/\$@
|
---|
129 | EOF
|
---|
130 | ) >> $MKFILE.tmp
|
---|
131 | }
|
---|
132 |
|
---|
133 | #----------------------------------#
|
---|
134 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
135 | #----------------------------------#
|
---|
136 | local i=$1
|
---|
137 | local PREV=$2
|
---|
138 | (
|
---|
139 | cat << EOF
|
---|
140 |
|
---|
141 | $i: $PREV
|
---|
142 | @\$(call echo_message, Building)
|
---|
143 | ${NO_PROGRESS} @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
144 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
145 | @\$(PRT_DU_CR) >>logs/\$@
|
---|
146 | EOF
|
---|
147 | ) >> $MKFILE.tmp
|
---|
148 | }
|
---|
149 |
|
---|
150 | #=======================
|
---|
151 |
|
---|
152 |
|
---|
153 | #======== UNPACK =======
|
---|
154 |
|
---|
155 | #----------------------------------#
|
---|
156 | LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
157 | #----------------------------------#
|
---|
158 | local FILE=$1
|
---|
159 | local optSAVE_PREVIOUS=$2
|
---|
160 |
|
---|
161 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
162 | (
|
---|
163 | cat << EOF
|
---|
164 | @\$(call remove_existing_dirs,$FILE)
|
---|
165 | EOF
|
---|
166 | ) >> $MKFILE.tmp
|
---|
167 | fi
|
---|
168 |
|
---|
169 | (
|
---|
170 | cat << EOF
|
---|
171 | @\$(call unpack,$FILE)
|
---|
172 | @\$(call get_pkg_root_LUSER)
|
---|
173 | EOF
|
---|
174 | ) >> $MKFILE.tmp
|
---|
175 | }
|
---|
176 |
|
---|
177 | #----------------------------------#
|
---|
178 | CHROOT_Unpack() { #
|
---|
179 | #----------------------------------#
|
---|
180 | local FILE=$1
|
---|
181 | local optSAVE_PREVIOUS=$2
|
---|
182 |
|
---|
183 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
184 | (
|
---|
185 | cat << EOF
|
---|
186 | @\$(call remove_existing_dirs2,$FILE)
|
---|
187 | EOF
|
---|
188 | ) >> $MKFILE.tmp
|
---|
189 | fi
|
---|
190 | (
|
---|
191 | cat << EOF
|
---|
192 | @\$(call unpack2,$FILE)
|
---|
193 | @\$(call get_pkg_root2)
|
---|
194 | EOF
|
---|
195 | ) >> $MKFILE.tmp
|
---|
196 | }
|
---|
197 |
|
---|
198 | #=======================
|
---|
199 |
|
---|
200 |
|
---|
201 | #===== TESTS LOGS ======
|
---|
202 |
|
---|
203 | #----------------------------------#
|
---|
204 | LUSER_wrt_test_log() { # Initialize testsuite log file
|
---|
205 | #----------------------------------#
|
---|
206 | local TESTLOGFILE=$1
|
---|
207 | (
|
---|
208 | cat << EOF
|
---|
209 | @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
210 | echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/\$@
|
---|
211 | EOF
|
---|
212 | ) >> $MKFILE.tmp
|
---|
213 | }
|
---|
214 |
|
---|
215 | #----------------------------------#
|
---|
216 | CHROOT_wrt_test_log() { #
|
---|
217 | #----------------------------------#
|
---|
218 | local TESTLOGFILE=$1
|
---|
219 | (
|
---|
220 | cat << EOF
|
---|
221 | @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
222 | echo "\$(nl_)\`date\`\$(nl_)" >test-logs/\$@
|
---|
223 | EOF
|
---|
224 | ) >> $MKFILE.tmp
|
---|
225 | }
|
---|
226 |
|
---|
227 | #=======================
|
---|
228 |
|
---|
229 |
|
---|
230 | #======== RUN AS =======
|
---|
231 |
|
---|
232 | #----------------------------------#
|
---|
233 | wrt_RunAsRoot() { # Some scripts must be run as root..
|
---|
234 | #----------------------------------#
|
---|
235 | local MOUNT_ENV
|
---|
236 | local file=$1
|
---|
237 |
|
---|
238 | case ${PROGNAME} in
|
---|
239 | lfs ) MOUNT_ENV="LFS" ;;
|
---|
240 | clfs ) MOUNT_ENV="CLFS" ;;
|
---|
241 | clfs2 ) MOUNT_ENV="CLFS" ;;
|
---|
242 | clfs3 ) MOUNT_ENV="CLFS" ;;
|
---|
243 | hlfs ) MOUNT_ENV="HLFS" ;;
|
---|
244 | *) echo "undefined progname $PROGNAME"; exit 1 ;;
|
---|
245 | esac
|
---|
246 |
|
---|
247 | (
|
---|
248 | cat << EOF
|
---|
249 | @export ${MOUNT_ENV}=\$(MOUNT_PT) && \\
|
---|
250 | ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 && \\
|
---|
251 | \$(PRT_DU) >>logs/\$@
|
---|
252 | EOF
|
---|
253 | ) >> $MKFILE.tmp
|
---|
254 | }
|
---|
255 |
|
---|
256 | #----------------------------------#
|
---|
257 | LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file
|
---|
258 | #----------------------------------#
|
---|
259 | local file=$1
|
---|
260 |
|
---|
261 | (
|
---|
262 | cat << EOF
|
---|
263 | @source ~/.bashrc && \\
|
---|
264 | \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1 && \\
|
---|
265 | \$(PRT_DU) >>logs/\$@
|
---|
266 | EOF
|
---|
267 | ) >> $MKFILE.tmp
|
---|
268 | }
|
---|
269 |
|
---|
270 | #----------------------------------#
|
---|
271 | CHROOT_wrt_RunAsRoot() { #
|
---|
272 | #----------------------------------#
|
---|
273 | local file=$1
|
---|
274 | (
|
---|
275 | cat << EOF
|
---|
276 | @source envars && \\
|
---|
277 | \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1 && \\
|
---|
278 | \$(PRT_DU_CR) >>logs/\$@
|
---|
279 | EOF
|
---|
280 | ) >> $MKFILE.tmp
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | #=======================
|
---|
285 |
|
---|
286 |
|
---|
287 | #====== COPY FSTAB =====
|
---|
288 |
|
---|
289 | #----------------------------------#
|
---|
290 | LUSER_wrt_CopyFstab() { #
|
---|
291 | #----------------------------------#
|
---|
292 | (
|
---|
293 | cat << EOF
|
---|
294 | @cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
295 | \$(PRT_DU) >>logs/\$@
|
---|
296 | EOF
|
---|
297 | ) >> $MKFILE.tmp
|
---|
298 | }
|
---|
299 |
|
---|
300 | #----------------------------------#
|
---|
301 | CHROOT_wrt_CopyFstab() { #
|
---|
302 | #----------------------------------#
|
---|
303 | (
|
---|
304 | cat << EOF
|
---|
305 | @cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\
|
---|
306 | \$(PRT_DU_CR) >>logs/\$@
|
---|
307 | EOF
|
---|
308 | ) >> $MKFILE.tmp
|
---|
309 | }
|
---|
310 |
|
---|
311 | #=======================
|
---|
312 |
|
---|
313 |
|
---|
314 | #==== INSTALLED FILES LOGS ====
|
---|
315 |
|
---|
316 | #----------------------------------#
|
---|
317 | LUSER_wrt_TouchTimestamp() { #
|
---|
318 | #----------------------------------#
|
---|
319 | (
|
---|
320 | cat << EOF
|
---|
321 | @\$(call touch_timestamp_LUSER)
|
---|
322 | EOF
|
---|
323 | ) >> $MKFILE.tmp
|
---|
324 | }
|
---|
325 |
|
---|
326 | #----------------------------------#
|
---|
327 | CHROOT_wrt_TouchTimestamp() { #
|
---|
328 | #----------------------------------#
|
---|
329 | (
|
---|
330 | cat << EOF
|
---|
331 | @\$(call touch_timestamp)
|
---|
332 | EOF
|
---|
333 | ) >> $MKFILE.tmp
|
---|
334 | }
|
---|
335 |
|
---|
336 | #----------------------------------#
|
---|
337 | LUSER_wrt_LogNewFiles() { #
|
---|
338 | #----------------------------------#
|
---|
339 | local name=$1
|
---|
340 | (
|
---|
341 | cat << EOF
|
---|
342 | @\$(call log_new_files_LUSER,$name)
|
---|
343 | EOF
|
---|
344 | ) >> $MKFILE.tmp
|
---|
345 | }
|
---|
346 |
|
---|
347 | #----------------------------------#
|
---|
348 | CHROOT_wrt_LogNewFiles() { #
|
---|
349 | #----------------------------------#
|
---|
350 | local name=$1
|
---|
351 | (
|
---|
352 | cat << EOF
|
---|
353 | @\$(call log_new_files,$name)
|
---|
354 | EOF
|
---|
355 | ) >> $MKFILE.tmp
|
---|
356 | }
|
---|
357 |
|
---|
358 | #=======================
|
---|
359 |
|
---|
360 |
|
---|
361 | #==== RM BUILD DIRS ====
|
---|
362 |
|
---|
363 | #----------------------------------#
|
---|
364 | LUSER_RemoveBuildDirs() { #
|
---|
365 | #----------------------------------#
|
---|
366 | local name=$1
|
---|
367 | (
|
---|
368 | cat << EOF
|
---|
369 | @\$(call remove_build_dirs,$name)
|
---|
370 | EOF
|
---|
371 | ) >> $MKFILE.tmp
|
---|
372 | }
|
---|
373 |
|
---|
374 | #----------------------------------#
|
---|
375 | CHROOT_wrt_RemoveBuildDirs() { #
|
---|
376 | #----------------------------------#
|
---|
377 | local name=$1
|
---|
378 | (
|
---|
379 | cat << EOF
|
---|
380 | @\$(call remove_build_dirs2,$name)
|
---|
381 | EOF
|
---|
382 | ) >> $MKFILE.tmp
|
---|
383 | }
|
---|
384 |
|
---|
385 | #=======================
|
---|
386 |
|
---|
387 |
|
---|
388 | #======== TOUCH ========
|
---|
389 |
|
---|
390 | #----------------------------------#
|
---|
391 | wrt_touch() { #
|
---|
392 | #----------------------------------#
|
---|
393 | (
|
---|
394 | cat << EOF
|
---|
395 | @\$(call housekeeping)
|
---|
396 | EOF
|
---|
397 | ) >> $MKFILE.tmp
|
---|
398 | }
|
---|
399 |
|
---|
400 | #=======================
|
---|