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.
|
andrewm@58
|
6
|
giuliomoro@262
|
7 # set defaults unless variables are already set
|
giuliomoro@445
|
8
|
giuliomoro@462
|
9 SCRIPTDIR=$(dirname "$0")
|
giuliomoro@462
|
10 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/
|
giuliomoro@462
|
11 . $SCRIPTDIR.bela_common || { echo "You must be in Bela/scripts to run these scripts" | exit 1; }
|
andrewm@58
|
12
|
giuliomoro@430
|
13 usage()
|
andrewm@58
|
14 {
|
andrewm@58
|
15 THIS_SCRIPT=`basename "$0"`
|
giuliomoro@369
|
16 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>"
|
andrewm@58
|
17 echo "
|
andrewm@58
|
18 This script copies a directory of source files to the BeagleBone, compiles
|
giuliomoro@377
|
19 and runs it. The Bela core files should have first been copied over
|
giuliomoro@377
|
20 using the setup_board.sh script supplied with Bela.
|
andrewm@58
|
21
|
andrewm@58
|
22 The source directory should contain at least one .c, .cpp or .S file.
|
andrewm@58
|
23 If the argument -n is passed, the output will not be run after compiling.
|
giuliomoro@369
|
24 The -c option passes command-line arguments to
|
giuliomoro@377
|
25 the Bela program; enclose the argument string in quotes.
|
andrewm@90
|
26
|
giuliomoro@425
|
27 -p arg : sets the name of the project to run (default: $BBB_PROJECT_NAME )
|
giuliomoro@439
|
28 -r arg : additional folder which contents will be copied to the destination folder. Use this, e.g.: for audio files or Pd/pyo sources
|
giuliomoro@439
|
29
|
giuliomoro@263
|
30 By default, the project runs in the foreground of the current terminal,
|
giuliomoro@369
|
31 within a screen session that can be detached later. The -f argument runs
|
giuliomoro@263
|
32 the project in the foreground of the current terminal, without screen, so
|
giuliomoro@369
|
33 the output can be piped to another destination. The -b argument runs it
|
giuliomoro@370
|
34 in a screen in the background, so no output is shown. The -m argument allows
|
giuliomoro@370
|
35 to pass arguments to the Makefile before the run target. For instance,
|
giuliomoro@425
|
36 pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific
|
giuliomoro@425
|
37 pre-built objects, or all the pre-built objects, respectively."
|
andrewm@58
|
38 }
|
andrewm@58
|
39
|
andrewm@58
|
40 OPTIND=1
|
andrewm@58
|
41
|
giuliomoro@439
|
42 while getopts "bc:m:nfFhp:r:b" opt; do
|
andrewm@58
|
43 case $opt in
|
andrewm@60
|
44 c) COMMAND_ARGS=$OPTARG
|
andrewm@60
|
45 ;;
|
giuliomoro@369
|
46 b) RUN_IN_FOREGROUND=0
|
giuliomoro@277
|
47 ;;
|
giuliomoro@369
|
48 f) RUN_WITHOUT_SCREEN=1
|
giuliomoro@277
|
49 ;;
|
andrewm@58
|
50 n) RUN_PROJECT=0
|
andrewm@58
|
51 ;;
|
giuliomoro@277
|
52 p) BBB_PROJECT_NAME=$OPTARG
|
giuliomoro@277
|
53 ;;
|
giuliomoro@439
|
54 r) ADDITIONAL_PATH=$OPTARG
|
giuliomoro@439
|
55 ;;
|
giuliomoro@370
|
56 m) BBB_MAKEFILE_OPTIONS=$OPTARG
|
giuliomoro@370
|
57 ;;
|
andrewm@58
|
58 h|\?) usage
|
andrewm@58
|
59 exit 1
|
andrewm@58
|
60 esac
|
andrewm@58
|
61 done
|
andrewm@58
|
62
|
andrewm@58
|
63 shift $((OPTIND-1))
|
andrewm@58
|
64
|
giuliomoro@439
|
65 #Only include all the files if the provided path is not empty
|
giuliomoro@439
|
66 [ -z "$ADDITIONAL_PATH" ] || ADDITIONAL_PATH="$ADDITIONAL_PATH/*"
|
giuliomoro@439
|
67
|
andrewm@58
|
68 # Check that we have a directory containing at least one source file
|
andrewm@58
|
69 # as an argument
|
giuliomoro@64
|
70
|
andrewm@58
|
71 if [ -z "$1" ]
|
andrewm@58
|
72 then
|
andrewm@58
|
73 usage
|
andrewm@58
|
74 exit
|
andrewm@58
|
75 fi
|
andrewm@58
|
76
|
giuliomoro@64
|
77 FIND_STRING="find $* -maxdepth 10000 -type f "
|
giuliomoro@472
|
78 EXTENSIONS_TO_FIND='\.cpp\|\.c\|\.S\|\.pd'
|
giuliomoro@472
|
79 FOUND_FILES=$($FIND_STRING | grep "$EXTENSIONS_TO_FIND")
|
giuliomoro@472
|
80 if [ -z "$FOUND_FILES" ]
|
andrewm@58
|
81 then
|
giuliomoro@472
|
82 printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n"
|
andrewm@58
|
83 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
|
andrewm@58
|
84 usage
|
andrewm@58
|
85 exit
|
andrewm@58
|
86 fi
|
andrewm@58
|
87
|
giuliomoro@275
|
88 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
|
giuliomoro@266
|
89 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
|
giuliomoro@266
|
90
|
giuliomoro@369
|
91 echo "Stopping running process..."
|
giuliomoro@369
|
92 # sets the date and stop running process
|
giuliomoro@443
|
93 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
|
94
|
giuliomoro@64
|
95 #concatenate arguments to form path.
|
giuliomoro@264
|
96 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
|
giuliomoro@64
|
97 for i in "$@" #parse input arguments
|
giuliomoro@64
|
98 do
|
giuliomoro@275
|
99 HOST_SOURCE_PATH+=" $1"
|
giuliomoro@64
|
100 shift
|
giuliomoro@64
|
101 # Copy new souce files to the board
|
giuliomoro@64
|
102 done
|
andrewm@58
|
103
|
andrewm@58
|
104 # Copy new source files to the board
|
andrewm@58
|
105 echo "Copying new source files to BeagleBone..."
|
giuliomoro@439
|
106 if [ -z "`which rsync`" ];
|
giuliomoro@264
|
107 then
|
giuliomoro@264
|
108 #if rsync is not available, brutally clean the destination folder
|
giuliomoro@264
|
109 #and copy over all the files again and recompile them
|
giuliomoro@435
|
110 ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
|
giuliomoro@439
|
111 scp -r $HOST_SOURCE_PATH $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER"
|
giuliomoro@264
|
112 else
|
giuliomoro@369
|
113 #rsync
|
giuliomoro@369
|
114 # --delete makes sure it removes files that are not in the origin folder
|
giuliomoro@369
|
115 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
|
giuliomoro@369
|
116 # --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@369
|
117 # 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@439
|
118 rsync -ac --out-format=" %n" --no-t --delete-after --exclude=$BBB_PROJECT_NAME --exclude=build $HOST_SOURCE_PATH"/" $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER/" #trailing slashes used here make sure rsync does not create another folder inside the target folder
|
giuliomoro@264
|
119 fi;
|
giuliomoro@64
|
120
|
giuliomoro@64
|
121 if [ $? -ne 0 ]
|
giuliomoro@64
|
122 then
|
giuliomoro@64
|
123 echo "Error while copying files"
|
giuliomoro@64
|
124 exit
|
giuliomoro@64
|
125 fi
|
andrewm@58
|
126
|
giuliomoro@377
|
127 # Make new Bela executable and run
|
giuliomoro@439
|
128 MAKE_COMMAND="make --no-print-directory QUIET=true -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS' $BBB_MAKEFILE_OPTIONS"
|
andrewm@58
|
129 if [ $RUN_PROJECT -eq 0 ]
|
andrewm@58
|
130 then
|
andrewm@58
|
131 echo "Building project..."
|
giuliomoro@323
|
132 ssh $BBB_ADDRESS "$MAKE_COMMAND"
|
andrewm@58
|
133 else
|
andrewm@58
|
134 echo "Building and running project..."
|
andrewm@90
|
135
|
andrewm@90
|
136 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
|
andrewm@90
|
137 then
|
giuliomoro@330
|
138 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
|
andrewm@90
|
139 elif [ $RUN_IN_FOREGROUND -eq 0 ]
|
andrewm@90
|
140 then
|
giuliomoro@323
|
141 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
|
andrewm@90
|
142 else
|
giuliomoro@323
|
143 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
|
andrewm@90
|
144 fi
|
giuliomoro@249
|
145 fi
|