diff options
Diffstat (limited to 'src/aclocal.m4')
-rw-r--r-- | src/aclocal.m4 | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/aclocal.m4 b/src/aclocal.m4 index eba78903a..09a692199 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -46,14 +46,44 @@ AC_DEFUN(AM_WITH_ERLANG, -module(conftest). -author('alexey@sevcom.net'). - + -export([[start/0]]). - + start() -> - EIDirS = code:lib_dir("erl_interface") ++ "\n", - RootDirS = code:root_dir() ++ "\n", - file:write_file("conftest.out", list_to_binary(EIDirS ++ RootDirS)), - halt(). + EIDirS = code:lib_dir("erl_interface") ++ "\n", + EILibS = libpath("erl_interface") ++ "\n", + RootDirS = code:root_dir() ++ "\n", + file:write_file("conftest.out", list_to_binary(EIDirS ++ EILibS ++ RootDirS)), + halt(). + +%% return physical architecture based on OS/Processor +archname() -> + ArchStr = erlang:system_info(system_architecture), + case os:type() of + {win32, _} -> "windows"; + {unix,UnixName} -> + Specs = string:tokens(ArchStr,"-"), + Cpu = case lists:nth(2,Specs) of + "pc" -> "x86"; + _ -> hd(Specs) + end, + atom_to_list(UnixName) ++ "-" ++ Cpu; + _ -> "generic" + end. + +%% Return arch-based library path or a default value if this directory +%% does not exist +libpath(App) -> + PrivDir = code:priv_dir(App), + ArchDir = archname(), + LibArchDir = filename:join([[PrivDir,"lib",ArchDir]]), + case file:list_dir(LibArchDir) of + %% Arch lib dir exists: We use it + {ok, _List} -> LibArchDir; + %% Arch lib dir does not exist: Return the default value + %% ({error, enoent}): + _Error -> code:lib_dir("erl_interface") ++ "/lib" + end. _EOF @@ -69,11 +99,15 @@ _EOF AC_MSG_ERROR([erlang program was not properly executed, (conftest.out was not produced)]) fi + # First line ERLANG_EI_DIR=`cat conftest.out | head -n 1` + # Second line + ERLANG_EI_LIB=`cat conftest.out | head -n 2 | tail -n 1` + # Third line ERLANG_DIR=`cat conftest.out | tail -n 1` ERLANG_CFLAGS="-I$ERLANG_EI_DIR/include -I$ERLANG_DIR/usr/include" - ERLANG_LIBS="-L$ERLANG_EI_DIR/lib -lerl_interface -lei" + ERLANG_LIBS="-L$ERLANG_EI_LIB -lerl_interface -lei" AC_SUBST(ERLANG_CFLAGS) AC_SUBST(ERLANG_LIBS) |