Mercurial > hg > beaglert
comparison scripts/build_project.sh @ 67:472e892c6e41
Merge newapi into default
author | Andrew McPherson <a.mcpherson@qmul.ac.uk> |
---|---|
date | Fri, 17 Jul 2015 15:28:18 +0100 |
parents | b89dd0c97a04 |
children | 91e1a3a220d4 |
comparison
equal
deleted
inserted
replaced
21:0d80ff9e2227 | 67:472e892c6e41 |
---|---|
1 #!/bin/bash | |
2 # | |
3 # This script compiles a BeagleRT project on the BeagleBone Black and | |
4 # optionally runs it. Pass a directory path in the first argument. | |
5 # The source files in this directory are copied to the board and compiled. | |
6 | |
7 BBB_ADDRESS="root@192.168.7.2" | |
8 BBB_PATH="~/BeagleRT" | |
9 RUN_PROJECT=1 | |
10 COMMAND_ARGS= | |
11 | |
12 function usage | |
13 { | |
14 THIS_SCRIPT=`basename "$0"` | |
15 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-n] <directory-with-source-files>" | |
16 echo " | |
17 This script copies a directory of source files to the BeagleBone, compiles | |
18 and runs it. The BeagleRT core files should have first been copied over | |
19 using the setup_board.sh script supplied with BeagleRT. | |
20 | |
21 The source directory should contain at least one .c, .cpp or .S file. | |
22 If the argument -n is passed, the output will not be run after compiling. | |
23 The argument -b will change the local path on the BeagleBone where the | |
24 BeagleRT files are found. The -c option passes command-line arguments to | |
25 the BeagleRT program; enclose the argument string in quotes." | |
26 } | |
27 | |
28 OPTIND=1 | |
29 | |
30 while getopts "b:c:nh" opt; do | |
31 case $opt in | |
32 b) BBB_PATH=$OPTARG | |
33 ;; | |
34 c) COMMAND_ARGS=$OPTARG | |
35 ;; | |
36 n) RUN_PROJECT=0 | |
37 ;; | |
38 h|\?) usage | |
39 exit 1 | |
40 esac | |
41 done | |
42 | |
43 shift $((OPTIND-1)) | |
44 | |
45 # Check that we have a directory containing at least one source file | |
46 # as an argument | |
47 | |
48 if [ -z "$1" ] | |
49 then | |
50 usage | |
51 exit | |
52 fi | |
53 | |
54 FIND_STRING="find $* -maxdepth 10000 -type f " | |
55 | |
56 C_FILES=$($FIND_STRING -name "*.c") | |
57 CPP_FILES=$($FIND_STRING -name "*.cpp") | |
58 ASM_FILES=$($FIND_STRING -name "*.S") | |
59 | |
60 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]] | |
61 then | |
62 echo "Please provide a directory containing .c, .cpp or .S files." | |
63 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]" | |
64 usage | |
65 exit | |
66 fi | |
67 | |
68 # Stop BeagleRT and clean out old source files | |
69 echo "Stopping BeagleRT and removing old source files..." | |
70 ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; make sourceclean -C $BBB_PATH" | |
71 | |
72 #concatenate arguments to form path. | |
73 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments | |
74 for i in "$@" #parse input arguments | |
75 do | |
76 if [ -d "$1" ] #check if the path is a folder | |
77 then #if it is, include all of its files | |
78 BBB_SOURCE_PATH+=" ${1}/* " | |
79 else | |
80 BBB_SOURCE_PATH+=" $1 " | |
81 fi | |
82 shift | |
83 # Copy new souce files to the board | |
84 done | |
85 | |
86 # Copy new source files to the board | |
87 echo "Copying new source files to BeagleBone..." | |
88 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" | |
89 | |
90 if [ $? -ne 0 ] | |
91 then | |
92 echo "Error while copying files" | |
93 exit | |
94 fi | |
95 | |
96 # Make new BeagleRT executable and run | |
97 if [ $RUN_PROJECT -eq 0 ] | |
98 then | |
99 echo "Building project..." | |
100 ssh $BBB_ADDRESS "make all -C $BBB_PATH" | |
101 else | |
102 echo "Building and running project..." | |
103 ssh $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" | |
104 fi |