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