comparison scripts/build_project.sh @ 523:42f6af3a5f1d prerelease

build_project and build_pd_heavy mostly done
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 23 Jun 2016 04:31:09 +0100
parents 8e48dd7c8c23
children 1ca196e35105
comparison
equal deleted inserted replaced
522:a084456960c9 523:42f6af3a5f1d
1 #!/bin/sh 1 #!/bin/sh
2 # 2 #
3 # This script compiles a Bela project on the BeagleBone Black and 3 # This script compiles a Bela project on the BeagleBone Black and
4 # optionally runs it. Pass a directory path in the first argument. 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. 5 # The source files in this directory are copied to the board and compiled.
6
7 # set defaults unless variables are already set 6 # set defaults unless variables are already set
8 7
9 SCRIPTDIR=$(dirname "$0") 8 SCRIPTDIR=$(dirname "$0")
10 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/ 9 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/
11 . $SCRIPTDIR.bela_common || { echo "You must be in Bela/scripts to run these scripts" | exit 1; } 10 . $SCRIPTDIR.bela_common || { echo "You must be in Bela/scripts to run these scripts" | exit 1; }
16 THIS_SCRIPT=`basename "$0"` 15 THIS_SCRIPT=`basename "$0"`
17 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>" 16 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>"
18 echo " 17 echo "
19 This script copies a directory of source files to the BeagleBone, compiles 18 This script copies a directory of source files to the BeagleBone, compiles
20 and runs it. The Bela core files should have first been copied over 19 and runs it. The Bela core files should have first been copied over
21 using the setup_board.sh script supplied with Bela. 20 using the \`update_board' script once.
21 The source directory should contain at least one .c, .cpp, .S or .pd file.
22 22
23 The source directory should contain at least one .c, .cpp or .S file. 23 "
24 If the argument -n is passed, the output will not be run after compiling. 24 build_script_usage
25 The -c option passes command-line arguments to 25 }
26 the Bela program; enclose the argument string in quotes. 26 # UNDOCUMENTED OPTION -s runs in a screen in the foreground
27 27
28 -p arg : sets the name of the project to run (default: $BBB_PROJECT_NAME ) 28 RUN_MODE=foreground
29 -r arg : additional folder which contents will be copied to the destination folder. Use this, e.g.: for audio files or Pd/pyo sources
30 29
31 By default, the project runs in the foreground of the current terminal, 30 # We are "whiling" $2 because the last command is going to be the path/to/project
32 within a screen session that can be detached later. The -f argument runs 31 [ $# -lt 2 ] && {
33 the project in the foreground of the current terminal, without screen, so 32 [ -d $1 ] || { usage; exit; }
34 the output can be piped to another destination. The -b argument runs it
35 in a screen in the background, so no output is shown. The -m argument allows
36 to pass arguments to the Makefile before the run target. For instance,
37 pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific
38 pre-built objects, or all the pre-built objects, respectively."
39 } 33 }
40
41 OPTIND=1
42
43 while [ "$2" != "" ]; do 34 while [ "$2" != "" ]; do
44 case $1 in 35 case $1 in
45 -c) 36 -c)
46 shift 37 shift
47 COMMAND_ARGS="$1" 38 COMMAND_ARGS="$1"
48 ;; 39 ;;
49 -b) 40 -b)
50 RUN_IN_FOREGROUND=0 41 RUN_MODE=screen
51 ;; 42 ;;
52 -f) 43 -f)
53 RUN_WITHOUT_SCREEN=1 44 RUN_MODE=foreground
45 ;;
46 -s)
47 RUN_MODE=screenfg
54 ;; 48 ;;
55 -n) 49 -n)
56 RUN_PROJECT=0 50 RUN_PROJECT=0
57 ;; 51 ;;
58 -p) 52 -p)
59 shift 53 shift
60 BBB_PROJECT_NAME="$1" 54 BBB_PROJECT_NAME="$1"
61 ;; 55 ;;
62 -r) 56 --clean)
63 shift 57 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean"
64 # TODO: this option can probably be removed, replaced by including multiple paths as regular positional arguments at the end.
65 ADDITIONAL_PATH="$1"
66 ;; 58 ;;
67 -m) 59 -m)
68 shift 60 shift
69 BBB_MAKEFILE_OPTIONS="$1" 61 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS $1"
70 ;; 62 ;;
71 --watch) 63 --watch)
72 WATCH=1 64 WATCH=1
73 ;; 65 ;;
74 -h|-\?) 66 -h|-\?)
82 esac 74 esac
83 shift 75 shift
84 done 76 done
85 77
86 78
87 #Only include all the files if the provided path is not empty
88 [ -z "$ADDITIONAL_PATH" ] || ADDITIONAL_PATH="$ADDITIONAL_PATH/*"
89
90 # Check that we have a directory containing at least one source file 79 # Check that we have a directory containing at least one source file
91 # as an argument 80 # as an argument
92 81
93 if [ -z "$1" ] 82 if [ -z "$1" ]
94 then 83 then
100 EXTENSIONS_TO_FIND='\.cpp\|\.c\|\.S\|\.pd' 89 EXTENSIONS_TO_FIND='\.cpp\|\.c\|\.S\|\.pd'
101 FOUND_FILES=$($FIND_STRING | grep "$EXTENSIONS_TO_FIND") 90 FOUND_FILES=$($FIND_STRING | grep "$EXTENSIONS_TO_FIND")
102 if [ -z "$FOUND_FILES" ] 91 if [ -z "$FOUND_FILES" ]
103 then 92 then
104 printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n" 93 printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n"
105 exit 94 exit 1
106 fi 95 fi
107 96
108 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here 97 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
109 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER 98 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
110 99
129 # Copy new source files to the board 118 # Copy new source files to the board
130 echo "Copying new source files to BeagleBone..." 119 echo "Copying new source files to BeagleBone..."
131 if [ -z "`which rsync`" ]; 120 if [ -z "`which rsync`" ];
132 then 121 then
133 #if rsync is not available, brutally clean the destination folder 122 #if rsync is not available, brutally clean the destination folder
134 #and copy over all the files again and recompile them
135 ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME"; 123 ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
136 scp -r $HOST_SOURCE_PATH $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER" 124 #and copy over all the files again
125 scp -r $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
137 else 126 else
138 #rsync 127 #rsync
139 # --delete makes sure it removes files that are not in the origin folder 128 # --delete makes sure it removes files that are not in the origin folder
140 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews 129 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
141 # --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 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
142 # 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. 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.
143 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 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
144 fi 133 fi
145 134
146 if [ $? -ne 0 ] 135 if [ $? -ne 0 ]
147 then 136 then
148 echo "Error while copying files" 137 echo "Error while copying files"
155 then 144 then
156 echo "Building project..." 145 echo "Building project..."
157 ssh $BBB_ADDRESS "$MAKE_COMMAND" 146 ssh $BBB_ADDRESS "$MAKE_COMMAND"
158 else 147 else
159 echo "Building and running project..." 148 echo "Building and running project..."
160 if [ $WATCH -eq 1 ] 149 case $RUN_MODE in
161 then 150 # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated
162 if [ $RUN_WITHOUT_SCREEN -eq 1 ]; 151 foreground)
163 then 152 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
164 # try to emulate run_without_screen: run with fifo 153 ;;
165 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo" & BACKGROUND_PROCESS_PID=$! 154 screen)
166 # run this in the background, it will be killed anyhow when the process stops. 155 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
167 # Either with the trap below or in another way 156 ;;
168 trap "kill $BACKGROUND_PROCESS_PID; exit 0;" 2 9 157 screenfg)
169 else 158 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
170 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" 159 ;;
171 fi 160 *)
172 else 161 echo $RUN_MODE
173 if [ $RUN_WITHOUT_SCREEN -ne 0 ] 162 error
174 then 163 ;;
175 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" 164 esac
176 elif [ $RUN_IN_FOREGROUND -eq 0 ]
177 then
178 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
179 else
180 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
181 fi
182 fi
183 fi 165 fi
184 } 166 }
185 # run it once and then (maybe) start waiting for changes 167 # run it once and then (maybe) start waiting for changes
186 uploadBuildRun 168 uploadBuildRun
187 169