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