blob: 90f079f258f4a712825d64ddc42b95ca23dac356 [file] [log] [blame]
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% Licensed under the Apache License, Version 2.0 (the "License"); you may not
%% use this file except in compliance with the License. You may obtain a copy of
%% the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
%% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
%% License for the specific language governing permissions and limitations under
%% the License.
Arch = erlang:system_info(system_architecture),
ICUConfig = fun(Args) ->
{0, Value} = eunit_lib:command("icu-config " ++ Args),
[C||C <- Value, C =/= $\n]
end,
GetFlag = fun(Name, Args) ->
case os:getenv(Name) of
false -> ICUConfig(Args);
Val -> Val
end
end,
GetFlag1 = fun(Name, Default) ->
case os:getenv(Name) of
false -> Default;
Val -> Val
end
end,
BuildStatic = os:getenv("COUCHDB_STATIC") =:= "1" andalso
os:getenv("USE_STATIC_ICU") =:= "1",
IsDarwin = case os:type() of
{unix, darwin} -> true;
_ -> false
end,
IsWindows = case os:type() of
{win32, nt} -> true;
_ -> false
end,
UseSystemIcu = IsDarwin andalso os:getenv("USE_STATIC_ICU") /= "1",
PortEnv = case {UseSystemIcu, BuildStatic, IsWindows} of
{true, _, false} ->
CFLAGS = GetFlag1("ICU_CFLAGS",
"-Iplatform/osx/icu -I/usr/include -fPIC"),
LDFLAGS = GetFlag1("ICU_LDFLAGS",
"-lpthread -lm -licucore -lstdc++ -L/usr/lib " ++
"$DRV_LDFLAGS -fPIC"),
[
{"CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
{"LDFLAGS", LDFLAGS}
];
{_, true, false} ->
CFLAGS = GetFlag1("ICU_CFLAGS", "-I.libs/icu/include"),
LDFLAGS = GetFlag1("ICU_LDFLAGS", ".libs/icu/lib/libicui18n.a " ++
".libs/icu/lib/libicuuc.a " ++
".libs/icu/lib/libicudata.a"),
[
{"DRV_CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
{"DRV_LDFLAGS", "-lstdc++ -fPIC $DRV_LDFLAGS " ++ LDFLAGS},
{"CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
{"LDFLAGS", "-lstdc++ -fPIC $DRV_LDFLAGS " ++ LDFLAGS}
];
{_, true, true} ->
throw("Static builds not supported on Windows.");
{_, false, false} ->
ICUCFLAGS = GetFlag("ICU_CFLAGS", "--cflags"),
ICUCXXFLAGS = GetFlag("ICU_CXXFLAGS", "--cxxflags"),
ICULDFLAGS = GetFlag("ICU_LDFLAGS", "--ldflags"),
ICUINCPATH = GetFlag("ICU_INCPATH", "--cppflags-searchpath"),
[
{"CFLAGS", ICUCFLAGS ++ " $CFLAGS " ++ ICUINCPATH},
{"CXXFLAGS", ICUCXXFLAGS ++ " $CXXFLAGS " ++ ICUINCPATH},
{"LDFLAGS", ICULDFLAGS ++ " $LDFLAGS"}
];
{_, false, true} ->
ICUCFLAGS = "",
ICUCXXFLAGS = "",
ICUINCPATH = "/I.libs\\icu\\include",
ICULDFLAGS = ".libs\\icu\\lib\\icuin.lib " ++
".libs\\icu\\lib\\icuuc.lib " ++
".libs\\icu\\lib\\icudt.lib",
[
{"CFLAGS", ICUCFLAGS ++ " $CFLAGS " ++ ICUINCPATH},
{"CXXFLAGS", ICUCXXFLAGS ++ " $CXXFLAGS " ++ ICUINCPATH},
{"LDFLAGS", ICULDFLAGS ++ " $LDFLAGS"}
]
end,
PortInfo = [{port_env, PortEnv},
{port_specs, [
{filename:join(["priv", Arch, "couch_collate.so"]),
["c_src/*.c"]}]},
{pre_hooks, [
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
compile, "./build_icu.sh"},
{"(win32|win64)", compile,
"powershell ./build_icu.ps1"}
]},
{post_hooks, [
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
clean, "./build_icu.sh clean"},
{"(win32|win64)", clean,
"powershell ./build_icu.ps1 -clean"}
]}
],
lists:keymerge(1,lists:keysort(1, PortInfo), lists:keysort(1, CONFIG)).