| andrewm@58 | 1 #!/bin/bash | 
| andrewm@58 | 2 # | 
| andrewm@58 | 3 # This script compiles a BeagleRT project on the BeagleBone Black and | 
| andrewm@58 | 4 # optionally runs it. Pass a directory path in the first argument. | 
| andrewm@58 | 5 # The source files in this directory are copied to the board and compiled. | 
| andrewm@58 | 6 | 
| andrewm@58 | 7 BBB_ADDRESS="root@192.168.7.2" | 
| andrewm@58 | 8 BBB_PATH="~/BeagleRT" | 
| andrewm@58 | 9 RUN_PROJECT=1 | 
| andrewm@60 | 10 COMMAND_ARGS= | 
| andrewm@58 | 11 | 
| andrewm@58 | 12 function usage | 
| andrewm@58 | 13 { | 
| andrewm@58 | 14     THIS_SCRIPT=`basename "$0"` | 
| andrewm@60 | 15     echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-n] <directory-with-source-files>" | 
| andrewm@58 | 16     echo " | 
| andrewm@58 | 17     This script copies a directory of source files to the BeagleBone, compiles | 
| andrewm@58 | 18     and runs it. The BeagleRT core files should have first been copied over | 
| andrewm@58 | 19     using the setup_board.sh script supplied with BeagleRT. | 
| andrewm@58 | 20 | 
| andrewm@58 | 21     The source directory should contain at least one .c, .cpp or .S file. | 
| andrewm@58 | 22     If the argument -n is passed, the output will not be run after compiling. | 
| andrewm@58 | 23     The argument -b will change the local path on the BeagleBone where the | 
| andrewm@60 | 24     BeagleRT files are found. The -c option passes command-line arguments to | 
| andrewm@60 | 25     the BeagleRT program; enclose the argument string in quotes." | 
| andrewm@58 | 26 } | 
| andrewm@58 | 27 | 
| andrewm@58 | 28 OPTIND=1 | 
| andrewm@58 | 29 | 
| andrewm@60 | 30 while getopts "b:c:nh" opt; do | 
| andrewm@58 | 31     case $opt in | 
| andrewm@58 | 32         b)            BBB_PATH=$OPTARG | 
| andrewm@58 | 33                       ;; | 
| andrewm@60 | 34         c)            COMMAND_ARGS=$OPTARG | 
| andrewm@60 | 35                       ;; | 
| andrewm@58 | 36         n)    	      RUN_PROJECT=0 | 
| andrewm@58 | 37                       ;; | 
| andrewm@58 | 38         h|\?)         usage | 
| andrewm@58 | 39                       exit 1 | 
| andrewm@58 | 40     esac | 
| andrewm@58 | 41 done | 
| andrewm@58 | 42 | 
| andrewm@58 | 43 shift $((OPTIND-1)) | 
| andrewm@58 | 44 | 
| andrewm@58 | 45 # Check that we have a directory containing at least one source file | 
| andrewm@58 | 46 # as an argument | 
| andrewm@58 | 47 if [ -z "$1" ] | 
| andrewm@58 | 48 then | 
| andrewm@58 | 49     usage | 
| andrewm@58 | 50     exit | 
| andrewm@58 | 51 fi | 
| andrewm@58 | 52 | 
| andrewm@58 | 53 C_FILES=$(find "$1" -maxdepth 1 -type f -name "*.c") | 
| andrewm@58 | 54 CPP_FILES=$(find "$1" -maxdepth 1 -type f -name "*.cpp") | 
| andrewm@58 | 55 ASM_FILES=$(find "$1" -maxdepth 1 -type f -name "*.S") | 
| andrewm@58 | 56 | 
| andrewm@58 | 57 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]] | 
| andrewm@58 | 58 then | 
| andrewm@58 | 59     echo "Please provide a directory containing .c, .cpp or .S files." | 
| andrewm@58 | 60 #    echo "Usage: $THIS_SCRIPT [directory-with-source-files]" | 
| andrewm@58 | 61     usage | 
| andrewm@58 | 62     exit | 
| andrewm@58 | 63 fi | 
| andrewm@58 | 64 | 
| andrewm@58 | 65 # Stop BeagleRT and clean out old source files | 
| andrewm@58 | 66 echo "Stopping BeagleRT and removing old source files..." | 
| andrewm@63 | 67 ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; sleep 0.5; make sourceclean -C $BBB_PATH" | 
| andrewm@58 | 68 | 
| andrewm@58 | 69 # Copy new source files to the board | 
| andrewm@58 | 70 echo "Copying new source files to BeagleBone..." | 
| andrewm@58 | 71 scp "$1"/* "$BBB_ADDRESS:$BBB_PATH/source/" | 
| andrewm@58 | 72 | 
| andrewm@58 | 73 # Make new BeagleRT executable and run | 
| andrewm@58 | 74 if [ $RUN_PROJECT -eq 0 ] | 
| andrewm@58 | 75 then | 
| andrewm@58 | 76     echo "Building project..." | 
| andrewm@58 | 77     ssh $BBB_ADDRESS "make all -C $BBB_PATH" | 
| andrewm@58 | 78 else | 
| andrewm@58 | 79     echo "Building and running project..." | 
| andrewm@61 | 80     ssh $BBB_ADDRESS "make all -C $BBB_PATH ; screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" | 
| andrewm@58 | 81 fi |