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