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