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