-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
155 lines (133 loc) · 3.78 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Makefile for building the NIF
#
# Makefile targets:
#
# all build and install the NIF
# clean clean build products and intermediates
#
# Variables to override:
#
# MIX_APP_PATH path to the build directory
#
# CC The C compiler
# CROSSCOMPILE crosscompiler prefix, if any
# CFLAGS compiler flags for compiling all C files
# LDFLAGS linker flags for linking all binaries
# ERL_CFLAGS additional compiler flags for files using Erlang header files
# ERL_EI_INCLUDE_DIR include path to header files (Possibly required for crosscompile)
#
SRC = c_src/sqlite3_nif.c
CFLAGS = -I"$(ERTS_INCLUDE_DIR)"
ifeq ($(EXQLITE_USE_SYSTEM),)
SRC += c_src/sqlite3.c
CFLAGS += -Ic_src
else
ifneq ($(EXQLITE_SYSTEM_LDFLAGS),)
LDFLAGS += $(EXQLITE_SYSTEM_LDFLAGS)
else
# best attempt to link the system library
# if the user didn't supply it in the environment
LDFLAGS += -lsqlite3
endif
endif
ifneq ($(DEBUG),)
CFLAGS += -g
else
CFLAGS += -DNDEBUG=1 -O2
endif
KERNEL_NAME := $(shell uname -s)
PREFIX = $(MIX_APP_PATH)/priv
BUILD = $(MIX_APP_PATH)/obj
LIB_NAME = $(PREFIX)/sqlite3_nif.so
ARCHIVE_NAME = $(PREFIX)/sqlite3_nif.a
OBJ = $(SRC:c_src/%.c=$(BUILD)/%.o)
ifneq ($(CROSSCOMPILE),)
ifeq ($(CROSSCOMPILE), Android)
CFLAGS += -fPIC -Os -z global
LDFLAGS += -fPIC -shared -lm
else
CFLAGS += -fPIC -fvisibility=hidden
LDFLAGS += -fPIC -shared
endif
else
ifeq ($(KERNEL_NAME), Linux)
CFLAGS += -fPIC -fvisibility=hidden
LDFLAGS += -fPIC -shared
endif
ifeq ($(KERNEL_NAME), Darwin)
CFLAGS += -fPIC
LDFLAGS += -dynamiclib -undefined dynamic_lookup
endif
ifeq (MINGW, $(findstring MINGW,$(KERNEL_NAME)))
CFLAGS += -fPIC
LDFLAGS += -fPIC -shared
LIB_NAME = $(PREFIX)/sqlite3_nif.dll
endif
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD NetBSD))
CFLAGS += -fPIC
LDFLAGS += -fPIC -shared
endif
endif
# ########################
# COMPILE TIME DEFINITIONS
# ########################
# For more information about these features being enabled, check out
# --> https://sqlite.org/compile.html
CFLAGS += -DSQLITE_THREADSAFE=1
CFLAGS += -DSQLITE_USE_URI=1
CFLAGS += -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1
CFLAGS += -DSQLITE_DQS=0
CFLAGS += -DHAVE_USLEEP=1
# TODO: The following features should be completely configurable by the person
# installing the nif. Just need to have certain environment variables
# enabled to support them.
CFLAGS += -DALLOW_COVERING_INDEX_SCAN=1
CFLAGS += -DENABLE_FTS3_PARENTHESIS=1
CFLAGS += -DENABLE_LOAD_EXTENSION=1
CFLAGS += -DENABLE_SOUNDEX=1
CFLAGS += -DENABLE_STAT4=1
CFLAGS += -DENABLE_UPDATE_DELETE_LIMIT=1
CFLAGS += -DSQLITE_ENABLE_FTS3=1
CFLAGS += -DSQLITE_ENABLE_FTS4=1
CFLAGS += -DSQLITE_ENABLE_FTS5=1
CFLAGS += -DSQLITE_ENABLE_GEOPOLY=1
CFLAGS += -DSQLITE_ENABLE_MATH_FUNCTIONS=1
CFLAGS += -DSQLITE_ENABLE_RBU=1
CFLAGS += -DSQLITE_ENABLE_RTREE=1
CFLAGS += -DSQLITE_OMIT_DEPRECATED=1
CFLAGS += -DSQLITE_ENABLE_DBSTAT_VTAB=1
# Add any extra flags set in the environment
ifneq ($(EXQLITE_SYSTEM_CFLAGS),)
CFLAGS += $(EXQLITE_SYSTEM_CFLAGS)
endif
# Set Erlang-specific compile flags
ifeq ($(CC_PRECOMPILER_CURRENT_TARGET),armv7l-linux-gnueabihf)
ERL_CFLAGS ?= -I"$(PRECOMPILE_ERL_EI_INCLUDE_DIR)"
else
ERL_CFLAGS ?= -I"$(ERL_EI_INCLUDE_DIR)"
endif
ifneq ($(STATIC_ERLANG_NIF),)
CFLAGS += -DSTATIC_ERLANG_NIF=1
endif
ifeq ($(STATIC_ERLANG_NIF),)
all: $(PREFIX) $(BUILD) $(LIB_NAME)
else
all: $(PREFIX) $(BUILD) $(ARCHIVE_NAME)
endif
$(BUILD)/%.o: c_src/%.c
@echo " CC $(notdir $@)"
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<
$(LIB_NAME): $(OBJ)
@echo " LD $(notdir $@)"
$(CC) -o $@ $^ $(LDFLAGS)
$(ARCHIVE_NAME): $(OBJ)
@echo " AR $(notdir $@)"
$(AR) -rv $@ $^
$(PREFIX) $(BUILD):
mkdir -p $@
clean:
$(RM) $(LIB_NAME) $(ARCHIVE_NAME) $(OBJ)
.PHONY: all clean
# Don't echo commands unless the caller exports "V=1"
${V}.SILENT: