blob: e0ff43473ebe35cf44418e56fc8746a09aa8bbc9 [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 Silvermana67ecc72013-09-28 13:53:53 -070020[ "${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 )
brians343bc112013-02-10 01:53:46 +000022
23AOS=`dirname $0`/..
Brian Silvermana67ecc72013-09-28 13:53:53 -070024NINJA_RELEASE=v1.4.0
25NINJA_DIR=${AOS}/externals/ninja-${NINJA_RELEASE}
brians343bc112013-02-10 01:53:46 +000026NINJA=${NINJA_DIR}/ninja
27# From chromium@154360:trunk/src/DEPS.
Brian Silvermana67ecc72013-09-28 13:53:53 -070028GYP_REVISION=1738
brians343bc112013-02-10 01:53:46 +000029GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION}
30GYP=${GYP_DIR}/gyp
31
Daniel Petti4e591f72013-09-13 04:51:20 +000032OUTDIR=${AOS}/../out_${OUT_NAME}
brians343bc112013-02-10 01:53:46 +000033BUILD_NINJA=${OUTDIR}/Default/build.ninja
34
Brian Silvermana67ecc72013-09-28 13:53:53 -070035[ -d ${NINJA_DIR} ] || git clone --branch ${NINJA_RELEASE} https://github.com/martine/ninja.git ${NINJA_DIR}
brians343bc112013-02-10 01:53:46 +000036[ -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.
43COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
44if [ ${PLATFORM} == crio ]; then
45 COMMONFLAGS+='-DAOS_INITNAME=aos_init_function_`readlink -f $out | sed \"s/[\/.]/_/g\"` '
46fi
47
48if [[ "${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 Petti4e591f72013-09-13 04:51:20 +000052 -I${AOS}/build/aos.gypi -Goutput_dir=out_${OUT_NAME} \
brians343bc112013-02-10 01:53:46 +000053 -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
63fi
64
65if [ "${ACTION}" == "clean" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070066 rm -r ${OUTDIR} || true
brians343bc112013-02-10 01:53:46 +000067else
Brian Silvermandff55a22013-04-28 18:11:00 -070068 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070069 NINJA_ACTION=${ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070070 else
Brian Silvermana67ecc72013-09-28 13:53:53 -070071 NINJA_ACTION=
Brian Silvermandff55a22013-04-28 18:11:00 -070072 fi
Daniel Petti8378ebf2013-10-29 01:45:33 +000073 ${NINJA} -C ${OUTDIR}/Default ${NINJA_ACTION} "$@"
Brian Silvermandff55a22013-04-28 18:11:00 -070074 if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
Daniel Pettib046c532013-10-29 03:40:40 +000075 [[ ${PLATFORM} =~ .*atom ]] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070076 rsync --progress -c -r \
Brian Silverman31c99c82013-09-29 16:51:17 -070077 ${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 Silvermandff55a22013-04-28 18:11:00 -070080 [ ${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"
90unld "FRC_UserProgram.out"
91ld < FRC_UserProgram.out
92END
93 fi
94 if [[ ${ACTION} == tests ]]; then
95 find ${OUTDIR}/Default/tests -executable -exec {} \;
96 fi
brians343bc112013-02-10 01:53:46 +000097fi