User Tools

Site Tools


keckcaves:pyvrui_linux_install

Installing PyVrui on Linux

Ubuntu 11.04

Install Packages From Repositories

Many of the required packages can be obtained from the repositories.

sudo apt-get install cmake libboost-dev libboost-python-dev gccxml python-pygccxml python-opengl

Currently PyVrui will only compile with gcc-4.4. Since Ubuntu ships with gcc-4.5 it is necessary to installed the previous version.

sudo apt-get install gcc-4.4

Install Packages From Source

Py++

PyVrui requires a patched version of the pyplusplus module. You can download it here. Unpack the tarfile in your python dist-packages directory.

cd /usr/local/lib/python2.7/dist-packages
sudo tar xzvf /path/to/pyplusplus_for_pyvrui.tgz

pypputils

Download pypputils.

tar xzvf pypputils.tgz
cd pypputils
sudo python setup.py install

Building PyVrui

  • Install into the Vrui source directory.
cd /path/to/Vrui-1.0-068
tar xzvf /path/to/pyvrui_headers.tgz
  • Replace the existing makefile with the following (be sure to set the

VRUI_DISTRIBUTION_DIR and VRUI_HEADERS_DIR variables).

  • Compile and install PyVrui
make
make install

makefile

# You should only have to modify the variables related to you
# Vrui installation. PyVrui has been tested with Vrui version
# 1.0-068.
override VRUI_DISTRIBUTION_DIR = # Path to Vrui source files
override VRUI_HEADERS_DIR = # Path to installed Vrui header files

# These variables should work for ubuntu-based systems.
override PYTHON_LIBRARY = python2.7
override BOOST_LIBRARY_DIR = /usr/lib
override BOOST_INCLUDE_DIR = /usr/include/boost
override BOOST_LIBRARY = boost_python-mt-py27
override CPP=g++-4.4

# makefile for Python extension module 'Vrui'

# Keep the definition of BUILD_DIR here, before any includes.
# includes alter the variable MAKEFILE_LIST.
BUILD_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

# Alter these variables according to your installation:
VRUI_DISTRIBUTION_DIR := $(HOME)/Vrui-1.0
VRUI_HEADERS_DIR      := $(HOME)/src/Vrui-1.0

MODULE_NAME := Vrui
WORKING_DIR := $(VRUI_HEADERS_DIR)

# BOOST_INCLUDE_DIR is the path to the directory that
# contains the boost/ directory which in turn contains
# the boost header files.
BOOST_INCLUDE_DIR := /usr/local/include/boost

# BOOST_LIBRARY_DIR is the path to the directory that
# contains the boost library files.
BOOST_LIBRARY_DIR := /usr/local/lib/boost

BOOST_LIBRARY  := boost_python-mt
PYTHON_LIBRARY := python2.6

# HEADERS is the list of header files to be processed.
# Each header file must be relative to $(WORKING_DIR).
# Note: For this project, all the headers are stored
# in pyVrui_headers.h.  Furthermore, this file is
# copied into the root of the Vrui source directory
# because Py++ automatically excludes any declarations
# that were defined outside of specified files' directories.
HEADERS =



######################################################################
# Build environment configuration

VRUI_DISTRIBUTION_DIR := $(realpath $(VRUI_DISTRIBUTION_DIR))
VRUI_HEADERS_DIR      := $(realpath $(VRUI_HEADERS_DIR))

WORKING_DIR        := $(realpath $(WORKING_DIR))
BOOST_INCLUDE_DIR  := $(realpath $(BOOST_INCLUDE_DIR))
BOOST_LIBRARY_DIR  := $(realpath $(BOOST_LIBRARY_DIR))
PYTHON_INCLUDE_DIR := $(realpath /usr/include/$(PYTHON_LIBRARY))
X11_INCLUDE_DIR    := $(realpath /usr/include/X11)
OUTPUT_DIR         := $(realpath $(BUILD_DIR))/generated

# The file named by OBJECTS_BUILT_MARKER is used to indicate
# that all the object files have been built.  We do it this way
# because there can be any number of files .cpp output by Py++.
OBJECTS_BUILT_MARKER := $(OUTPUT_DIR)/OBJECTS_BUILT

SHELL   := /bin/bash
CPP     := g++
PYTHON  := /usr/bin/env $(PYTHON_LIBRARY)
IPYTHON := /usr/bin/env ipython
STUB_GENERATOR = $(PYTHON) "$(STUB_GENERATOR_SCRIPT_ABSPATH)"

FILES_TO_REMOVE_FOR_CLEAN     = "$(BUILD_DIR)/Vrui/$(MODULE_NAME).so" "$(STUB_GENERATOR_SCRIPT_ABSPATH)" "$(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH)" *.pyc
FILES_TO_REMOVE_FOR_DISTCLEAN =
ifneq ($(OUTPUT_DIR),$(BUILD_DIR))
	FILES_TO_REMOVE_FOR_CLEAN += "$(OUTPUT_DIR)"
endif

# Set up flags for the C++ compiler:
CFLAGS  = -Wall -fPIC -ansi -ftemplate-depth-128 "-I$(WORKING_DIR)" "-I$(BUILD_DIR)" "-I$(OUTPUT_DIR)" "-I$(PYTHON_INCLUDE_DIR)" "-I$(BOOST_INCLUDE_DIR)" "-I$(X11_INCLUDE_DIR)"
LDFLAGS = "-L$(BOOST_LIBRARY_DIR)" "-l$(BOOST_LIBRARY)" "-l$(PYTHON_LIBRARY)"

STUB_GENERATOR_INCLUDE_PATHS = "$(WORKING_DIR)", "$(BUILD_DIR)", "$(OUTPUT_DIR)", "$(PYTHON_INCLUDE_DIR)", "$(BOOST_INCLUDE_DIR)", "$(X11_INCLUDE_DIR)"
STUB_GENERATOR_DEFINE_SYMBOLS =
STUB_GENERATOR_UNDEFINE_SYMBOLS =

HOST_OS = $(shell uname -s)
ifeq ($(HOST_OS),Linux)
	CFLAGS  += -DDEFINE_STATICS_FOR_SHARED_LIBRARY
	LDFLAGS += -Wl,-E -shared
	STUB_GENERATOR_INCLUDE_PATHS +=
	STUB_GENERATOR_DEFINE_SYMBOLS = "__LINUX__"
	STUB_GENERATOR_UNDEFINE_SYMBOLS =
else
	ifeq ($(HOST_OS),Darwin)
		# /usr/X11/include contains the GL header directory on Darwin (Mac OS X)
		CFLAGS  += "-I/usr/X11/include"
		CFLAGS  += -DDEFINE_STATICS_FOR_SHARED_LIBRARY
		LDFLAGS += -dynamiclib -headerpad_max_install_names
		STUB_GENERATOR_INCLUDE_PATHS += , "/usr/X11/include"
		STUB_GENERATOR_DEFINE_SYMBOLS = "__DARWIN__"
		STUB_GENERATOR_UNDEFINE_SYMBOLS =
	endif
endif

ifdef DEBUG
	CFLAGS += -g2 -O0 -fno-inline -dynamic -no-cpp-precomp -gdwarf-2
else
	CFLAGS += -g0 -O3
endif

include $(VRUI_DISTRIBUTION_DIR)/etc/Vrui$(patsubst %, .debug, $(DEBUG)).makeinclude
CFLAGS  += $(VRUI_CFLAGS)
# Linking with the GL library on Ubuntu Linux 9.04 exhibits the behavior that
# a C++ exception thrown and caught without even crossing back over to Python
# causes the whole program to segfault.
LDFLAGS += $(subst -lGL ,,$(VRUI_LINKFLAGS))



######################################################################
# $(MODULE_NAME).so dependencies

