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