Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
fix static build
When built statically the nif couldn't be loaded. This patch fix the
following:

- make sure that the patches are applied.
- fix LDFLAGS order

While I am here add a unitest to fix the lib.
  • Loading branch information
benoitc committed Feb 15, 2014
1 parent 8ecdb84 commit 985a7f80ca114738c4d108a0a95167a1c85c4985
Showing 7 changed files with 687 additions and 14 deletions.
@@ -0,0 +1,4 @@
ebin
t/*.beam
.dists
.libs
@@ -0,0 +1,28 @@
ERL ?= erl
ERLC ?= erlc
REBAR ?= rebar

all: compile

static:
@USE_STATIC_ICU="1" COUCHDB_STATIC="1" $(REBAR) compile


compile:
@$(REBAR) compile

clean:
@$(REBAR) clean
@rm -f t/*.beam

test:
@$(ERLC) -o t/ t/etap.erl
prove t/*.t

verbose-test:
@$(ERLC) -o t/ t/etap.erl
prove -v t/*.t

cover: test
@ERL_FLAGS="-pa ./ebin -pa ./t" \
$(ERL) -detached -noshell -eval 'etap_report:create()' -s init stop
@@ -85,7 +85,7 @@ build_icu()
$GUNZIP -c $DISTDIR/$ICU_DISTNAME | $TAR xf -

# apply patches
cd $STATICLIBS/icu
cd $STATICLIBS
for P in $PATCHES/icu/*.patch; do \
(patch -p0 -i $P || echo "skipping patch"); \
done
@@ -37,7 +37,6 @@ GetFlag1 = fun(Name, Default) ->
BuildStatic = os:getenv("COUCHDB_STATIC") =:= "1" andalso
os:getenv("USE_STATIC_ICU") =:= "1",


IsDarwin = case os:type() of
{unix, darwin} -> true;
_ -> false
@@ -59,13 +58,14 @@ PortEnv = case {UseSystemIcu, BuildStatic} of

{_, true} ->
CFLAGS = GetFlag1("ICU_CFLAGS", "-I.libs/icu/include"),
LDFLAGS = GetFlag1("ICU_LDFLAGS", "-lstdc++ -fPIC " ++
".libs/icu/lib/libicui18n.a " ++
".libs/icu/lib/libicuuc.a " ++
".libs/icu/lib/libicudata.a"),
LDFLAGS = GetFlag1("ICU_LDFLAGS", ".libs/icu/lib/libicui18n.a " ++
".libs/icu/lib/libicuuc.a " ++
".libs/icu/lib/libicudata.a"),
[
{"DRV_CFLAGS", "$DRV_CFLAGS " ++ CFLAGS ++ " -D BSD_SOURCE"},
{"DRV_LDFLAGS", "$DRV_LDFLAGS " ++ LDFLAGS}
{"DRV_CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
{"DRV_LDFLAGS", "-lstdc++ -fPIC $DRV_LDFLAGS " ++ LDFLAGS},
{"CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
{"LDFLAGS", "-lstdc++ -fPIC $DRV_LDFLAGS " ++ LDFLAGS}
];
{_, false} ->
ICUCFLAGS = GetFlag("ICU_CFLAGS", "--cflags"),
@@ -31,12 +31,8 @@ init() ->
end,
NumScheds = erlang:system_info(schedulers),
Arch = erlang:system_info(system_architecture),
(catch erlang:load_nif(filename:join([PrivDir, Arch, ?MODULE]),
NumScheds)),
case erlang:system_info(otp_release) of
"R13B03" -> true;
_ -> ok
end.
SoPath = filename:join([PrivDir, Arch, ?MODULE]),
erlang:load_nif(SoPath, NumScheds).

%% @doc compare 2 string, result is -1 for lt, 0 for eq and 1 for gt.
-spec collate(binary(), binary()) -> 0 | -1 | 1.
@@ -0,0 +1,33 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -pa ./ebin -pa ./t

% 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.

main(_) ->
etap:plan(2),
test(),
etap:end_tests().

test() ->
etap:is(
couch_collate:collate(<<"foo">>, <<"bar">>),
1,
"Can collate stuff"
),
etap:is(
couch_collate:collate(<<"A">>, <<"aa">>),
-1,
"Collate's non-ascii style."
),
ok.

0 comments on commit 985a7f8

Please sign in to comment.