Skip to content

Commit

Permalink
Support building on windows (google#1)
Browse files Browse the repository at this point in the history
* Support building on windows

* Delete erlang.mk

* Fix travis-ci
  • Loading branch information
Gilbert authored and zmstone committed Mar 22, 2020
1 parent cd9001a commit 4a0da85
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 6,631 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ebin/
*.crashdump
_build/
rebar.lock
.erlang.mk
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ notifications:
email: false

otp_release:
- 18.1
- 17.4
- 21.3

script:
- make vsn-check
- make eunit
- make clean
- rebar compile
- make clean
- wget https://s3.amazonaws.com/rebar3/rebar3
- chmod 755 rebar3
- ./rebar3 compile
Expand Down
28 changes: 8 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
PROJECT = snappyer
PROJECT_DESCRIPTION = Snappy as nif for Erlang
PROJECT_VERSION = 1.2.4
all: compile

SP = 2
compile:
@rebar compile

CPPFLAGS = -Wno-sign-compare -Wno-unused-function
LDFLAGS += -shared -lstdc++
tests:
@rebar eunit

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CXXFLAGS = -O3 -arch x86_64
LDFLAGS += -arch x86_64 -flat_namespace -undefined suppress
endif
clean:
@rebar clean

ERLC_OPTS = -Werror +warn_unused_vars +warn_shadow_vars +warn_unused_import +warn_obsolete_guard +debug_info

include erlang.mk

vsn-check:
$(verbose) ./vsn-check.sh $(PROJECT_VERSION)

hex-publish: distclean
rebar3 hex publish
.PHONY: clean compile tests
74 changes: 74 additions & 0 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]>

CURDIR := $(shell pwd)
BASEDIR := $(abspath $(CURDIR)/..)

PROJECT ?= $(notdir $(BASEDIR))
PROJECT := erlang-sha3

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
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)
5 changes: 5 additions & 0 deletions c_src/snappy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif


namespace snappy {

Expand Down
Loading

0 comments on commit 4a0da85

Please sign in to comment.