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.

299 lines
8.4 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. LDLIBS=
  65. ######### C #########
  66. ifeq ($(BUILD_FOR),Linux)
  67. CC=gcc -std=c99 -pthread
  68. else ifeq ($(BUILD_FOR),Darwin)
  69. # clang issues a warning when "-pthread" is used for linking.
  70. # So, include it in CFLAGS, and not in CC
  71. CC=clang -std=c99
  72. endif
  73. ifeq ($(BUILD_FOR),Linux)
  74. CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=auto
  75. else ifeq ($(BUILD_FOR),Darwin)
  76. CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
  77. endif
  78. # The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
  79. # The tests do not work properly, if compiled with -DNDEBUG
  80. ifeq ($(BUILD_FOR),Linux)
  81. ifdef WARN
  82. CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
  83. else
  84. CFLAGS+= -w
  85. endif
  86. ifdef DEBUG
  87. CFLAGS+= -g -ggdb -DDEBUG_ERRORSTACK
  88. else
  89. CFLAGS+= -O3 -DNDEBUG
  90. endif
  91. else ifeq ($(BUILD_FOR),Darwin)
  92. ifdef WARN
  93. CFLAGS+= -Wall -pedantic
  94. else
  95. CFLAGS+= -w
  96. endif
  97. ifdef DEBUG
  98. CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
  99. else
  100. CFLAGS+= -O3 -DNDEBUG
  101. endif
  102. endif
  103. # Additional CFLAGS used for compiling ASN1C-generated code
  104. ifeq ($(BUILD_FOR),Linux)
  105. # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
  106. # _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
  107. # otherwise printed during the compilation of every asn1c-generated C file.
  108. # It's a glibc specific warning, only present in few versions around ~2.19.
  109. # See https://lwn.net/Articles/590381/ for a discussion.
  110. CFLAGS_GENERATED=-D_DEFAULT_SOURCE
  111. else ifeq ($(BUILD_FOR),Darwin)
  112. CFLAGS_GENERATED=
  113. endif
  114. ######### C++ #########
  115. ifeq ($(BUILD_FOR),Linux)
  116. CXX=g++ -std=gnu++11 -pthread
  117. else ifeq ($(BUILD_FOR),Darwin)
  118. # clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
  119. CXX=clang -std=c++11
  120. endif
  121. # The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
  122. # The tests do not work properly, if compiled with -DNDEBUG
  123. ifeq ($(BUILD_FOR),Linux)
  124. CXXFLAGS=-fdiagnostics-color=auto -I../src -I../asn.1 $(ETPAN_INC)
  125. ifdef WARN
  126. CXXFLAGS+=
  127. else
  128. CXXFLAGS+= -w
  129. endif
  130. ifdef DEBUG
  131. CXXFLAGS+= -g -ggdb
  132. else
  133. CXXFLAGS+= -O3 -DNDEBUG
  134. endif
  135. else ifeq ($(BUILD_FOR),Darwin)
  136. CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
  137. ifdef WARN
  138. CXXFLAGS+=
  139. else
  140. CXXFLAGS+= -w
  141. endif
  142. ifdef DEBUG
  143. CXXFLAGS+= -O0 -g
  144. else
  145. CXXFLAGS+= -O3 -DNDEBUG
  146. endif
  147. endif
  148. ######### C and C++ #########
  149. ifeq ($(BUILD_FOR),Darwin)
  150. CPPFLAGS=-D_DARWIN_C_SOURCE
  151. else
  152. CPPFLAGS=
  153. endif
  154. ######### YML2 #########
  155. YML2_PATH=$(HOME)/yml2
  156. YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
  157. YML2_OPTS=--encoding=utf8
  158. ######### asn1c #########
  159. # asn1c binary
  160. ASN1C=asn1c
  161. # asn1c include search flag
  162. ASN1C_INC=
  163. #ASN1C_INC=-I$(HOME)/include
  164. ######### pEp MIME #########
  165. PEP_MIME = 1
  166. PEP_MIME_SRC=$(HOME)/src/pEpMIME/src
  167. ######### libetpan #########
  168. # libetpan library search flag
  169. #
  170. ETPAN_LIB=
  171. #ETPAN_LIB=-L$(HOME)/lib
  172. # libetpan include search flag
  173. ETPAN_INC=
  174. #ETPAN_INC=-I$(HOME)/include
  175. ######### sqlite3 #########
  176. # If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
  177. # Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
  178. SQLITE3_FROM_OS=placeholder
  179. ######### OpenPGP #########
  180. # Selects OpenPGP implementation. must be `SEQUOIA`
  181. OPENPGP=SEQUOIA
  182. # Sequoia-specific variables
  183. SEQUOIA_CFLAGS=
  184. SEQUOIA_LDFLAGS=
  185. SEQUOIA_LIB=
  186. SEQUOIA_INC=
  187. ######### Engine internals #########
  188. # C macros (not environment variables) that can be overridden:
  189. # DEFAULT_KEYSERVER - string with default keyserver
  190. # CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
  191. # Example:
  192. # EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
  193. EXTRA_MACROS=
  194. ######### Misc #########
  195. # FIXME Maybe include these variables here.
  196. # Check how they are used throughout the project before setting them here
  197. #LLDB_BIN
  198. # Add this for running tests in debugger
  199. #TEST_DEBUGGER=lldb --batch -o r
  200. # comma-separated list of tests to exclude from gensuite (relevant for running tests only)
  201. EXCLUDE=
  202. ######### Footer #########
  203. -include $(HERE)/local.conf
  204. ifdef BUILD_CONFIG
  205. include $(BUILD_CONFIG)
  206. endif
  207. ######### Post processing assignments ########
  208. # These variables are ineffective when set anywhere else but here.
  209. # KB: I have no idea why we do this - it totally defeats the purpose of
  210. # local.conf.
  211. # For now: set if has no value.
  212. ifeq ($(OPENPGP),SEQUOIA)
  213. ifeq ($(SEQUOIA_CFLAGS),)
  214. SEQUOIA_CFLAGS=$(shell pkg-config --cflags-only-other sequoia-openpgp)
  215. endif
  216. ifeq ($(SEQUOIA_LDFLAGS),)
  217. SEQUOIA_LDFLAGS=$(shell pkg-config --libs-only-L --libs-only-other sequoia-openpgp)
  218. endif
  219. ifeq ($(SEQUOIA_LIB),)
  220. SEQUOIA_LIB=$(shell pkg-config --libs-only-l sequoia-openpgp)
  221. endif
  222. ifeq ($(SEQUOIA_INC),)
  223. SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
  224. endif
  225. CFLAGS+= $(SEQUOIA_CFLAGS)
  226. LD_FLAGS+= $(SEQUOIA_LDFLAGS)
  227. endif
  228. # YML_PATH is needed in the environment of every call to a program of the YML2 distribution
  229. export YML_PATH=$(YML2_PATH)
  230. ifdef PEP_MIME
  231. ifndef PEP_MIME_SRC
  232. $(error "Compiling with the PEP_MIME option set requires the value of PEP_MIME_SRC to be set to the source directory for libpEpMIME")
  233. else
  234. $(shell mkdir -p pEpMIME)
  235. $(shell cp $(PEP_MIME_SRC)/*.{cc,hh,hxx} $(HERE)/pEpMIME)
  236. $(shell cp $(PEP_MIME_SRC)/Makefile $(HERE)/pEpMIME)
  237. ETPAN_LIB=
  238. ETPAN_INC=
  239. endif
  240. else
  241. endif