blob: bf9d2eb5536a91411073c1e0759e40e102cb26dd [file] [log] [blame]
Brian Silvermana67ecc72013-09-28 13:53:53 -07001#!/bin/bash
brians343bc112013-02-10 01:53:46 +00002#set -x
3
Brian Silvermana67ecc72013-09-28 13:53:53 -07004set -e
5
brians343bc112013-02-10 01:53:46 +00006# This file should be called to build the code.
Brian Silvermana67ecc72013-09-28 13:53:53 -07007# Usage: build.sh platform main_file.gyp debug [action]...
brians343bc112013-02-10 01:53:46 +00008
9PLATFORM=$1
10GYP_MAIN=$2
11DEBUG=$3
Daniel Pettied2ee752013-09-27 04:26:13 +000012OUT_NAME=$4
13ACTION=$5
brians343bc112013-02-10 01:53:46 +000014
Daniel Petti8378ebf2013-10-29 01:45:33 +000015shift 4
Daniel Pettib046c532013-10-29 03:40:40 +000016shift || true # We might not have a 5th argument if ACTION is empty.
Brian Silvermana67ecc72013-09-28 13:53:53 -070017
brians343bc112013-02-10 01:53:46 +000018export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
19
Brian Silverman41abe012014-02-08 18:25:02 -080020[ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "linux" -o "${PLATFORM}" == "linux-amd64" ] || ( echo Platform "(${PLATFORM})" must be '"crio", "linux", or "linux-amd64"'. ; exit 1 )
Brian Silvermana67ecc72013-09-28 13:53:53 -070021[ "${DEBUG}" == "yes" -o "${DEBUG}" == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
brians343bc112013-02-10 01:53:46 +000022
23AOS=`dirname $0`/..
brians343bc112013-02-10 01:53:46 +000024
Daniel Pettie16297b2013-11-18 14:03:32 -080025OUTDIR=${AOS}/../output/${OUT_NAME}
Brian Silvermanf10de2a2013-11-16 19:56:11 -080026BUILD_NINJA=${OUTDIR}/build.ninja
brians343bc112013-02-10 01:53:46 +000027
Brian Silverman41abe012014-02-08 18:25:02 -080028${AOS}/build/download_externals.sh arm
29${AOS}/build/download_externals.sh amd64
Brian Silvermanf10de2a2013-11-16 19:56:11 -080030. $(dirname $0)/tools_config
brians343bc112013-02-10 01:53:46 +000031
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.
35COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
brians343bc112013-02-10 01:53:46 +000036
37if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
38 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
Brian Silvermanacee44a2014-02-12 14:07:37 -080039 echo 'Running gyp...' 1>&2
Brian Silvermanf10de2a2013-11-16 19:56:11 -080040 # 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 Petti4b25ad82013-11-19 11:33:23 -080046 '${OUT_NAME}': {}
Brian Silvermanf10de2a2013-11-16 19:56:11 -080047 }
48 }
49}
50END
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 Silverman41abe012014-02-08 18:25:02 -080055 -DOS=$(echo ${PLATFORM} | sed 's/-.*//g') -DPLATFORM=${PLATFORM} \
56 -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080057 ${GYP_MAIN}
brians343bc112013-02-10 01:53:46 +000058 # 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 Silvermanacee44a2014-02-12 14:07:37 -080066 echo 'Done running gyp.' 1>&2
brians343bc112013-02-10 01:53:46 +000067fi
68
69if [ "${ACTION}" == "clean" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070070 rm -r ${OUTDIR} || true
brians343bc112013-02-10 01:53:46 +000071else
Brian Silverman14fd0fb2014-01-14 21:42:01 -080072 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070073 NINJA_ACTION=${ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070074 else
Brian Silvermana67ecc72013-09-28 13:53:53 -070075 NINJA_ACTION=
Brian Silvermandff55a22013-04-28 18:11:00 -070076 fi
Brian Silvermanf10de2a2013-11-16 19:56:11 -080077 ${NINJA} -C ${OUTDIR} ${NINJA_ACTION} "$@"
Brian Silverman14fd0fb2014-01-14 21:42:01 -080078 if [[ ${ACTION} == deploy ]]; then
79 [[ ${PLATFORM} == linux ]] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070080 rsync --progress -c -r \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080081 ${OUTDIR}/outputs/* \
Brian Silverman14fd0fb2014-01-14 21:42:01 -080082 driver@`${AOS}/build/get_ip prime`:/home/driver/robot_code/bin
83 ssh driver@`${AOS}/build/get_ip prime` "sync; sync; sync"
Brian Silvermandff55a22013-04-28 18:11:00 -070084 [ ${PLATFORM} == crio ] && \
85 ncftpput `${AOS}/build/get_ip robot` / \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080086 ${OUTDIR}/lib/FRC_UserProgram.out
Brian Silvermandff55a22013-04-28 18:11:00 -070087 fi
Brian Silvermandff55a22013-04-28 18:11:00 -070088 if [[ ${ACTION} == tests ]]; then
Brian Silvermanf10de2a2013-11-16 19:56:11 -080089 find ${OUTDIR}/tests -executable -exec {} \;
Brian Silvermandff55a22013-04-28 18:11:00 -070090 fi
brians343bc112013-02-10 01:53:46 +000091fi