Skip to content

Commit c7d27fb

Browse files
authored
Merge pull request #64 from vinoski/otp23-fixes
Avoid erl_interface lib if nonexistent
2 parents c089345 + c0465b3 commit c7d27fb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ BELOW HERE BE DRAGONS
101101
%% * port_env - Erlang list of key/value pairs which will control
102102
%% the environment when running the compiler and linker.
103103
%% Variables set in the surrounding system shell are taken
104-
%% into consideration when expanding port_env.
104+
%% into consideration when expanding port_env. Note that
105+
%% for ERL_LDFLAGS, -lerl_interface is used for only those
106+
%% Erlang/OTP versions where it exists (those prior to
107+
%% version 23.0).
105108
%%
106109
%% By default, the following variables are defined:
107110
%% CC - C compiler

src/pc_port_env.erl

+11-3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ erts_dir() ->
198198
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
199199

200200
default_env() ->
201+
ErlInterfaceIncludeDir = erl_interface_dir(include),
202+
ErlInterfaceHeader = filename:join(ErlInterfaceIncludeDir, "erl_interface.h"),
203+
ErlInterfaceLibs = case filelib:is_file(ErlInterfaceHeader) of
204+
true -> ["erl_interface", "ei"];
205+
false -> ["ei"]
206+
end,
201207
Arch = os:getenv("REBAR_TARGET_ARCH"),
202208
Vsn = os:getenv("REBAR_TARGET_ARCH_VSN"),
203209
[
@@ -236,12 +242,13 @@ default_env() ->
236242

237243
{"ERL_CFLAGS", lists:concat(
238244
[
239-
" -I\"", erl_interface_dir(include),
245+
" -I\"", ErlInterfaceIncludeDir,
240246
"\" -I\"", filename:join(erts_dir(), "include"),
241247
"\" "
242248
])},
243249
{"ERL_EI_LIBDIR", lists:concat(["\"", erl_interface_dir(lib), "\""])},
244-
{"ERL_LDFLAGS" , " -L$ERL_EI_LIBDIR -lerl_interface -lei"},
250+
{"ERL_LDFLAGS" , lists:concat([" -L$ERL_EI_LIBDIR"] ++
251+
[" -l"++EiLib || EiLib <- ErlInterfaceLibs])},
245252
{"ERLANG_ARCH" , rebar_api:wordsize()},
246253
{"ERLANG_TARGET", rebar_api:get_arch()},
247254

@@ -293,7 +300,8 @@ default_env() ->
293300
"$LINKER $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS /OUT:$PORT_OUT_FILE"},
294301
%% ERL_CFLAGS are ok as -I even though strictly it should be /I
295302
{"win32", "ERL_LDFLAGS",
296-
" /LIBPATH:$ERL_EI_LIBDIR erl_interface.lib ei.lib"},
303+
lists:concat([" /LIBPATH:$ERL_EI_LIBDIR "] ++
304+
[EiLib++".lib " || EiLib <- ErlInterfaceLibs])},
297305
{"win32", "DRV_CFLAGS", "/Zi /Wall $ERL_CFLAGS"},
298306
{"win32", "DRV_LDFLAGS", "/DLL $ERL_LDFLAGS"}
299307
].

0 commit comments

Comments
 (0)