[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 |
|
---|
[aec4483] | 17 |
|
---|
| 18 | SHELL = /bin/bash
|
---|
[195ed9f] | 19 |
|
---|
| 20 | SRC = /sources
|
---|
| 21 | MOUNT_PT = $BUILDDIR
|
---|
| 22 | PKG_LST = $PKG_LST
|
---|
| 23 | LUSER = $LUSER
|
---|
| 24 | LGROUP = $LGROUP
|
---|
[962793a] | 25 | LHOME = $LHOME
|
---|
[195ed9f] | 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)/logs
|
---|
| 32 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
|
---|
| 33 |
|
---|
| 34 | crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
| 35 | crLOGDIR = /\$(SCRIPT_ROOT)/logs
|
---|
| 36 | crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
|
---|
| 37 |
|
---|
| 38 | SU_LUSER = su - \$(LUSER) -c
|
---|
[962793a] | 39 | LUSER_HOME = \$(LHOME)/\$(LUSER)
|
---|
[195ed9f] | 40 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
|
---|
| 41 | PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n"
|
---|
| 42 |
|
---|
[3e7ceed] | 43 | ADD_REPORT = $REPORT
|
---|
| 44 | ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
|
---|
| 45 | ADD_BLFS_TOOLS = $BLFS_TOOL
|
---|
[1838bc7] | 46 |
|
---|
| 47 |
|
---|
[195ed9f] | 48 | export PATH := \${PATH}:/usr/sbin
|
---|
| 49 |
|
---|
| 50 | include makefile-functions
|
---|
| 51 |
|
---|
| 52 | EOF
|
---|
| 53 | ) > $MKFILE
|
---|
| 54 | }
|
---|
[fe30c61] | 55 |
|
---|
| 56 | #=======================
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | #==== PACKAGES NAMES ===
|
---|
| 60 |
|
---|
| 61 | #----------------------------------#
|
---|
| 62 | get_package_tarball_name() { #
|
---|
| 63 | #----------------------------------#
|
---|
| 64 | local script_name=`echo ${1} | sed -e 's@[0-9]\{1\}-@@'`
|
---|
| 65 |
|
---|
| 66 | # The use of 'head' is necessary to limit the return value to the FIRST match..
|
---|
| 67 | # hopefully this will not cause problems.
|
---|
| 68 | #
|
---|
| 69 | case $script_name in
|
---|
| 70 | tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 71 | ;;
|
---|
[3c38ab0] | 72 | uClibc)
|
---|
| 73 | if [[ "${PROGNAME}" = "clfs3" ]]; then
|
---|
| 74 | echo $(grep "^uClibc-" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 75 | else
|
---|
| 76 | echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 77 | fi
|
---|
| 78 | ;;
|
---|
[fe30c61] | 79 | linux-headers)
|
---|
[62d690d] | 80 | if [[ "${PROGNAME}" = "lfs" ]] || [[ "${PROGNAME}" = "hlfs" ]] ; then
|
---|
[fe30c61] | 81 | # Uses kernel headers directly
|
---|
| 82 | echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 83 | else
|
---|
[62d690d] | 84 | # CLFS{,2,3} use massaged headers package
|
---|
[fe30c61] | 85 | echo $(grep "^linux-headers-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 86 | fi
|
---|
| 87 | ;;
|
---|
| 88 | *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 89 | ;;
|
---|
| 90 | esac
|
---|
| 91 |
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | #=======================
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | #==== TARGET HEADER ====
|
---|
| 98 |
|
---|
| 99 | #----------------------------------#
|
---|
| 100 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
| 101 | #----------------------------------#
|
---|
| 102 | local i=$1
|
---|
| 103 | local PREV=$2
|
---|
| 104 | (
|
---|
| 105 | cat << EOF
|
---|
| 106 |
|
---|
| 107 | $i: $PREV
|
---|
| 108 | @\$(call echo_message, Building)
|
---|
[c180dec] | 109 | @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
[fe30c61] | 110 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
| 111 | @\$(PRT_DU) >>logs/\$@
|
---|
| 112 | EOF
|
---|
| 113 | ) >> $MKFILE.tmp
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | #----------------------------------#
|
---|
| 117 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
| 118 | #----------------------------------#
|
---|
| 119 | local i=$1
|
---|
| 120 | local PREV=$2
|
---|
| 121 | (
|
---|
| 122 | cat << EOF
|
---|
| 123 |
|
---|
| 124 | $i: $PREV
|
---|
| 125 | @\$(call echo_message, Building)
|
---|
[c180dec] | 126 | @export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
|
---|
[6bb080e] | 127 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
| 128 | @\$(PRT_DU_CR) >>logs/\$@
|
---|
[fe30c61] | 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
|
---|
[6bb080e] | 192 | @echo "export TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
[10c8b78] | 193 | echo "\$(nl_)\`date\`\$(nl_)" >\$(TESTLOGDIR)/\$@
|
---|
[fe30c61] | 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 && \\
|
---|
[6bb080e] | 205 | echo "\$(nl_)\`date\`\$(nl_)" >test-logs/\$@
|
---|
[fe30c61] | 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 | #=======================
|
---|