annotate scripts/build_project.sh @ 330:276a8517da13 prerelease

build_project now updates the date of the files on the bbb
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 04 Jun 2016 15:23:52 +0100
parents b99b8ab317dd
children 75689b7cd57b
rev   line source
andrewm@58 1 #!/bin/bash
andrewm@58 2 #
andrewm@58 3 # This script compiles a BeagleRT 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@266 9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/"
giuliomoro@266 10 [ -z "$BBB_SCREEN_NAME" ] && BBB_SCREEN_NAME="BeagleRT"
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"`
andrewm@90 22 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
andrewm@58 23 echo "
andrewm@58 24 This script copies a directory of source files to the BeagleBone, compiles
andrewm@58 25 and runs it. The BeagleRT core files should have first been copied over
andrewm@58 26 using the setup_board.sh script supplied with BeagleRT.
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.
andrewm@58 30 The argument -b will change the local path on the BeagleBone where the
andrewm@60 31 BeagleRT files are found. The -c option passes command-line arguments to
andrewm@90 32 the BeagleRT program; enclose the argument string in quotes.
andrewm@90 33
giuliomoro@263 34 By default, the project runs in the foreground of the current terminal,
andrewm@90 35 within a screen session that can be detached later. The -F argument runs
giuliomoro@263 36 the project in the foreground of the current terminal, without screen, so
giuliomoro@263 37 the output can be piped to another destination. The -f argument runs it
giuliomoro@263 38 in a screen in the background, so no output is shown."
andrewm@58 39 }
andrewm@58 40
andrewm@58 41 OPTIND=1
andrewm@58 42
giuliomoro@277 43 while getopts "b:c:nfFhp:" opt; do
andrewm@58 44 case $opt in
giuliomoro@264 45 b) BBB_BELA_HOME=$OPTARG
andrewm@58 46 ;;
andrewm@60 47 c) COMMAND_ARGS=$OPTARG
andrewm@60 48 ;;
giuliomoro@264 49 f) RUN_IN_FOREGROUND=0
giuliomoro@277 50 ;;
giuliomoro@264 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 ;;
andrewm@58 57 h|\?) usage
andrewm@58 58 exit 1
andrewm@58 59 esac
andrewm@58 60 done
andrewm@58 61
andrewm@58 62 shift $((OPTIND-1))
andrewm@58 63
andrewm@58 64 # Check that we have a directory containing at least one source file
andrewm@58 65 # as an argument
giuliomoro@64 66
andrewm@58 67 if [ -z "$1" ]
andrewm@58 68 then
andrewm@58 69 usage
andrewm@58 70 exit
andrewm@58 71 fi
andrewm@58 72
giuliomoro@64 73 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@64 74
giuliomoro@64 75 C_FILES=$($FIND_STRING -name "*.c")
giuliomoro@64 76 CPP_FILES=$($FIND_STRING -name "*.cpp")
giuliomoro@64 77 ASM_FILES=$($FIND_STRING -name "*.S")
andrewm@58 78
andrewm@58 79 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
andrewm@58 80 then
andrewm@58 81 echo "Please provide a directory containing .c, .cpp or .S files."
andrewm@58 82 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
andrewm@58 83 usage
andrewm@58 84 exit
andrewm@58 85 fi
andrewm@58 86
giuliomoro@275 87 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@266 88 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@266 89
andrewm@58 90 # Stop BeagleRT and clean out old source files
giuliomoro@261 91 echo "Stopping running program..."
giuliomoro@261 92 # sets the date, stops the running process
giuliomoro@266 93 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; screen -X -S '"$BBB_SCREEN_NAME"' quit &>/dev/null;"
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@264 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@266 110 ssh bbb "make -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
giuliomoro@266 111 scp $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
giuliomoro@264 112 else
giuliomoro@264 113 #rsync --delete makes sure it removes files that are not in the origin folder
giuliomoro@330 114 rsync -ogprv --delete-after --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 115 fi;
giuliomoro@64 116
giuliomoro@64 117 if [ $? -ne 0 ]
giuliomoro@64 118 then
giuliomoro@64 119 echo "Error while copying files"
giuliomoro@64 120 exit
giuliomoro@64 121 fi
andrewm@58 122
andrewm@58 123 # Make new BeagleRT executable and run
giuliomoro@323 124 MAKE_COMMAND="make -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
andrewm@58 125 if [ $RUN_PROJECT -eq 0 ]
andrewm@58 126 then
andrewm@58 127 echo "Building project..."
giuliomoro@323 128 ssh $BBB_ADDRESS "$MAKE_COMMAND"
andrewm@58 129 else
andrewm@58 130 echo "Building and running project..."
andrewm@90 131
andrewm@90 132 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
andrewm@90 133 then
giuliomoro@330 134 echo ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
giuliomoro@330 135 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
andrewm@90 136 elif [ $RUN_IN_FOREGROUND -eq 0 ]
andrewm@90 137 then
giuliomoro@330 138 echo ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
giuliomoro@323 139 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
andrewm@90 140 else
giuliomoro@330 141 echo ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
giuliomoro@323 142 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
andrewm@90 143 fi
giuliomoro@249 144 fi