Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
c_src/*.o
c_src/*/*.o
.eunit
ebin/
priv/*.so
_build
rebar.lock
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
all:
./rebar -v get-deps
./rebar -v compile
./rebar3 compile

clean:
./rebar -v delete-deps
./rebar -v clean
./rebar3 clean

clean-deps: clean
rm -rf _build

eunit:
./rebar -v eunit
./rebar3 eunit
82 changes: 82 additions & 0 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Based on c_src.mk from erlang.mk by Loic Hoguin <essen@ninenines.eu>

CURDIR := $(shell pwd)
BASEDIR := $(abspath $(CURDIR)/..)

PROJECT ?= $(notdir $(BASEDIR))
PROJECT := $(strip $(PROJECT))

ERTS_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)]).")
ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)]).")
ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)]).")

C_SRC_DIR = $(CURDIR)
C_SRC_OUTPUT ?= $(CURDIR)/../priv/sha3_nifs.so

# System type and C compiler/flags.

UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall
CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
else ifeq ($(UNAME_SYS), FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall
CXXFLAGS ?= -O3 -finline-functions -Wall
else ifeq ($(UNAME_SYS), Linux)
CC ?= gcc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -lstdc++
endif

UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_ARCH), x86_64)
C_OPT_SRC_DIR := $(CURDIR)/opt64
else ifeq ($(UNAME_ARCH), i368)
C_OPT_SRC_DIR := $(CURDIR)/opt32
endif

CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)

LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
LDFLAGS += -shared

# Verbosity.

c_verbose_0 = @echo " C " $(?F);
c_verbose = $(c_verbose_$(V))

cpp_verbose_0 = @echo " CPP " $(?F);
cpp_verbose = $(cpp_verbose_$(V))

link_verbose_0 = @echo " LD " $(@F);
link_verbose = $(link_verbose_$(V))

SOURCES := $(shell find $(C_SRC_DIR) $(C_OPT_SRC_DIR) -maxdepth 1 -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))

COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

$(C_SRC_OUTPUT): $(OBJECTS)
@mkdir -p $(BASEDIR)/priv/
$(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)

%.o: %.c
$(COMPILE_C) $(OUTPUT_OPTION) $<

%.o: %.cc
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

%.o: %.C
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

%.o: %.cpp
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

clean:
@rm -f $(C_SRC_OUTPUT) $(OBJECTS)
Binary file removed rebar
Binary file not shown.
33 changes: 8 additions & 25 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,11 @@
{erl_opts, [warnings_as_errors]}.

{deps, [
{hex, ".*", {git, "git://github.com/b/hex", "HEAD"}}
]}.

{port_specs, [
{"-32-unix$", "priv/sha3_nifs.so", ["c_src/*.c", "c_src/opt32/*.c"]},
{"-64-unix$", "priv/sha3_nifs.so", ["c_src/*.c", "c_src/opt64/*.c"]}
]}.

{port_env, [
%% Make sure to link -lstdc++ on linux or solaris
{"(linux|solaris)", "CXXFLAGS", "-O2"},
{"(linux|solaris)", "LDFLAGS", "$LDFLAGS -lstdc++"},

%% OS X Leopard flags for 64-bit
{"darwin9\.*-64-unix", "CXXFLAGS", "-O2 -m64"},
{"darwin9\.*-64-unix", "LDFLAGS", "-arch x86_64 -lstdc++"},

%% OS X Snow Leopard flags for 32-bit
{"darwin1?\.*-32-unix", "CXXFLAGS", "-O2 -m32"},
{"darwin1?\.*-32-unix", "LDFLAGS", "-arch i386"},

%% OS X Snow Leopard/Lion flags for 64-bit
{"darwin1?\.*-64-unix", "CXXFLAGS", "-O2 -m64"},
{"darwin1?\.*-64-unix", "LDFLAGS", "-arch x86_64"}
]}.
{hex, ".*", {git, "https://github.com/b/hex.git", "HEAD"}}
]}.
{pre_hooks,
[{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd)", compile, "gmake -C c_src"}]}.
{post_hooks,
[{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(freebsd)", clean, "gmake -C c_src clean"}]}.
Binary file added rebar3
Binary file not shown.
2 changes: 1 addition & 1 deletion test/sha3_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parse_triples([Len, Msg, Md|Lines], Acc) ->

msgkat(Set, Bits, Fun) ->
{ok, Cwd} = file:get_cwd(),
Filename = filename:join([Cwd, "..", "test", "data", Set ++ "MsgKAT.zip"]),
Filename = filename:join([Cwd, "test", "data", Set ++ "MsgKAT.zip"]),
{ok, ZipHandle} = zip:zip_open(Filename, [memory]),
{ok, {_, Data}} = zip:zip_get(Set ++ "MsgKAT_" ++ integer_to_list(Bits) ++ ".txt", ZipHandle),
Lines = lists:filter(
Expand Down