-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (55 loc) · 1.68 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
# https://hexdocs.pm/nerves/environment-variables.html
# run with:
# mix compile
# mix clean
# https://www.erlang.org/doc/tutorial/nif.html
# compile flags at the end
SRCDIR = src
DSTDIR = priv
UNAME := $(shell uname -s)
MIX_TARGET ?= host
C_CFLAGS = -g -O3 -Werror -pedantic -Wall -Wextra -D_XOPEN_SOURCE=700
C_LDFLAGS = -fPIC
VT_TARGET = $(DSTDIR)/vt
VT_SOURCES = $(SRCDIR)/vt.c
VT_CFLAGS = $(C_CFLAGS)
VT_LDFLAGS= $(C_LDFLAGS)
PTS_TARGET = $(DSTDIR)/pts
PTS_SOURCES = $(SRCDIR)/pts.c
PTS_CFLAGS = $(C_CFLAGS)
PTS_LDFLAGS= $(C_LDFLAGS)
PTM_TARGET = $(DSTDIR)/ptm
PTM_SOURCES = $(SRCDIR)/ptm.c
PTM_CFLAGS = $(C_CFLAGS)
PTM_LDFLAGS= $(C_LDFLAGS)
NIF_TARGET = $(DSTDIR)/nif.so
NIF_SOURCES = $(SRCDIR)/nif.c
NIF_CFLAGS = $(C_CFLAGS) -I$(ERTS_INCLUDE_DIR)
NIF_LDFLAGS = $(C_LDFLAGS) -shared
ifeq ($(MIX_TARGET),host)
ifeq ($(UNAME),Darwin)
PTM_CFLAGS += -D_DARWIN_C_SOURCE
NIF_CFLAGS += -D_DARWIN_C_SOURCE
NIF_LDFLAGS = -undefined dynamic_lookup -dynamiclib
endif
endif
.PHONY: all clean post
all: $(VT_TARGET) $(PTS_TARGET) $(PTM_TARGET) $(NIF_TARGET) post
$(VT_TARGET): $(VT_SOURCES)
[ -d $(DSTDIR) ] || mkdir -p $(DSTDIR)
$(CC) $(VT_CFLAGS) $(VT_SOURCES) -o $@ $(VT_LDFLAGS)
$(PTS_TARGET): $(PTS_SOURCES)
[ -d $(DSTDIR) ] || mkdir -p $(DSTDIR)
$(CC) $(PTS_CFLAGS) $(PTS_SOURCES) -o $@ $(PTS_LDFLAGS)
$(PTM_TARGET): $(PTM_SOURCES)
[ -d $(DSTDIR) ] || mkdir -p $(DSTDIR)
$(CC) $(PTM_CFLAGS) $(PTM_SOURCES) -o $@ $(PTM_LDFLAGS)
$(NIF_TARGET): $(NIF_SOURCES)
[ -d $(DSTDIR) ] || mkdir -p $(DSTDIR)
$(CC) $(NIF_CFLAGS) $(NIF_SOURCES) -o $@ $(NIF_LDFLAGS)
# macos generates folders priv/TARGET.dSYM
post:
rm -fR $(DSTDIR)/*.dSYM
env | sort > Makefile.$(MIX_TARGET).env
clean:
rm -fR $(DSTDIR)/*