2020-09-25 21:01:48 +00:00
|
|
|
# Copyright (c) 2020 Status Research & Development GmbH. Licensed under
|
|
|
|
# either of:
|
|
|
|
# - Apache License, version 2.0
|
|
|
|
# - MIT license
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
SHELL := bash # the shell used internally by Make
|
|
|
|
|
|
|
|
# used inside the included makefiles
|
|
|
|
BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
|
|
|
|
|
|
|
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk
|
|
|
|
|
|
|
|
.PHONY: \
|
|
|
|
all \
|
|
|
|
clean \
|
2020-11-12 20:28:55 +00:00
|
|
|
clean-build-dirs \
|
|
|
|
clean-generator \
|
|
|
|
clean-nimterop \
|
2020-09-25 21:01:48 +00:00
|
|
|
deps \
|
|
|
|
sqlite \
|
|
|
|
sqlite.nim \
|
|
|
|
sqlite3.c \
|
|
|
|
test \
|
|
|
|
toast \
|
|
|
|
update
|
|
|
|
|
|
|
|
ifeq ($(NIM_PARAMS),)
|
|
|
|
# "variables.mk" was not included, so we update the submodules.
|
|
|
|
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
|
|
|
|
.DEFAULT:
|
|
|
|
+@ echo -e "Git submodules not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \
|
|
|
|
$(GIT_SUBMODULE_UPDATE); \
|
|
|
|
echo
|
|
|
|
# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself:
|
|
|
|
# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
|
|
|
|
#
|
|
|
|
# After restarting, it will execute its original goal, so we don't have to start a child Make here
|
|
|
|
# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great?
|
|
|
|
|
|
|
|
else # "variables.mk" was included. Business as usual until the end of this file.
|
|
|
|
|
|
|
|
all: sqlite.nim
|
|
|
|
|
|
|
|
# must be included after the default target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
|
|
|
|
|
|
|
|
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
|
|
|
|
detected_OS := Windows
|
|
|
|
else ifeq ($(strip $(shell uname)),Darwin)
|
|
|
|
detected_OS := macOS
|
|
|
|
else
|
2020-11-12 20:28:55 +00:00
|
|
|
# e.g. Linux
|
|
|
|
detected_OS := $(strip $(shell uname))
|
2020-09-25 21:01:48 +00:00
|
|
|
endif
|
|
|
|
|
2020-11-12 20:28:55 +00:00
|
|
|
clean: | clean-common clean-build-dirs clean-generator clean-nimterop
|
|
|
|
|
|
|
|
clean-build-dirs:
|
2020-09-25 21:01:48 +00:00
|
|
|
rm -rf \
|
|
|
|
sqlcipher \
|
|
|
|
sqlite \
|
|
|
|
test/build
|
|
|
|
|
2020-11-12 20:28:55 +00:00
|
|
|
clean-generator:
|
|
|
|
rm -rf \
|
|
|
|
generator/generate \
|
|
|
|
generator/generate.exe \
|
|
|
|
generator/generate.dSYM
|
|
|
|
|
|
|
|
clean-nimterop:
|
|
|
|
rm -rf \
|
|
|
|
$(NIMTEROP_TOAST) \
|
|
|
|
$(NIMTEROP_TOAST).dSYM
|
|
|
|
|
2020-09-25 21:01:48 +00:00
|
|
|
deps: | deps-common
|
|
|
|
|
|
|
|
update: | update-common
|
|
|
|
|
2020-10-23 21:39:06 +00:00
|
|
|
SSL_STATIC ?= true
|
2020-09-25 21:01:48 +00:00
|
|
|
SSL_INCLUDE_DIR ?= /usr/include
|
|
|
|
ifeq ($(SSL_INCLUDE_DIR),)
|
|
|
|
override SSL_INCLUDE_DIR = /usr/include
|
|
|
|
endif
|
|
|
|
SSL_LIB_DIR ?= /usr/lib/x86_64-linux-gnu
|
|
|
|
ifeq ($(SSL_LIB_DIR),)
|
|
|
|
override SSL_LIB_DIR = /usr/lib/x86_64-linux-gnu
|
|
|
|
endif
|
|
|
|
ifndef SSL_LDFLAGS
|
|
|
|
ifeq ($(SSL_STATIC),false)
|
|
|
|
SSL_LDFLAGS := -L$(SSL_LIB_DIR) -lcrypto
|
|
|
|
else
|
2020-10-23 21:39:06 +00:00
|
|
|
SSL_LDFLAGS := $(SSL_LIB_DIR)/libcrypto.a
|
2020-09-25 21:01:48 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
SSL_LDFLAGS += -lws2_32
|
|
|
|
endif
|
|
|
|
endif
|
2020-11-12 20:28:55 +00:00
|
|
|
ifeq ($(SSL_STATIC),false)
|
|
|
|
SSL_LDFLAGS_SQLITE3_C ?= $(SSL_LDFLAGS)
|
|
|
|
else
|
|
|
|
# SQLCipher's configure script fails if SSL_LIB_DIR isn't supplied with -L in LDFLAGS
|
|
|
|
SSL_LDFLAGS_SQLITE3_C ?= -L$(SSL_LIB_DIR) $(SSL_LDFLAGS)
|
|
|
|
endif
|
2020-09-25 21:01:48 +00:00
|
|
|
|
2020-10-23 21:39:06 +00:00
|
|
|
SQLITE_STATIC ?= true
|
|
|
|
SQLITE_CDEFS ?= -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=3
|
|
|
|
SQLITE_CFLAGS ?= -I$(SSL_INCLUDE_DIR) -pthread
|
|
|
|
ifndef SQLITE_LDFLAGS
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
SQLITE_LDFLAGS := -lwinpthread
|
|
|
|
else
|
|
|
|
SQLITE_LDFLAGS := -lpthread
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
SQLITE3_C ?= $(shell pwd)/sqlite/sqlite3.c
|
2020-10-20 17:48:38 +00:00
|
|
|
SQLITE3_H ?= $(shell pwd)/sqlite/sqlite3.h
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
$(SQLITE3_C): | deps
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
sed -i "s/tr -d '\\\\\\n'/tr -d '\\\\\\r\\\\\\n'/" vendor/sqlcipher/configure
|
|
|
|
endif
|
|
|
|
echo -e $(BUILD_MSG) "SQLCipher's SQLite C amalgamation"
|
2020-10-23 21:39:06 +00:00
|
|
|
+ mkdir -p sqlite
|
|
|
|
cd vendor/sqlcipher && \
|
2020-09-25 21:01:48 +00:00
|
|
|
./configure \
|
2020-10-23 21:39:06 +00:00
|
|
|
CFLAGS="$(SQLITE_CDEFS) $(SQLITE_CFLAGS)" \
|
|
|
|
LDFLAGS="$(SQLITE_LDFLAGS) $(SSL_LDFLAGS_SQLITE3_C)" \
|
2020-09-25 21:01:48 +00:00
|
|
|
$(HANDLE_OUTPUT)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
2020-10-23 21:39:06 +00:00
|
|
|
sed -i "/TOP =/c\\\\\\TOP := \$$(shell cygpath -m \$$(shell pwd))" vendor/sqlcipher/Makefile
|
|
|
|
sed -i "s/\$$(TCLSH_CMD) \$$(TOP)\\/tool\\/mkshellc.tcl/\$$(TCLSH_CMD) \$$(shell pwd)\\/tool\\/mkshellc.tcl/" vendor/sqlcipher/Makefile
|
2020-09-25 21:01:48 +00:00
|
|
|
endif
|
|
|
|
cd vendor/sqlcipher && $(MAKE) sqlite3.c $(HANDLE_OUTPUT)
|
2020-10-23 21:39:06 +00:00
|
|
|
cp \
|
|
|
|
vendor/sqlcipher/sqlite3.c \
|
|
|
|
vendor/sqlcipher/sqlite3.h \
|
|
|
|
sqlite/
|
2020-11-12 20:28:55 +00:00
|
|
|
cd vendor/sqlcipher && git clean -dfx $(HANDLE_OUTPUT)
|
|
|
|
([[ $(detected_OS) = Windows ]] && \
|
|
|
|
cd vendor/sqlcipher && \
|
|
|
|
git stash $(HANDLE_OUTPUT) && \
|
|
|
|
git stash drop $(HANDLE_OUTPUT)) || true
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
sqlite3.c: $(SQLITE3_C)
|
|
|
|
|
2020-10-23 21:39:06 +00:00
|
|
|
SQLITE_STATIC_LIB ?= $(shell pwd)/sqlcipher/sqlcipher.a
|
|
|
|
SQLITE_STATIC_OBJ ?= sqlcipher/sqlcipher.o
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
$(SQLITE_STATIC_LIB): $(SQLITE3_C)
|
|
|
|
echo -e $(BUILD_MSG) "SQLCipher static library"
|
2020-10-23 21:39:06 +00:00
|
|
|
+ mkdir -p sqlcipher
|
|
|
|
$(ENV_SCRIPT) $(CC) \
|
2020-09-25 21:01:48 +00:00
|
|
|
$(SQLITE_CDEFS) \
|
|
|
|
$(SQLITE_CFLAGS) \
|
2020-10-23 21:39:06 +00:00
|
|
|
$(SQLITE3_C) \
|
|
|
|
-c \
|
|
|
|
-o $(SQLITE_STATIC_OBJ) $(HANDLE_OUTPUT)
|
|
|
|
$(ENV_SCRIPT) ar rcs $(SQLITE_STATIC_LIB) $(SQLITE_STATIC_OBJ) $(HANDLE_OUTPUT)
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
ifndef SHARED_LIB_EXT
|
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
SHARED_LIB_EXT := dylib
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
SHARED_LIB_EXT := dll
|
|
|
|
else
|
|
|
|
SHARED_LIB_EXT := so
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2020-10-23 21:39:06 +00:00
|
|
|
SQLITE_SHARED_LIB ?= $(shell pwd)/sqlcipher/libsqlcipher.$(SHARED_LIB_EXT)
|
2020-09-25 21:01:48 +00:00
|
|
|
|
2020-10-23 21:39:06 +00:00
|
|
|
ifndef PLATFORM_FLAGS_SHARED_LIB
|
2020-09-25 21:01:48 +00:00
|
|
|
ifeq ($(detected_OS),macOS)
|
2020-10-23 21:39:06 +00:00
|
|
|
PLATFORM_FLAGS_SHARED_LIB := -shared -dylib
|
2020-10-20 17:48:38 +00:00
|
|
|
else
|
2020-10-23 21:39:06 +00:00
|
|
|
PLATFORM_FLAGS_SHARED_LIB := -shared -fPIC
|
2020-09-25 21:01:48 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(SQLITE_SHARED_LIB): $(SQLITE3_C)
|
|
|
|
echo -e $(BUILD_MSG) "SQLCipher shared library"
|
2020-10-23 21:39:06 +00:00
|
|
|
+ mkdir -p sqlcipher
|
|
|
|
$(ENV_SCRIPT) $(CC) \
|
2020-09-25 21:01:48 +00:00
|
|
|
$(SQLITE_CDEFS) \
|
|
|
|
$(SQLITE_CFLAGS) \
|
2020-10-23 21:39:06 +00:00
|
|
|
$(SQLITE3_C) \
|
2020-10-20 17:48:38 +00:00
|
|
|
$(SQLITE_LDFLAGS) \
|
2020-10-23 21:39:06 +00:00
|
|
|
$(SSL_LDFLAGS) \
|
|
|
|
$(PLATFORM_FLAGS_SHARED_LIB) \
|
2020-09-25 21:01:48 +00:00
|
|
|
-o $(SQLITE_SHARED_LIB) $(HANDLE_OUTPUT)
|
|
|
|
|
|
|
|
ifndef SQLITE_LIB
|
|
|
|
ifneq ($(SQLITE_STATIC),false)
|
|
|
|
SQLITE_LIB := $(SQLITE_STATIC_LIB)
|
|
|
|
else
|
|
|
|
SQLITE_LIB := $(SQLITE_SHARED_LIB)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
sqlite: $(SQLITE_LIB)
|
|
|
|
|
|
|
|
ifndef NIMTEROP_TOAST
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIMTEROP_TOAST := vendor/nimterop/nimterop/toast.exe
|
|
|
|
else
|
|
|
|
NIMTEROP_TOAST := vendor/nimterop/nimterop/toast
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(NIMTEROP_TOAST): | deps
|
|
|
|
echo -e $(BUILD_MSG) "Nimterop toast"
|
|
|
|
+ cd vendor/nimterop && \
|
|
|
|
$(ENV_SCRIPT) nim c $(NIM_PARAMS) \
|
|
|
|
--define:danger \
|
|
|
|
--hints:off \
|
|
|
|
--nimcache:../../nimcache/nimterop \
|
|
|
|
nimterop/toast.nim
|
|
|
|
rm -rf $(NIMTEROP_TOAST).dSYM
|
|
|
|
|
|
|
|
toast: $(NIMTEROP_TOAST)
|
|
|
|
|
|
|
|
SQLITE_NIM ?= sqlcipher/sqlite.nim
|
|
|
|
|
|
|
|
$(SQLITE_NIM): $(NIMTEROP_TOAST) $(SQLITE_LIB)
|
|
|
|
echo -e $(BUILD_MSG) "Nim wrapper for SQLCipher"
|
|
|
|
+ mkdir -p sqlcipher
|
2020-10-20 17:48:38 +00:00
|
|
|
SQLITE_CDEFS="$(SQLITE_CDEFS)" \
|
2020-09-25 21:01:48 +00:00
|
|
|
SQLITE_STATIC="$(SQLITE_STATIC)" \
|
|
|
|
SQLITE3_H="$(SQLITE3_H)" \
|
|
|
|
SQLITE_LIB="$(SQLITE_LIB)" \
|
|
|
|
$(ENV_SCRIPT) nim c $(NIM_PARAMS) \
|
|
|
|
--nimcache:nimcache/sqlcipher \
|
|
|
|
--verbosity:0 \
|
2020-10-23 21:39:06 +00:00
|
|
|
generator/generate.nim > $(SQLITE_NIM) 2> /dev/null
|
2020-11-12 20:28:55 +00:00
|
|
|
$(MAKE) clean-generator
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
sqlite.nim: $(SQLITE_NIM)
|
|
|
|
|
|
|
|
test: $(SQLITE_NIM)
|
2020-10-20 17:48:38 +00:00
|
|
|
ifeq ($(detected_OS),macOS)
|
2020-09-25 21:01:48 +00:00
|
|
|
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
|
2020-10-23 21:39:06 +00:00
|
|
|
SSL_STATIC="$(SSL_STATIC)" \
|
2020-09-25 21:01:48 +00:00
|
|
|
$(ENV_SCRIPT) nimble tests
|
2020-10-20 17:48:38 +00:00
|
|
|
else ifeq ($(detected_OS),Windows)
|
2020-10-23 21:39:06 +00:00
|
|
|
PATH="$(shell dirname $(SQLITE_SHARED_LIB)):$(shell dirname $(SSL_LIB_DIR)):$(SSL_LIB_DIR):$${PATH}" \
|
2020-10-20 17:48:38 +00:00
|
|
|
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
|
2020-10-23 21:39:06 +00:00
|
|
|
SSL_STATIC="$(SSL_STATIC)" \
|
2020-10-20 17:48:38 +00:00
|
|
|
$(ENV_SCRIPT) nimble tests
|
|
|
|
else
|
2020-10-23 21:39:06 +00:00
|
|
|
LD_LIBRARY_PATH="$(shell dirname $(SQLITE_SHARED_LIB)):$(SSL_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}" \
|
2020-10-20 17:48:38 +00:00
|
|
|
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
|
2020-10-23 21:39:06 +00:00
|
|
|
SSL_STATIC="$(SSL_STATIC)" \
|
2020-10-20 17:48:38 +00:00
|
|
|
$(ENV_SCRIPT) nimble tests
|
|
|
|
endif
|
2020-09-25 21:01:48 +00:00
|
|
|
|
|
|
|
endif # "variables.mk" was not included
|