This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
81 lines (64 loc) · 2.02 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Makefile for building the NIF
#
# Makefile targets:
#
# all/install build and install the NIF
# clean clean build products and intermediates
#
# Variables to override:
#
# MIX_APP_PATH path to the build directory
# MIX_ENV Mix build environment - "test" forces use of the stub
#
# CXX C++ compiler
# CROSSCOMPILE crosscompiler prefix, if any
# CXXFLAGS compiler flags for compiling all C++ files
# ERL_CXXFLAGS additional compiler flags for files using Erlang header files
# ERL_EI_INCLUDE_DIR include path to ei.h (Required for crosscompile)
# ERL_EI_LIBDIR path to libei.a (Required for crosscompile)
# LDFLAGS linker flags for linking all binaries
# ERL_LDFLAGS additional linker flags for projects referencing Erlang libraries
PREFIX = $(MIX_APP_PATH)/priv
BUILD = $(MIX_APP_PATH)/obj
NIF = $(PREFIX)/libjason.so
CXXFLAGS ?= -O2 -Wall -Wextra -std=c++2a -fno-exceptions
# Check that we're on a supported build platform
ifeq ($(CROSSCOMPILE),)
# Not crosscompiling, so check that we're on Linux.
ifneq ($(shell uname -s),Linux)
LDFLAGS += -undefined dynamic_lookup -dynamiclib
else
LDFLAGS += -fPIC -shared
CXXFLAGS += -fPIC
endif
else
# Crosscompiled build
LDFLAGS += -fPIC -shared
CXXFLAGS += -fPIC
endif
ifeq ($(MIX_ENV),test)
CXXFLAGS += -DMIX_TEST
endif
# Set Erlang-specific compile and linker flags
ERL_CXXFLAGS ?= -I$(ERL_EI_INCLUDE_DIR)
ERL_LDFLAGS ?= -L$(ERL_EI_LIBDIR) -lei
SRC = c_src/jason.cxx
HEADERS =$(wildcard c_src/*.h)
OBJ = $(SRC:c_src/%.cxx=$(BUILD)/%.o)
all: install
install: $(PREFIX) $(BUILD) $(NIF)
$(OBJ): $(HEADERS) Makefile
$(BUILD)/%.o: c_src/%.cxx
@echo " CXX $(notdir $@)"
$(CXX) -c $(ERL_CXXFLAGS) $(CXXFLAGS) -o $@ $<
$(NIF): $(OBJ)
@echo " LD $(notdir $@)"
$(CXX) -o $@ $(ERL_LDFLAGS) $(LDFLAGS) $^
$(PREFIX) $(BUILD):
mkdir -p $@
c_src/jason.cxx: c_src/unicode.hh
clean:
$(RM) $(NIF) $(OBJ)
.PHONY: all clean install
# Don't echo commands unless the caller exports "V=1"
${V}.SILENT: