p≡p engine FORK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
9.0 KiB

2 years ago
  1. # Copyright 2017, pEp Foundation
  2. # This file is part of pEpEngine
  3. # This file may be used under the terms of the GNU General Public License version 3
  4. # see LICENSE.txt
  5. # See `doc/build-<your platform>.md` for documentation on how to build, and customize your build.
  6. # This file sets all the make variables that allow you to customize a build.
  7. # There are 3 ways in which you can customize your build:
  8. # 1) Edit the variable assignments in this file (this is a tracked file, so your repository will be dirty)
  9. # 2) Create `local.conf` and fill it with variable assignments.
  10. # 3) Set the environment variable `BUILD_CONFIG` to an absolute path.
  11. # The variable assignments found in the make file at the path indicated by `BUILD_CONFIG` will be evaluated.
  12. # Customization options are applied in the order given above. Later variable assignments take precedence over earlier ones.
  13. # It is possible to use multiple variants simultaniously.
  14. # If nothing is changed according to these 3 methods, a default configuration for your platform (specified below) will be used for the build.
  15. ######### Header #########
  16. HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
  17. ######### General #########
  18. # To use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
  19. # All the *_INC and *_LIB variables are command line flags, not paths.
  20. # Thus, all *_INC variables' values must start with "-I", and all *_LIB variables' values must start with "-L".
  21. BUILD_ON:=$(shell uname)
  22. # This variable specifies the platform that the engine should be cross-compiled for.
  23. BUILD_FOR=$(BUILD_ON)
  24. # Cross-compiling is currently not supported.
  25. # Maybe you can hack something with `local.conf`.
  26. ifneq ($(BUILD_ON),$(BUILD_FOR))
  27. $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON).)
  28. endif
  29. # Installation path prefix for libraries and binaries, except for system.db
  30. PREFIX=$(HOME)
  31. # pEp files and directories
  32. #
  33. # the PER_USER_DIRECTORY will be in $(HOME), respectively
  34. # in debug builds the PER_USER_DIRECTORY will be in $(PEP_HOME) instead if set
  35. #
  36. # PER_MACHINE_DIRECTORY is calculated depending on platform; overwrite if
  37. # necessary
  38. #PER_USER_DIRECTORY=.pEp
  39. PER_MACHINE_DIRECTORY=/usr/local/share/pEp
  40. # Filename of the pEpEngine library
  41. ifeq ($(BUILD_FOR),Linux)
  42. TARGET=libpEpEngine.so
  43. else ifeq ($(BUILD_FOR),Darwin)
  44. TARGET=libpEpEngine.dylib
  45. endif
  46. # If empty, create a release build.
  47. # Otherwise, create a debug build.
  48. # This variable is ineffective when set anywhere else but here.
  49. DEBUG=placeholder
  50. # If empty, suppress compiler warnings.
  51. # Otherwise, print warnings.
  52. # This variable is ineffective when set anywhere else but here.
  53. WARN=placeholder
  54. ######### C and C++ #########
  55. TARGET_ARCH=
  56. # The following two variables will be appended to.
  57. # You can thus not set them to a final, fixed value here.
  58. ifeq ($(BUILD_FOR),Linux)
  59. LDFLAGS+=
  60. else ifeq ($(BUILD_FOR),Darwin)
  61. # "-bind_at_load" helps find symbol resolution errors faster
  62. LDFLAGS+=-bind_at_load
  63. endif
  64. # Are we wiping this on purpose?
  65. LDLIBS=
  66. ######### C #########
  67. ifeq ($(BUILD_FOR),Linux)
  68. CC=gcc
  69. else ifeq ($(BUILD_FOR),Darwin)
  70. CC=clang
  71. endif
  72. CFLAGS+=-std=c99 -pthread
  73. CFLAGS+=-fPIC -fstrict-aliasing
  74. ifeq ($(BUILD_FOR),Linux)
  75. CFLAGS+=-fdiagnostics-color=auto
  76. else ifeq ($(BUILD_FOR),Darwin)
  77. CFLAGS+=-fcolor-diagnostics
  78. endif
  79. # The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
  80. # The tests do not work properly, if compiled with -DNDEBUG
  81. ifeq ($(BUILD_FOR),Linux)
  82. ifdef WARN
  83. CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
  84. else
  85. CFLAGS+= -w
  86. endif
  87. ifdef DEBUG
  88. CFLAGS+= -g -ggdb -DDEBUG_ERRORSTACK
  89. else
  90. CFLAGS+= -O3 -DNDEBUG
  91. endif
  92. else ifeq ($(BUILD_FOR),Darwin)
  93. ifdef WARN
  94. CFLAGS+= -Wall -pedantic
  95. else
  96. CFLAGS+= -w
  97. endif
  98. ifdef DEBUG
  99. CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
  100. else
  101. CFLAGS+= -O3 -DNDEBUG
  102. endif
  103. endif
  104. # Additional CFLAGS used for compiling ASN1C-generated code
  105. ifeq ($(BUILD_FOR),Linux)
  106. # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
  107. # _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
  108. # otherwise printed during the compilation of every asn1c-generated C file.
  109. # It's a glibc specific warning, only present in few versions around ~2.19.
  110. # See https://lwn.net/Articles/590381/ for a discussion.
  111. CPPFLAGS_GENERATED=-D_DEFAULT_SOURCE
  112. else ifeq ($(BUILD_FOR),Darwin)
  113. CPPFLAGS_GENERATED=
  114. endif
  115. ######### C++ #########
  116. ifeq ($(BUILD_FOR),Linux)
  117. CXX=g++
  118. CXXFLAGS+=-std=gnu++11
  119. else ifeq ($(BUILD_FOR),Darwin)
  120. CXX=clang
  121. CXXFLAGS+=-std=c++11
  122. endif
  123. CXXFLAGS+=-pthread
  124. # The flag -DNDEBUG will always be removed from CPPFLAGS for compiling tests.
  125. #
  126. # The tests do not work properly, if compiled with -DNDEBUG
  127. ifeq ($(BUILD_FOR),Linux)
  128. CXXFLAGS+=-fdiagnostics-color=auto -I../src -I../asn.1 $(ETPAN_INC)
  129. ifdef WARN
  130. CXXFLAGS+=
  131. else
  132. CXXFLAGS+= -w
  133. endif
  134. ifdef DEBUG
  135. CXXFLAGS+= -g -ggdb
  136. else
  137. CXXFLAGS+= -O3
  138. CPPFLAGS+= -DNDEBUG
  139. endif
  140. else ifeq ($(BUILD_FOR),Darwin)
  141. CXXFLAGS+=-fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
  142. ifdef WARN
  143. CXXFLAGS+=
  144. else
  145. CXXFLAGS+= -w
  146. endif
  147. ifdef DEBUG
  148. CXXFLAGS+= -O0 -g
  149. else
  150. CXXFLAGS+= -O3
  151. CPPFLAGS+= -DNDEBUG
  152. endif
  153. endif
  154. ######### C and C++ #########
  155. ifeq ($(BUILD_FOR),Darwin)
  156. CPPFLAGS+=-D_DARWIN_C_SOURCE
  157. LDLIBS+=-liconv
  158. else
  159. LDLIBS+=-luuid
  160. endif
  161. ######### YML2 #########
  162. YML2_PATH=$(HOME)/yml2
  163. YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
  164. YML2_OPTS=--encoding=utf8
  165. ######### asn1c #########
  166. # asn1c binary
  167. ASN1C=asn1c
  168. # asn1c include search flag
  169. ASN1C_INC=
  170. #ASN1C_INC=-I$(HOME)/include
  171. ######### sqlite3 #########
  172. # If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
  173. # Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
  174. SQLITE3_FROM_OS=placeholder
  175. ######### MIME #########
  176. ######### pEp MIME #########
  177. # Set pEpMIME= anything (there are ifdefs on it) in your local.conf if you want
  178. # to compile built-in pEpMIME (requires a separate libppEpMIME source repo to be
  179. # checked out elsewhere on the system - define or redefine these in local.conf
  180. # if you want to use it; otherwise, we default to etpan. (This will eventually
  181. # become the default, but not yet.
  182. #
  183. PEP_MIME=
  184. PEP_MIME_SRC=$(HOME)/src/pEpMIME/src
  185. ######### libetpan #########
  186. # libetpan library search flag
  187. #
  188. ETPAN_LIB=
  189. #ETPAN_LIB=-L$(HOME)/lib
  190. # libetpan include search flag
  191. ETPAN_INC=
  192. #ETPAN_INC=-I$(HOME)/include
  193. ######### OpenPGP #########
  194. # Selects OpenPGP implementation. must be `SEQUOIA`
  195. OPENPGP=SEQUOIA
  196. # Sequoia-specific variables
  197. SEQUOIA_CFLAGS+=
  198. SEQUOIA_LDFLAGS+=
  199. SEQUOIA_LIB=
  200. SEQUOIA_INC=
  201. ######### Engine internals #########
  202. # C macros (not environment variables) that can be overridden:
  203. # DEFAULT_KEYSERVER - string with default keyserver
  204. # CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
  205. # Example:
  206. # EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
  207. EXTRA_MACROS=
  208. ######### Misc #########
  209. # FIXME Maybe include these variables here.
  210. # Check how they are used throughout the project before setting them here
  211. #LLDB_BIN
  212. # Add this for running tests in debugger
  213. #TEST_DEBUGGER=lldb --batch -o r
  214. # comma-separated list of tests to exclude from gensuite (relevant for running tests only)
  215. EXCLUDE=
  216. ######### Footer #########
  217. ################################
  218. # Include local.conf for any overrides and additional flags
  219. ################################
  220. -include $(HERE)/local.conf
  221. ifdef BUILD_CONFIG
  222. include $(BUILD_CONFIG)
  223. endif
  224. ######### Post processing assignments ########
  225. # If sequoia has been set up and the SEQUOIA flags aren't defined, set them up.
  226. # Otherwise, add them to the CFLAGS/CXXFLAGS/LDFLAGS and library/include variables
  227. ifeq ($(OPENPGP),SEQUOIA)
  228. ifeq ($(SEQUOIA_CFLAGS),)
  229. SEQUOIA_CFLAGS+=$(shell pkg-config --cflags-only-other sequoia-openpgp)
  230. endif
  231. ifeq ($(SEQUOIA_LDFLAGS),)
  232. SEQUOIA_LDFLAGS+=$(shell pkg-config --libs-only-L --libs-only-other sequoia-openpgp)
  233. endif
  234. ifeq ($(SEQUOIA_LIB),)
  235. SEQUOIA_LIB=$(shell pkg-config --libs-only-l sequoia-openpgp)
  236. endif
  237. ifeq ($(SEQUOIA_INC),)
  238. SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
  239. endif
  240. CFLAGS+= $(SEQUOIA_CFLAGS)
  241. CXXFLAGS+= $(SEQUOIA_CFLAGS)
  242. LD_FLAGS+= $(SEQUOIA_LDFLAGS)
  243. endif
  244. # YML_PATH is needed in the environment of every call to a program of the YML2 distribution
  245. export YML_PATH=$(YML2_PATH)
  246. # Postprocess for pEpMIME
  247. ifdef PEP_MIME
  248. # Replace c++11 with c++14 for now (limiting the subst to the ++11 means it doesn't matter if gnu or not)
  249. CXXFLAGS:=$(subst ++11,++14,$(CXXFLAGS)) -fPIC -fvisibility=hidden
  250. endif
  251. ifdef PEP_MIME
  252. ifndef PEP_MIME_SRC
  253. $(error "Compiling with the PEP_MIME option set requires the value of PEP_MIME_SRC to be set to the source directory for libpEpMIME")
  254. else
  255. CPPFLAGS+=-DPEP_BUILTIN_MIME
  256. LDLIBS+=-lstdc++
  257. ETPAN_LIB=
  258. ETPAN_INC=
  259. endif
  260. endif