Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Raspberry Pi cross-compilation support to makefile #2590

Merged
merged 3 commits into from May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorflow/contrib/makefile/.gitignore
@@ -0,0 +1,2 @@
gen/
downloads/
9 changes: 8 additions & 1 deletion tensorflow/contrib/makefile/Makefile
Expand Up @@ -95,7 +95,7 @@ PROTOGENDIR := $(GENDIR)proto/
# Settings for the target compiler.
CXX := gcc
OPTFLAGS := -O0
CXXFLAGS := --std=c++11
CXXFLAGS := --std=c++11 $(OPTFLAGS)
LDFLAGS := \
-L/usr/local/lib
INCLUDES := \
Expand Down Expand Up @@ -127,6 +127,13 @@ endif
ifeq ($(TARGET),LINUX)
LIBS += -ldl
endif
# If we're cross-compiling for the Raspberry Pi, use the right gcc.
ifeq ($(TARGET),PI)
CXX := arm-linux-gnueabihf-g++
LDFLAGS := -L$(GENDIR)protobuf_pi/lib/ -Wl,--no-whole-archive
LIBS += -ldl
LIBFLAGS += -Wl,--allow-multiple-definition -Wl,--whole-archive
endif

# Set up Android building
ifeq ($(TARGET),ANDROID)
Expand Down
21 changes: 21 additions & 0 deletions tensorflow/contrib/makefile/README.md
Expand Up @@ -130,6 +130,27 @@ to register ops and kernels.
The example Xcode project in tensorflow/contrib/ios_example shows how to use the
static library in a simple app.

## Raspberry Pi

The easiest way to build for the Raspberry Pi is to cross-compile from Linux.
To use this makefile to do that, you first need to install the right version of
the compiler to target the Pi, using a command like this on your Linux machine:

```bash
sudo apt-get install g++-arm-linux-gnueabihf
```

After that, run `tensorflow/contrib/makefile/compile_pi_protobuf.sh` to build a
version of the protobuf library aimed at the Pi. Then you should be able to run:

```bash
make -f tensorflow/contrib/makefile/Makefile TARGET=PI
```

This will build the static library, and the example benchmark executable. You
can then copy the `tensorflow/contrib/makefile/gen/bin/benchmark` program over
to your Raspberry Pi, and run it there.

## Dependencies

The Makefile loads in a list of dependencies stored in text files. These files
Expand Down
33 changes: 33 additions & 0 deletions tensorflow/contrib/makefile/compile_pi_protobuf.sh
@@ -0,0 +1,33 @@
#!/bin/bash -x
# Builds protobuf 3 for iOS.

cd tensorflow/contrib/makefile

GENDIR=`pwd`/gen/protobuf_pi/
LIBDIR=${GENDIR}
mkdir -p ${LIBDIR}

CXX=arm-linux-gnueabihf-g++

cd downloads/protobuf

./autogen.sh
if [ $? -ne 0 ]
then
echo "./autogen.sh command failed."
exit 1
fi

make distclean
./configure \
--build=i686-pc-linux-gnu \
--host=arm-linux \
--target=arm-linux \
--disable-shared \
--enable-cross-compile \
--with-protoc=protoc \
--prefix=${LIBDIR} \
--exec-prefix=${LIBDIR} \
"CXX=${CXX}" \
make
make install