annotate scripts/build_project.sh @ 464:8fcfbfb32aa0 prerelease

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