Transitioning to common.mk

common.mk will make it easier to build with ebuild files. Unfortunately it requires
source files to have the extension .cc, whereas the aosp code uses .cpp, so all source
files had been renamed to .cc.

BUG=chromium:329015
TEST=manual testing with the demo program
wqx

Change-Id: I94dcf6bdf9923b302471fb8517df80e7f4cfe9fe
Reviewed-on: https://chromium-review.googlesource.com/181228
Reviewed-by: Dennis Kempin <denniskempin@chromium.org>
Tested-by: Dennis Kempin <denniskempin@chromium.org>
diff --git a/Makefile b/Makefile
index 28fc25f..57c3e91 100644
--- a/Makefile
+++ b/Makefile
@@ -1,97 +1,13 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
-DESTDIR = /usr
-LIBDIR = $(DESTDIR)/lib
-SHAREDIR = $(DESTDIR)/share/libsuggest
+include common.mk
 
-AOSP_SOURCE_FILES=src/aosp/compability/log_utils_mock.cpp\
-	src/aosp/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp\
-	src/aosp/suggest/policyimpl/typing/scoring_params.cpp\
-	src/aosp/suggest/policyimpl/typing/typing_weighting.cpp\
-	src/aosp/suggest/policyimpl/typing/typing_suggest_policy.cpp\
-	src/aosp/suggest/policyimpl/typing/typing_traversal.cpp\
-	src/aosp/suggest/policyimpl/typing/typing_scoring.cpp\
-	src/aosp/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/header/header_policy.cpp\
-	src/aosp/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/bigram/dynamic_bigram_list_policy.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp\
-	src/aosp/suggest/policyimpl/dictionary/patricia_trie_reading_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/patricia_trie_policy.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_helper.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_helper.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dictionary_structure_with_buffer_policy_factory.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_gc_event_listeners.cpp\
-	src/aosp/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp\
-	src/aosp/suggest/policyimpl/dictionary/utils/format_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/utils/byte_array_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.cpp\
-	src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.cpp\
-	src/aosp/suggest/core/session/dic_traverse_session.cpp\
-	src/aosp/suggest/core/dicnode/dic_node_utils.cpp\
-	src/aosp/suggest/core/dicnode/dic_nodes_cache.cpp\
-	src/aosp/suggest/core/dicnode/dic_node.cpp\
-	src/aosp/suggest/core/suggest.cpp\
-	src/aosp/suggest/core/policy/weighting.cpp\
-	src/aosp/suggest/core/layout/proximity_info_state.cpp\
-	src/aosp/suggest/core/layout/proximity_info.cpp\
-	src/aosp/suggest/core/layout/proximity_info_state_utils.cpp\
-	src/aosp/suggest/core/layout/additional_proximity_chars.cpp\
-	src/aosp/suggest/core/layout/proximity_info_params.cpp\
-	src/aosp/suggest/core/dictionary/bigram_dictionary.cpp\
-	src/aosp/suggest/core/dictionary/multi_bigram_map.cpp\
-	src/aosp/suggest/core/dictionary/digraph_utils.cpp\
-	src/aosp/suggest/core/dictionary/bloom_filter.cpp\
-	src/aosp/suggest/core/dictionary/dictionary.cpp\
-	src/aosp/utils/char_utils.cpp\
-	src/aosp/utils/autocorrection_threshold_utils.cpp
+LIBDIR ?= /usr/lib
 
-SUGGEST_SOURCE_FILES=src/suggest.cpp
+all: CXX_LIBRARY(src/libsuggest.so)
+clean: CLEAN(src/libsuggest.so) CLEAN(src/demo)
+install: install-lib install-header
 
