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