annotate scripts/build_project.sh @ 377:a430a16d2c02 prerelease

Updated scripts so that the Bela folder on the bbb is ~/Bela. Note: BeagleRT_startup.sh is still the same (because the reference to it needs to be changed in /etc/init.d/ ....
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 11 Jun 2016 01:54:43 +0100
parents 137a87b745d2
children 99de323c13b3
rev   line source
andrewm@58 1 #!/bin/bash
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
andrewm@58 19 function 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@263 33 By default, the project runs in the foreground of the current terminal,
giuliomoro@369 34 within a screen session that can be detached later. The -f argument runs
giuliomoro@263 35 the project in the foreground of the current terminal, without screen, so
giuliomoro@369 36 the output can be piped to another destination. The -b argument runs it
giuliomoro@370 37 in a screen in the background, so no output is shown. The -m argument allows
giuliomoro@370 38 to pass arguments to the Makefile before the run target. For instance,
giuliomoro@370 39 pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific pre-built
giuliomoro@370 40 objects, or all the pre-built objects, respectively."
andrewm@58 41 }
andrewm@58 42
andrewm@58 43 OPTIND=1
andrewm@58 44
giuliomoro@370 45 while getopts "bc:m:nfFhp:" opt; do
andrewm@58 46 case $opt in
andrewm@60 47 c) COMMAND_ARGS=$OPTARG
andrewm@60 48 ;;
giuliomoro@369 49 b) RUN_IN_FOREGROUND=0
giuliomoro@277 50 ;;
giuliomoro@369 51 f) RUN_WITHOUT_SCREEN=1
giuliomoro@277 52 ;;
andrewm@58 53 n) RUN_PROJECT=0
andrewm@58 54 ;;
giuliomoro@277 55 p) BBB_PROJECT_NAME=$OPTARG
giuliomoro@277 56 ;;
giuliomoro@370 57 m) BBB_MAKEFILE_OPTIONS=$OPTARG
giuliomoro@370 58 ;;
andrewm@58 59 h|\?) usage
andrewm@58 60 exit 1
andrewm@58 61 esac
andrewm@58 62 done
andrewm@58 63
andrewm@58 64 shift $((OPTIND-1))
andrewm@58 65
andrewm@58 66 # Check that we have a directory containing at least one source file
andrewm@58 67 # as an argument
giuliomoro@64 68
andrewm@58 69 if [ -z "$1" ]
andrewm@58 70 then
andrewm@58 71 usage
andrewm@58 72 exit
andrewm@58 73 fi
andrewm@58 74
giuliomoro@64 75 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@64 76
giuliomoro@64 77 C_FILES=$($FIND_STRING -name "*.c")
giuliomoro@64 78 CPP_FILES=$($FIND_STRING -name "*.cpp")
giuliomoro@64 79 ASM_FILES=$($FIND_STRING -name "*.S")
andrewm@58 80
andrewm@58 81 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
andrewm@58 82 then
andrewm@58 83 echo "Please provide a directory containing .c, .cpp or .S files."
andrewm@58 84 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
andrewm@58 85 usage
andrewm@58 86 exit
andrewm@58 87 fi
andrewm@58 88
giuliomoro@275 89 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@266 90 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@266 91
giuliomoro@369 92 echo "Stopping running process..."
giuliomoro@369 93 # sets the date and stop running process
giuliomoro@369 94 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; make -C $BBB_BELA_HOME stop"
giuliomoro@64 95
giuliomoro@64 96 #concatenate arguments to form path.
giuliomoro@264 97 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
giuliomoro@64 98 for i in "$@" #parse input arguments
giuliomoro@64 99 do
giuliomoro@275 100 HOST_SOURCE_PATH+=" $1"
giuliomoro@64 101 shift
giuliomoro@64 102 # Copy new souce files to the board
giuliomoro@64 103 done
andrewm@58 104
andrewm@58 105 # Copy new source files to the board
andrewm@58 106 echo "Copying new source files to BeagleBone..."
giuliomoro@264 107 if [ -z `which rsync` ];
giuliomoro@264 108 then
giuliomoro@264 109 #if rsync is not available, brutally clean the destination folder
giuliomoro@264 110 #and copy over all the files again and recompile them
giuliomoro@266 111 ssh bbb "make -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
giuliomoro@266 112 scp $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
giuliomoro@264 113 else
giuliomoro@369 114 #rsync
giuliomoro@369 115 # --delete makes sure it removes files that are not in the origin folder
giuliomoro@369 116 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
giuliomoro@369 117 # --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 118 # 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@370 119
giuliomoro@370 120 echo rsync -avc --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@370 121 rsync -avc --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@264 122 fi;
giuliomoro@64 123
giuliomoro@64 124 if [ $? -ne 0 ]
giuliomoro@64 125 then
giuliomoro@64 126 echo "Error while copying files"
giuliomoro@64 127 exit
giuliomoro@64 128 fi
andrewm@58 129
giuliomoro@377 130 # Make new Bela executable and run
giuliomoro@370 131 MAKE_COMMAND="make -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS' $BBB_MAKEFILE_OPTIONS"
andrewm@58 132 if [ $RUN_PROJECT -eq 0 ]
andrewm@58 133 then
andrewm@58 134 echo "Building project..."
giuliomoro@323 135 ssh $BBB_ADDRESS "$MAKE_COMMAND"
andrewm@58 136 else
andrewm@58 137 echo "Building and running project..."
andrewm@90 138
andrewm@90 139 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
andrewm@90 140 then
giuliomoro@330 141 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
andrewm@90 142 elif [ $RUN_IN_FOREGROUND -eq 0 ]
andrewm@90 143 then
giuliomoro@323 144 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
andrewm@90 145 else
giuliomoro@323 146 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
andrewm@90 147 fi
giuliomoro@249 148 fi