Skip to content

Commit

Permalink
Upgrade to rebar3
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Paradise <marc@chef.io>
  • Loading branch information
Marc Paradise committed Oct 17, 2016
1 parent 434f87e commit ee9c0ec
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
priv/
c_src/*.o
ebin/
_build/
.rebar
18 changes: 12 additions & 6 deletions Makefile
@@ -1,10 +1,16 @@
all:
@./rebar compile
all: compile dialyzer

compile:
@./rebar3 compile

dialyzer:
@./rebar3 dialyzer

clean:
@./rebar clean
$(if $(wildcard ebin/), rmdir ebin/)
$(if $(wildcard priv/), rmdir priv/)
@./rebar3 clean
$(if $(wildcard _build/), rm -rf _build/)
$(if $(wildcard ebin/), rm -rf ebin/)
$(if $(wildcard priv/), rm -rf priv/)

run: all
run: compile
@./run.escript
74 changes: 74 additions & 0 deletions c_src/Makefile
@@ -0,0 +1,74 @@
# 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(\"~s/erts-~s/include/\", [code:root_dir(), erlang:system_info(version)]).")
ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s\", [code:lib_dir(erl_interface, include)]).")
ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s\", [code:lib_dir(erl_interface, lib)]).")

C_SRC_DIR = $(CURDIR)
C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).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 -Wmissing-prototypes
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 -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)
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)

LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei -lncurses
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) -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.
12 changes: 8 additions & 4 deletions rebar.config
@@ -1,7 +1,11 @@

{erl_opts, [debug_info]}.
{deps, []}.

{port_env, [{"LDFLAGS", "$LDFLAGS -lncurses"}]}.
{pre_hooks,
[{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd)", compile, "make -C c_src"}]}.
{post_hooks,
[{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(freebsd)", clean, "make -C c_src clean"}]}.

{port_specs, [
{"priv/encurses.so", ["c_src/encurses.c"]}
]}.
1 change: 1 addition & 0 deletions rebar.lock
@@ -0,0 +1 @@
[].
Binary file added rebar3
Binary file not shown.
2 changes: 1 addition & 1 deletion run.escript
@@ -1,4 +1,4 @@
#!/usr/bin/env escript
%%! -noinput -pa ./ebin +A 10
%%! -noinput -pa ./ebin -pa _build/default/lib/encurses/ebin +A 10
-include_lib("include/encurses.hrl").
main(_) -> encurses_demo:go().

0 comments on commit ee9c0ec

Please sign in to comment.