summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Belt <andrewpbelt@gmail.com>2022-11-28 17:57:17 -0500
committerAndrew Belt <andrewpbelt@gmail.com>2022-11-28 18:02:57 -0500
commit75f90aa95e3da44cc19c133c857c181f118febf9 (patch)
treec9bda80a9356ac64b87a6dbae8f518f8f88ffdbb
parentd614db5436ebb45be3dc6143c52fde9102dd7bb8 (diff)
Allow cross-compiling plugins by setting CROSS_COMPILE environment variable to a machine triplet.
-rw-r--r--arch.mk6
-rw-r--r--compile.mk6
-rw-r--r--dep.mk6
3 files changed, 17 insertions, 1 deletions
diff --git a/arch.mk b/arch.mk
index a93cb92e..a2a75a34 100644
--- a/arch.mk
+++ b/arch.mk
@@ -1,4 +1,8 @@
-MACHINE := $(shell $(CC) -dumpmachine)
+ifdef CROSS_COMPILE
+ MACHINE := $(CROSS_COMPILE)
+else
+ MACHINE ?= $(shell $(CC) -dumpmachine)
+endif
ifneq (,$(findstring x86_64-,$(MACHINE)))
ARCH_X64 := 1
diff --git a/compile.mk b/compile.mk
index b72fd683..011b4363 100644
--- a/compile.mk
+++ b/compile.mk
@@ -20,6 +20,12 @@ FLAGS += -Wall -Wextra -Wno-unused-parameter
# C++ standard
CXXFLAGS += -std=c++11
+# Define compiler/linker target if cross-compiling
+ifdef CROSS_COMPILE
+ FLAGS += --target=$(MACHINE)
+ LDFLAGS += --target=$(MACHINE)
+endif
+
# Architecture-independent flags
ifdef ARCH_X64
FLAGS += -DARCH_X64
diff --git a/dep.mk b/dep.mk
index 7db35fb5..41fe5896 100644
--- a/dep.mk
+++ b/dep.mk
@@ -10,6 +10,12 @@ DEP_FLAGS += -g -O3
# Static libs don't usually compiled with -fPIC, but since we're including them in a shared library, it's needed.
DEP_FLAGS += -fPIC
+# Define compiler/linker target if cross-compiling
+ifdef CROSS_COMPILE
+ DEP_FLAGS += --target=$(MACHINE)
+ DEP_LDFLAGS += --target=$(MACHINE)
+endif
+
ifdef ARCH_X64
DEP_FLAGS += -march=nehalem
endif