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