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