-SUGGEST_DEMO_FILES=src/demo.cpp
-
-CXXFLAGS=-Iinclude -Isrc/aosp -Isrc/aosp/compability -Isrc -std=c++11
-
-
-# libsuggest.so library
-
-LIB_SOURCES=$(SUGGEST_SOURCE_FILES) $(AOSP_SOURCE_FILES)
-LIB_OBJECTS=$(LIB_SOURCES:%.cpp=%.pic.o)
-
-libsuggest.so: $(LIB_OBJECTS)
-	g++ -shared -o libsuggest.so $(CXXFLAGS) $(LIB_OBJECTS)
-
-%.pic.o: %.cpp
-	g++ $(CXXFLAGS) -fPIC -MD -g -c -o $@ $<
-
-
-# suggest_demo executable
-
-DEMO_SOURCES=$(SUGGEST_DEMO_FILES) $(LIB_SOURCES)
-DEMO_OBJECTS=$(DEMO_SOURCES:%.cpp=%.pie.o)
-
-suggest_demo: libsuggest.so $(DEMO_OBJECTS)
-	g++ -o suggest_demo -lsuggest -lncurses -L. $(CXXFLAGS) $(DEMO_OBJECTS)
-
-%.pie.o: %.cpp
-	g++ $(CXXFLAGS) -MD -g -c -o $@ $<
-
-# common rules
-
-ALL_OBJECTS=$(DEMO_OBJECTS) $(LIB_OBJECTS)
-
-clean:
-	rm libsuggest.so | true
-	rm suggest_demo | true
-	rm $(ALL_OBJECTS) | true
-
-install: libsuggest.so
-	install -D -m 0755 libsuggest.so $(LIBDIR)/libsuggest.so
-	install -D -m 0755 dicts/en_US.dict $(SHAREDIR)/en_US.dict
-
-all: libsuggest.so suggest_demo
-
--include $(ALL_OBJECTS:%.o=%.d)
\ No newline at end of file
+demo: CXX_BINARY(src/demo)
\ No newline at end of file
diff --git a/common.mk b/common.mk
new file mode 100644
index 0000000..7939883
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,845 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# If this file is part of another source distribution, it's license may be
+# stored in LICENSE.makefile or LICENSE.common.mk.
+#
+# NOTE NOTE NOTE
+#  The authoritative common.mk is located in:
+#    https://chromium.googlesource.com/chromiumos/platform/common-mk.git
+#  Please make all changes there, then copy into place in other repos.
+# NOTE NOTE NOTE
+#
+# This file provides a common architecture for building C/C++ source trees.
+# It uses recursive makefile inclusion to create a single make process which
+# can be built in the source tree or with the build artifacts placed elsewhere.
+#
+# It is fully parallelizable for all targets, including static archives.
+#
+# To use:
+# 1. Place common.mk in your top source level
+# 2. In your top-level Makefile, place "include common.mk" at the top
+# 3. In all subdirectories, create a 'module.mk' file that starts with:
+#      include common.mk
+#    And then contains the remainder of your targets.
+# 4. All build targets should look like:
+#    relative/path/target: relative/path/obj.o
+#
+# See existing makefiles for rule examples.
+#
+# Exported macros:
+#   - cc_binary, cxx_binary provide standard compilation steps for binaries
+#   - cxx_library, cc_library provide standard compilation steps for
+#     shared objects.
+#   All of the above optionally take an argument for extra flags.
+#   - update_archive creates/updates a given .a target
+#
+# Instead of using the build macros, most users can just use wrapped targets:
+#   - CXX_BINARY, CC_BINARY, CC_STATIC_BINARY, CXX_STATIC_BINARY
+#   - CXX_LIBRARY, CC_LIBRARY, CC_STATIC_LIBRARY, CXX_STATIC_LIBRARY
+#   - E.g., CXX_BINARY(mahbinary): foo.o
+#   - object.depends targets may be used when a prerequisite is required for an
+#     object file. Because object files result in multiple build artifacts to
+#     handle PIC and PIE weirdness. E.g.
+#       foo.o.depends: generated/dbus.h
+#   - TEST(binary) or TEST(CXX_BINARY(binary)) may be used as a prerequisite
+#     for the tests target to trigger an automated test run.
+#   - CLEAN(file_or_dir) dependency can be added to 'clean'.
+#
+# If source code is being generated, rules will need to be registered for
+# compiling the objects.  This can be done by adding one of the following
+# to the Makefile:
+#   - For C source files
+#     $(eval $(call add_object_rules,sub/dir/gen_a.o sub/dir/gen_b.o,CC,c))
+#   - For C++ source files
+#     $(eval $(call add_object_rules,sub/dir/gen_a.o sub/dir/gen_b.o,CXX,cc))
+#
+# Exported targets meant to have prerequisites added to:
+#  - all - Your desired targets should be given
+#  - tests - Any TEST(test_binary) targets should be given
+#  - FORCE - force the given target to run regardless of changes
+#            In most cases, using .PHONY is preferred.
+#
+# Possible command line variables:
+#   - COLOR=[0|1] to set ANSI color output (default: 1)
+#   - VERBOSE=[0|1] to hide/show commands (default: 0)
+#   - MODE=[opt|dbg|profiling] (default: opt)
+#          opt - Enable optimizations for release builds
+#          dbg - Turn down optimization for debugging
+#          profiling - Turn off optimization and turn on profiling/coverage
+#                      support.
+#   - ARCH=[x86|arm|supported qemu name] (default: from portage or uname -m)
+#   - SPLITDEBUG=[0|1] splits debug info in target.debug (default: 0)
+#        If NOSTRIP=1, SPLITDEBUG will never strip the final emitted objects.
+#   - NOSTRIP=[0|1] determines if binaries are stripped. (default: 1)
+#        NOSTRIP=0 and MODE=opt will also drop -g from the CFLAGS.
+#   - VALGRIND=[0|1] runs tests under valgrind (default: 0)
+#   - OUT=/path/to/builddir puts all output in given path (default: $PWD)
+#   - VALGRIND_ARGS="" supplies extra memcheck arguments
+#
+# Per-target(-ish) variable:
+#   - NEEDS_ROOT=[0|1] allows a TEST() target to run with root.
+#     Default is 0 unless it is running under QEmu.
+#   - NEEDS_MOUNTS=[0|1] allows a TEST() target running on QEmu to get
+#     setup mounts in the $(SYSROOT)
+#
+# Caveats:
+# - Directories or files with spaces in them DO NOT get along with GNU Make.
+#   If you need them, all uses of dir/notdir/etc will need to have magic
+#   wrappers.  Proceed at risk to your own sanity.
+# - External CXXFLAGS and CFLAGS should be passed via the environment since
+#   this file does not use 'override' to control them.
+# - Our version of GNU Make doesn't seem to support the 'private' variable
+#   annotation, so you can't tag a variable private on a wrapping target.
+
+# Behavior configuration variables
+SPLITDEBUG ?= 0
+NOSTRIP ?= 1
+VALGRIND ?= 0
+COLOR ?= 1
+VERBOSE ?= 0
+MODE ?= opt
+ARCH ?= $(shell uname -m)
+NEEDS_ROOT = 0
+NEEDS_MOUNTS = 0
+
+# Put objects in a separate tree based on makefile locations
+# This means you can build a tree without touching it:
+#   make -C $SRCDIR  # will create ./build-$(MODE)
+# Or
+#   make -C $SRCDIR OUT=$PWD
+# This variable is extended on subdir calls and doesn't need to be re-called.
+OUT ?= $(PWD)/
+
+# Make OUT now so we can use realpath.
+$(shell mkdir -p "$(OUT)")
+
+# TODO(wad) Relative paths are resolved against SRC and not the calling dir.
+# Ensure a command-line supplied OUT has a slash
+override OUT := $(realpath $(OUT))/
+
+# SRC is not meant to be set by the end user, but during make call relocation.
+# $(PWD) != $(CURDIR) all the time.
+export SRC ?= $(CURDIR)
+
+# Re-start in the $(OUT) directory if we're not there.
+# We may be invoked using -C or bare and we need to ensure behavior
+# is consistent so we check both PWD vs OUT and PWD vs CURDIR.
+override RELOCATE_BUILD := 0
+ifneq (${PWD}/,${OUT})
+override RELOCATE_BUILD := 1
+endif
+# Make sure we're running with no builtin targets. They cause
+# leakage and mayhem!
+ifneq (${PWD},${CURDIR})
+override RELOCATE_BUILD := 1
+# If we're run from the build dir, don't let it get cleaned up later.
+ifeq (${PWD}/,${OUT})
+$(shell touch "$(PWD)/.dont_delete_on_clean")
+endif
+endif  # ifneq (${PWD},${CURDIR}
+
+# "Relocate" if we need to restart without implicit rules.
+ifeq ($(subst r,,$(MAKEFLAGS)),$(MAKEFLAGS))
+override RELOCATE_BUILD := 1
+endif
+
+ifeq (${RELOCATE_BUILD},1)
+# By default, silence build output. Reused below as well.
+QUIET = @
+ifeq ($(VERBOSE),1)
+  QUIET=
+endif
+
+# This target will override all targets, including prerequisites. To avoid
+# calling $(MAKE) once per prereq on the given CMDGOAL, we guard it with a local
+# variable.
+RUN_ONCE := 0
+MAKECMDGOALS ?= all
+# Keep the rules split as newer make does not allow them to be declared
+# on the same line.  But the way :: rules work, the _all here will also
+# invoke the %:: rule while retaining "_all" as the default.
+_all::
+%::
+	$(if $(filter 0,$(RUN_ONCE)), \
+	  cd "$(OUT)" && \
+	  $(MAKE) -r -I "$(SRC)" -f "$(CURDIR)/Makefile" \
+	    SRC="$(CURDIR)" OUT="$(OUT)" $(foreach g,$(MAKECMDGOALS),"$(g)"),)
+	$(eval RUN_ONCE := 1)
+pass-to-subcall := 1
+endif
+
+ifeq ($(pass-to-subcall),)
+
+# Only call MODULE if we're in a submodule
+MODULES_LIST := $(filter-out Makefile %.d,$(MAKEFILE_LIST))
+ifeq ($(words $(filter-out Makefile common.mk %.d $(SRC)/Makefile \
+                           $(SRC)/common.mk,$(MAKEFILE_LIST))),0)
+
+# All the top-level defines outside of module.mk.
+
+#
+# Helper macros
+#
+
+# Create the directory if it doesn't yet exist.
+define auto_mkdir
+  $(if $(wildcard $(dir $1)),$2,$(QUIET)mkdir -p "$(dir $1)")
+endef
+
+# Creates the actual archive with an index.
+# The target $@ must end with .pic.a or .pie.a.
+define update_archive
+  $(call auto_mkdir,$(TARGET_OR_MEMBER))
+  $(QUIET)# Create the archive in one step to avoid parallel use accessing it
+  $(QUIET)# before all the symbols are present.
+  @$(ECHO) "AR		$(subst \
+$(SRC)/,,$(^:.o=$(suffix $(basename $(TARGET_OR_MEMBER))).o)) \
+-> $(subst $(SRC)/,,$(TARGET_OR_MEMBER))"
+  $(QUIET)$(AR) rcs $(TARGET_OR_MEMBER) \
+          $(subst $(SRC)/,,$(^:.o=$(suffix $(basename $(TARGET_OR_MEMBER))).o))
+endef
+
+# Default compile from objects using pre-requisites but filters out
+# subdirs and .d files.
+define cc_binary
+  $(call COMPILE_BINARY_implementation,CC,$(CFLAGS) $(1),$(EXTRA_FLAGS))
+endef
+
+define cxx_binary
+  $(call COMPILE_BINARY_implementation,CXX,$(CXXFLAGS) $(1),$(EXTRA_FLAGS))
+endef
+
+# Default compile from objects using pre-requisites but filters out
+# subdirs and .d files.
+define cc_library
+  $(call COMPILE_LIBRARY_implementation,CC,$(CFLAGS) $(1),$(EXTRA_FLAGS))
+endef
+define cxx_library
+  $(call COMPILE_LIBRARY_implementation,CXX,$(CXXFLAGS) $(1),$(EXTRA_FLAGS))
+endef
+
+# Deletes files silently if they exist. Meant for use in any local
+# clean targets.
+define silent_rm
+  $(if $(wildcard $(1)),
+  $(QUIET)($(ECHO) -n '$(COLOR_RED)CLEANFILE$(COLOR_RESET)		' && \
+    $(ECHO) '$(subst $(OUT)/,,$(wildcard $(1)))' && \
+    $(RM) $(1) 2>/dev/null) || true,)
+endef
+define silent_rmdir
+  $(if $(wildcard $(1)),
+    $(if $(wildcard $(1)/*),
+  $(QUIET)# $(1) not empty [$(wildcard $(1)/*)]. Not deleting.,
+  $(QUIET)($(ECHO) -n '$(COLOR_RED)CLEANDIR$(COLOR_RESET)		' && \
+    $(ECHO) '$(subst $(OUT)/,,$(wildcard $(1)))' && \
+    $(RMDIR) $(1) 2>/dev/null) || true),)
+endef
+
+#
+# Default variable values
+#
+
+# Only override toolchain vars if they are from make.
+CROSS_COMPILE ?=
+define override_var
+ifneq ($(filter undefined default,$(origin $1)),)
+$1 = $(CROSS_COMPILE)$2
+endif
+endef
+$(eval $(call override_var,AR,ar))
+$(eval $(call override_var,CC,gcc))
+$(eval $(call override_var,CXX,g++))
+$(eval $(call override_var,OBJCOPY,objcopy))
+$(eval $(call override_var,PKG_CONFIG,pkg-config))
+$(eval $(call override_var,RANLIB,ranlib))
+$(eval $(call override_var,STRIP,strip))
+
+RMDIR ?= rmdir
+ECHO = /bin/echo -e
+
+ifeq ($(lastword $(subst /, ,$(CC))),clang)
+CDRIVER = clang
+else
+CDRIVER = gcc
+endif
+
+ifeq ($(lastword $(subst /, ,$(CXX))),clang++)
+CXXDRIVER = clang
+else
+CXXDRIVER = gcc
+endif
+
+# To update these from an including Makefile:
+#  CXXFLAGS += -mahflag  # Append to the list
+#  CXXFLAGS := -mahflag $(CXXFLAGS) # Prepend to the list
+#  CXXFLAGS := $(filter-out badflag,$(CXXFLAGS)) # Filter out a value
+# The same goes for CFLAGS.
+COMMON_CFLAGS-gcc := -fstack-protector-strong -fvisibility=internal -ggdb3 \
+  -Wa,--noexecstack
+COMMON_CFLAGS-clang := -fstack-protector-all -fvisibility=hidden -ggdb
+COMMON_CFLAGS := -Wall -Werror -fno-strict-aliasing -O1 -Wformat=2
+CXXFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CXXDRIVER))
+CFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CDRIVER))
+CPPFLAGS += -D_FORTIFY_SOURCE=2
+
+
+ifeq ($(MODE),opt)
+  # Up the optimizations.
+  CFLAGS := $(filter-out -O1,$(CFLAGS)) -O2
+  CXXFLAGS := $(filter-out -O1,$(CXXFLAGS)) -O2
+  # Only drop -g* if symbols aren't desired.
+  ifeq ($(NOSTRIP),0)
+    # TODO: do we want -fomit-frame-pointer on x86?
+    CFLAGS := $(filter-out -ggdb3,$(CFLAGS))
+    CXXFLAGS := $(filter-out -ggdb3,$(CXXFLAGS))
+  endif
+endif
+
+ifeq ($(MODE),profiling)
+  CFLAGS := $(CFLAGS) -O0 -g  --coverage
+  CXXFLAGS := $(CXXFLAGS) -O0 -g  --coverage
+  LDFLAGS := $(LDFLAGS) --coverage
+endif
+
+LDFLAGS := $(LDFLAGS) -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now
+
+# Fancy helpers for color if a prompt is defined
+ifeq ($(COLOR),1)
+COLOR_RESET = \x1b[0m
+COLOR_GREEN = \x1b[32;01m
+COLOR_RED = \x1b[31;01m
+COLOR_YELLOW = \x1b[33;01m
+endif
+
+# By default, silence build output.
+QUIET = @
+ifeq ($(VERBOSE),1)
+  QUIET=
+endif
+
+#
+# Implementation macros for compile helpers above
+#
+
+# Useful for dealing with pie-broken toolchains.
+# Call make with PIE=0 to disable default PIE use.
+OBJ_PIE_FLAG = -fPIE
+COMPILE_PIE_FLAG = -pie
+ifeq ($(PIE),0)
+  OBJ_PIE_FLAG =
+  COMPILE_PIE_FLAG =
+endif
+
+# Favor member targets first for CXX_BINARY(%) magic.
+# And strip out nested members if possible.
+LP := (
+RP := )
+TARGET_OR_MEMBER = $(lastword $(subst $(LP), ,$(subst $(RP),,$(or $%,$@))))
+
+# Default compile from objects using pre-requisites but filters out
+# all non-.o files.
+define COMPILE_BINARY_implementation
+  @$(ECHO) "LD$(1)		$(subst $(PWD)/,,$(TARGET_OR_MEMBER))"
+  $(call auto_mkdir,$(TARGET_OR_MEMBER))
+  $(QUIET)$($(1)) $(COMPILE_PIE_FLAGS) -o $(TARGET_OR_MEMBER) \
+    $(2) $(LDFLAGS) \
+    $(filter %.o %.a,$(^:.o=.pie.o)) \
+    $(foreach so,$(filter %.so,$^),-L$(dir $(so)) \
+                            -l$(patsubst lib%,%,$(basename $(notdir $(so))))) \
+    $(LDLIBS)
+  $(call conditional_strip)
+  @$(ECHO) -n "BIN		"
+  @$(ECHO) "$(COLOR_GREEN)$(subst $(PWD)/,,$(TARGET_OR_MEMBER))$(COLOR_RESET)"
+  @$(ECHO) "	$(COLOR_YELLOW)-----$(COLOR_RESET)"
+endef
+
+# TODO: add version support extracted from PV environment variable
+#ifeq ($(PV),9999)
+#$(warning PV=$(PV). If shared object versions matter, please force PV=.)
+#endif
+# Then add -Wl,-soname,$@.$(PV) ?
+
+# Default compile from objects using pre-requisites but filters out
+# all non-.o values. (Remember to add -L$(OUT) -llib)
+COMMA := ,
+define COMPILE_LIBRARY_implementation
+  @$(ECHO) "SHARED$(1)	$(subst $(PWD)/,,$(TARGET_OR_MEMBER))"
+  $(call auto_mkdir,$(TARGET_OR_MEMBER))
+  $(QUIET)$($(1)) -shared -Wl,-E -o $(TARGET_OR_MEMBER) \
+    $(2) $(LDFLAGS) \
+    $(if $(filter %.a,$^),-Wl$(COMMA)--whole-archive,) \
+    $(filter %.o ,$(^:.o=.pic.o)) \
+    $(foreach a,$(filter %.a,$^),-L$(dir $(a)) \
+                            -l$(patsubst lib%,%,$(basename $(notdir $(a))))) \
+    $(foreach so,$(filter %.so,$^),-L$(dir $(so)) \
+                            -l$(patsubst lib%,%,$(basename $(notdir $(so))))) \
+    $(LDLIBS)
+  $(call conditional_strip)
+  @$(ECHO) -n "LIB		$(COLOR_GREEN)"
+  @$(ECHO) "$(subst $(PWD)/,,$(TARGET_OR_MEMBER))$(COLOR_RESET)"
+  @$(ECHO) "	$(COLOR_YELLOW)-----$(COLOR_RESET)"
+endef
+
+define conditional_strip
+  $(if $(filter 0,$(NOSTRIP)),$(call strip_artifact))
+endef
+
+define strip_artifact
+  @$(ECHO) "STRIP		$(subst $(OUT)/,,$(TARGET_OR_MEMBER))"
+  $(if $(filter 1,$(SPLITDEBUG)), @$(ECHO) -n "DEBUG	"; \
+    $(ECHO) "$(COLOR_YELLOW)\
+$(subst $(OUT)/,,$(TARGET_OR_MEMBER)).debug$(COLOR_RESET)")
+  $(if $(filter 1,$(SPLITDEBUG)), \
+    $(QUIET)$(OBJCOPY) --only-keep-debug "$(TARGET_OR_MEMBER)" \
+      "$(TARGET_OR_MEMBER).debug")
+  $(if $(filter-out dbg,$(MODE)),$(QUIET)$(STRIP) --strip-unneeded \
+    "$(TARGET_OR_MEMBER)",)
+endef
+
+#
+# Global pattern rules
+#
+
+# Below, the archive member syntax is abused to create fancier
+# syntactic sugar for recipe authors that avoids needed to know
+# subcall options.  The downside is that make attempts to look
+# into the phony archives for timestamps. This will cause the final
+# target to be rebuilt/linked on _every_ call to make even when nothing
+# has changed.  Until a better way presents itself, we have helpers that
+# do the stat check on make's behalf.  Dodgy but simple.
+define old_or_no_timestamp
+  $(if $(realpath $%),,$(1))
+  $(if $(shell find $^ -cnewer "$%" 2>/dev/null),$(1))
+endef
+
+define check_deps
+  $(if $(filter 0,$(words $^)),\
+    $(error Missing dependencies or declaration of $@($%)),)
+endef
+
+# Build a cxx target magically
+CXX_BINARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cxx_binary))
+clean: CLEAN(CXX_BINARY*)
+
+CC_BINARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cc_binary))
+clean: CLEAN(CC_BINARY*)
+
+CXX_STATIC_BINARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cxx_binary,-static))
+clean: CLEAN(CXX_STATIC_BINARY*)
+
+CC_STATIC_BINARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cc_binary,-static))
+clean: CLEAN(CC_STATIC_BINARY*)
+
+CXX_LIBRARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cxx_library))
+clean: CLEAN(CXX_LIBRARY*)
+
+CXX_LIBARY(%):
+	$(error Typo alert! LIBARY != LIBRARY)
+
+CC_LIBRARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call cc_library))
+clean: CLEAN(CC_LIBRARY*)
+
+CC_LIBARY(%):
+	$(error Typo alert! LIBARY != LIBRARY)
+
+CXX_STATIC_LIBRARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call update_archive))
+clean: CLEAN(CXX_STATIC_LIBRARY*)
+
+CXX_STATIC_LIBARY(%):
+	$(error Typo alert! LIBARY != LIBRARY)
+
+CC_STATIC_LIBRARY(%):
+	$(call check_deps)
+	$(call old_or_no_timestamp,$(call update_archive))
+clean: CLEAN(CC_STATIC_LIBRARY*)
+
+CC_STATIC_LIBARY(%):
+	$(error Typo alert! LIBARY != LIBRARY)
+
+
+TEST(%): % qemu_chroot_install
+	$(call TEST_implementation)
+.PHONY: TEST
+
+# multiple targets with a wildcard need to share an directory.
+# Don't use this directly it just makes sure the directory is removed _after_
+# the files are.
+CLEANFILE(%):
+	$(call silent_rm,$(TARGET_OR_MEMBER))
+.PHONY: CLEANFILE
+
+CLEAN(%): CLEANFILE(%)
+	$(QUIET)# CLEAN($%) meta-target called
+	$(if $(filter-out $(PWD)/,$(dir $(abspath $(TARGET_OR_MEMBER)))), \
+	  $(call silent_rmdir,$(dir $(abspath $(TARGET_OR_MEMBER)))),\
+	  $(QUIET)# Not deleting $(dir $(abspath $(TARGET_OR_MEMBER))) yet.)
+.PHONY: CLEAN
+
+#
+# Top-level objects and pattern rules
+#
+
+# All objects for .c files at the top level
+C_OBJECTS = $(patsubst $(SRC)/%.c,%.o,$(wildcard $(SRC)/*.c))
+
+
+# All objects for .cxx files at the top level
+CXX_OBJECTS = $(patsubst $(SRC)/%.cc,%.o,$(wildcard $(SRC)/*.cc))
+
+# Note, the catch-all pattern rules don't work in subdirectories because
+# we're building from the $(OUT) directory. At the top-level (here) they will
+# work, but we go ahead and match using the module form.  Then we can place a
+# generic pattern rule to capture leakage from the main Makefile. (Later in the
+# file.)
+#
+# The reason target specific pattern rules work well for modules,
+# MODULE_C_OBJECTS, is because it scopes the behavior to the given target which
+# ensures we get a relative directory offset from $(OUT) which otherwise would
+# not match without further magic on a per-subdirectory basis.
+
+# Creates object file rules. Call with eval.
+# $(1) list of .o files
+# $(2) source type (CC or CXX)
+# $(3) source suffix (cc or c)
+# $(4) compiler flag name (CFLAGS or CXXFLAGS)
+# $(5) source dir: _only_ if $(SRC). Leave blank for obj tree.
+define add_object_rules
+$(patsubst %.o,%.pie.o,$(1)): %.pie.o: $(5)%.$(3) %.o.depends
+	$$(call auto_mkdir,$$@)
+	$$(call OBJECT_PATTERN_implementation,$(2),\
+          $$(basename $$@),$$($(4)) $$(CPPFLAGS) $$(OBJ_PIE_FLAG))
+
+$(patsubst %.o,%.pic.o,$(1)): %.pic.o: $(5)%.$(3) %.o.depends
+	$$(call auto_mkdir,$$@)
+	$$(call OBJECT_PATTERN_implementation,$(2),\
+          $$(basename $$@),$$($(4)) $$(CPPFLAGS) -fPIC)
+
+# Placeholder for depends
+$(patsubst %.o,%.o.depends,$(1)):
+	$$(call auto_mkdir,$$@)
+	$$(QUIET)touch "$$@"
+
+$(1): %.o: %.pic.o %.pie.o
+	$$(call auto_mkdir,$$@)
+	$$(QUIET)touch "$$@"
+endef
+
+define OBJECT_PATTERN_implementation
+  @$(ECHO) "$(1)		$(subst $(SRC)/,,$<) -> $(2).o"
+  $(call auto_mkdir,$@)
+  $(QUIET)$($(1)) -c -MD -MF $(2).d $(3) -o $(2).o $<
+  $(QUIET)# Wrap all the deps in $$(wildcard) so a missing header
+  $(QUIET)# won't cause weirdness.  First we remove newlines and \,
+  $(QUIET)# then wrap it.
+  $(QUIET)sed -i -e :j -e '$$!N;s|\\\s*\n| |;tj' \
+    -e 's|^\(.*\s*:\s*\)\(.*\)$$|\1 $$\(wildcard \2\)|' $(2).d
+endef
+
+# Now actually register handlers for C(XX)_OBJECTS.
+$(eval $(call add_object_rules,$(C_OBJECTS),CC,c,CFLAGS,$(SRC)/))
+$(eval $(call add_object_rules,$(CXX_OBJECTS),CXX,cc,CXXFLAGS,$(SRC)/))
+
+# Disable default pattern rules to help avoid leakage.
+# These may already be handled by '-r', but let's keep it to be safe.
+%: %.o ;
+%.a: %.o ;
+%.o: %.c ;
+%.o: %.cc ;
+
+# NOTE: A specific rule for archive objects is avoided because parallel
+#       update of the archive causes build flakiness.
+# Instead, just make the objects the prerequisites and use update_archive
+# To use the foo.a(obj.o) functionality, targets would need to specify the
+# explicit object they expect on the prerequisite line.
+
+#
+# Architecture detection and QEMU wrapping
+#
+
+HOST_ARCH ?= $(shell uname -m)
+override ARCH := $(strip $(ARCH))
+override HOST_ARCH := $(strip $(HOST_ARCH))
+# emake will supply "x86" or "arm" for ARCH, but
+# if uname -m runs and you get x86_64, then this subst
+# will break.
+ifeq ($(subst x86,i386,$(ARCH)),i386)
+  QEMU_ARCH := $(subst x86,i386,$(ARCH))  # x86 -> i386
+else ifeq ($(subst amd64,x86_64,$(ARCH)),x86_64)
+  QEMU_ARCH := $(subst amd64,x86_64,$(ARCH))  # amd64 -> x86_64
+else
+  QEMU_ARCH = $(ARCH)
+endif
+override QEMU_ARCH := $(strip $(QEMU_ARCH))
+
+# If we're cross-compiling, try to use qemu for running the tests.
+ifneq ($(QEMU_ARCH),$(HOST_ARCH))
+  ifeq ($(SYSROOT),)
+    $(info SYSROOT not defined. qemu-based testing disabled)
+  else
+    # A SYSROOT is assumed for QEmu use.
+    USE_QEMU ?= 1
+
+    # Allow 64-bit hosts to run 32-bit without qemu.
+    ifeq ($(HOST_ARCH),x86_64)
+      ifeq ($(QEMU_ARCH),i386)
+        USE_QEMU = 0
+      endif
+    endif
+  endif
+else
+  USE_QEMU ?= 0
+endif
+
+SYSROOT_OUT = $(OUT)
+ifneq ($(SYSROOT),)
+  SYSROOT_OUT = $(subst $(SYSROOT),,$(OUT))
+else
+  # Default to / when all the empty-sysroot logic is done.
+  SYSROOT = /
+endif
+
+
+#
+# Output full configuration at top level
+#
+
+# Don't show on clean
+ifneq ($(MAKECMDGOALS),clean)
+  $(info build configuration:)
+  $(info - OUT=$(OUT))
+  $(info - SRC=$(SRC))
+  $(info - MODE=$(MODE))
+  $(info - SPLITDEBUG=$(SPLITDEBUG))
+  $(info - NOSTRIP=$(NOSTRIP))
+  $(info - VALGRIND=$(VALGRIND))
+  $(info - COLOR=$(COLOR))
+  $(info - ARCH=$(ARCH))
+  $(info - QEMU_ARCH=$(QEMU_ARCH))
+  $(info - SYSROOT=$(SYSROOT))
+  $(info )
+endif
+
+#
+# Standard targets with detection for when they are improperly configured.
+#
+
+# all does not include tests by default
+all:
+	$(QUIET)(test -z "$^" && \
+	$(ECHO) "You must add your targets as 'all' prerequisites") || true
+	$(QUIET)test -n "$^"
+
+# Builds and runs tests for the target arch
+# Run them in parallel
+# After the test have completed, if profiling, run coverage analysis
+tests:
+ifeq ($(MODE),profiling)
+	@$(ECHO) -n "COVERAGE		gcov "
+	@$(ECHO) "[$(COLOR_YELLOW)STARTED$(COLOR_RESET)]"
+	$(QUIET)(FILES="";						\
+		for GCNO in `find . -name "*.gcno"`;			\
+		do							\
+			GCDA="$${GCNO%.gcno}.gcda";			\
+			[ -e $${GCDA} ] && FILES="$${FILES} $${GCDA}";	\
+		done;							\
+		gcov -l $${FILES})
+	@$(ECHO) -n "COVERAGE		gcov "
+	@$(ECHO) "[$(COLOR_YELLOW)FINISHED$(COLOR_RESET)]"
+	@$(ECHO) -n "COVERAGE		lcov "
+	@$(ECHO) "[$(COLOR_YELLOW)STARTED$(COLOR_RESET)]"
+	$(QUIET)lcov --capture --directory . --output-file=lcov-coverage.info
+	$(QUIET)genhtml lcov-coverage.info --output-directory lcov-html
+	@$(ECHO) -n "COVERAGE		lcov "
+	@$(ECHO) "[$(COLOR_YELLOW)FINISHED$(COLOR_RESET)]"
+endif
+.PHONY: tests
+
+qemu_clean:
+	$(call if_qemu,$(call silent_rm,$(OUT)/qemu-$(QEMU_ARCH)))
+
+qemu_chroot_install:
+ifeq ($(USE_QEMU),1)
+	$(QUIET)$(ECHO) "QEMU   Preparing qemu-$(QEMU_ARCH)"
+	$(QUIET)cp -fu /usr/bin/qemu-$(QEMU_ARCH) $(OUT)/qemu-$(QEMU_ARCH)
+	$(QUIET)chmod a+rx $(OUT)/qemu-$(QEMU_ARCH)
+endif
+.PHONY: qemu_clean qemu_chroot_install
+
+# TODO(wad) Move to -L $(SYSROOT) and fakechroot when qemu-user
+#           doesn't hang traversing /proc from SYSROOT.
+QEMU_CMD =
+ROOT_CMD = $(if $(filter 1,$(NEEDS_ROOT)),sudo , )
+MOUNT_CMD = $(if $(filter 1,$(NEEDS_MOUNTS)),$(ROOT_CMD) mount, \#)
+UMOUNT_CMD = $(if $(filter 1,$(NEEDS_MOUNTS)),$(ROOT_CMD) umount, \#)
+QEMU_LDPATH = $(SYSROOT_LDPATH):/lib64:/lib:/usr/lib64:/usr/lib
+ROOT_CMD_LDPATH = $(SYSROOT_LDPATH):$(SYSROOT)/lib64:
+ROOT_CMD_LDPATH := $(ROOT_CMD_LDPATH):$(SYSROOT)/lib:$(SYSROOT)/usr/lib64:
+ROOT_CMD_LDPATH := $(ROOT_CMD_LDPATH):$(SYSROOT)/usr/lib
+ifeq ($(USE_QEMU),1)
+  export QEMU_CMD = \
+   sudo chroot $(SYSROOT) $(SYSROOT_OUT)qemu-$(QEMU_ARCH) \
+   -drop-ld-preload \
+   -E LD_LIBRARY_PATH="$(QEMU_LDPATH):$(patsubst $(OUT),,$(LD_DIRS))" \
+   -E HOME="$(HOME)" --
+  # USE_QEMU conditional function
+  define if_qemu
+    $(1)
+  endef
+else
+  ROOT_CMD = $(if $(filter 1,$(NEEDS_ROOT)),sudo, ) \
+    LD_LIBRARY_PATH="$(ROOT_CMD_LDPATH):$(LD_DIRS)"
+  define if_qemu
+    $(2)
+  endef
+endif
+
+VALGRIND_CMD =
+ifeq ($(VALGRIND),1)
+  VALGRIND_CMD = /usr/bin/valgrind --tool=memcheck $(VALGRIND_ARGS) --
+endif
+
+define TEST_implementation
+  $(QUIET)$(call TEST_setup)
+  $(QUIET)$(call TEST_run)
+  $(QUIET)$(call TEST_teardown)
+  $(QUIET)exit $$(cat $(OUT)$(TARGET_OR_MEMBER).status.test)
+endef
+
+define TEST_setup
+  @$(ECHO) -n "TEST		$(TARGET_OR_MEMBER) "
+  @$(ECHO) "[$(COLOR_YELLOW)SETUP$(COLOR_RESET)]"
+  $(QUIET)# Setup a target-specific results file
+  $(QUIET)(echo 1 > $(OUT)$(TARGET_OR_MEMBER).status.test)
+  $(QUIET)(echo > $(OUT)$(TARGET_OR_MEMBER).cleanup.test)
+  $(QUIET)# No setup if we are not using QEMU
+  $(QUIET)# TODO(wad) this is racy until we use a vfs namespace
+  $(call if_qemu,\
+    $(QUIET)sudo mkdir -p "$(SYSROOT)/proc" "$(SYSROOT)/dev")
+  $(call if_qemu,\
+    $(QUIET)$(MOUNT_CMD) --bind /proc "$(SYSROOT)/proc")
+  $(call if_qemu,\
+    $(QUIET)$(MOUNT_CMD) --bind /dev "$(SYSROOT)/dev")
+  $(call if_qemu,\
+    $(QUIET)(echo "$(UMOUNT_CMD) -l '$(SYSROOT)/proc'" \
+             >> "$(OUT)$(TARGET_OR_MEMBER).cleanup.test"))
+  $(call if_qemu,\
+    $(QUIET)(echo "$(UMOUNT_CMD) -l '$(SYSROOT)/dev'" \
+             >> "$(OUT)$(TARGET_OR_MEMBER).cleanup.test"))
+endef
+
+define TEST_teardown
+  @$(ECHO) -n "TEST		$(TARGET_OR_MEMBER) "
+  @$(ECHO) "[$(COLOR_YELLOW)TEARDOWN$(COLOR_RESET)]"
+  $(call if_qemu, $(QUIET)$(SHELL) "$(OUT)$(TARGET_OR_MEMBER).cleanup.test")
+endef
+
+# Use GTEST_ARGS.[arch] if defined.
+override GTEST_ARGS.real = \
+ $(call if_qemu,$(GTEST_ARGS.qemu.$(QEMU_ARCH)),$(GTEST_ARGS.host.$(HOST_ARCH)))
+
+define TEST_run
+  @$(ECHO) -n "TEST		$(TARGET_OR_MEMBER) "
+  @$(ECHO) "[$(COLOR_GREEN)RUN$(COLOR_RESET)]"
+  $(QUIET)(echo 1 > "$(OUT)$(TARGET_OR_MEMBER).status.test")
+  -($(ROOT_CMD) $(QEMU_CMD) $(VALGRIND_CMD) \
+    "$(strip $(call if_qemu, $(SYSROOT_OUT),$(OUT))$(TARGET_OR_MEMBER))" \
+      $(if $(filter-out 0,$(words $(GTEST_ARGS.real))),$(GTEST_ARGS.real),\
+           $(GTEST_ARGS)) && \
+    echo 0 > "$(OUT)$(TARGET_OR_MEMBER).status.test")
+endef
+
+# Recursive list reversal so that we get RMDIR_ON_CLEAN in reverse order.
+define reverse
+$(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
+endef
+
+clean: qemu_clean
+clean: CLEAN($(OUT)*.d) CLEAN($(OUT)*.o) CLEAN($(OUT)*.debug)
+clean: CLEAN($(OUT)*.test) CLEAN($(OUT)*.depends)
+clean: CLEAN($(OUT)*.gcno) CLEAN($(OUT)*.gcda) CLEAN($(OUT)*.gcov)
+clean: CLEAN($(OUT)lcov-coverage.info) CLEAN($(OUT)lcov-html)
+
+clean:
+	$(QUIET)# Always delete the containing directory last.
+	$(call silent_rmdir,$(OUT))
+
+FORCE: ;
+# Empty rule for use when no special targets are needed, like large_tests
+NONE:
+
+.PHONY: clean NONE valgrind NONE
+.DEFAULT_GOAL  :=  all
+# Don't let make blow away "intermediates"
+.PRECIOUS: %.pic.o %.pie.o %.a %.pic.a %.pie.a %.test
+
+# Start accruing build info
+OUT_DIRS = $(OUT)
+LD_DIRS = $(OUT)
+SRC_DIRS = $(SRC)
+
+include $(wildcard $(OUT)*.d)
+SUBMODULE_DIRS = $(wildcard $(SRC)/*/module.mk)
+include $(SUBMODULE_DIRS)
+
+
+else  ## In duplicate inclusions of common.mk
+
+# Get the current inclusion directory without a trailing slash
+MODULE := $(patsubst %/,%, \
+           $(dir $(lastword $(filter-out %common.mk,$(MAKEFILE_LIST)))))
+MODULE := $(subst $(SRC)/,,$(MODULE))
+MODULE_NAME := $(subst /,_,$(MODULE))
+#VPATH := $(MODULE):$(VPATH)
+
+
+# Depth first
+$(eval OUT_DIRS += $(OUT)$(MODULE))
+$(eval SRC_DIRS += $(OUT)$(MODULE))
+$(eval LD_DIRS := $(LD_DIRS):$(OUT)$(MODULE))
+
+# Add the defaults from this dir to rm_clean
+clean: CLEAN($(OUT)$(MODULE)/*.d) CLEAN($(OUT)$(MODULE)/*.o)
+clean: CLEAN($(OUT)$(MODULE)/*.debug) CLEAN($(OUT)$(MODULE)/*.test)
+clean: CLEAN($(OUT)$(MODULE)/*.depends)
+clean: CLEAN($(OUT)$(MODULE)/*.gcno) CLEAN($(OUT)$(MODULE)/*.gcda)
+clean: CLEAN($(OUT)$(MODULE)/*.gcov) CLEAN($(OUT)lcov-coverage.info)
+clean: CLEAN($(OUT)lcov-html)
+
+$(info + submodule: $(MODULE_NAME))
+# We must eval otherwise they may be dropped.
+MODULE_C_OBJECTS = $(patsubst $(SRC)/$(MODULE)/%.c,$(MODULE)/%.o,\
+  $(wildcard $(SRC)/$(MODULE)/*.c))
+$(eval $(MODULE_NAME)_C_OBJECTS ?= $(MODULE_C_OBJECTS))
+MODULE_CXX_OBJECTS = $(patsubst $(SRC)/$(MODULE)/%.cc,$(MODULE)/%.o,\
+  $(wildcard $(SRC)/$(MODULE)/*.cc))
+$(eval $(MODULE_NAME)_CXX_OBJECTS ?= $(MODULE_CXX_OBJECTS))
+
+# Note, $(MODULE) is implicit in the path to the %.c.
+# See $(C_OBJECTS) for more details.
+# Register rules for the module objects.
+$(eval $(call add_object_rules,$(MODULE_C_OBJECTS),CC,c,CFLAGS,$(SRC)/))
+$(eval $(call add_object_rules,$(MODULE_CXX_OBJECTS),CXX,cc,CXXFLAGS,$(SRC)/))
+
+# Continue recursive inclusion of module.mk files
+SUBMODULE_DIRS = $(wildcard $(SRC)/$(MODULE)/*/module.mk)
+include $(wildcard $(OUT)$(MODULE)/*.d)
+include $(SUBMODULE_DIRS)
+
+endif
+endif  ## pass-to-subcall wrapper for relocating the call directory
diff --git a/cpp2cc.sh b/cpp2cc.sh
new file mode 100644
index 0000000..285e12b
--- /dev/null
+++ b/cpp2cc.sh
@@ -0,0 +1 @@
+for f in `find -name \*.cpp` ; do mv $f `dirname $f`/`basename $f cpp`cc; done
diff --git a/include/module.mk b/include/module.mk
new file mode 100755
index 0000000..840fe23
--- /dev/null
+++ b/include/module.mk
@@ -0,0 +1,15 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+include common.mk
+
+HEADER  = suggest/types.h \
+		  suggest/suggest.h
+
+install-header: CXX_LIBRARY(src/libsuggest.so)
+	set -e; \
+	for h in $(HEADER); do \
+		install -D -m 0644 $(SRC)/include/$$h \
+			$(DESTDIR)/usr/include/$$h; \
+	done
diff --git a/include/suggest/suggest.h b/include/suggest/suggest.h
index 500bb3d..2e0a983 100644
--- a/include/suggest/suggest.h
+++ b/include/suggest/suggest.h
@@ -10,6 +10,8 @@
 
 #include "types.h"
 
+#define SUGGEST_EXPORT __attribute__((visibility("default")))
+
 namespace suggest {
 
 class SuggestEngine;
@@ -20,8 +22,8 @@
 // but keep in mind that all calculations are made in integer arithmetics.
 // the rectangle is defined as location of the top left corner and size.
 struct Key {
-	Key() {}
-	Key(vec2f location, vec2f size, charcode _code) :
+	SUGGEST_EXPORT Key() {}
+	SUGGEST_EXPORT Key(vec2f location, vec2f size, charcode _code) :
 		rect(location, size), code(_code) {
 	}
 
@@ -41,16 +43,16 @@
 // Next to the coordinates of a touch, suggest needs to know which
 // character your keyboard recognized and displays to the users.
 struct Touch {
-	Touch() {}
-	Touch(vec2f pos, charcode code);
+	SUGGEST_EXPORT Touch() {}
+	SUGGEST_EXPORT Touch(vec2f pos, charcode code);
 
 	// create touch based on location only. Looks up which key is
 	// at this location.
-	Touch(vec2f pos, const SuggestEngine& engine);
+	SUGGEST_EXPORT Touch(vec2f pos, const SuggestEngine& engine);
 
 	// create a touch based on char code, assumes the key is hit right at
 	// the center.
-	Touch(charcode code, const SuggestEngine& engine);
+	SUGGEST_EXPORT Touch(charcode code, const SuggestEngine& engine);
 
 	vec2f pos;
 	charcode code;
@@ -62,7 +64,7 @@
 // The provided locale name will be used to pick the right dictionary
 // from /usr/share/libsuggest/
 struct SuggestParameters {
-	SuggestParameters(std::string locale);
+	SUGGEST_EXPORT SuggestParameters(std::string locale);
 
 	vec2f grid_cells;
 	float search_box_size_factor;
@@ -94,6 +96,7 @@
 
 // To hide the implementation details of the SuggestEngine class
 // (especially for hiding the AOSP API)
+SUGGEST_EXPORT
 SuggestEngine* NewSuggestEngine(vec2f keyboard_size, vec2f common_key_size,
 						        const std::vector<Key> &keylist,
 						        const SuggestParameters &parameters);
diff --git a/src/aosp/compability/log_utils_mock.cpp b/src/aosp/compability/log_utils_mock.cc
similarity index 100%
rename from src/aosp/compability/log_utils_mock.cpp
rename to src/aosp/compability/log_utils_mock.cc
diff --git a/src/aosp/compability/module.mk b/src/aosp/compability/module.mk
new file mode 100755
index 0000000..2519031
--- /dev/null
+++ b/src/aosp/compability/module.mk
@@ -0,0 +1,5 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
+
diff --git a/src/aosp/module.mk b/src/aosp/module.mk
new file mode 100755
index 0000000..ef560f7
--- /dev/null
+++ b/src/aosp/module.mk
@@ -0,0 +1,24 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
+
+AOSP_OBJ_FILES=\
+	$(src_aosp_compability_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_gesture_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_typing_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_dictionary_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_dictionary_bigram_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_dictionary_header_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_dictionary_utils_CXX_OBJECTS)\
+	$(src_aosp_suggest_policyimpl_dictionary_shortcut_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_session_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_dicnode_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_dictionary_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_policy_CXX_OBJECTS)\
+	$(src_aosp_suggest_core_layout_CXX_OBJECTS)\
+	src/aosp/utils/char_utils.o\
+	src/aosp/utils/autocorrection_threshold_utils.o
+
+CXX_LIBRARY(src/libsuggest.so): $(AOSP_OBJ_FILES)
\ No newline at end of file
diff --git a/src/aosp/suggest/core/dicnode/dic_node.cpp b/src/aosp/suggest/core/dicnode/dic_node.cc
similarity index 100%
rename from src/aosp/suggest/core/dicnode/dic_node.cpp
rename to src/aosp/suggest/core/dicnode/dic_node.cc
diff --git a/src/aosp/suggest/core/dicnode/dic_node_utils.cpp b/src/aosp/suggest/core/dicnode/dic_node_utils.cc
similarity index 100%
rename from src/aosp/suggest/core/dicnode/dic_node_utils.cpp
rename to src/aosp/suggest/core/dicnode/dic_node_utils.cc
diff --git a/src/aosp/suggest/core/dicnode/dic_nodes_cache.cpp b/src/aosp/suggest/core/dicnode/dic_nodes_cache.cc
similarity index 100%
rename from src/aosp/suggest/core/dicnode/dic_nodes_cache.cpp
rename to src/aosp/suggest/core/dicnode/dic_nodes_cache.cc
diff --git a/src/aosp/suggest/core/dicnode/internal/module.mk b/src/aosp/suggest/core/dicnode/internal/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/dicnode/internal/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/dicnode/module.mk b/src/aosp/suggest/core/dicnode/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/dicnode/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/dictionary/bigram_dictionary.cpp b/src/aosp/suggest/core/dictionary/bigram_dictionary.cc
similarity index 100%
rename from src/aosp/suggest/core/dictionary/bigram_dictionary.cpp
rename to src/aosp/suggest/core/dictionary/bigram_dictionary.cc
diff --git a/src/aosp/suggest/core/dictionary/bloom_filter.cpp b/src/aosp/suggest/core/dictionary/bloom_filter.cc
similarity index 100%
rename from src/aosp/suggest/core/dictionary/bloom_filter.cpp
rename to src/aosp/suggest/core/dictionary/bloom_filter.cc
diff --git a/src/aosp/suggest/core/dictionary/dictionary.cpp b/src/aosp/suggest/core/dictionary/dictionary.cc
similarity index 100%
rename from src/aosp/suggest/core/dictionary/dictionary.cpp
rename to src/aosp/suggest/core/dictionary/dictionary.cc
diff --git a/src/aosp/suggest/core/dictionary/digraph_utils.cpp b/src/aosp/suggest/core/dictionary/digraph_utils.cc
similarity index 100%
rename from src/aosp/suggest/core/dictionary/digraph_utils.cpp
rename to src/aosp/suggest/core/dictionary/digraph_utils.cc
diff --git a/src/aosp/suggest/core/dictionary/module.mk b/src/aosp/suggest/core/dictionary/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/dictionary/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/dictionary/multi_bigram_map.cpp b/src/aosp/suggest/core/dictionary/multi_bigram_map.cc
similarity index 100%
rename from src/aosp/suggest/core/dictionary/multi_bigram_map.cpp
rename to src/aosp/suggest/core/dictionary/multi_bigram_map.cc
diff --git a/src/aosp/suggest/core/layout/additional_proximity_chars.cpp b/src/aosp/suggest/core/layout/additional_proximity_chars.cc
similarity index 100%
rename from src/aosp/suggest/core/layout/additional_proximity_chars.cpp
rename to src/aosp/suggest/core/layout/additional_proximity_chars.cc
diff --git a/src/aosp/suggest/core/layout/module.mk b/src/aosp/suggest/core/layout/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/layout/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/layout/proximity_info.cpp b/src/aosp/suggest/core/layout/proximity_info.cc
similarity index 100%
rename from src/aosp/suggest/core/layout/proximity_info.cpp
rename to src/aosp/suggest/core/layout/proximity_info.cc
diff --git a/src/aosp/suggest/core/layout/proximity_info_params.cpp b/src/aosp/suggest/core/layout/proximity_info_params.cc
similarity index 100%
rename from src/aosp/suggest/core/layout/proximity_info_params.cpp
rename to src/aosp/suggest/core/layout/proximity_info_params.cc
diff --git a/src/aosp/suggest/core/layout/proximity_info_state.cpp b/src/aosp/suggest/core/layout/proximity_info_state.cc
similarity index 100%
rename from src/aosp/suggest/core/layout/proximity_info_state.cpp
rename to src/aosp/suggest/core/layout/proximity_info_state.cc
diff --git a/src/aosp/suggest/core/layout/proximity_info_state_utils.cpp b/src/aosp/suggest/core/layout/proximity_info_state_utils.cc
similarity index 100%
rename from src/aosp/suggest/core/layout/proximity_info_state_utils.cpp
rename to src/aosp/suggest/core/layout/proximity_info_state_utils.cc
diff --git a/src/aosp/suggest/core/module.mk b/src/aosp/suggest/core/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/policy/module.mk b/src/aosp/suggest/core/policy/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/policy/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/policy/weighting.cpp b/src/aosp/suggest/core/policy/weighting.cc
similarity index 100%
rename from src/aosp/suggest/core/policy/weighting.cpp
rename to src/aosp/suggest/core/policy/weighting.cc
diff --git a/src/aosp/suggest/core/session/dic_traverse_session.cpp b/src/aosp/suggest/core/session/dic_traverse_session.cc
similarity index 100%
rename from src/aosp/suggest/core/session/dic_traverse_session.cpp
rename to src/aosp/suggest/core/session/dic_traverse_session.cc
diff --git a/src/aosp/suggest/core/session/module.mk b/src/aosp/suggest/core/session/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/core/session/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/core/suggest.cpp b/src/aosp/suggest/core/suggest.cc
similarity index 100%
rename from src/aosp/suggest/core/suggest.cpp
rename to src/aosp/suggest/core/suggest.cc
diff --git a/src/aosp/suggest/module.mk b/src/aosp/suggest/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/bigram/dynamic_bigram_list_policy.cpp b/src/aosp/suggest/policyimpl/dictionary/bigram/dynamic_bigram_list_policy.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/bigram/dynamic_bigram_list_policy.cpp
rename to src/aosp/suggest/policyimpl/dictionary/bigram/dynamic_bigram_list_policy.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/bigram/module.mk b/src/aosp/suggest/policyimpl/dictionary/bigram/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/dictionary/bigram/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/dictionary/dictionary_structure_with_buffer_policy_factory.cpp b/src/aosp/suggest/policyimpl/dictionary/dictionary_structure_with_buffer_policy_factory.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dictionary_structure_with_buffer_policy_factory.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dictionary_structure_with_buffer_policy_factory.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_gc_event_listeners.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_gc_event_listeners.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_gc_event_listeners.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_gc_event_listeners.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_helper.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_helper.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_helper.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_helper.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_helper.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_helper.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_helper.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_helper.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/dynamic_patricia_trie_writing_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/header/header_policy.cpp b/src/aosp/suggest/policyimpl/dictionary/header/header_policy.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/header/header_policy.cpp
rename to src/aosp/suggest/policyimpl/dictionary/header/header_policy.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/header/header_read_write_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/header/header_read_write_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/header/module.mk b/src/aosp/suggest/policyimpl/dictionary/header/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/dictionary/header/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/dictionary/module.mk b/src/aosp/suggest/policyimpl/dictionary/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/dictionary/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/dictionary/patricia_trie_policy.cpp b/src/aosp/suggest/policyimpl/dictionary/patricia_trie_policy.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/patricia_trie_policy.cpp
rename to src/aosp/suggest/policyimpl/dictionary/patricia_trie_policy.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/patricia_trie_reading_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/patricia_trie_reading_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/patricia_trie_reading_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/patricia_trie_reading_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/shortcut/module.mk b/src/aosp/suggest/policyimpl/dictionary/shortcut/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/dictionary/shortcut/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp b/src/aosp/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
rename to src/aosp/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/byte_array_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/utils/byte_array_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/utils/byte_array_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/utils/byte_array_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/format_utils.cpp b/src/aosp/suggest/policyimpl/dictionary/utils/format_utils.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/dictionary/utils/format_utils.cpp
rename to src/aosp/suggest/policyimpl/dictionary/utils/format_utils.cc
diff --git a/src/aosp/suggest/policyimpl/dictionary/utils/module.mk b/src/aosp/suggest/policyimpl/dictionary/utils/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/dictionary/utils/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp b/src/aosp/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp
rename to src/aosp/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cc
diff --git a/src/aosp/suggest/policyimpl/gesture/module.mk b/src/aosp/suggest/policyimpl/gesture/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/gesture/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/module.mk b/src/aosp/suggest/policyimpl/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/typing/module.mk b/src/aosp/suggest/policyimpl/typing/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/typing/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/suggest/policyimpl/typing/scoring_params.cpp b/src/aosp/suggest/policyimpl/typing/scoring_params.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/typing/scoring_params.cpp
rename to src/aosp/suggest/policyimpl/typing/scoring_params.cc
diff --git a/src/aosp/suggest/policyimpl/typing/typing_scoring.cpp b/src/aosp/suggest/policyimpl/typing/typing_scoring.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/typing/typing_scoring.cpp
rename to src/aosp/suggest/policyimpl/typing/typing_scoring.cc
diff --git a/src/aosp/suggest/policyimpl/typing/typing_suggest_policy.cpp b/src/aosp/suggest/policyimpl/typing/typing_suggest_policy.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/typing/typing_suggest_policy.cpp
rename to src/aosp/suggest/policyimpl/typing/typing_suggest_policy.cc
diff --git a/src/aosp/suggest/policyimpl/typing/typing_traversal.cpp b/src/aosp/suggest/policyimpl/typing/typing_traversal.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/typing/typing_traversal.cpp
rename to src/aosp/suggest/policyimpl/typing/typing_traversal.cc
diff --git a/src/aosp/suggest/policyimpl/typing/typing_weighting.cpp b/src/aosp/suggest/policyimpl/typing/typing_weighting.cc
similarity index 100%
rename from src/aosp/suggest/policyimpl/typing/typing_weighting.cpp
rename to src/aosp/suggest/policyimpl/typing/typing_weighting.cc
diff --git a/src/aosp/suggest/policyimpl/utils/module.mk b/src/aosp/suggest/policyimpl/utils/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/suggest/policyimpl/utils/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/aosp/utils/autocorrection_threshold_utils.cpp b/src/aosp/utils/autocorrection_threshold_utils.cc
similarity index 100%
rename from src/aosp/utils/autocorrection_threshold_utils.cpp
rename to src/aosp/utils/autocorrection_threshold_utils.cc
diff --git a/src/aosp/utils/char_utils.cpp b/src/aosp/utils/char_utils.cc
similarity index 100%
rename from src/aosp/utils/char_utils.cpp
rename to src/aosp/utils/char_utils.cc
diff --git a/src/aosp/utils/log_utils.cpp b/src/aosp/utils/log_utils.cc
similarity index 100%
rename from src/aosp/utils/log_utils.cpp
rename to src/aosp/utils/log_utils.cc
diff --git a/src/aosp/utils/module.mk b/src/aosp/utils/module.mk
new file mode 100755
index 0000000..58a0fea
--- /dev/null
+++ b/src/aosp/utils/module.mk
@@ -0,0 +1,4 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
diff --git a/src/demo.cpp b/src/demo.cc
similarity index 97%
rename from src/demo.cpp
rename to src/demo.cc
index 37b20cc..c9e8741 100644
--- a/src/demo.cpp
+++ b/src/demo.cc
@@ -53,7 +53,8 @@
 	// create suggestion engine with key list
 	std::unique_ptr<SuggestEngine> engine(NewSuggestEngine(
 		keyboard_size, common_key_size, keys, SuggestParameters("en_US")));
-	engine->LoadDictionary("en_US");
+	if(!engine->LoadDictionary("en_US"))
+		return -1;
 
 	// do some test touches and receive suggestions
 	std::unique_ptr<SuggestSession> session(engine->NewSession());
diff --git a/src/module.mk b/src/module.mk
new file mode 100755
index 0000000..b6040f6
--- /dev/null
+++ b/src/module.mk
@@ -0,0 +1,18 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+include common.mk
+
+CPPFLAGS += -I$(SRC)/include -I$(SRC)/src/aosp -I$(SRC)/src/aosp/compability -std=c++11 -Wno-deprecated -Wno-error=sign-compare -D FLAG_DEBUG
+
+SUGGEST_OBJ_FILES=src/suggest.o
+
+SUGGEST_DEMO_OBJ_FILES=src/demo.o
+
+CXX_LIBRARY(src/libsuggest.so): $(SUGGEST_OBJ_FILES)
+
+CXX_BINARY(src/demo): LDFLAGS += -lncurses -Lsrc -lsuggest
+CXX_BINARY(src/demo): $(SUGGEST_DEMO_OBJ_FILES) CXX_LIBRARY(src/libsuggest.so)
+
+install-lib: CXX_LIBRARY(src/libsuggest.so)
+	install -D -m 0755 src/libsuggest.so $(DESTDIR)$(LIBDIR)/libsuggest.so
diff --git a/src/suggest.cpp b/src/suggest.cc
similarity index 89%
rename from src/suggest.cpp
rename to src/suggest.cc
index 918b814..820532d 100644
--- a/src/suggest.cpp
+++ b/src/suggest.cc
@@ -83,18 +83,18 @@
             }
          }
        }
-#ifdef DEBUG
-      for (int y=0; y<GRID_CELLS_Y; ++y) {
-         for (int x=0; x<GRID_CELLS_X; ++x) {
+#ifdef FLAG_DEBUG
+      for (int y=0; y<p.grid_cells.y; ++y) {
+         for (int x=0; x<p.grid_cells.x; ++x) {
                AKLOGI("(%d, %d) = %c %c %c %c %c %c %c %c", x, y,
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 0],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 1],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 2],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 3],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 4],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 5],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 6],
-                      (char)proximityChars[((y * grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 7]);
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 0],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 1],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 2],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 3],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 4],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 5],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 6],
+                      (char)proximityChars[((y * p.grid_cells.x) + x) * MAX_PROXIMITY_CHARS_SIZE + 7]);
            }
        }
 #endif
@@ -144,6 +144,7 @@
                dict_filename.c_str(), 0, filesize, false);
 
       dictionary_.reset(new Dictionary(&fakeEnv, dict_structure_));
+      return true;
    }
 
    virtual Key GetKeyAt(vec2f pos) const {
@@ -164,10 +165,6 @@
       return Key::InvalidKey;
    }
 
-   virtual charcode CodeAt(vec2f pos) {
-
-   }
-
    virtual SuggestSession* NewSession() {
       return new SuggestSessionImpl(this);
    }