Mercurial > hg > beaglert
comparison scripts/build_project.sh @ 108:3068421c0737 ultra-staging
Merged default into ultra-staging
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 00:35:15 +0100 |
parents | c74006ef86ca |
children | f2d47df23c68 |
comparison
equal
deleted
inserted
replaced
54:d3f869b98147 | 108:3068421c0737 |
---|---|
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 RUN_IN_FOREGROUND=0 | |
12 RUN_WITHOUT_SCREEN=0 | |
13 | |
14 function usage | |
15 { | |
16 THIS_SCRIPT=`basename "$0"` | |
17 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>" | |
18 echo " | |
19 This script copies a directory of source files to the BeagleBone, compiles | |
20 and runs it. The BeagleRT core files should have first been copied over | |
21 using the setup_board.sh script supplied with BeagleRT. | |
22 | |
23 The source directory should contain at least one .c, .cpp or .S file. | |
24 If the argument -n is passed, the output will not be run after compiling. | |
25 The argument -b will change the local path on the BeagleBone where the | |
26 BeagleRT files are found. The -c option passes command-line arguments to | |
27 the BeagleRT program; enclose the argument string in quotes. | |
28 | |
29 The -f argument runs the project in the foreground of the current terminal, | |
30 within a screen session that can be detached later. The -F argument runs | |
31 the project in the foreground of the current terminal, without screen, so | |
32 the output can be piped to another destination." | |
33 } | |
34 | |
35 OPTIND=1 | |
36 | |
37 while getopts "b:c:nfFh" opt; do | |
38 case $opt in | |
39 b) BBB_PATH=$OPTARG | |
40 ;; | |
41 c) COMMAND_ARGS=$OPTARG | |
42 ;; | |
43 f) RUN_IN_FOREGROUND=1 | |
44 ;; | |
45 F) RUN_WITHOUT_SCREEN=1 | |
46 ;; | |
47 n) RUN_PROJECT=0 | |
48 ;; | |
49 h|\?) usage | |
50 exit 1 | |
51 esac | |
52 done | |
53 | |
54 shift $((OPTIND-1)) | |
55 | |
56 # Check that we have a directory containing at least one source file | |
57 # as an argument | |
58 | |
59 if [ -z "$1" ] | |
60 then | |
61 usage | |
62 exit | |
63 fi | |
64 | |
65 FIND_STRING="find $* -maxdepth 10000 -type f " | |
66 | |
67 C_FILES=$($FIND_STRING -name "*.c") | |
68 CPP_FILES=$($FIND_STRING -name "*.cpp") | |
69 ASM_FILES=$($FIND_STRING -name "*.S") | |
70 | |
71 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]] | |
72 then | |
73 echo "Please provide a directory containing .c, .cpp or .S files." | |
74 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]" | |
75 usage | |
76 exit | |
77 fi | |
78 | |
79 # Stop BeagleRT and clean out old source files | |
80 echo "Stopping BeagleRT and removing old source files..." | |
81 ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit &>/dev/null; pkill BeagleRT ; make sourceclean -C $BBB_PATH" | |
82 | |
83 #concatenate arguments to form path. | |
84 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments | |
85 for i in "$@" #parse input arguments | |
86 do | |
87 if [ -d "$1" ] #check if the path is a folder | |
88 then #if it is, include all of its files | |
89 BBB_SOURCE_PATH+=" ${1}/* " | |
90 else | |
91 BBB_SOURCE_PATH+=" $1 " | |
92 fi | |
93 shift | |
94 # Copy new souce files to the board | |
95 done | |
96 | |
97 # Copy new source files to the board | |
98 echo "Copying new source files to BeagleBone..." | |
99 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" | |
100 | |
101 if [ $? -ne 0 ] | |
102 then | |
103 echo "Error while copying files" | |
104 exit | |
105 fi | |
106 | |
107 # Make new BeagleRT executable and run | |
108 if [ $RUN_PROJECT -eq 0 ] | |
109 then | |
110 echo "Building project..." | |
111 ssh $BBB_ADDRESS "make all -C $BBB_PATH" | |
112 else | |
113 echo "Building and running project..." | |
114 | |
115 if [ $RUN_WITHOUT_SCREEN -ne 0 ] | |
116 then | |
117 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && $BBB_PATH/BeagleRT $COMMAND_ARGS" | |
118 elif [ $RUN_IN_FOREGROUND -eq 0 ] | |
119 then | |
120 ssh $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" | |
121 else | |
122 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT $BBB_PATH/BeagleRT $COMMAND_ARGS" | |
123 fi | |
124 fi |