Fixed P4 tools build script for Ubuntu 14

+ bumped version of p4runtime and BMv2
+ minor update to bmv2.py

Change-Id: I7784b075b2e6015bb3eef1286011968303b66129
diff --git a/tools/dev/bin/onos-setup-p4-dev b/tools/dev/bin/onos-setup-p4-dev
index f3573a1..65179ef 100755
--- a/tools/dev/bin/onos-setup-p4-dev
+++ b/tools/dev/bin/onos-setup-p4-dev
@@ -15,8 +15,8 @@
 set -e
 
 BUILD_DIR=~/p4tools
-BMV2_COMMIT="41c1f2ed487ff086a1d582069e8bc68cab8ffdb0"
-PI_COMMIT="f110570ca0c8ddc5feaf5028b08a0f477ceb4eea"
+BMV2_COMMIT="654e9c3794273b481284d8bafecfc74c7ffd643d"
+PI_COMMIT="8051d54c9c3415ca800db232a226189fd17ad60a"
 P4C_COMMIT="adce375fd961a9e467c7e77ad1bef647ef28e5e8"
 P4C_BM_COMMIT="8f4abeaa6f8374aaf95ea2aacfc2b750069391b5"
 PROTOBUF_COMMIT="tags/v3.0.2"
@@ -26,13 +26,18 @@
 
 function do_requirements {
     sudo apt update
+    #FIXME the following two lines seem like they are not required, at least for 16.04
     sudo apt install -y python-software-properties software-properties-common
     sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
     sudo apt update
-    sudo apt install -y \
+    #FIXME 14.04 needs special gcc, 16.04 can use apt-get default
+    sudo apt install -y --no-install-recommends \
         autoconf \
         automake \
         bison \
+        build-essential \
+        cmake \
+        cpp \
         curl \
         dpkg-dev \
         flex \
@@ -40,20 +45,38 @@
         gcc-4.9 \
         git \
         libboost-dev \
+        libboost-filesystem-dev \
         libboost-iostreams-dev \
+        libboost-program-options-dev \
+        libboost-system-dev \
+        libboost-test-dev \
+        libboost-thread-dev \
+        libc6-dev \
+        libevent-dev \
+        libffi-dev \
         libfl-dev \
         libgc-dev \
+        libgc1c2 \
+        libgflags-dev \
         libgmp-dev \
+        libgmp10 \
+        libgmpxx4ldbl \
+        libjudy-dev \
+        libpcap-dev \
         libreadline6 \
         libreadline6-dev \
+        libssl-dev \
         libtool \
-        libc6-dev \
         make \
+        mktemp \
         pkg-config \
         python \
+        python-dev \
         python-ipaddr \
+        python-pip \
         python-scapy \
         tcpdump \
+        wget \
         unzip
 
     # Needed for p4c.
@@ -62,7 +85,6 @@
 }
 
 function do_protobuf {
-    # Protobuf
     cd ${BUILD_DIR}
     if [ ! -d protobuf ]; then
       git clone https://github.com/google/protobuf.git
@@ -70,15 +92,19 @@
     cd protobuf
     git fetch
     git checkout ${PROTOBUF_COMMIT}
+
+    export CFLAGS="-Os"
+    export CXXFLAGS="-Os"
+    export LDFLAGS="-Wl,-s"
     ./autogen.sh
     ./configure --prefix=/usr
     make -j${NUM_CORES}
     sudo make install
     sudo ldconfig
+    unset CFLAGS CXXFLAGS LDFLAGS
 }
 
 function do_grpc {
-    # gRPC
     cd ${BUILD_DIR}
     if [ ! -d grpc ]; then
       git clone https://github.com/grpc/grpc.git
@@ -87,30 +113,15 @@
     git fetch
     git checkout ${GRPC_COMMIT}
     git submodule update --init
-    make -j${NUM_CORES}
-    sudo make install
-    sudo ldconfig
-}
 
-function do_bmv2 {
-    # BMv2 part 1 (without PI)
-    cd ${BUILD_DIR}
-    if [ ! -d bmv2 ]; then
-        git clone https://github.com/p4lang/behavioral-model.git bmv2
-    fi
-    cd bmv2
-    git fetch
-    git checkout ${BMV2_COMMIT}
-    ./install_deps.sh
-    ./autogen.sh
-    ./configure --enable-debugger
+    export LDFLAGS="-Wl,-s"
     make -j${NUM_CORES}
     sudo make install
     sudo ldconfig
+    unset LDFLAGS
 }
 
 function do_p4runtime {
-    # P4Runtime (PI)
     cd ${BUILD_DIR}
     if [ ! -d p4runtime ]; then
         git clone https://github.com/p4lang/PI.git p4runtime
@@ -119,17 +130,26 @@
     git fetch
     git checkout ${PI_COMMIT}
     git submodule update --init --recursive
+
     ./autogen.sh
-    ./configure --with-bmv2 --with-proto
+    ./configure --with-proto --without-cli --without-internal-rpc
     make -j${NUM_CORES}
     sudo make install
     sudo ldconfig
 }
 
-function do_bmv2_with_pi {
-    # BMv2 part 2 (with PI)
-    cd ${BUILD_DIR}/bmv2
-    ./configure --enable-debugger --with-pi
+function do_bmv2 {
+    cd ${BUILD_DIR}
+    if [ ! -d bmv2 ]; then
+        git clone https://github.com/p4lang/behavioral-model.git bmv2
+    fi
+    cd bmv2
+    git fetch
+    git checkout ${BMV2_COMMIT}
+
+    ./autogen.sh
+    # FIXME: to build with debugger, we need to install nanomsg first (see bmv2's install_deps.sh)
+    ./configure --without-thrift --without-nanomsg --with-pi
     make -j${NUM_CORES}
     sudo make install
     sudo ldconfig
@@ -144,7 +164,6 @@
 }
 
 function do_p4c {
-    # p4c
     cd ${BUILD_DIR}
     if [ ! -d p4c ]; then
         git clone https://github.com/p4lang/p4c.git
@@ -153,6 +172,7 @@
     git fetch
     git checkout ${P4C_COMMIT}
     git submodule update --init --recursive
+
     ./bootstrap.sh
     cd build
     make -j${NUM_CORES}
@@ -160,8 +180,9 @@
     sudo ldconfig
 }
 
+# FIXME: Can we deprecate this?
 function do_p4c_bm {
-    # p4c-bmv2 (old BMv2 compiler)
+    # old BMv2 compiler
     cd ${BUILD_DIR}
     if [ ! -d p4c-bmv2 ]; then
         git clone https://github.com/p4lang/p4c-bm.git p4c-bmv2
@@ -196,6 +217,7 @@
         echo "# Building ${proj_dir} (${commit_id})"
         echo "#"
         if ! ${DID_REQUIREMENTS} = true; then
+        #FIXME need version check for 14.04 vs 16.04
             do_requirements
             DID_REQUIREMENTS=true
         fi
@@ -213,9 +235,8 @@
 # In dependency order.
 check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf
 check_and_do ${GRPC_COMMIT} grpc do_grpc
-check_and_do ${BMV2_COMMIT} bmv2 do_bmv2
 check_and_do ${PI_COMMIT} p4runtime do_p4runtime
-check_and_do ${BMV2_COMMIT} bmv2 do_bmv2_with_pi
+check_and_do ${BMV2_COMMIT} bmv2 do_bmv2
 check_and_do ${P4C_COMMIT} p4c do_p4c
 check_and_do ${P4C_BM_COMMIT} p4c-bmv2 do_p4c_bm