CFG_ABSPATH                            := $(BUILD_DIR)/py$(MODULE_NAME)_configuration.py
UCP_ABSPATH                            := $(BUILD_DIR)/py$(MODULE_NAME)_ucp.py
DECLARATIONS_HEADER_ABSPATH            := $(realpath $(BUILD_DIR)/py$(MODULE_NAME)_declarations.h)
INTERNALS_HEADER_ABSPATH               := $(realpath $(BUILD_DIR)/py$(MODULE_NAME)_internals.h)
DEFINITIONS_FILE_ABSPATH               := $(realpath $(BUILD_DIR)/py$(MODULE_NAME)_definitions.cpp)
DEFINITIONS_COPY_ABSPATH               := $(OUTPUT_DIR)/py$(MODULE_NAME)_definitions.cpp
STUB_GENERATOR_SCRIPT_ABSPATH          := $(BUILD_DIR)/stub_generator.py
CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH := $(BUILD_DIR)/code_generator_explorer.py
REDEF_FPCLASSIFY_ABSPATH               := $(realpath $(BUILD_DIR)/redef_fpclassify.h)
PYVRUI_HEADERS_ABSPATH                 := $(realpath $(BUILD_DIR)/pyVrui_headers.h)
PYVRUI_HEADERS_COPY_ABSPATH            := $(VRUI_HEADERS_DIR)/pyVrui_headers.h
HEADERS_ABSPATH                        := $(REDEF_FPCLASSIFY_ABSPATH) $(PYVRUI_HEADERS_COPY_ABSPATH) $(foreach header, $(HEADERS), $(realpath $(WORKING_DIR)/$(header))) $(DECLARATIONS_HEADER_ABSPATH)
HEADERS_ABSPATH_PYEXPR                 := ["$(REDEF_FPCLASSIFY_ABSPATH)", "$(PYVRUI_HEADERS_COPY_ABSPATH)", $(foreach header, $(HEADERS), "$(realpath $(WORKING_DIR)/$(header))",) "$(DECLARATIONS_HEADER_ABSPATH)" ]

$(BUILD_DIR)/Vrui/$(MODULE_NAME).so: $(OUTPUT_DIR)/$(MODULE_NAME).so
	@rm -fr "$(BUILD_DIR)/Vrui/$(MODULE_NAME).so"
	ln -s "$(OUTPUT_DIR)/$(MODULE_NAME).so" "$(BUILD_DIR)/Vrui/$(MODULE_NAME).so"

$(OUTPUT_DIR)/$(MODULE_NAME).so:    $(OBJECTS_BUILT_MARKER)
$(OUTPUT_DIR)/py$(MODULE_NAME).o:   $(OUTPUT_DIR)/py$(MODULE_NAME).cpp $(HEADERS_ABSPATH) $(INTERNALS_HEADER_ABSPATH) $(REDEF_FPCLASSIFY_ABSPATH) $(PYVRUI_HEADERS_COPY_ABSPATH)
$(OUTPUT_DIR)/py$(MODULE_NAME).cpp: $(STUB_GENERATOR_SCRIPT_ABSPATH) $(CFG_ABSPATH) $(UCP_ABSPATH) $(HEADERS_ABSPATH) $(INTERNALS_HEADER_ABSPATH) $(REDEF_FPCLASSIFY_ABSPATH) $(PYVRUI_HEADERS_COPY_ABSPATH)

$(STUB_GENERATOR_SCRIPT_ABSPATH):
	@echo -n 'from pypputils import stub_generator; print stub_generator.generate_script()' | $(PYTHON) >"$(STUB_GENERATOR_SCRIPT_ABSPATH)"

$(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH):
	@echo -n 'from pypputils import code_generator_explorer; print code_generator_explorer.generate_script()' | $(PYTHON) >"$(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH)"



######################################################################
# Rules

.PHONY: all
all: scripts $(BUILD_DIR)/Vrui/$(MODULE_NAME).so

.PHONY: scripts
scripts: $(STUB_GENERATOR_SCRIPT_ABSPATH) $(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH)

.PHONY: clean
clean:
	@cd "$(BUILD_DIR)" && rm -fr $(FILES_TO_REMOVE_FOR_CLEAN)

.PHONY: distclean
distclean: clean
	@cd "$(BUILD_DIR)" && rm -f $(FILES_TO_REMOVE_FOR_DISTCLEAN)

.PHONY: install
install:
	@cd "$(BUILD_DIR)" && $(PYTHON) setup.py install

