andrewm@58: #!/bin/bash andrewm@58: # andrewm@58: # This script compiles a BeagleRT project on the BeagleBone Black and andrewm@58: # optionally runs it. Pass a directory path in the first argument. andrewm@58: # The source files in this directory are copied to the board and compiled. andrewm@58: andrewm@58: BBB_ADDRESS="root@192.168.7.2" andrewm@58: BBB_PATH="~/BeagleRT" andrewm@58: RUN_PROJECT=1 andrewm@60: COMMAND_ARGS= andrewm@58: andrewm@58: function usage andrewm@58: { andrewm@58: THIS_SCRIPT=`basename "$0"` andrewm@60: echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-n] " andrewm@58: echo " andrewm@58: This script copies a directory of source files to the BeagleBone, compiles andrewm@58: and runs it. The BeagleRT core files should have first been copied over andrewm@58: using the setup_board.sh script supplied with BeagleRT. andrewm@58: andrewm@58: The source directory should contain at least one .c, .cpp or .S file. andrewm@58: If the argument -n is passed, the output will not be run after compiling. andrewm@58: The argument -b will change the local path on the BeagleBone where the andrewm@60: BeagleRT files are found. The -c option passes command-line arguments to andrewm@60: the BeagleRT program; enclose the argument string in quotes." andrewm@58: } andrewm@58: andrewm@58: OPTIND=1 andrewm@58: andrewm@60: while getopts "b:c:nh" opt; do andrewm@58: case $opt in andrewm@58: b) BBB_PATH=$OPTARG andrewm@58: ;; andrewm@60: c) COMMAND_ARGS=$OPTARG andrewm@60: ;; andrewm@58: n) RUN_PROJECT=0 andrewm@58: ;; andrewm@58: h|\?) usage andrewm@58: exit 1 andrewm@58: esac andrewm@58: done andrewm@58: andrewm@58: shift $((OPTIND-1)) andrewm@58: andrewm@58: # Check that we have a directory containing at least one source file andrewm@58: # as an argument andrewm@58: if [ -z "$1" ] andrewm@58: then andrewm@58: usage andrewm@58: exit andrewm@58: fi andrewm@58: andrewm@58: C_FILES=$(find "$1" -maxdepth 1 -type f -name "*.c") andrewm@58: CPP_FILES=$(find "$1" -maxdepth 1 -type f -name "*.cpp") andrewm@58: ASM_FILES=$(find "$1" -maxdepth 1 -type f -name "*.S") andrewm@58: andrewm@58: if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]] andrewm@58: then andrewm@58: echo "Please provide a directory containing .c, .cpp or .S files." andrewm@58: # echo "Usage: $THIS_SCRIPT [directory-with-source-files]" andrewm@58: usage andrewm@58: exit andrewm@58: fi andrewm@58: andrewm@58: # Stop BeagleRT and clean out old source files andrewm@58: echo "Stopping BeagleRT and removing old source files..." andrewm@63: ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; sleep 0.5; make sourceclean -C $BBB_PATH" andrewm@58: andrewm@58: # Copy new source files to the board andrewm@58: echo "Copying new source files to BeagleBone..." andrewm@58: scp "$1"/* "$BBB_ADDRESS:$BBB_PATH/source/" andrewm@58: andrewm@58: # Make new BeagleRT executable and run andrewm@58: if [ $RUN_PROJECT -eq 0 ] andrewm@58: then andrewm@58: echo "Building project..." andrewm@58: ssh $BBB_ADDRESS "make all -C $BBB_PATH" andrewm@58: else andrewm@58: echo "Building and running project..." andrewm@61: ssh $BBB_ADDRESS "make all -C $BBB_PATH ; screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" andrewm@58: fi