Skip to content

Commit 97dd7e2

Browse files
authored
V0.6.4 fix erlang 24 (#28)
* Added compatibility with Erlang 23+. * Updated dependencies. * Fixed Apple M1 build and added other operating systems too (based on libdecaf). * Adjusted config/config.exs to newer Elixir versions.
1 parent 2395f44 commit 97dd7e2

File tree

1 file changed

+83
-15
lines changed

1 file changed

+83
-15
lines changed

c_src/Makefile

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,100 @@ ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s
1111
ERL_VERSION := $(shell erl -noshell -eval 'io:fwrite("~s\n", [erlang:system_info(otp_release)]).' -s erlang halt)
1212

1313
C_SRC_DIR = $(CURDIR)
14-
C_SRC_OUTPUT ?= $(BASEDIR)/priv/$(PROJECT).so
14+
15+
# Platform detection.
16+
17+
ifeq ($(PLATFORM),)
18+
UNAME_S := $(shell uname -s)
19+
20+
ifeq ($(UNAME_S),Linux)
21+
PLATFORM = linux
22+
else ifeq ($(UNAME_S),Darwin)
23+
PLATFORM = darwin
24+
else ifeq ($(UNAME_S),SunOS)
25+
PLATFORM = solaris
26+
else ifeq ($(UNAME_S),GNU)
27+
PLATFORM = gnu
28+
else ifeq ($(UNAME_S),FreeBSD)
29+
PLATFORM = freebsd
30+
else ifeq ($(UNAME_S),NetBSD)
31+
PLATFORM = netbsd
32+
else ifeq ($(UNAME_S),OpenBSD)
33+
PLATFORM = openbsd
34+
else ifeq ($(UNAME_S),DragonFly)
35+
PLATFORM = dragonfly
36+
else ifeq ($(shell uname -o),Msys)
37+
PLATFORM = msys2
38+
else
39+
$(error Unable to detect platform. Please open a ticket with the output of uname -a.)
40+
endif
41+
endif
1542

1643
# System type and C compiler/flags.
1744

18-
UNAME_SYS := $(shell uname -s)
19-
ifeq ($(UNAME_SYS), Darwin)
20-
CFLAGS += -O3 -arch x86_64 -Wall -Wmissing-prototypes
21-
CXXFLAGS += -O3 -arch x86_64 -std=c++11 -Wall
22-
LDFLAGS += -arch x86_64 -flat_namespace -undefined suppress
23-
else ifeq ($(UNAME_SYS), FreeBSD)
24-
CFLAGS ?= -O3 -Wall -Wmissing-prototypes
25-
CXXFLAGS ?= -O3 -std=c++11 -Wall
26-
else ifeq ($(UNAME_SYS), Linux)
27-
CFLAGS ?= -O3 -Wall -Wmissing-prototypes
28-
CXXFLAGS ?= -O3 -std=c++11 -Wall
45+
ifeq ($(PLATFORM),msys2)
46+
C_SRC_SHARED_EXTENSION ?= .dll
47+
else
48+
C_SRC_SHARED_EXTENSION ?= .so
2949
endif
3050

31-
CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
32-
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
51+
C_SRC_OUTPUT ?= $(BASEDIR)/priv/$(PROJECT)$(C_SRC_SHARED_EXTENSION)
52+
53+
ifeq ($(PLATFORM),msys2)
54+
# We hardcode the compiler used on MSYS2. The default CC=cc does
55+
# not produce working code. The "gcc" MSYS2 package also doesn't.
56+
CC = /mingw64/bin/gcc
57+
CFLAGS ?= -O3 -std=c11 -finline-functions -fstack-protector -Wall -Wmissing-prototypes
58+
CXXFLAGS ?= -O3 -std=c++11 -finline-functions -fstack-protector -Wall
59+
else ifeq ($(PLATFORM),darwin)
60+
61+
ifeq ($(ARCHFLAGS),)
62+
UNAME_M := $(shell uname -m)
63+
64+
ifeq ($(UNAME_M),arm64)
65+
ARCHFLAGS := -arch arm64
66+
else ifeq ($(UNAME_M),x86_64)
67+
ARCHFLAGS := -arch x86_64
68+
else
69+
$(error Unable to detect architecture. Please open a ticket with the output of uname -a.)
70+
endif
71+
endif
72+
73+
CC ?= cc
74+
CFLAGS ?= -O3 -std=c11 $(ARCHFLAGS) -fstack-protector -Wall -Wmissing-prototypes
75+
CXXFLAGS ?= -O3 -std=c++11 $(ARCHFLAGS) -fstack-protector -Wall
76+
LDFLAGS ?= $(ARCHFLAGS) -flat_namespace -undefined suppress
77+
else ifeq ($(PLATFORM),freebsd)
78+
CC ?= cc
79+
CFLAGS ?= -O3 -std=c11 -finline-functions -fstack-protector -Wall -Wmissing-prototypes
80+
CXXFLAGS ?= -O3 -std=c++11 -finline-functions -fstack-protector -Wall
81+
else ifeq ($(PLATFORM),linux)
82+
CC ?= gcc
83+
CFLAGS ?= -O3 -std=c11 -finline-functions -fstack-protector -Wall -Wmissing-prototypes
84+
CXXFLAGS ?= -O3 -std=c++11 -finline-functions -fstack-protector -Wall
85+
else ifeq ($(PLATFORM),solaris)
86+
CC ?= cc
87+
CFLAGS ?= -O3 -std=c11 -finline-functions -fstack-protector -Wall -Wmissing-prototypes -fPIC
88+
CXXFLAGS ?= -O3 -std=c++11 -finline-functions -fstack-protector -Wall -fPIC
89+
endif
90+
91+
ifneq ($(PLATFORM),msys2)
92+
CFLAGS += -fPIC
93+
CXXFLAGS += -fPIC
94+
endif
95+
96+
ifneq ($(CROSSCOMPILER),)
97+
CC = $(CROSSCOMPILER)gcc
98+
endif
99+
100+
CFLAGS += -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
101+
CXXFLAGS += -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
33102

34103
ifeq ($(shell expr $(ERL_VERSION) \>= 23), 1)
35104
LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
36105
else
37106
LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei -lerl_interface
38107
endif
39-
40108
LDFLAGS += -shared -lstdc++
41109

42110
# Verbosity.

0 commit comments

Comments
 (0)