Mercurial > hg > beaglert
diff 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 |
line wrap: on
line diff
--- a/scripts/build_project.sh Thu Jun 23 03:46:56 2016 +0100 +++ b/scripts/build_project.sh Thu Jun 23 04:31:09 2016 +0100 @@ -3,7 +3,6 @@ # This script compiles a Bela project on the BeagleBone Black and # optionally runs it. Pass a directory path in the first argument. # The source files in this directory are copied to the board and compiled. - # set defaults unless variables are already set SCRIPTDIR=$(dirname "$0") @@ -18,28 +17,20 @@ echo " This script copies a directory of source files to the BeagleBone, compiles and runs it. The Bela core files should have first been copied over - using the setup_board.sh script supplied with Bela. + using the \`update_board' script once. + The source directory should contain at least one .c, .cpp, .S or .pd file. - The source directory should contain at least one .c, .cpp or .S file. - If the argument -n is passed, the output will not be run after compiling. - The -c option passes command-line arguments to - the Bela program; enclose the argument string in quotes. +" + build_script_usage +} +# UNDOCUMENTED OPTION -s runs in a screen in the foreground - -p arg : sets the name of the project to run (default: $BBB_PROJECT_NAME ) - -r arg : additional folder which contents will be copied to the destination folder. Use this, e.g.: for audio files or Pd/pyo sources +RUN_MODE=foreground - By default, the project runs in the foreground of the current terminal, - within a screen session that can be detached later. The -f argument runs - the project in the foreground of the current terminal, without screen, so - the output can be piped to another destination. The -b argument runs it - in a screen in the background, so no output is shown. The -m argument allows - to pass arguments to the Makefile before the run target. For instance, - pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific - pre-built objects, or all the pre-built objects, respectively." +# We are "whiling" $2 because the last command is going to be the path/to/project +[ $# -lt 2 ] && { + [ -d $1 ] || { usage; exit; } } - -OPTIND=1 - while [ "$2" != "" ]; do case $1 in -c) @@ -47,10 +38,13 @@ COMMAND_ARGS="$1" ;; -b) - RUN_IN_FOREGROUND=0 + RUN_MODE=screen ;; -f) - RUN_WITHOUT_SCREEN=1 + RUN_MODE=foreground + ;; + -s) + RUN_MODE=screenfg ;; -n) RUN_PROJECT=0 @@ -59,14 +53,12 @@ shift BBB_PROJECT_NAME="$1" ;; - -r) - shift - # TODO: this option can probably be removed, replaced by including multiple paths as regular positional arguments at the end. - ADDITIONAL_PATH="$1" + --clean) + BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean" ;; -m) shift - BBB_MAKEFILE_OPTIONS="$1" + BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS $1" ;; --watch) WATCH=1 @@ -84,9 +76,6 @@ done -#Only include all the files if the provided path is not empty -[ -z "$ADDITIONAL_PATH" ] || ADDITIONAL_PATH="$ADDITIONAL_PATH/*" - # Check that we have a directory containing at least one source file # as an argument @@ -102,7 +91,7 @@ if [ -z "$FOUND_FILES" ] then printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n" - exit + exit 1 fi BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here @@ -131,16 +120,16 @@ if [ -z "`which rsync`" ]; then #if rsync is not available, brutally clean the destination folder - #and copy over all the files again and recompile them ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME"; - scp -r $HOST_SOURCE_PATH $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER" + #and copy over all the files again + scp -r $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER" else #rsync # --delete makes sure it removes files that are not in the origin folder # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews # --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 # 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. - 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 + 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 fi if [ $? -ne 0 ] @@ -157,29 +146,22 @@ ssh $BBB_ADDRESS "$MAKE_COMMAND" else echo "Building and running project..." - if [ $WATCH -eq 1 ] - then - if [ $RUN_WITHOUT_SCREEN -eq 1 ]; - then - # try to emulate run_without_screen: run with fifo - ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo" & BACKGROUND_PROCESS_PID=$! - # run this in the background, it will be killed anyhow when the process stops. - # Either with the trap below or in another way - trap "kill $BACKGROUND_PROCESS_PID; exit 0;" 2 9 - else - ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" - fi - else - if [ $RUN_WITHOUT_SCREEN -ne 0 ] - then - ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" - elif [ $RUN_IN_FOREGROUND -eq 0 ] - then - ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" - else - ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" - fi - fi + case $RUN_MODE in + # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated + foreground) + ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" + ;; + screen) + ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" + ;; + screenfg) + ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" + ;; + *) + echo $RUN_MODE + error + ;; + esac fi } # run it once and then (maybe) start waiting for changes