[erlang-questions] Building a C port

Michael Truog mjtruog@REDACTED
Sat Oct 15 03:05:54 CEST 2011


Answers below:

On 10/14/2011 02:53 PM, Tom Burdick wrote:
> I'm looking to wrap libsamplerate and am looking for some advice on
> how to go about it.
>
> I can't use NIF or port driver as libsamplerate is GPL. NIF or a port
> driver don't seem to be the right solution anyways as libsamplerate
> may take awhile to do some work and report back.
>
> So I'm left thinking either a C port or a C node would be best, I'm
> leaning towards a C port implementation.
>
> The C port example however as it shows running gcc with -I and -L
> flags pointing to a particular erlang install. I'd like to make my
> port portable so that it can compile on different machines with
> possible different versions of erlang without having to always specify
> where erlang is installed, or even worse where erl_interface is
> located.
>
> Do people use autotools for this? Is there a project template that
> uses autotools for this?

Some people use autotools for this.  I have within CloudI, so there is an example there:
https://github.com/okeuday/CloudI/blob/master/src/configure.ac

You will notice that I am using "AC_ERLANG_CHECK_LIB([erl_interface])".  That configuration is probably more complex than what you want, but it does integrate with rebar in a way where rebar is built during the configuration.  That way you don't need a random rebar binary in your source tree (from an unknown Erlang version!).

I also have GEPD (https://github.com/okeuday/generic-erlang-port--driver-) which could allow you to switch between port and port_driver based on "whether you had permission to from the software author", or something like that, so you don't violate the GPL.  Please keep in mind I am not a lawyer, nor am I giving you legal advice.

> Could I use rebar instead?

Yes, you might be able to use rebar for doing this, but rebar integration with C/C++ port/port_driver/nif is both minimal and ad-hoc.  So, you won't have something flexible like autotools where you can use macros to add extra checking, if you need it.  Rebar integration should work for a simple case where you don't case as much about where the various executables are coming from and where the output files are going.

Good luck,
Michael




More information about the erlang-questions mailing list