Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 1 | #!/bin/bash |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 2 | #set -x |
| 3 | |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 4 | set -e |
| 5 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | # This file should be called to build the code. |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 7 | # Usage: build.sh platform main_file.gyp debug [action]... |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 8 | |
| 9 | PLATFORM=$1 |
| 10 | GYP_MAIN=$2 |
| 11 | DEBUG=$3 |
Daniel Petti | ed2ee75 | 2013-09-27 04:26:13 +0000 | [diff] [blame] | 12 | OUT_NAME=$4 |
| 13 | ACTION=$5 |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 14 | |
Daniel Petti | 8378ebf | 2013-10-29 01:45:33 +0000 | [diff] [blame] | 15 | shift 4 |
Daniel Petti | b046c53 | 2013-10-29 03:40:40 +0000 | [diff] [blame] | 16 | shift || true # We might not have a 5th argument if ACTION is empty. |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 17 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 18 | export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"} |
| 19 | |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame^] | 20 | [ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "linux" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "linux"'. ; exit 1 ) |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 21 | [ "${DEBUG}" == "yes" -o "${DEBUG}" == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 ) |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 22 | |
| 23 | AOS=`dirname $0`/.. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 24 | |
Daniel Petti | e16297b | 2013-11-18 14:03:32 -0800 | [diff] [blame] | 25 | OUTDIR=${AOS}/../output/${OUT_NAME} |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 26 | BUILD_NINJA=${OUTDIR}/build.ninja |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 27 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 28 | ${AOS}/build/download_externals.sh |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 29 | . $(dirname $0)/tools_config |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 30 | |
| 31 | # The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'. |
| 32 | # The '"' at either end is so that it creates a string constant when expanded |
| 33 | # in the C/C++ code. |
| 34 | COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' " |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 35 | |
| 36 | if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \ |
| 37 | "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 38 | # This is a gyp "file" that we pipe into gyp so that it will put the output |
| 39 | # in a directory named what we want where we want it. |
| 40 | GYP_INCLUDE=$(cat <<END |
| 41 | { |
| 42 | 'target_defaults': { |
| 43 | 'configurations': { |
Daniel Petti | 4b25ad8 | 2013-11-19 11:33:23 -0800 | [diff] [blame] | 44 | '${OUT_NAME}': {} |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | } |
| 48 | END |
| 49 | ) |
| 50 | echo "${GYP_INCLUDE}" | ${GYP} \ |
| 51 | --check --depth=${AOS}/.. --no-circular-check -f ninja \ |
| 52 | -I${AOS}/build/aos.gypi -I/dev/stdin -Goutput_dir=output \ |
| 53 | -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \ |
| 54 | ${GYP_MAIN} |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 55 | # Have to substitute "command = $compiler" so that it doesn't try to |
| 56 | # substitute them in the linker commands, where it doesn't work. |
| 57 | sed -i "s:command = \$cc:\\0 ${COMMONFLAGS}:g ; \ |
| 58 | s:command = \$cxx:\\0 ${COMMONFLAGS}:g" \ |
| 59 | ${BUILD_NINJA} |
| 60 | if [ ${PLATFORM} == crio ]; then |
| 61 | sed -i 's/nm -gD/nm/g' ${BUILD_NINJA} |
| 62 | fi |
| 63 | fi |
| 64 | |
| 65 | if [ "${ACTION}" == "clean" ]; then |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 66 | rm -r ${OUTDIR} || true |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 67 | else |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame^] | 68 | if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" ]; then |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 69 | NINJA_ACTION=${ACTION} |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 70 | else |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 71 | NINJA_ACTION= |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 72 | fi |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 73 | ${NINJA} -C ${OUTDIR} ${NINJA_ACTION} "$@" |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame^] | 74 | if [[ ${ACTION} == deploy ]]; then |
| 75 | [[ ${PLATFORM} == linux ]] && \ |
Brian Silverman | 6b894d7 | 2013-08-28 16:21:30 -0700 | [diff] [blame] | 76 | rsync --progress -c -r \ |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 77 | ${OUTDIR}/outputs/* \ |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame^] | 78 | driver@`${AOS}/build/get_ip prime`:/home/driver/robot_code/bin |
| 79 | ssh driver@`${AOS}/build/get_ip prime` "sync; sync; sync" |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 80 | [ ${PLATFORM} == crio ] && \ |
| 81 | ncftpput `${AOS}/build/get_ip robot` / \ |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 82 | ${OUTDIR}/lib/FRC_UserProgram.out |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 83 | fi |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 84 | if [[ ${ACTION} == tests ]]; then |
Brian Silverman | f10de2a | 2013-11-16 19:56:11 -0800 | [diff] [blame] | 85 | find ${OUTDIR}/tests -executable -exec {} \; |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 86 | fi |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 87 | fi |