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 | |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 15 | shift 3 |
| 16 | shift || true # We might not have a 4th argument if ACTION is empty. |
| 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 | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 20 | [ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 ) |
| 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`/.. |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 24 | NINJA_RELEASE=v1.4.0 |
| 25 | NINJA_DIR=${AOS}/externals/ninja-${NINJA_RELEASE} |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 26 | NINJA=${NINJA_DIR}/ninja |
| 27 | # From chromium@154360:trunk/src/DEPS. |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 28 | GYP_REVISION=1738 |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 29 | GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION} |
| 30 | GYP=${GYP_DIR}/gyp |
| 31 | |
Daniel Petti | 4e591f7 | 2013-09-13 04:51:20 +0000 | [diff] [blame] | 32 | OUTDIR=${AOS}/../out_${OUT_NAME} |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 33 | BUILD_NINJA=${OUTDIR}/Default/build.ninja |
| 34 | |
Brian Silverman | a67ecc7 | 2013-09-28 13:53:53 -0700 | [diff] [blame] | 35 | [ -d ${NINJA_DIR} ] || git clone --branch ${NINJA_RELEASE} https://github.com/martine/ninja.git ${NINJA_DIR} |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 36 | [ -x ${NINJA} ] || ${NINJA_DIR}/bootstrap.py |
| 37 | [ -d ${GYP_DIR} ] || ( svn co http://gyp.googlecode.com/svn/trunk -r ${GYP_REVISION} ${GYP_DIR} && patch -p1 -d ${GYP_DIR} < ${AOS}/externals/gyp.patch ) |
| 38 | ${AOS}/build/download_externals.sh |
| 39 | |
| 40 | # The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'. |
| 41 | # The '"' at either end is so that it creates a string constant when expanded |
| 42 | # in the C/C++ code. |
| 43 | COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' " |
| 44 | if [ ${PLATFORM} == crio ]; then |
| 45 | COMMONFLAGS+='-DAOS_INITNAME=aos_init_function_`readlink -f $out | sed \"s/[\/.]/_/g\"` ' |
| 46 | fi |
| 47 | |
| 48 | if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \ |
| 49 | "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then |
| 50 | ${GYP} \ |
| 51 | --check --depth=${AOS}/.. --no-circular-check -f ninja \ |
Daniel Petti | 4e591f7 | 2013-09-13 04:51:20 +0000 | [diff] [blame] | 52 | -I${AOS}/build/aos.gypi -Goutput_dir=out_${OUT_NAME} \ |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 53 | -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \ |
| 54 | ${GYP_MAIN} |
| 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 | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 68 | if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; 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 |
Daniel Petti | 39ad1f1 | 2013-10-28 00:03:33 +0000 | [diff] [blame^] | 73 | ${NINJA} -C ${OUTDIR}/Default ${NINJA_ACTION} |
Brian Silverman | dff55a2 | 2013-04-28 18:11:00 -0700 | [diff] [blame] | 74 | if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then |
Daniel Petti | 39ad1f1 | 2013-10-28 00:03:33 +0000 | [diff] [blame^] | 75 | [ ${PLATFORM} == atom ] || [ ${PLATFORM} == bot3_atom] && \ |
Brian Silverman | 6b894d7 | 2013-08-28 16:21:30 -0700 | [diff] [blame] | 76 | rsync --progress -c -r \ |
Brian Silverman | 31c99c8 | 2013-09-29 16:51:17 -0700 | [diff] [blame] | 77 | ${OUTDIR}/Default/outputs/* \ |
| 78 | driver@`${AOS}/build/get_ip fitpc`:/home/driver/robot_code/bin |
| 79 | ssh driver@`${AOS}/build/get_ip fitpc` "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` / \ |
| 82 | ${OUTDIR}/Default/lib/FRC_UserProgram.out |
| 83 | fi |
| 84 | if [[ ${ACTION} == redeploy ]]; then |
| 85 | if [[ ${PLATFORM} != crio ]]; then |
| 86 | echo "Platform ${PLATFORM} does not support redeploy." 1>&2 |
| 87 | exit 1 |
| 88 | fi |
| 89 | ${OUTDIR}/../out_atom/Default/outputs/netconsole <<"END" |
| 90 | unld "FRC_UserProgram.out" |
| 91 | ld < FRC_UserProgram.out |
| 92 | END |
| 93 | fi |
| 94 | if [[ ${ACTION} == tests ]]; then |
| 95 | find ${OUTDIR}/Default/tests -executable -exec {} \; |
| 96 | fi |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 97 | fi |