updated most things to work on Wheezy

I haven't done the new opencv packages yet, so I just didn't test
compiling that stuff.

Almost all of the changes were related to user-defined string literals
breaking things like "%"PRIu32" (in our code and other people's).
diff --git a/aos/atom_code/camera/HTTPStreamer.cpp b/aos/atom_code/camera/HTTPStreamer.cpp
index a5d42b1..8a896c5 100644
--- a/aos/atom_code/camera/HTTPStreamer.cpp
+++ b/aos/atom_code/camera/HTTPStreamer.cpp
@@ -225,7 +225,7 @@
             to_write_ = snprintf(scratch_, sizeof(scratch_),
                                 "\r\n--boundarydonotcross\r\n"
                                 "Content-Type: image/jpeg\r\n"
-                                "Content-Length: %"PRId32"\r\n"
+                                "Content-Length: %" PRId32 "\r\n"
                                 "X-Timestamp: %ld.%06ld\r\n"
                                 "\r\n",
                                 size_,
diff --git a/aos/atom_code/camera/Reader.cpp b/aos/atom_code/camera/Reader.cpp
index b9dc36d..5f30cfe 100644
--- a/aos/atom_code/camera/Reader.cpp
+++ b/aos/atom_code/camera/Reader.cpp
@@ -121,10 +121,11 @@
 
   void QueueBuffer(v4l2_buffer *buf) {
     if (xioctl(fd_, VIDIOC_QBUF, buf) == -1) {
-      LOG(WARNING, "ioctl VIDIOC_QBUF(%d, %p) failed with %d: %s. losing buf #%"PRIu32"\n",
+      LOG(WARNING, "ioctl VIDIOC_QBUF(%d, %p) failed with %d: %s."
+          " losing buf #%" PRIu32 "\n",
           fd_, &buf, errno, strerror(errno), buf->index);
     } else {
-      LOG(DEBUG, "put buf #%"PRIu32" into driver's queue\n", buf->index);
+      LOG(DEBUG, "put buf #%" PRIu32 " into driver's queue\n", buf->index);
       ++queued_;
     }
   }
@@ -156,7 +157,7 @@
     }
     --queued_;
     if (buf.index >= Buffers::kNumBuffers) {
-      LOG(ERROR, "buf.index (%"PRIu32") is >= kNumBuffers (%u)\n",
+      LOG(ERROR, "buf.index (%" PRIu32 ") is >= kNumBuffers (%u)\n",
           buf.index, Buffers::kNumBuffers);
       return;
     }
@@ -164,7 +165,8 @@
     Buffers::Message *const msg = static_cast<Buffers::Message *>(
         aos_queue_get_msg(queue_));
     if (msg == NULL) {
-      LOG(WARNING, "couldn't get a message to send buf #%"PRIu32" from queue %p."
+      LOG(WARNING,
+          "couldn't get a message to send buf #%" PRIu32 " from queue %p."
           " re-queueing now\n", buf.index, queue_);
       QueueBuffer(&buf);
       return;
@@ -174,12 +176,13 @@
     memcpy(&msg->timestamp, &buf.timestamp, sizeof(msg->timestamp));
     msg->sequence = buf.sequence;
     if (aos_queue_write_msg_free(queue_, msg, OVERRIDE) == -1) {
-      LOG(WARNING, "sending message %p with buf #%"PRIu32" to queue %p failed."
+      LOG(WARNING,
+          "sending message %p with buf #%" PRIu32 " to queue %p failed."
           " re-queueing now\n", msg, buf.index, queue_);
       QueueBuffer(&buf);
       return;
     } else {
-      LOG(DEBUG, "sent message off to queue %p with buffer #%"PRIu32"\n",
+      LOG(DEBUG, "sent message off to queue %p with buffer #%" PRIu32 "\n",
           queue_, buf.index);
     }
   }
@@ -207,8 +210,8 @@
   // Sets one of the camera's user-control values.
   // Prints the old and new values.
   // Just prints a message if the camera doesn't support this control or value.
-  bool SetCameraControl(int id, const char *name, int value) {
-    struct v4l2_control getArg = {id, 0};
+  bool SetCameraControl(uint32_t id, const char *name, int value) {
+    struct v4l2_control getArg = {id, 0U};
     int r = xioctl(fd_, VIDIOC_G_CTRL, &getArg);
     if (r == 0) {
       if (getArg.value == value) {
diff --git a/aos/atom_code/core/LogStreamer.cpp b/aos/atom_code/core/LogStreamer.cpp
index a7151ad..d3d4928 100644
--- a/aos/atom_code/core/LogStreamer.cpp
+++ b/aos/atom_code/core/LogStreamer.cpp
@@ -26,7 +26,7 @@
   InitNRT();
 
   const time::Time now = time::Time::Now();
-  printf("starting at %"PRId32"s%"PRId32"ns---------------------------------\n",
+  printf("starting at %" PRId32 "s%" PRId32 "ns-----------------------------\n",
          now.sec(), now.nsec());
 
   int index = 0;
diff --git a/aos/atom_code/ipc_lib/mutex.cpp b/aos/atom_code/ipc_lib/mutex.cpp
index 6bf5df5..4f908dd 100644
--- a/aos/atom_code/ipc_lib/mutex.cpp
+++ b/aos/atom_code/ipc_lib/mutex.cpp
@@ -20,14 +20,14 @@
 
 void Mutex::Lock() {
   if (mutex_grab(&impl_) != 0) {
-    LOG(FATAL, "mutex_grab(%p(=%"PRIu32")) failed because of %d: %s\n",
+    LOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed because of %d: %s\n",
         &impl_, impl_, errno, strerror(errno));
   }
 }
 
 void Mutex::Unlock() {
   if (mutex_unlock(&impl_) != 0) {
-    LOG(FATAL, "mutex_unlock(%p(=%"PRIu32")) failed because of %d: %s\n",
+    LOG(FATAL, "mutex_unlock(%p(=%" PRIu32 ")) failed because of %d: %s\n",
         &impl_, impl_, errno, strerror(errno));
   }
 }
diff --git a/aos/atom_code/ipc_lib/queue_test.cpp b/aos/atom_code/ipc_lib/queue_test.cpp
index 6fb6eca..e9ac8d5 100644
--- a/aos/atom_code/ipc_lib/queue_test.cpp
+++ b/aos/atom_code/ipc_lib/queue_test.cpp
@@ -258,13 +258,14 @@
         aos_queue_read_msg(args->queue, args->flags));
     if (msg == NULL) {
       if (args->data != -1) {
-        snprintf(failure, kFailureSize, "expected data of %"PRId16" but got NULL message",
+        snprintf(failure, kFailureSize,
+                 "expected data of %" PRId16 " but got NULL message",
                  args->data);
       }
     } else {
       if (args->data != msg->data) {
         snprintf(failure, kFailureSize,
-                 "expected data of %"PRId16" but got %"PRId16" instead",
+                 "expected data of %" PRId16 " but got %" PRId16 " instead",
                  args->data, msg->data);
       }
       aos_queue_free_msg(args->queue, msg);
diff --git a/aos/atom_code/output/HTTPServer.cpp b/aos/atom_code/output/HTTPServer.cpp
index b593938..9a3b359 100644
--- a/aos/atom_code/output/HTTPServer.cpp
+++ b/aos/atom_code/output/HTTPServer.cpp
@@ -25,7 +25,7 @@
     LOG(FATAL, "couldn't create an evhttp\n");
   }
   if (evhttp_bind_socket(http_, "0.0.0.0", port) != 0) {
-    LOG(FATAL, "evhttp_bind_socket(%p, \"0.0.0.0\", %"PRIu16") failed\n",
+    LOG(FATAL, "evhttp_bind_socket(%p, \"0.0.0.0\", %" PRIu16 ") failed\n",
         http_, port);
   }
   evhttp_set_gencb(http_, StaticServeFile, this);
diff --git a/aos/atom_code/queue-tmpl.h b/aos/atom_code/queue-tmpl.h
index f9761bd..bb043e1 100644
--- a/aos/atom_code/queue-tmpl.h
+++ b/aos/atom_code/queue-tmpl.h
@@ -171,7 +171,8 @@
 void Queue<T>::Init() {
   if (queue_ == NULL) {
     // Signature of the message.
-    aos_type_sig kQueueSignature{sizeof(T), T::kHash, T::kQueueLength};
+    aos_type_sig kQueueSignature{sizeof(T), static_cast<int>(T::kHash),
+      T::kQueueLength};
 
     queue_ = aos_fetch_queue(queue_name_, &kQueueSignature);
     queue_msg_.set_queue(queue_);
diff --git a/aos/atom_code/starter/starter.cc b/aos/atom_code/starter/starter.cc
index 8f8a65d..ccee67e 100644
--- a/aos/atom_code/starter/starter.cc
+++ b/aos/atom_code/starter/starter.cc
@@ -187,7 +187,7 @@
       if (watchers.count(notifyevt->wd) != 1) {
         LOG(WARNING, "couldn't find whose watch ID %d is\n", notifyevt->wd);
       } else {
-        LOG(DEBUG, "mask=%"PRIu32"\n", notifyevt->mask);
+        LOG(DEBUG, "mask=%" PRIu32 "\n", notifyevt->mask);
         // If it was something that means the file got deleted.
         if (notifyevt->mask & (IN_MOVE_SELF | IN_DELETE_SELF | IN_IGNORED)) {
           watchers[notifyevt->wd]->WatchDeleted();
diff --git a/aos/build/download_externals.sh b/aos/build/download_externals.sh
index 4f999b2..f671ac3 100755
--- a/aos/build/download_externals.sh
+++ b/aos/build/download_externals.sh
@@ -1,4 +1,6 @@
-#!/bin/bash -e
+#!/bin/bash
+
+set -e
 
 AOS=`dirname $0`/..
 EXTERNALS=${AOS}/externals
@@ -9,7 +11,7 @@
 [ -d ${GCCDIST} ] || ( cd ${EXTERNALS} && unzip -q ${GCCDIST}.zip )
 
 # get eigen
-EIGEN_VERSION=3.0.5
+EIGEN_VERSION=3.1.3
 EIGEN_DIR=${EXTERNALS}/eigen-${EIGEN_VERSION}
 [ -f ${EIGEN_DIR}.tar.bz2 ] || wget http://bitbucket.org/eigen/eigen/get/${EIGEN_VERSION}.tar.bz2 -O ${EIGEN_DIR}.tar.bz2
 [ -d ${EIGEN_DIR} ] || ( mkdir ${EIGEN_DIR} && tar --strip-components=1 -C ${EIGEN_DIR} -xf ${EIGEN_DIR}.tar.bz2 )
@@ -46,16 +48,24 @@
 [ -d ${GTEST_DIR} ] || ( unzip ${GTEST_ZIP} -d ${TMPDIR} && mv ${TMPDIR}/gtest-${GTEST_VERSION} ${GTEST_DIR} && cd ${GTEST_DIR} && patch -p1 < ../gtest.patch )
 
 # get and build ctemplate
-CTEMPLATE_VERSION=2.2
+# This is the next revision after the 2.2 release and it only adds spaces to
+# make gcc 4.7 with --std=c++11 happy (user-defined string literals...).
+CTEMPLATE_VERSION=129
 CTEMPLATE_DIR=${EXTERNALS}/ctemplate-${CTEMPLATE_VERSION}
 CTEMPLATE_PREFIX=${CTEMPLATE_DIR}-prefix
 CTEMPLATE_LIB=${CTEMPLATE_PREFIX}/lib/libctemplate.a
-CTEMPLATE_URL=http://ctemplate.googlecode.com/files
-CTEMPLATE_URL=${CTEMPLATE_URL}/ctemplate-${CTEMPLATE_VERSION}.tar.gz
-[ -f ${CTEMPLATE_DIR}.tar.gz ] || \
-	wget ${CTEMPLATE_URL} -O ${CTEMPLATE_DIR}.tar.gz
-[ -d ${CTEMPLATE_DIR} ] || ( mkdir ${CTEMPLATE_DIR} && tar \
-	--strip-components=1 -C ${CTEMPLATE_DIR} -xf ${CTEMPLATE_DIR}.tar.gz )
+CTEMPLATE_URL=http://ctemplate.googlecode.com
+if [[ "${CTEMPLATE_VERSION}" =~ /\./ ]]; then
+	CTEMPLATE_URL=${CTEMPLATE_URL}/files/ctemplate-${CTEMPLATE_VERSION}.tar.gz
+	[ -f ${CTEMPLATE_DIR}.tar.gz ] || \
+		wget ${CTEMPLATE_URL} -O ${CTEMPLATE_DIR}.tar.gz
+	[ -d ${CTEMPLATE_DIR} ] || ( mkdir ${CTEMPLATE_DIR} && tar \
+		--strip-components=1 -C ${CTEMPLATE_DIR} -xf ${CTEMPLATE_DIR}.tar.gz )
+else
+	CTEMPLATE_URL=${CTEMPLATE_URL}/svn/trunk
+	[ -d ${CTEMPLATE_DIR} ] || \
+		svn checkout ${CTEMPLATE_URL} -r ${CTEMPLATE_VERSION} ${CTEMPLATE_DIR}
+fi
 [ -f ${CTEMPLATE_LIB} ] || env -i PATH="${PATH}" \
 	CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
 	bash -c "cd ${CTEMPLATE_DIR} && ./configure --disable-shared \
@@ -96,3 +106,18 @@
 COMPILER_RT_DIR=${EXTERNALS}/compiler-rt-${COMPILER_RT_VERSION}
 COMPILER_RT_URL=http://llvm.org/svn/llvm-project/compiler-rt/tags/${COMPILER_RT_TAG}
 [ -d ${COMPILER_RT_DIR} ] || svn checkout ${COMPILER_RT_URL} ${COMPILER_RT_DIR}
+
+# get and build libevent
+LIBEVENT_VERSION=2.0.21
+LIBEVENT_DIR=${EXTERNALS}/libevent-${LIBEVENT_VERSION}
+LIBEVENT_PREFIX=${LIBEVENT_DIR}-prefix
+LIBEVENT_LIB=${LIBEVENT_PREFIX}/lib/libevent.a
+LIBEVENT_URL=https://github.com/downloads/libevent/libevent
+LIBEVENT_URL=${LIBEVENT_URL}/libevent-${LIBEVENT_VERSION}-stable.tar.gz
+[ -f ${LIBEVENT_DIR}.tar.gz ] || wget ${LIBEVENT_URL} -O ${LIBEVENT_DIR}.tar.gz
+[ -d ${LIBEVENT_DIR} ] || ( mkdir ${LIBEVENT_DIR} && tar \
+  --strip-components=1 -C ${LIBEVENT_DIR} -xf ${LIBEVENT_DIR}.tar.gz )
+[ -f ${LIBEVENT_LIB} ] || env -i PATH="${PATH}" \
+  CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
+  bash -c "cd ${LIBEVENT_DIR} && ./configure \
+  --prefix=`readlink -f ${LIBEVENT_PREFIX}` && make && make install"
diff --git a/aos/build/externals.gyp b/aos/build/externals.gyp
index 06bd225..0dcabf2 100644
--- a/aos/build/externals.gyp
+++ b/aos/build/externals.gyp
@@ -6,14 +6,15 @@
     'externals_abs': '<!(readlink -f ../externals)',
 
 # These versions have to be kept in sync with the ones in download_externals.sh.
-    'eigen_version': '3.0.5',
+    'eigen_version': '3.1.3',
     'gtest_version': '1.6.0-p1',
     'onejar_version': '0.97',
-    'ctemplate_version': '2.2',
+    'ctemplate_version': '129',
     'gflags_version': '2.0',
     'libusb_version': '1.0.9',
     'libusb_apiversion': '1.0',
     'compiler_rt_version': 'RELEASE_32_final',
+    'libevent_version': '2.0.21',
   },
   'targets': [
     {
@@ -97,11 +98,13 @@
       },
     },
     {
-# TODO(brians) convert this to downloading + building
       'target_name': 'libevent',
       'type': 'none',
       'link_settings': {
-        'libraries': ['-levent'],
+        'libraries': ['<(externals_abs)/libevent-<(libevent_version)-prefix/lib/libevent.a'],
+      },
+      'direct_dependent_settings': {
+        'include_dirs': ['<(externals)/libevent-<(libevent_version)-prefix/include'],
       },
     },
     {
diff --git a/aos/build/queues/objects/queue.rb b/aos/build/queues/objects/queue.rb
index 5693486..e993eb9 100644
--- a/aos/build/queues/objects/queue.rb
+++ b/aos/build/queues/objects/queue.rb
@@ -38,14 +38,14 @@
                        "float" => "%f",
                        "char" => "%c",
                        "double" => "%f",
-                       "uint8_t" => "%\"PRIu8\"",
-                       "uint16_t" => "%\"PRIu16\"",
-                       "uint32_t" => "%\"PRIu32\"",
-                       "uint64_t" => "%\"PRIu64\"",
-                       "int8_t" => "%\"PRId8\"",
-                       "int16_t" => "%\"PRId16\"",
-                       "int32_t" => "%\"PRId32\"",
-                       "int64_t" => "%\"PRId64\""}
+                       "uint8_t" => "%\" PRIu8 \"",
+                       "uint16_t" => "%\" PRIu16 \"",
+                       "uint32_t" => "%\" PRIu32 \"",
+                       "uint64_t" => "%\" PRIu64 \"",
+                       "int8_t" => "%\" PRId8 \"",
+                       "int16_t" => "%\" PRId16 \"",
+                       "int32_t" => "%\" PRId32 \"",
+                       "int64_t" => "%\" PRId64 \""}
         def toPrintFormat()
 		if(format = PrintFormat[@type])
 			return format;
diff --git a/aos/build/queues/output/message_dec.rb b/aos/build/queues/output/message_dec.rb
index 0e957be..a643392 100644
--- a/aos/build/queues/output/message_dec.rb
+++ b/aos/build/queues/output/message_dec.rb
@@ -1,4 +1,9 @@
-require "sha1"
+begin
+  require "sha1"
+rescue LoadError
+  require "digest/sha1"
+end
+
 class Target::MessageDec < Target::Node
 	attr_accessor :name,:loc,:parent,:msg_hash
 	def initialize(name)
@@ -118,7 +123,7 @@
 		ts = (@members.collect { |elem|
 			elem.type + " " + elem.name
 		}).join(";")
-		self.msg_hash = "0x#{SHA1.hexdigest(ts)[-8..-1]}"
+		self.msg_hash = "0x#{Digest::SHA1.hexdigest(ts)[-8..-1]}"
 		type_class.add_member("enum {kQueueLength = 1234, kHash = #{self.msg_hash}}")
 		@members.each do |elem|
 			type_class.add_member(elem.create_usage(cpp_tree))
diff --git a/aos/build/queues/output/q_file.rb b/aos/build/queues/output/q_file.rb
index af76ee1..5e016c0 100644
--- a/aos/build/queues/output/q_file.rb
+++ b/aos/build/queues/output/q_file.rb
@@ -1,4 +1,9 @@
-require "sha1"
+begin
+  require "sha1"
+rescue LoadError
+  require "digest/sha1"
+end
+
 module Target
 end
 class Target::Node
@@ -76,7 +81,7 @@
 		ts = (@queues.collect { |queue|
 			queue.msg_hash()
 		}).join("") + name
-		return "0x#{SHA1.hexdigest(ts)[-8..-1]}"
+		return "0x#{Digest::SHA1.hexdigest(ts)[-8..-1]}"
 	end
 	def create(cpp_tree)
 		return if(@extern)
diff --git a/aos/common/Configuration.cpp b/aos/common/Configuration.cpp
index 2c9a7be..edf5212 100644
--- a/aos/common/Configuration.cpp
+++ b/aos/common/Configuration.cpp
@@ -14,6 +14,7 @@
 #else
 #include <ifaddrs.h>
 #endif
+#include <unistd.h>
 
 #ifndef __VXWORKS__
 #include "aos/common/logging/logging.h"
diff --git a/aos/common/input/driver_station_data.cc b/aos/common/input/driver_station_data.cc
index 803d46a..6b078d4 100644
--- a/aos/common/input/driver_station_data.cc
+++ b/aos/common/input/driver_station_data.cc
@@ -30,6 +30,8 @@
       return values.control.autonomous();
     case ControlBit::kEnabled:
       return values.control.enabled();
+    default:
+      __builtin_unreachable();
   }
 }
 
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 147d6ba..bced835 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -111,8 +111,8 @@
 }
 
 void PrintMessage(FILE *output, const LogMessage &message) {
-  fprintf(output, "%s(%"PRId32")(%05"PRIu16"): %s at"
-          " %010"PRId32".%09"PRId32"s: %s",
+  fprintf(output, "%s(%" PRId32 ")(%05" PRIu16 "): %s at"
+          " %010" PRId32 ".%09" PRId32 "s: %s",
           message.name, static_cast<int32_t>(message.source), message.sequence,
           log_str(message.level), message.seconds, message.nseconds,
           message.message);
diff --git a/aos/common/logging/logging_impl_test.cc b/aos/common/logging/logging_impl_test.cc
index f64f3d6..16a0285 100644
--- a/aos/common/logging/logging_impl_test.cc
+++ b/aos/common/logging/logging_impl_test.cc
@@ -53,7 +53,7 @@
     }
     internal::Context *context = internal::Context::Get();
     if (log_implementation->message().source != context->source) {
-      Die("got a message from %"PRIu32", but we're %"PRIu32"\n",
+      Die("got a message from %" PRIu32 ", but we're %" PRIu32 "\n",
           static_cast<uint32_t>(log_implementation->message().source),
           static_cast<uint32_t>(context->source));
     }
diff --git a/aos/common/queue.cc b/aos/common/queue.cc
index 7e7f2a1..b3a4799 100644
--- a/aos/common/queue.cc
+++ b/aos/common/queue.cc
@@ -30,7 +30,7 @@
 }
 
 size_t Message::Print(char *buffer, int length) const {
-  return snprintf(buffer, length, "%"PRId32".%09"PRId32"s",
+  return snprintf(buffer, length, "%" PRId32 ".%09" PRId32 "s",
                   sent_time.sec(), sent_time.nsec());
 }
 
diff --git a/aos/common/scoped_fd.h b/aos/common/scoped_fd.h
index f31ffa5..eb22f80 100644
--- a/aos/common/scoped_fd.h
+++ b/aos/common/scoped_fd.h
@@ -1,3 +1,5 @@
+#include <unistd.h>
+
 #include "aos/common/macros.h"
 #include "aos/common/logging/logging.h"
 
diff --git a/aos/common/sensors/sensor_receiver-tmpl.h b/aos/common/sensors/sensor_receiver-tmpl.h
index 2220496..8ebef22 100644
--- a/aos/common/sensors/sensor_receiver-tmpl.h
+++ b/aos/common/sensors/sensor_receiver-tmpl.h
@@ -71,7 +71,8 @@
       }
 #endif
     } else {
-      LOG(INFO, "packet %"PRId32" late. is packet #%d, wanted #%"PRId64" now\n",
+      LOG(INFO,
+          "packet %" PRId32 " late. is packet #%d, wanted #%" PRId64 " now\n",
           data_.count, (data_.count - start_count_) / kSendsPerCycle,
           (NextLoopTime() - start_time_).ToNSec() / kLoopFrequency.ToNSec());
       good = false;
@@ -163,8 +164,8 @@
         ReceiveData();
         received_time = time::Time::Now();
         if (GoodPacket()) {
-          LOG(DEBUG, "checking packet count=%"PRId32
-              " received at %"PRId32"s%"PRId32"ns\n",
+          LOG(DEBUG, "checking packet count=%" PRId32
+              " received at %" PRId32 "s%" PRId32 "ns\n",
               data_.count, received_time.sec(), received_time.nsec());
           // If |the difference between the goal time for this numbered packet
           // and the time we actually got this one| is too big.
@@ -172,7 +173,8 @@
                 kSensorSendFrequency * (data_.count - start_count_)) -
                received_time).abs() > kSensorSendFrequency) {
             LOG(INFO, "rejected time of the last good packet. "
-                "got %"PRId32"s%"PRId32"ns. wanted %"PRId32"s%"PRId32"ns\n",
+                "got %" PRId32 "s%" PRId32 "ns."
+                " wanted %" PRId32 "s%" PRId32 "ns\n",
                 received_time.sec(), received_time.nsec(),
                 goal_time.sec(), goal_time.nsec());
             ++bad_count;
@@ -199,18 +201,18 @@
   DoReceiveData();
 
   if (data_.count < 0) {
-    LOG(FATAL, "data count overflowed. currently %"PRId32"\n", data_.count);
+    LOG(FATAL, "data count overflowed. currently %" PRId32 "\n", data_.count);
   }
   if (data_.count < old_count) {
-    LOG(INFO, "count reset. was %"PRId32", now %"PRId32"\n",
+    LOG(INFO, "count reset. was %" PRId32 ", now %" PRId32 "\n",
         old_count, data_.count);
     return true;
   }
   if (data_.count < start_count_) {
-    LOG(INFO, "count reset. started at %"PRId32", now %"PRId32"\n",
+    LOG(INFO, "count reset. started at %" PRId32 ", now %" PRId32 "\n",
         start_count_, data_.count);
   }
-  LOG(DEBUG, "received data count %"PRId32"\n", data_.count);
+  LOG(DEBUG, "received data count %" PRId32 "\n", data_.count);
   return false;
 }
 
diff --git a/aos/common/sensors/sensors.h b/aos/common/sensors/sensors.h
index a6b2bfa..78fd8a9 100644
--- a/aos/common/sensors/sensors.h
+++ b/aos/common/sensors/sensors.h
@@ -69,7 +69,7 @@
                                           sizeof(checksum),
                                           sizeof(*this) - sizeof(checksum));
     if (checksum != expected) {
-      LOG(INFO, "expected %"PRIx32" but got %"PRIx32"\n",
+      LOG(INFO, "expected %" PRIx32 " but got %" PRIx32 "\n",
           expected, checksum);
       return false;
     }
diff --git a/aos/common/time.cc b/aos/common/time.cc
index 75ea196..bc3ffe2 100644
--- a/aos/common/time.cc
+++ b/aos/common/time.cc
@@ -70,7 +70,7 @@
 
 void Time::Check() {
   if (nsec_ >= kNSecInSec || nsec_ < 0) {
-    LOG(FATAL, "0 <= nsec_(%"PRId32") < %"PRId32" isn't true.\n",
+    LOG(FATAL, "0 <= nsec_(%" PRId32 ") < %" PRId32 " isn't true.\n",
         nsec_, kNSecInSec);
   }
   static_assert(aos::shm_ok<Time>::value,
diff --git a/aos/externals/.gitignore b/aos/externals/.gitignore
index 64c3acf..80bd460 100644
--- a/aos/externals/.gitignore
+++ b/aos/externals/.gitignore
@@ -1,8 +1,8 @@
-/ctemplate-2.2-prefix/
-/ctemplate-2.2.tar.gz
-/ctemplate-2.2/
-/eigen-3.0.5.tar.bz2
-/eigen-3.0.5/
+/ctemplate-129-prefix/
+/ctemplate-129.tar.gz
+/ctemplate-129/
+/eigen-3.1.3.tar.bz2
+/eigen-3.1.3/
 /gccdist.zip
 /gccdist/
 /gtest-1.6.0-p1/
@@ -22,3 +22,6 @@
 /libusb-1.0.9.tar.bz2
 /libusb-1.0.9/
 /compiler-rt-RELEASE_32_final/
+/libevent-2.0.21-prefix/
+/libevent-2.0.21.tar.gz
+/libevent-2.0.21/
diff --git a/frc971/constants.cpp b/frc971/constants.cpp
index af8c432..989b77e 100644
--- a/frc971/constants.cpp
+++ b/frc971/constants.cpp
@@ -109,7 +109,7 @@
 const Values *GetValues() {
   // TODO(brians): Make this use the new Once construct.
   if (values == NULL) {
-    LOG(INFO, "creating a Constants for team %"PRIu16"\n",
+    LOG(INFO, "creating a Constants for team %" PRIu16 "\n",
         ::aos::robot_state->team_id);
     switch (::aos::robot_state->team_id) {
       case kCompTeamNumber:
@@ -151,7 +151,7 @@
                             kPracticeCameraCenter};
         break;
       default:
-        LOG(ERROR, "unknown team #%"PRIu16"\n",
+        LOG(ERROR, "unknown team #%" PRIu16 "\n",
             aos::robot_state->team_id);
         return NULL;
     }
diff --git a/frc971/control_loops/drivetrain/drivetrain.cc b/frc971/control_loops/drivetrain/drivetrain.cc
index cbb4225..548113e 100644
--- a/frc971/control_loops/drivetrain/drivetrain.cc
+++ b/frc971/control_loops/drivetrain/drivetrain.cc
@@ -248,12 +248,6 @@
     bad_pos = true;
   }
 
-  bool bad_output = false;
-  if (output == NULL) {
-    LOG(WARNING, "no output\n");
-    bad_output = true;
-  }
-
   double wheel = goal->steering;
   double throttle = goal->throttle;
   bool quickturn = goal->quickturn;
diff --git a/frc971/control_loops/index/index.cc b/frc971/control_loops/index/index.cc
index 90eaf6e..f8dbada 100644
--- a/frc971/control_loops/index/index.cc
+++ b/frc971/control_loops/index/index.cc
@@ -235,7 +235,8 @@
   // Make goal easy to work with and sanity check it.
   Goal goal_enum = static_cast<Goal>(goal->goal_state);
   if (goal->goal_state < 0 || goal->goal_state > 5) {
-    LOG(ERROR, "Goal state is %"PRId32" which is out of range.  Going to HOLD.\n",
+    LOG(ERROR,
+        "Goal state is %" PRId32 " which is out of range.  Going to HOLD.\n",
         goal->goal_state);
     goal_enum = Goal::HOLD;
   }
@@ -783,7 +784,7 @@
           }
           if (hopper_disc_count_ != 0) {
             LOG(ERROR,
-                "Emptied the hopper out but there are still %"PRId32" discs there\n",
+                "Emptied the hopper out but there are still %" PRId32 " discs there\n",
                 hopper_disc_count_);
             hopper_disc_count_ = 0;
           }
@@ -811,7 +812,7 @@
       case Goal::INTAKE:
         safe_goal_ = Goal::READY_SHOOTER;
         safe_to_change_state = false;
-        LOG(INFO, "We have %"PRId32" discs, time to preload automatically\n",
+        LOG(INFO, "We have %" PRId32 " discs, time to preload automatically\n",
             hopper_disc_count_);
         break;
       case Goal::READY_SHOOTER:
diff --git a/gyro_board/src/libusb-driver/get.cc b/gyro_board/src/libusb-driver/get.cc
index b3cdc28..4d7f7cb 100644
--- a/gyro_board/src/libusb-driver/get.cc
+++ b/gyro_board/src/libusb-driver/get.cc
@@ -53,11 +53,10 @@
 
 std::string GyroDriver::GetDebugData() {
   char data[64];
-  int r;
   int transferred;
-  r = dev_handle_->bulk_transfer(0x82,
-      (unsigned char *)data, sizeof(data),
-      &transferred, 0);
+  dev_handle_->bulk_transfer(0x82,
+                             (unsigned char *)data, sizeof(data),
+                             &transferred, 0);
   return std::string(data, transferred);
 }
 
@@ -130,7 +129,7 @@
     if (count < 100) continue;
     count = 0;
     
-    printf("angle: %"PRId64"\n", real_data->gyro_angle);
+    printf("angle: %" PRId64 "\n", real_data->gyro_angle);
     printf("drivel: %d\n", real_data->left_drive);
     printf("driver: %d\n", real_data->right_drive);
     printf("shooter: %d\n", real_data->shooter);
diff --git a/vision/CameraProcessor.h b/vision/CameraProcessor.h
index 8d51cd8..096defb 100644
--- a/vision/CameraProcessor.h
+++ b/vision/CameraProcessor.h
@@ -63,12 +63,12 @@
 		cv::MemStorage g_storage; // opencv storage
 		static const int HIST_SIZE = 20; // dimension of histogram
 								 // ie number of scan lines
-		static const double HIST_SIZE_F = 1.0/20.0; // step size
+		static constexpr double HIST_SIZE_F = 1.0/20.0; // step size
 											// should be 1/HIST_SIZE
 		double vert_hist[HIST_SIZE]; // desired vertical histogram
 		double horz_hist[HIST_SIZE]; // desired horizontal histogram
 		// defines the minimum dist for a match
-		static const double HIST_MATCH = 1.9;
+		static constexpr double HIST_MATCH = 1.9;
 		double calcHistComponent(
 				cv::Point2i start,
 				cv::Point2i end,