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