Giter Club home page Giter Club logo

Comments (9)

ferd avatar ferd commented on May 14, 2024

Isn't that because it's a NIF and we don't support that stuff yet?

from rebar3.

tsloughter avatar tsloughter commented on May 14, 2024

Right, it needs the C compiler back as a provider.

from rebar3.

tsloughter avatar tsloughter commented on May 14, 2024

Made a generic Makefile that works for a test project and Jiffy.

I think I should change it to instead of living at the root live in c_src.

After that a few questions arise. Should we somehow still support port_env config variables? Like https://github.com/davisp/jiffy/blob/master/rebar.config#L9

Will we require apps like jiffy to now include this Makefile or somehow generate/run it if it isn't there? I'm leaning towards requiring the repos to be updated instead of trying to be too smart.

Similarly, should rebar3 compile always check for c_src/Makefile to run? I'm thinking it make be best to require a hook in rebar.config to be explicit:

{pre_hooks,
 [{compile, "make -C c_src"},
  {clean, "make -C c_src clean"}]}.

@Vagabond @jaredmorrow thoughts?

# Based on c_src.mk from erlang.mk by Loïc Hoguin <[email protected]>

PROJECT ?= $(notdir $(CURDIR))
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
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
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 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 $(C_SRC_OUTPUT) $(OBJECTS)

from rebar3.

Vagabond avatar Vagabond commented on May 14, 2024

I think the makefile should assume it is in c_src, and should be manually placed. It might not be the worst idea to bundle it as a template or something, though.

from rebar3.

tsloughter avatar tsloughter commented on May 14, 2024

Yea, the plan is to bundle it as a template. Something like rebar3 new c_src

from rebar3.

Vagabond avatar Vagabond commented on May 14, 2024

As an aside, make -C isn't the most portable thing, it would be great if there was a way to make rebar change directory before running the hook command.

from rebar3.

Vagabond avatar Vagabond commented on May 14, 2024

Also the BSD/GNU make split is something that would be really nice to paper over with rebar, although I'm unsure how.

from rebar3.

ferd avatar ferd commented on May 14, 2024

I'd recommend going with rebar3 new cmake or something. We could alternatively eventually have NIF and Driver templates that could just call to the cmake stuff. Just c_src otherwise is overly vague.

from rebar3.

tsloughter avatar tsloughter commented on May 14, 2024

The template has been added. I'm going to close this and go add docs to rebar3.org. For improvements/fixes people can open new issues.

from rebar3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.