build.sh 2.86 KB
Newer Older
Michael Wu's avatar
Michael Wu committed
1 2
#!/bin/bash

John Ford's avatar
John Ford committed
3 4 5 6 7 8 9 10 11
# We want to figure out if we need to re-run the firmware
# extraction routine.  The first time we run build.sh, we
# store the hash of important files.  On subsequent runs,
# we check if the hash is the same as the previous run.
# If the hashes differ, we use a per-device script to redo
# the firmware extraction
function configure_device() {
    hash_file="$OUT/firmware.hash"

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    # Make sure that our assumption that device codenames are unique
    # across vendors is true
    if [ $(ls -d device/*/$DEVICE 2> /dev/null | wc -l) -gt 1 ] ; then
        echo $DEVICE is ambiguous \"$(ls -d device/*/$DEVICE 2> /dev/null)\"
        return 1
    fi

    # Select which blob setup script to use, if any.  We currently
    # assume that $DEVICE maps to the filesystem location, which is true
    # for the devices we support now (oct 2012) that do not require blobs.
    # The emulator uses a $DEVICE of 'emulator' but its device/ directory
    # uses the 'goldfish' name.
    if [ -f device/*/$DEVICE/download-blobs.sh ] ; then
        important_files="device/*/$DEVICE/download-blobs.sh"
        script="cd device/*/$DEVICE && ./download-blobs.sh"
    elif [ -f device/*/$DEVICE/extract-files.sh ] ; then
        important_files="device/*/$DEVICE/extract-files.sh"
        script="cd device/*/$DEVICE && ./extract-files.sh"
    else
        important_files=
        script=
    fi
John Ford's avatar
John Ford committed
34 35 36 37

    # If we have files that are important to look at, we need
    # to check if they've changed
    if [ -n "$important_files" ] ; then
38
        new_hash=$(cat $important_files | openssl sha1)
John Ford's avatar
John Ford committed
39 40 41 42
        if [ -f "$hash_file" ] ; then
            old_hash=$(cat "$hash_file")
        fi
        if [ "$old_hash" != "$new_hash" ] ; then
Andreas Gal's avatar
Andreas Gal committed
43
            echo Blob setup script has changed, re-running &&
John Ford's avatar
John Ford committed
44 45 46 47 48 49 50 51 52 53 54
            sh -c "$script" &&
            mkdir -p "$(dirname "$hash_file")" &&
            echo "$new_hash" > "$hash_file"
        fi
    else
        rm -f $hash_file
    fi

    return $?
}

55
unset CDPATH
Michael Wu's avatar
Michael Wu committed
56
. setup.sh &&
57 58
if [ -f patches/patch.sh ] ; then
    . patches/patch.sh
59
fi &&
John Ford's avatar
John Ford committed
60
configure_device &&
Michael Wu's avatar
Michael Wu committed
61
time nice -n19 make $MAKE_FLAGS $@
62 63 64 65 66 67 68

ret=$?
echo -ne \\a
if [ $ret -ne 0 ]; then
	echo
	echo \> Build failed\! \<
	echo
69
	echo Build with \|./build.sh -j1\| for better messages
70 71 72 73
	echo If all else fails, use \|rm -rf objdir-gecko\| to clobber gecko and \|rm -rf out\| to clobber everything else.
else
	case "$1" in
	"gecko")
74 75 76 77 78
		echo Run \|./build.sh snod\| to update the system image.
		echo Run \|./flash.sh gecko\| to update gecko.
		if echo $DEVICE | grep generic > /dev/null ; then
			echo $(tput setaf 1)$(tput bold)You must update the system image for emulator to pick up the updated gecko.$(tput sgr0)
		fi
79 80
		;;
	*)
81 82 83 84 85
		if echo $DEVICE | grep generic > /dev/null ; then
			echo Run \|./run-emulator.sh\| to start the emulator
		else
			echo Run \|./flash.sh\| to flash all partitions of your device
		fi
86 87 88 89 90 91
		;;
	esac
	exit 0
fi

exit $ret