diff --git a/.gitignore b/.gitignore index 6666f22..16cb905 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,25 @@ .eunit deps erln8.config + +.rebar3 +_* +.eunit +*.o +*.beam +*.plt +*.swp +*.swo +.erlang.cookie +ebin +log +erl_crash.dump +.rebar +_rel +_deps +_plugins +_tdeps +logs +c_src/*.o +c_src/env.mk +priv diff --git a/Makefile b/Makefile deleted file mode 100644 index 025486e..0000000 --- a/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -REBAR?=./rebar - - -all: build - - -clean: - $(REBAR) clean - rm -rf logs - rm -rf .eunit - rm -f test/*.beam - - -distclean: clean - git clean -fxd - - -devmarker: - @touch .jiffy.dev - - -depends: devmarker - @if test ! -d ./deps/proper; then \ - $(REBAR) get-deps; \ - fi - - -build: depends - $(REBAR) compile - - -eunit: - $(REBAR) eunit skip_deps=true - - -check: build eunit - - -%.beam: %.erl - erlc -o test/ $< - - -.PHONY: all clean distclean depends build etap eunit check diff --git a/c_src/Makefile b/c_src/Makefile new file mode 100755 index 0000000..1ce89f9 --- /dev/null +++ b/c_src/Makefile @@ -0,0 +1,61 @@ +ERL ?= erl +BASEDIR=$(CURDIR) +PRIVDIR=$(BASEDIR)/../priv + +NIF_DIR=$(BASEDIR) +NIF_ENV=$(BASEDIR)/env.mk + +NIF_SOURCES := $(shell find $(NIF_DIR) -type f \( -name "*.c" -o -name "*.cc" \)) +NIF_OBJS=$(addsuffix .o, $(basename $(NIF_SOURCES))) +NIF_SO=$(PRIVDIR)/jiffy.so + + +UNAME_SYS := $(shell uname -s) +ifeq ($(UNAME_SYS), Darwin) + CC ?= cc + CFLAGS ?= -O3 -std=c99 -arch x86_64 -Wall -Wmissing-prototypes + LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress +else ifeq ($(UNAME_SYS), FreeBSD) + CC ?= cc + CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -finline-functions -Wall +else ifeq ($(UNAME_SYS), Linux) + CC ?= gcc + CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -finline-functions -Wall +endif + +CFLAGS += -fPIC -I$(ERTS_INCLUDE_DIR) -I$(ERL_INTERFACE_INCLUDE_DIR) +LDLIBS += -L$(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei +LDFLAGS += -shared + + + +all: $(NIF_ENV) $(NIF_SO) + +clean: + @rm -rf $(NIF_SO) $(NIF_OBJS) + +distclean: clean + @rm -rf $(NIF_ENV) + +$(NIF_SO): $(NIF_OBJS) + @mkdir -p $(PRIVDIR) + $(CC) $(NIF_OBJS) $(LDFLAGS) $(LDLIBS) -o $(NIF_SO) + +%.o: %.c + echo $(NIF_SOURCES) + @$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +$(NIF_ENV): + @$(ERL) -eval "file:write_file(\"$(NIF_ENV)\", \ + io_lib:format( \ + \"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \ + \"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \ + \"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \ + [code:root_dir(), erlang:system_info(version), \ + code:lib_dir(erl_interface, include), \ + code:lib_dir(erl_interface, lib)])), \ + halt()." + +-include $(NIF_ENV) diff --git a/rebar b/rebar deleted file mode 100755 index 36ef011..0000000 Binary files a/rebar and /dev/null differ diff --git a/rebar.config b/rebar.config index 3d725b6..109404e 100644 --- a/rebar.config +++ b/rebar.config @@ -1,33 +1,3 @@ -{port_specs, [ - {"priv/jiffy.so", [ - "c_src/*.c", - "c_src/*.cc", - "c_src/double-conversion/*.cc" - ]} -]}. - -{port_env, [ - {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)", - "CFLAGS", "$CFLAGS -g -Wall -Werror -O3 -fno-strict-aliasing"}, - {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)", - "CXXFLAGS", "$CXXFLAGS -g -Wall -Werror -O3"}, - - {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)", - "LDFLAGS", "$LDFLAGS -lstdc++"}, - - %% OS X Leopard flags for 64-bit - {"darwin9.*-64$", "CXXFLAGS", "-m64"}, - {"darwin9.*-64$", "LDFLAGS", "-arch x86_64"}, - - %% OS X Snow Leopard flags for 32-bit - {"darwin10.*-32$", "CXXFLAGS", "-m32"}, - {"darwin10.*-32$", "LDFLAGS", "-arch i386"}, - - %% This will merge into basho/rebar/rebar.config eventually - {"win32", "CFLAGS", "/Wall /DWIN32 /D_WINDOWS /D_WIN32 /DWINDOWS"}, - {"win32", "CXXFLAGS", "-g -Wall -O3"} -]}. - {erl_opts, [ {platform_define, "R1(1|2|3|4|5|6)", 'JIFFY_NO_MAPS'} ]}. @@ -43,3 +13,9 @@ rebar_gdb_plugin ]}. +{pre_hooks, [{"(linux|darwin|solaris)", compile, "make -C c_src"}, + {"(freebsd|netbsd|openbsd)", compile, "gmake -C c_src"}]}. + +{post_hooks, [{"(linux|darwin|solaris)", clean, "make -C c_src clean"}, + {"(freebsd|netbsd|openbsd)", compile, "gmake -C c_src clean"}]}. + diff --git a/rebar.config.script b/rebar.config.script deleted file mode 100644 index e5f561d..0000000 --- a/rebar.config.script +++ /dev/null @@ -1,37 +0,0 @@ -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -% Only include PropEr as a dependency when the JIFFY_DEV -% environment variable is defined. This allows downstream -% applications to avoid requiring PropEr. -% -% This script is based on the example provided with Rebar. - -ErlOpts = [{d, 'JIFFY_DEV'}], - -Proper = [ - {proper, ".*", {git, "git://github.com/manopapad/proper.git", "master"}} -], - -ConfigPath = filename:dirname(SCRIPT), -DevMarker = filename:join([ConfigPath, ".jiffy.dev"]), - -case filelib:is_file(DevMarker) orelse os:getenv("TRAVIS") == "true" of - true -> - % Don't override existing dependencies - Config0 = case lists:keyfind(deps, 1, CONFIG) of - false -> - CONFIG ++ [{deps, Proper}]; - {deps, DepsList} -> - lists:keyreplace(deps, 1, CONFIG, {deps, DepsList ++ Proper}) - end, - Config1 = case lists:keyfind(erl_opts, 1, Config0) of - false -> - Config0 ++ [{erl_opts, ErlOpts}]; - {erl_opts, Opts} -> - NewOpts = {erl_opts, Opts ++ ErlOpts}, - lists:keyreplace(erl_opts, 1, Config0, NewOpts) - end; - false -> - CONFIG -end. diff --git a/test/jiffy_10_short_double_tests.erl b/test/jiffy_10_short_double_tests.erl index d66e1ea..f9ef071 100644 --- a/test/jiffy_10_short_double_tests.erl +++ b/test/jiffy_10_short_double_tests.erl @@ -8,7 +8,7 @@ -include("jiffy_util.hrl"). -filename() -> "../test/cases/short-doubles.txt". +filename() -> "test/cases/short-doubles.txt". short_double_test_() ->