giuliomoro@425
|
1 #!/bin/sh
|
andrewm@58
|
2 #
|
giuliomoro@377
|
3 # This script compiles a Bela 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.
|
giuliomoro@262
|
6 # set defaults unless variables are already set
|
giuliomoro@445
|
7
|
giuliomoro@462
|
8 SCRIPTDIR=$(dirname "$0")
|
giuliomoro@462
|
9 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/
|
giuliomoro@462
|
10 . $SCRIPTDIR.bela_common || { echo "You must be in Bela/scripts to run these scripts" | exit 1; }
|
andrewm@58
|
11
|
giuliomoro@512
|
12 WATCH="0"
|
giuliomoro@430
|
13 usage()
|
andrewm@58
|
14 {
|
giuliomoro@512
|
15 THIS_SCRIPT=`basename "$0"`
|
giuliomoro@512
|
16 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>"
|
giuliomoro@512
|
17 echo "
|
giuliomoro@512
|
18 This script copies a directory of source files to the BeagleBone, compiles
|
giuliomoro@512
|
19 and runs it. The Bela core files should have first been copied over
|
giuliomoro@523
|
20 using the \`update_board' script once.
|
giuliomoro@523
|
21 The source directory should contain at least one .c, .cpp, .S or .pd file.
|
andrewm@58
|
22
|
giuliomoro@523
|
23 "
|
giuliomoro@523
|
24 build_script_usage
|
giuliomoro@523
|
25 }
|
giuliomoro@523
|
26 # UNDOCUMENTED OPTION -s runs in a screen in the foreground
|
giuliomoro@512
|
27
|
giuliomoro@523
|
28 RUN_MODE=foreground
|
giuliomoro@512
|
29
|
giuliomoro@523
|
30 # We are "whiling" $2 because the last command is going to be the path/to/project
|
giuliomoro@523
|
31 [ $# -lt 2 ] && {
|
giuliomoro@523
|
32 [ -d $1 ] || { usage; exit; }
|
andrewm@58
|
33 }
|
giuliomoro@512
|
34 while [ "$2" != "" ]; do
|
giuliomoro@512
|
35 case $1 in
|
giuliomoro@512
|
36 -c)
|
giuliomoro@512
|
37 shift
|
giuliomoro@512
|
38 COMMAND_ARGS="$1"
|
giuliomoro@512
|
39 ;;
|
giuliomoro@512
|
40 -b)
|
giuliomoro@523
|
41 RUN_MODE=screen
|
giuliomoro@512
|
42 ;;
|
giuliomoro@512
|
43 -f)
|
giuliomoro@523
|
44 RUN_MODE=foreground
|
giuliomoro@523
|
45 ;;
|
giuliomoro@523
|
46 -s)
|
giuliomoro@523
|
47 RUN_MODE=screenfg
|
giuliomoro@512
|
48 ;;
|
giuliomoro@512
|
49 -n)
|
giuliomoro@512
|
50 RUN_PROJECT=0
|
giuliomoro@512
|
51 ;;
|
giuliomoro@512
|
52 -p)
|
giuliomoro@512
|
53 shift
|
giuliomoro@512
|
54 BBB_PROJECT_NAME="$1"
|
giuliomoro@512
|
55 ;;
|
giuliomoro@523
|
56 --clean)
|
giuliomoro@523
|
57 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean"
|
giuliomoro@512
|
58 ;;
|
giuliomoro@512
|
59 -m)
|
giuliomoro@512
|
60 shift
|
giuliomoro@523
|
61 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS $1"
|
giuliomoro@512
|
62 ;;
|
giuliomoro@512
|
63 --watch)
|
giuliomoro@512
|
64 WATCH=1
|
giuliomoro@512
|
65 ;;
|
giuliomoro@512
|
66 -h|-\?)
|
giuliomoro@512
|
67 usage
|
giuliomoro@512
|
68 exit 0
|
giuliomoro@512
|
69 ;;
|
giuliomoro@512
|
70 *)
|
giuliomoro@512
|
71 usage
|
giuliomoro@512
|
72 exit 1
|
giuliomoro@512
|
73 ;;
|
giuliomoro@512
|
74 esac
|
giuliomoro@512
|
75 shift
|
andrewm@58
|
76 done
|
andrewm@58
|
77
|
andrewm@58
|
78
|
andrewm@58
|
79 # Check that we have a directory containing at least one source file
|
andrewm@58
|
80 # as an argument
|
giuliomoro@64
|
81
|
andrewm@58
|
82 if [ -z "$1" ]
|
andrewm@58
|
83 then
|
giuliomoro@512
|
84 usage
|
giuliomoro@512
|
85 exit 2
|
andrewm@58
|
86 fi
|
andrewm@58
|
87
|
giuliomoro@64
|
88 FIND_STRING="find $* -maxdepth 10000 -type f "
|
giuliomoro@472
|
89 EXTENSIONS_TO_FIND='\.cpp\|\.c\|\.S\|\.pd'
|
giuliomoro@472
|
90 FOUND_FILES=$($FIND_STRING | grep "$EXTENSIONS_TO_FIND")
|
giuliomoro@472
|
91 if [ -z "$FOUND_FILES" ]
|
andrewm@58
|
92 then
|
giuliomoro@512
|
93 printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n"
|
giuliomoro@523
|
94 exit 1
|
andrewm@58
|
95 fi
|
andrewm@58
|
96
|
giuliomoro@275
|
97 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
|
giuliomoro@266
|
98 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
|
giuliomoro@266
|
99
|
giuliomoro@369
|
100 echo "Stopping running process..."
|
giuliomoro@369
|
101 # sets the date and stop running process
|
giuliomoro@443
|
102 ssh $BBB_ADDRESS "date -s \"`date '+%Y%m%d %T %Z'`\" > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; make QUIET=true --no-print-directory -C $BBB_BELA_HOME stop"
|
giuliomoro@64
|
103
|
giuliomoro@64
|
104 #concatenate arguments to form path.
|
giuliomoro@264
|
105 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
|
giuliomoro@64
|
106 for i in "$@" #parse input arguments
|
giuliomoro@64
|
107 do
|
giuliomoro@512
|
108 HOST_SOURCE_PATH+=" $1"
|
giuliomoro@512
|
109 shift
|
giuliomoro@512
|
110 # Copy new souce files to the board
|
giuliomoro@64
|
111 done
|
andrewm@58
|
112
|
giuliomoro@512
|
113 # This file is used to keep track of when the last upload was made,
|
giuliomoro@512
|
114 # so to check for modifications if WATCH is active
|
giuliomoro@512
|
115 reference_time_file="$SCRIPTDIR/../tmp/"
|
giuliomoro@512
|
116 uploadBuildRun(){
|
giuliomoro@512
|
117 [ $WATCH -eq 1 ] && touch $reference_time_file
|
giuliomoro@512
|
118 # Copy new source files to the board
|
giuliomoro@512
|
119 echo "Copying new source files to BeagleBone..."
|
giuliomoro@512
|
120 if [ -z "`which rsync`" ];
|
giuliomoro@512
|
121 then
|
giuliomoro@512
|
122 #if rsync is not available, brutally clean the destination folder
|
giuliomoro@512
|
123 ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
|
giuliomoro@523
|
124 #and copy over all the files again
|
giuliomoro@523
|
125 scp -r $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
|
giuliomoro@512
|
126 else
|
giuliomoro@512
|
127 #rsync
|
giuliomoro@512
|
128 # --delete makes sure it removes files that are not in the origin folder
|
giuliomoro@512
|
129 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
|
giuliomoro@512
|
130 # --no-t makes sure file timestamps are not preserved, so that the Makefile will not think that targets are up to date when replacing files on the BBB
|
giuliomoro@512
|
131 # with older files from the host. This will solve 99% of the issues with Makefile thinking a target is up to date when it is not.
|
giuliomoro@523
|
132 rsync -ac --out-format=" %n" --no-t --delete-after --exclude=$BBB_PROJECT_NAME --exclude=build $HOST_SOURCE_PATH"/" "$BBB_NETWORK_TARGET_FOLDER/" #trailing slashes used here make sure rsync does not create another folder inside the target folder
|
giuliomoro@512
|
133 fi
|
giuliomoro@64
|
134
|
giuliomoro@512
|
135 if [ $? -ne 0 ]
|
giuliomoro@512
|
136 then
|
giuliomoro@512
|
137 echo "Error while copying files"
|
giuliomoro@512
|
138 exit
|
giuliomoro@512
|
139 fi
|
giuliomoro@512
|
140
|
giuliomoro@512
|
141 # Make new Bela executable and run
|
giuliomoro@512
|
142 MAKE_COMMAND="make --no-print-directory QUIET=true -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS' $BBB_MAKEFILE_OPTIONS"
|
giuliomoro@512
|
143 if [ $RUN_PROJECT -eq 0 ]
|
giuliomoro@512
|
144 then
|
giuliomoro@512
|
145 echo "Building project..."
|
giuliomoro@512
|
146 ssh $BBB_ADDRESS "$MAKE_COMMAND"
|
giuliomoro@512
|
147 else
|
giuliomoro@512
|
148 echo "Building and running project..."
|
giuliomoro@523
|
149 case $RUN_MODE in
|
giuliomoro@523
|
150 # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated
|
giuliomoro@523
|
151 foreground)
|
giuliomoro@523
|
152 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
|
giuliomoro@523
|
153 ;;
|
giuliomoro@523
|
154 screen)
|
giuliomoro@523
|
155 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
|
giuliomoro@523
|
156 ;;
|
giuliomoro@523
|
157 screenfg)
|
giuliomoro@523
|
158 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
|
giuliomoro@523
|
159 ;;
|
giuliomoro@523
|
160 *)
|
giuliomoro@523
|
161 echo $RUN_MODE
|
giuliomoro@523
|
162 error
|
giuliomoro@523
|
163 ;;
|
giuliomoro@523
|
164 esac
|
giuliomoro@512
|
165 fi
|
giuliomoro@512
|
166 }
|
giuliomoro@512
|
167 # run it once and then (maybe) start waiting for changes
|
giuliomoro@512
|
168 uploadBuildRun
|
giuliomoro@512
|
169
|
giuliomoro@512
|
170 if [ $WATCH -ne 0 ]; then
|
giuliomoro@512
|
171 while true
|
giuliomoro@512
|
172 do
|
giuliomoro@512
|
173 echo "Waiting for changes in $HOST_SOURCE_PATH, or press ctrl-c to terminate"
|
giuliomoro@512
|
174 CORE_DIR="$SCRIPTDIR/../core"
|
giuliomoro@512
|
175 INCLUDE_DIR="$SCRIPTDIR/../include"
|
giuliomoro@512
|
176 wait_for_change $HOST_SOURCE_PATH "$reference_time_file" && {
|
giuliomoro@512
|
177 echo "Content of "$HOST_SOURCE_PATH" has changed"
|
giuliomoro@512
|
178 }
|
giuliomoro@512
|
179 echo "Files changed"
|
giuliomoro@512
|
180 uploadBuildRun
|
giuliomoro@512
|
181 done
|
giuliomoro@64
|
182 fi
|