blob: 72e6c7ad57c5781fccd594e8189848dd9e878139 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#!/bin/bash -e
2#set -x
3
4# This file should be called to build the code.
5# Usage: build.sh platform main_file.gyp debug [action]
6
7PLATFORM=$1
8GYP_MAIN=$2
9DEBUG=$3
10ACTION=$4
Daniel Petti4e591f72013-09-13 04:51:20 +000011OUT_NAME=$5
brians343bc112013-02-10 01:53:46 +000012
13export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
14
15[ ${PLATFORM} == "crio" -o ${PLATFORM} == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
16[ ${DEBUG} == "yes" -o ${DEBUG} == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
17
18AOS=`dirname $0`/..
19NINJA_DIR=${AOS}/externals/ninja
20NINJA=${NINJA_DIR}/ninja
21# From chromium@154360:trunk/src/DEPS.
22GYP_REVISION=1488
23GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION}
24GYP=${GYP_DIR}/gyp
25
Daniel Petti4e591f72013-09-13 04:51:20 +000026OUTDIR=${AOS}/../out_${OUT_NAME}
brians343bc112013-02-10 01:53:46 +000027BUILD_NINJA=${OUTDIR}/Default/build.ninja
28
29[ -d ${NINJA_DIR} ] || git clone --branch release https://github.com/martine/ninja.git ${NINJA_DIR}
30[ -x ${NINJA} ] || ${NINJA_DIR}/bootstrap.py
31[ -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 )
32${AOS}/build/download_externals.sh
33
34# The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'.
35# The '"' at either end is so that it creates a string constant when expanded
36# in the C/C++ code.
37COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
38if [ ${PLATFORM} == crio ]; then
39 COMMONFLAGS+='-DAOS_INITNAME=aos_init_function_`readlink -f $out | sed \"s/[\/.]/_/g\"` '
40fi
41
42if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
43 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
44 ${GYP} \
45 --check --depth=${AOS}/.. --no-circular-check -f ninja \
Daniel Petti4e591f72013-09-13 04:51:20 +000046 -I${AOS}/build/aos.gypi -Goutput_dir=out_${OUT_NAME} \
brians343bc112013-02-10 01:53:46 +000047 -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
48 ${GYP_MAIN}
49 # Have to substitute "command = $compiler" so that it doesn't try to
50 # substitute them in the linker commands, where it doesn't work.
51 sed -i "s:command = \$cc:\\0 ${COMMONFLAGS}:g ; \
52 s:command = \$cxx:\\0 ${COMMONFLAGS}:g" \
53 ${BUILD_NINJA}
54 if [ ${PLATFORM} == crio ]; then
55 sed -i 's/nm -gD/nm/g' ${BUILD_NINJA}
56 fi
57fi
58
59if [ "${ACTION}" == "clean" ]; then
60 rm -r ${OUTDIR}
61else
Brian Silvermandff55a22013-04-28 18:11:00 -070062 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
63 GYP_ACTION=${ACTION}
64 else
65 GYP_ACTION=
66 fi
brians343bc112013-02-10 01:53:46 +000067 ${NINJA} -C ${OUTDIR}/Default ${GYP_ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070068 if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
69 [ ${PLATFORM} == atom ] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070070 rsync --progress -c -r \
Brian Silvermandff55a22013-04-28 18:11:00 -070071 ${OUTDIR}/Default/outputs/* \
72 driver@`${AOS}/build/get_ip fitpc`:/home/driver/robot_code/bin
73 [ ${PLATFORM} == crio ] && \
74 ncftpput `${AOS}/build/get_ip robot` / \
75 ${OUTDIR}/Default/lib/FRC_UserProgram.out
76 fi
77 if [[ ${ACTION} == redeploy ]]; then
78 if [[ ${PLATFORM} != crio ]]; then
79 echo "Platform ${PLATFORM} does not support redeploy." 1>&2
80 exit 1
81 fi
82 ${OUTDIR}/../out_atom/Default/outputs/netconsole <<"END"
83unld "FRC_UserProgram.out"
84ld < FRC_UserProgram.out
85END
86 fi
87 if [[ ${ACTION} == tests ]]; then
88 find ${OUTDIR}/Default/tests -executable -exec {} \;
89 fi
brians343bc112013-02-10 01:53:46 +000090fi