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