annotate scripts/build_project.sh @ 262:b491eb027f82 prerelease

build_project.sh defaults rewritten.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 16 May 2016 14:59:36 +0100
parents f51132ee0080
children 7fe0d7c54bce
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@262 9 [ -z "$BBB_PATH" ] && BBB_PATH="~/BeagleRT"
giuliomoro@262 10 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
giuliomoro@262 11 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
giuliomoro@262 12 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
giuliomoro@262 13 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
giuliomoro@262 14 [ -z "$SCREEN_NAME" ] && SCREEN_NAME=Bela
andrewm@58 15
andrewm@58 16 function usage
andrewm@58 17 {
andrewm@58 18 THIS_SCRIPT=`basename "$0"`
andrewm@90 19 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
andrewm@58 20 echo "
andrewm@58 21 This script copies a directory of source files to the BeagleBone, compiles
andrewm@58 22 and runs it. The BeagleRT core files should have first been copied over
andrewm@58 23 using the setup_board.sh script supplied with BeagleRT.
andrewm@58 24
andrewm@58 25 The source directory should contain at least one .c, .cpp or .S file.
andrewm@58 26 If the argument -n is passed, the output will not be run after compiling.
andrewm@58 27 The argument -b will change the local path on the BeagleBone where the
andrewm@60 28 BeagleRT files are found. The -c option passes command-line arguments to
andrewm@90 29 the BeagleRT program; enclose the argument string in quotes.
andrewm@90 30
andrewm@90 31 The -f argument runs the project in the foreground of the current terminal,
andrewm@90 32 within a screen session that can be detached later. The -F argument runs
andrewm@90 33 the project in the foreground of the current terminal, without screen, so
andrewm@90 34 the output can be piped to another destination."
andrewm@58 35 }
andrewm@58 36
andrewm@58 37 OPTIND=1
andrewm@58 38
andrewm@90 39 while getopts "b:c:nfFh" opt; do
andrewm@58 40 case $opt in
andrewm@58 41 b) BBB_PATH=$OPTARG
andrewm@58 42 ;;
andrewm@60 43 c) COMMAND_ARGS=$OPTARG
andrewm@60 44 ;;
andrewm@90 45 f) RUN_IN_FOREGROUND=1
andrewm@90 46 ;;
andrewm@90 47 F) RUN_WITHOUT_SCREEN=1
andrewm@90 48 ;;
andrewm@58 49 n) RUN_PROJECT=0
andrewm@58 50 ;;
andrewm@58 51 h|\?) usage
andrewm@58 52 exit 1
andrewm@58 53 esac
andrewm@58 54 done
andrewm@58 55
andrewm@58 56 shift $((OPTIND-1))
andrewm@58 57
andrewm@58 58 # Check that we have a directory containing at least one source file
andrewm@58 59 # as an argument
giuliomoro@64 60
andrewm@58 61 if [ -z "$1" ]
andrewm@58 62 then
andrewm@58 63 usage
andrewm@58 64 exit
andrewm@58 65 fi
andrewm@58 66
giuliomoro@64 67 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@64 68
giuliomoro@64 69 C_FILES=$($FIND_STRING -name "*.c")
giuliomoro@64 70 CPP_FILES=$($FIND_STRING -name "*.cpp")
giuliomoro@64 71 ASM_FILES=$($FIND_STRING -name "*.S")
andrewm@58 72
andrewm@58 73 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
andrewm@58 74 then
andrewm@58 75 echo "Please provide a directory containing .c, .cpp or .S files."
andrewm@58 76 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
andrewm@58 77 usage
andrewm@58 78 exit
andrewm@58 79 fi
andrewm@58 80
andrewm@58 81 # Stop BeagleRT and clean out old source files
giuliomoro@261 82 echo "Stopping running program..."
giuliomoro@261 83 # sets the date, stops the running process
giuliomoro@261 84 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; screen -X -S '"$SCREEN_NAME"' quit &>/dev/null;"
giuliomoro@64 85
giuliomoro@64 86 #concatenate arguments to form path.
giuliomoro@64 87 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments
giuliomoro@64 88 for i in "$@" #parse input arguments
giuliomoro@64 89 do
giuliomoro@64 90 if [ -d "$1" ] #check if the path is a folder
giuliomoro@64 91 then #if it is, include all of its files
giuliomoro@64 92 BBB_SOURCE_PATH+=" ${1}/* "
giuliomoro@64 93 else
giuliomoro@64 94 BBB_SOURCE_PATH+=" $1 "
giuliomoro@64 95 fi
giuliomoro@64 96 shift
giuliomoro@64 97 # Copy new souce files to the board
giuliomoro@64 98 done
andrewm@58 99
andrewm@58 100 # Copy new source files to the board
andrewm@58 101 echo "Copying new source files to BeagleBone..."
giuliomoro@64 102 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/"
giuliomoro@64 103
giuliomoro@64 104 if [ $? -ne 0 ]
giuliomoro@64 105 then
giuliomoro@64 106 echo "Error while copying files"
giuliomoro@64 107 exit
giuliomoro@64 108 fi
andrewm@58 109
andrewm@58 110 # Make new BeagleRT executable and run
andrewm@58 111 if [ $RUN_PROJECT -eq 0 ]
andrewm@58 112 then
andrewm@58 113 echo "Building project..."
andrewm@58 114 ssh $BBB_ADDRESS "make all -C $BBB_PATH"
andrewm@58 115 else
andrewm@58 116 echo "Building and running project..."
andrewm@90 117
andrewm@90 118 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
andrewm@90 119 then
giuliomoro@249 120 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && ../BeagleRT $COMMAND_ARGS"
andrewm@90 121 elif [ $RUN_IN_FOREGROUND -eq 0 ]
andrewm@90 122 then
giuliomoro@261 123 ssh $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME -d -m ../BeagleRT $COMMAND_ARGS"
andrewm@90 124 else
giuliomoro@261 125 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME ../BeagleRT $COMMAND_ARGS"
andrewm@90 126 fi
giuliomoro@249 127 fi