.PHONY: explorer
explorer: $(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH) $(HEADERS_ABSPATH) $(INTERNALS_HEADER_ABSPATH)
	@mkdir -p "$(OUTPUT_DIR)"  # because it's an include directory, too
	@$(IPYTHON) -i "$(CODE_GENERATOR_EXPLORER_SCRIPT_ABSPATH)" '$(MODULE_NAME)' '$(HEADERS_ABSPATH_PYEXPR)' '$(WORKING_DIR)' '$(OUTPUT_DIR)' '[$(STUB_GENERATOR_INCLUDE_PATHS)]' '[$(STUB_GENERATOR_DEFINE_SYMBOLS)]' '[$(STUB_GENERATOR_UNDEFINE_SYMBOLS)]'

# Note: $(OUTPUT_DIR)/py$(MODULE_NAME).cpp is touched at the end of the process
# because $(STUB_GENERATOR) will leave $(OUTPUT_DIR)/%.cpp unaltered if
# $(OUTPUT_DIR)/%.cpp already exists and it is determined that no changes will
# be made in the newly-generated version.  Note also that when multiple files are
# generated, $(OUTPUT_DIR)/py$(MODULE_NAME).cpp is not generated (instead, the
# generated files are of the form $(OUTPUT_DIR)/$(MODULE_NAME)*.cpp), but yet a
# zero-length $(OUTPUT_DIR)/py$(MODULE_NAME).cpp file is created by the "touch" at
# the end and this serves as a marker for the completion of the .cpp file generation.
$(OUTPUT_DIR)/%.cpp:
	@mkdir -p "$(OUTPUT_DIR)"
	$(STUB_GENERATOR) -setup None '$(HEADERS_ABSPATH_PYEXPR)' '$(@:$(OUTPUT_DIR)/py%.cpp=%)' '$(WORKING_DIR)' '$(OUTPUT_DIR)' '[$(STUB_GENERATOR_INCLUDE_PATHS)]' '[$(STUB_GENERATOR_DEFINE_SYMBOLS)]' '[$(STUB_GENERATOR_UNDEFINE_SYMBOLS)]' && touch '$@'

$(DEFINITIONS_COPY_ABSPATH): $(DEFINITIONS_FILE_ABSPATH)
	@\cp "$(DEFINITIONS_FILE_ABSPATH)" "$(DEFINITIONS_COPY_ABSPATH)"

$(PYVRUI_HEADERS_COPY_ABSPATH): $(PYVRUI_HEADERS_ABSPATH)
	@\cp "$(PYVRUI_HEADERS_ABSPATH)" "$(PYVRUI_HEADERS_COPY_ABSPATH)"

# Note: don't use $(OBJECTS) in place of $(OUTPUT_DIR)/*.o below because
# the recursive invokation will still have an empty $(OBJECTS).
# The recursive invokation would occur when the build had been started
# with none of the .cpp files having been generated.
$(OUTPUT_DIR)/%.so: $(OBJECTS)
	@echo "Linking \"$@\"..."
	@$(CPP) -o '$@' $(OUTPUT_DIR)/*.o $(LDFLAGS)

define OBJECT_RULE_TEMPLATE
$(2): $(1) $(DECLARATIONS_HEADER_ABSPATH) $(INTERNALS_HEADER_ABSPATH)
	@echo "Compiling \"$(2)\"..."
	@\rm -f "$(OBJECTS_BUILT_MARKER)"
	@$(CPP) -c -o "$(2)" "$(1)" $(CFLAGS)
OBJECTS += $(2)
endef
$(foreach cppfile,$(wildcard $(OUTPUT_DIR)/*.cpp),$(eval $(call OBJECT_RULE_TEMPLATE,$(cppfile),$(cppfile:%.cpp=%.o))))
	
$(OBJECTS_BUILT_MARKER): $(OUTPUT_DIR)/py$(MODULE_NAME).cpp $(DEFINITIONS_COPY_ABSPATH) $(OBJECTS)
ifeq ($(OBJECTS),)
	@# The objects were built (as prerequisites to this rule);
	@# Recurse so that the effects are seen by the OBJECT_RULE_TEMPLATE invokations.
	@$(MAKE)
endif
	@touch "$(OBJECTS_BUILT_MARKER)"
keckcaves/pyvrui_linux_install.txt · Last modified: 2011/11/03 12:32 by jvanaals