annotate scripts/build_project.sh @ 439:e49ae69acbe8 prerelease

Rebuilt run_pd_libpd.sh. Minor fixes, adjusted verbosity
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 18 Jun 2016 04:19:17 +0100
parents ad3f61134bb4
children a9af964ac18a
rev   line source
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@262 8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
giuliomoro@377 9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
giuliomoro@377 10 [ -z "$BBB_SCREEN_NAME" ] && BBB_SCREEN_NAME="Bela"
giuliomoro@262 11 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
giuliomoro@262 12 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
giuliomoro@262 13 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
giuliomoro@262 14 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
giuliomoro@264 15 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
giuliomoro@277 16 [ -z "$BBB_DEFAULT_PROJECT_NAME" ] && BBB_DEFAULT_PROJECT_NAME="scriptUploadedProject"
giuliomoro@277 17 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
andrewm@58 18
giuliomoro@430 19 usage()
andrewm@58 20 {
andrewm@58 21 THIS_SCRIPT=`basename "$0"`
giuliomoro@369 22 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>"
andrewm@58 23 echo "
andrewm@58 24 This script copies a directory of source files to the BeagleBone, compiles
giuliomoro@377 25 and runs it. The Bela core files should have first been copied over
giuliomoro@377 26 using the setup_board.sh script supplied with Bela.
andrewm@58 27
andrewm@58 28 The source directory should contain at least one .c, .cpp or .S file.
andrewm@58 29 If the argument -n is passed, the output will not be run after compiling.
giuliomoro@369 30 The -c option passes command-line arguments to
giuliomoro@377 31 the Bela program; enclose the argument string in quotes.
andrewm@90 32
giuliomoro@425 33 -p arg : sets the name of the project to run (default: $BBB_PROJECT_NAME )
giuliomoro@439 34 -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 35
giuliomoro@263 36 By default, the project runs in the foreground of the current terminal,
giuliomoro@369 37 within a screen session that can be detached later. The -f argument runs
giuliomoro@263 38 the project in the foreground of the current terminal, without screen, so
giuliomoro@369 39 the output can be piped to another destination. The -b argument runs it
giuliomoro@370 40 in a screen in the background, so no output is shown. The -m argument allows
giuliomoro@370 41 to pass arguments to the Makefile before the run target. For instance,
giuliomoro@425 42 pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific
giuliomoro@425 43 pre-built objects, or all the pre-built objects, respectively."
andrewm@58 44 }
andrewm@58 45
andrewm@58 46 OPTIND=1
andrewm@58 47
giuliomoro@439 48 while getopts "bc:m:nfFhp:r:b" opt; do
andrewm@58 49 case $opt in
andrewm@60 50 c) COMMAND_ARGS=$OPTARG
andrewm@60 51 ;;
giuliomoro@369 52 b) RUN_IN_FOREGROUND=0
giuliomoro@277 53 ;;
giuliomoro@369 54 f) RUN_WITHOUT_SCREEN=1
giuliomoro@277 55 ;;
andrewm@58 56 n) RUN_PROJECT=0
andrewm@58 57 ;;
giuliomoro@277 58 p) BBB_PROJECT_NAME=$OPTARG
giuliomoro@277 59 ;;
giuliomoro@439 60 r) ADDITIONAL_PATH=$OPTARG
giuliomoro@439 61 ;;
giuliomoro@370 62 m) BBB_MAKEFILE_OPTIONS=$OPTARG
giuliomoro@370 63 ;;
andrewm@58 64 h|\?) usage
andrewm@58 65 exit 1
andrewm@58 66 esac
andrewm@58 67 done
andrewm@58 68
andrewm@58 69 shift $((OPTIND-1))
andrewm@58 70
giuliomoro@439 71 #Only include all the files if the provided path is not empty
giuliomoro@439 72 [ -z "$ADDITIONAL_PATH" ] || ADDITIONAL_PATH="$ADDITIONAL_PATH/*"
giuliomoro@439 73
andrewm@58 74 # Check that we have a directory containing at least one source file
andrewm@58 75 # as an argument
giuliomoro@64 76
andrewm@58 77 if [ -z "$1" ]
andrewm@58 78 then
andrewm@58 79 usage
andrewm@58 80 exit
andrewm@58 81 fi
andrewm@58 82
giuliomoro@64 83 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@64 84
giuliomoro@64 85 C_FILES=$($FIND_STRING -name "*.c")
giuliomoro@64 86 CPP_FILES=$($FIND_STRING -name "*.cpp")
giuliomoro@64 87 ASM_FILES=$($FIND_STRING -name "*.S")
andrewm@58 88
giuliomoro@439 89 if [ -z "$C_FILES" ] && [ -z "$CPP_FILES" ] && [ -z "$ASM_FILES" ]
andrewm@58 90 then
andrewm@58 91 echo "Please provide a directory containing .c, .cpp or .S files."
andrewm@58 92 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
andrewm@58 93 usage
andrewm@58 94 exit
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@439 102 ssh $BBB_ADDRESS "date -s '`date`' > /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@275 108 HOST_SOURCE_PATH+=" $1"
giuliomoro@64 109 shift
giuliomoro@64 110 # Copy new souce files to the board
giuliomoro@64 111 done
andrewm@58 112
andrewm@58 113 # Copy new source files to the board
andrewm@58 114 echo "Copying new source files to BeagleBone..."
giuliomoro@439 115 if [ -z "`which rsync`" ];
giuliomoro@264 116 then
giuliomoro@264 117 #if rsync is not available, brutally clean the destination folder
giuliomoro@264 118 #and copy over all the files again and recompile them
giuliomoro@435 119 ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
giuliomoro@439 120 scp -r $HOST_SOURCE_PATH $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER"
giuliomoro@264 121 else
giuliomoro@369 122 #rsync
giuliomoro@369 123 # --delete makes sure it removes files that are not in the origin folder
giuliomoro@369 124 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
giuliomoro@369 125 # --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 126 # 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 127 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 128 fi;
giuliomoro@64 129
giuliomoro@64 130 if [ $? -ne 0 ]
giuliomoro@64 131 then
giuliomoro@64 132 echo "Error while copying files"
giuliomoro@64 133 exit
giuliomoro@64 134 fi
andrewm@58 135
giuliomoro@377 136 # Make new Bela executable and run
giuliomoro@439 137 MAKE_COMMAND="make --no-print-directory QUIET=true -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS' $BBB_MAKEFILE_OPTIONS"
andrewm@58 138 if [ $RUN_PROJECT -eq 0 ]
andrewm@58 139 then
andrewm@58 140 echo "Building project..."
giuliomoro@323 141 ssh $BBB_ADDRESS "$MAKE_COMMAND"
andrewm@58 142 else
andrewm@58 143 echo "Building and running project..."
andrewm@90 144
andrewm@90 145 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
andrewm@90 146 then
giuliomoro@330 147 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
andrewm@90 148 elif [ $RUN_IN_FOREGROUND -eq 0 ]
andrewm@90 149 then
giuliomoro@323 150 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
andrewm@90 151 else
giuliomoro@323 152 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
andrewm@90 153 fi
giuliomoro@249 154 fi