Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some portability improvements #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions c_src/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

UNAME=$(shell uname)

ifeq ($(UNAME),Darwin)
SHLIB_CFLAGS=-fPIC -bundle -flat_namespace -undefined suppress
else
SHLIB_CFLAGS=-fPIC -shared
endif

CFLAGS +=-fPIC -I. $(shell erl -noinput -eval 'io:format("-I~s -I~s/erts-~s/include", [code:lib_dir(erl_interface, include), code:root_dir(), erlang:system_info(version)]), halt(0).')
LDFLAGS +=$(shell erl -noinput -eval 'io:format("-L~s", [code:lib_dir(erl_interface, lib)]), halt(0).')

all: ../priv/lib/gen_socket.so

clean:
rm -f ../priv/lib/*.so
rm -f *.o

../priv/lib/gen_socket.so: gen_socket.o
(test -d ../priv/lib || mkdir -p ../priv/lib)
$(CC) $(LDFLAGS) $(SHLIB_CFLAGS) -lei -lerl_interface gen_socket.o -o ../priv/lib/gen_socket.so
16 changes: 7 additions & 9 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
CFLAGS +=-fPIC -I. $(shell erl -noinput -eval 'io:format("-I~s -I~s/erts-~s/include", [code:lib_dir(erl_interface, include), code:root_dir(), erlang:system_info(version)]), halt(0).')
# a stub makefile for BSD make.
# just redirect to GNU make, which is commonly available as "gmake".

all: ../priv/lib/gen_socket.so
TARGETS=all clean

clean:
rm -f ../priv/lib/*.so
rm -f *.o

../priv/lib/gen_socket.so: gen_socket.o
(test -d ../priv/lib || mkdir -p ../priv/lib)
$(CC) $(LDFLAGS) -fPIC -shared -lei -lerl_interface gen_socket.o -o ../priv/lib/gen_socket.so
.for T in ${TARGETS}
${T}:
@gmake ${T}
.endfor
7 changes: 7 additions & 0 deletions c_src/gen_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <sys/socket.h>

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

#include "erl_nif.h"
#include "erl_driver.h"
#include "gen_socket.h"
Expand Down