aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--build/clean.mk10
-rw-r--r--build/defs.mk24
-rw-r--r--build/hexagon.mk95
-rw-r--r--build/main.mk26
-rw-r--r--build/outdir.mk12
-rw-r--r--platform/platform.mk20
8 files changed, 194 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 64876898..6a0298c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ bazel-chre
bazel-genfiles
bazel-out
bazel-testlogs
+out
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..c81481a0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
+#
+# All Makefile logic is located in the build/ directory and the main entry-point
+# is included here for convenience.
+#
+
+include build/main.mk
diff --git a/build/clean.mk b/build/clean.mk
new file mode 100644
index 00000000..3609caa2
--- /dev/null
+++ b/build/clean.mk
@@ -0,0 +1,10 @@
+#
+# Cleanup the project by removing the output directory.
+#
+
+include build/defs.mk
+
+.PHONY: clean
+
+clean:
+ rm -rf $(OUT)
diff --git a/build/defs.mk b/build/defs.mk
new file mode 100644
index 00000000..360701ca
--- /dev/null
+++ b/build/defs.mk
@@ -0,0 +1,24 @@
+#
+# Common global constants used as part of the build.
+#
+
+# Build Artifacts Directory ####################################################
+
+OUT=out
+
+# Common Compiler Flags ########################################################
+
+# CHRE requires C++11 support.
+COMMON_CFLAGS += -std=c++11
+
+# Configure warnings.
+COMMON_CFLAGS += -Wall
+COMMON_CFLAGS += -Werror
+
+# Disable exceptions and RTTI.
+COMMON_CFLAGS += -fno-exceptions
+COMMON_CFLAGS += -fno-rtti
+
+# Enable the linker to garbage collect unused code and variables.
+COMMON_CFLAGS += -fdata-sections
+COMMON_CFLAGS += -ffunction-sections
diff --git a/build/hexagon.mk b/build/hexagon.mk
new file mode 100644
index 00000000..f548c65c
--- /dev/null
+++ b/build/hexagon.mk
@@ -0,0 +1,95 @@
+#
+# Build CHRE into a static archive to be linked by the toolchain.
+#
+
+include build/defs.mk
+
+.PHONY: hexagon
+
+# Hexagon Check ################################################################
+
+# If building for the Hexagon target, ensure that the user has specified a path
+# to the Hexagon toolchain that they wish to use.
+
+ifneq ($(filter hexagon all, $(MAKECMDGOALS)),)
+ifeq ($(HEXAGON_TOOLS_PREFIX),)
+$(error "You must supply a HEXAGON_TOOLS_PREFIX environment variable \
+ containing a path to the hexagon toolchain. Example: \
+ $$HOME/Qualcomm/HEXAGON_Tools/8.0.07")
+endif
+
+ifeq ($(HEXAGON_SDK_PREFIX),)
+$(error "You must supply a HEXAGON_SDK_PREFIX environment variable \
+ containing a path to the hexagon SDK. Example: \
+ $$HOME/Qualcomm/Hexagon_SDK/3.0")
+endif
+endif
+
+# Hexagon Tools ################################################################
+
+HEXAGON_CC = $(HEXAGON_TOOLS_PREFIX)/Tools/bin/hexagon-clang
+HEXAGON_AR = $(HEXAGON_TOOLS_PREFIX)/Tools/bin/hexagon-ar
+
+# Hexagon Compiler Flags #######################################################
+
+HEXAGON_CFLAGS += $(COMMON_CFLAGS)
+
+# Include paths.
+HEXAGON_CFLAGS += -I$(HEXAGON_SDK_PREFIX)/incs
+HEXAGON_CFLAGS += -I$(HEXAGON_SDK_PREFIX)/incs/stddef/
+
+# Enable position independence.
+HEXAGON_CFLAGS += -fpic
+
+# Enable hexagon v6.2 architecture.
+HEXAGON_CFLAGS += -mv62
+
+# Disable splitting double registers.
+HEXAGON_CFLAGS += -mllvm -disable-hsdr
+
+# Enable the POSIX threading model.
+HEXAGON_CFLAGS += -mthread-model posix
+
+# This code is loaded into a dynamic module. Define this symbol in the event
+# that any Qualcomm code needs it.
+HEXAGON_CFLAGS += -D__V_DYNAMIC__
+
+# TODO: Consider options for setting the optimization level. Maybe an
+# environment variable can suffice here.
+HEXAGON_CFLAGS += -O0
+
+# TODO: Probably want to disable this when compiling for >-O0.
+HEXAGON_CFLAGS += -D_DEBUG
+
+# Hexagon Static Archive #######################################################
+
+HEXAGON_ARFLAGS = -rsc
+
+HEXAGON_ARCHIVE = $(OUT)/hexagon/libchre.a
+
+# Hexagon Objects ##############################################################
+
+HEXAGON_SRCS += $(COMMON_SRCS)
+HEXAGON_OBJS = $(patsubst %.cc, $(OUT)/hexagon/%.o, $(HEXAGON_SRCS))
+HEXAGON_DIRS = $(sort $(dir $(HEXAGON_OBJS)))
+
+# Top-level Hexagon Build Rule #################################################
+
+hexagon: $(OUT) $(HEXAGON_DIRS) $(HEXAGON_ARCHIVE)
+
+all: hexagon
+
+# Output Directories ###########################################################
+
+$(HEXAGON_DIRS):
+ mkdir -p $@
+
+# Link #########################################################################
+
+$(HEXAGON_ARCHIVE): $(HEXAGON_OBJS)
+ $(HEXAGON_AR) $(HEXAGON_ARFLAGS) $@ $^
+
+# Compile ######################################################################
+
+$(HEXAGON_OBJS): $(OUT)/hexagon/%.o: %.cc
+ $(HEXAGON_CC) $(HEXAGON_CFLAGS) -c $< -o $@
diff --git a/build/main.mk b/build/main.mk
new file mode 100644
index 00000000..6017792f
--- /dev/null
+++ b/build/main.mk
@@ -0,0 +1,26 @@
+#
+# This is the main entry-point for the CHRE Makefile build system. Different
+# components of the build are included below.
+#
+
+ifeq ($(MAKECMDGOALS),)
+define EMPTY_GOALS_ERROR
+You must specify a target to build. Currently supported targets are:
+ - all
+ - hexagon
+endef
+$(error $(EMPTY_GOALS_ERROR))
+endif
+
+# The all target to build all source
+.PHONY: all
+all:
+
+# Include mk files from each subdirectory.
+# TODO: Add mk files for core, chre_api, util
+include platform/platform.mk
+
+# Include all build submodules.
+include build/hexagon.mk
+include build/outdir.mk
+include build/clean.mk
diff --git a/build/outdir.mk b/build/outdir.mk
new file mode 100644
index 00000000..2f7a01fd
--- /dev/null
+++ b/build/outdir.mk
@@ -0,0 +1,12 @@
+#
+# All build artifacts are output in a directory called out/ at the root of the
+# project.
+#
+
+include build/defs.mk
+
+#
+# Ensure that the output directory exists.
+#
+$(OUT):
+ mkdir -p $(OUT)
diff --git a/platform/platform.mk b/platform/platform.mk
new file mode 100644
index 00000000..7e37ac44
--- /dev/null
+++ b/platform/platform.mk
@@ -0,0 +1,20 @@
+#
+# Platform Makefile
+#
+
+# Common Compiler Flags ########################################################
+
+# Include paths.
+COMMON_CFLAGS += -Iplatform/include
+
+# Common Source Files ##########################################################
+
+COMMON_SRCS += platform/slpi/init.cc
+
+# Hexagon-specific Compiler Flags ##############################################
+
+# Include paths.
+HEXAGON_CFLAGS += -Iplatform/slpi/include
+
+# Symbols required by the runtime for conditional compilation.
+HEXAGON_CFLAGS += -DCHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_DEBUG