Skip to content

Commit

Permalink
Fix build error for ARM Mac
Browse files Browse the repository at this point in the history
A non-backward compatible build change is implemented for cross-compilation,
which requires to define CROSS_COMPILE environment variable. It's only
applicable to environments where the build and execution happen on hosts
with different C++ compilers.
  • Loading branch information
saleyn committed Jul 8, 2024
1 parent 3f1db3b commit 54b95cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.d
*.swp
*.tgz
*.dump
doc
priv
ebin
Expand Down
15 changes: 9 additions & 6 deletions c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ CURDIR := $(shell pwd)
BASEDIR := $(abspath $(dir $(CURDIR)))
PROJECT ?= erlexec
PROJECT := $(strip $(PROJECT))
CXX ?= g++

ERL_CXXFLAGS ?= $(shell erl -noshell -noinput -eval "io:format(\"-I~ts/erts-~ts/include -I~ts\", [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)]), halt(0).")
ERL_LDFLAGS ?= $(shell erl -noshell -noinput -eval "io:format(\"-L~ts\", [code:lib_dir(erl_interface, lib)]), halt(0).")
ERL_CXXFLAGS ?= $(shell erl -noshell -noinput -eval 'io:format("-I~ts/erts-~ts/include -I~ts", [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)]), halt(0).')
ERL_LDFLAGS ?= $(shell erl -noshell -noinput -eval 'io:format("-L~ts", [code:lib_dir(erl_interface, lib)]), halt(0).')

CXXFLAGS += -g -std=c++11 -finline-functions -Wall -DHAVE_PTRACE -MMD
USE_POLL ?= 1
Expand All @@ -15,10 +16,11 @@ UNAME_SYS := $(shell uname -s | tr 'A-Z' 'a-z')

# For cross building using erlang:system_info() does not work as rebar runs
# using the build hosts Erlang runtime.
# If CXX environment variable is defined we are most likely running in a cross environment.
ifeq ($(CXX),)
CXX := g++
TARGET := $(shell erl -noshell -noinput -eval "io:format("~s\n", [erlang:system_info(system_architecture)]), halt(0).")
# If CROSS_COMPILE environment variable is defined we are most likely running
# in a cross environment. In this case use the architecture name reported by
# the C++ compiler.
ifeq ($(CROSS_COMPILE),)
TARGET := $(shell erl -noshell -noinput -eval 'io:format("~s\n", [erlang:system_info(system_architecture)]), halt(0).')
else
TARGET := $(shell $(CXX) -dumpmachine)
endif
Expand Down Expand Up @@ -118,6 +120,7 @@ clean:
info:
@echo "SOURCES: $(SOURCES)"
@echo "OBJECTS: $(OBJECTS)"
@echo "TARGET: $(TARGET)"
@echo "OUTPUT: $(EXE_OUTPUT)"
@echo "OUT_DIR: $(EXE_DIR)"

Expand Down

0 comments on commit 54b95cb

Please sign in to comment.