p≡p engine
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.

374 lines
11 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. ifeq ($(BUILD_FOR),OS/390)
  28. $(warning Generating sources for z/OS)
  29. endif
  30. ONLY_GENERATE=true
  31. endif
  32. # Installation path prefix for libraries and binaries, except for system.db
  33. PREFIX=$(HOME)
  34. # pEp files and directories
  35. #
  36. # the PER_USER_DIRECTORY will be in $(HOME), respectively
  37. # in debug builds the PER_USER_DIRECTORY will be in $(PEP_HOME) instead if set
  38. #
  39. # PER_MACHINE_DIRECTORY is calculated depending on platform; overwrite if
  40. # necessary
  41. #PER_USER_DIRECTORY=.pEp
  42. PER_MACHINE_DIRECTORY=/usr/local/share/pEp
  43. # Filename of the pEpEngine library
  44. ifeq ($(BUILD_FOR),OS/390)
  45. TARGET=libpEpEngine.so
  46. else ifeq ($(BUILD_FOR),Linux)
  47. TARGET=libpEpEngine.so
  48. else ifeq ($(BUILD_FOR),Darwin)
  49. TARGET=libpEpEngine.dylib
  50. endif
  51. # If empty, create a release build.
  52. # Otherwise, create a debug build.
  53. # This variable is ineffective when set anywhere else but here.
  54. DEBUG=placeholder
  55. # If empty, suppress compiler warnings.
  56. # Otherwise, print warnings.
  57. # This variable is ineffective when set anywhere else but here.
  58. WARN=placeholder
  59. ######### C and C++ #########
  60. TARGET_ARCH=
  61. # The following two variables will be appended to.
  62. # You can thus not set them to a final, fixed value here.
  63. ifeq ($(BUILD_FOR),Linux)
  64. LDFLAGS+=
  65. else ifeq ($(BUILD_FOR),Darwin)
  66. # "-bind_at_load" helps find symbol resolution errors faster
  67. LDFLAGS+=-bind_at_load
  68. endif
  69. # Are we wiping this on purpose?
  70. LDLIBS=
  71. ifeq ($(BUILD_FOR),OS/390)
  72. CC=xlclang
  73. else ifeq ($(BUILD_FOR),Linux)
  74. CC=gcc -std=c99 -pthread
  75. else ifeq ($(BUILD_FOR),Darwin)
  76. CC=clang
  77. endif
  78. ifeq ($(BUILD_FOR),OS/390)
  79. CFLAGS= -Wno-gnu-include-next -qnosearch -I$(HERE) -I.
  80. CFLAGS+= -I/usr/include
  81. CFLAGS+= -DZOS -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -qlanglvl=NOLIBEXT
  82. else ifeq ($(BUILD_FOR),Linux)
  83. CFLAGS+=-fPIC -fstrict-aliasing -fdiagnostics-color=auto
  84. else ifeq ($(BUILD_FOR),Darwin)
  85. CFLAGS+=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
  86. endif
  87. # The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
  88. # The tests do not work properly, if compiled with -DNDEBUG
  89. ifeq ($(BUILD_FOR),OS/390)
  90. ifdef WARN
  91. CFLAGS+= -Wall -pedantic
  92. else
  93. CFLAGS+= -w
  94. endif
  95. ifdef DEBUG
  96. CFLAGS+= -g -DDEBUG_ERRORSTACK
  97. else
  98. CFLAGS+= -O3 -DNDEBUG
  99. endif
  100. else ifeq ($(BUILD_FOR),Linux)
  101. ifdef WARN
  102. CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
  103. else
  104. CFLAGS+= -w
  105. endif
  106. ifdef DEBUG
  107. CFLAGS+= -g -ggdb -DDEBUG_ERRORSTACK
  108. else
  109. CFLAGS+= -O3 -DNDEBUG
  110. endif
  111. else ifeq ($(BUILD_FOR),Darwin)
  112. ifdef WARN
  113. CFLAGS+= -Wall -pedantic
  114. else
  115. CFLAGS+= -w
  116. endif
  117. ifdef DEBUG
  118. CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
  119. else
  120. CFLAGS+= -O3 -DNDEBUG
  121. endif
  122. endif
  123. # Additional CFLAGS used for compiling ASN1C-generated code
  124. ifeq ($(BUILD_FOR),Linux)
  125. # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
  126. # _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
  127. # otherwise printed during the compilation of every asn1c-generated C file.
  128. # It's a glibc specific warning, only present in few versions around ~2.19.
  129. # See https://lwn.net/Articles/590381/ for a discussion.
  130. CPPFLAGS_GENERATED=-D_DEFAULT_SOURCE
  131. else ifeq ($(BUILD_FOR),Darwin)
  132. CPPFLAGS_GENERATED=
  133. endif
  134. ######### C++ #########
  135. ifeq ($(BUILD_FOR),Linux)
  136. CXX=g++
  137. CXXFLAGS+=-std=gnu++11
  138. else ifeq ($(BUILD_FOR),Darwin)
  139. # clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
  140. CXX=clang -std=c++11
  141. else ifeq ($(BUILD_FOR),OS/390)
  142. CXX=xlclang++ -std=c++11
  143. endif
  144. ifneq ($(BUILD_FOR),OS/390)
  145. CXXFLAGS+=-pthread
  146. endif
  147. # The flag -DNDEBUG will always be removed from CPPFLAGS for compiling tests.
  148. #
  149. # The tests do not work properly, if compiled with -DNDEBUG
  150. ifeq ($(BUILD_FOR),OS/390)
  151. CXXFLAGS+= -fdiagnostics-color=auto -Wno-gnu-include-next
  152. CXXFLAGS+= -qnosearch -I$(HERE) -I. -I../src -I../asn.1 $(ETPAN_INC) -I/usr/lpp/java/J8.0_64/include -I/usr/include
  153. CXXFLAGS+= -DZOS -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L
  154. ifdef WARN
  155. CXXFLAGS+=
  156. else
  157. CXXFLAGS+= -w
  158. endif
  159. ifdef DEBUG
  160. CXXFLAGS+= -g
  161. else
  162. CXXFLAGS+= -O3 -DNDEBUG
  163. endif
  164. else ifeq ($(BUILD_FOR),Linux)
  165. CXXFLAGS+=-fdiagnostics-color=auto -I../src -I../asn.1 $(ETPAN_INC)
  166. ifdef WARN
  167. CXXFLAGS+=
  168. else
  169. CXXFLAGS+= -w
  170. endif
  171. ifdef DEBUG
  172. CXXFLAGS+= -g -ggdb
  173. else
  174. CXXFLAGS+= -O3
  175. CPPFLAGS+= -DNDEBUG
  176. endif
  177. else ifeq ($(BUILD_FOR),Darwin)
  178. CXXFLAGS+=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
  179. ifdef WARN
  180. CXXFLAGS+=
  181. else
  182. CXXFLAGS+= -w
  183. endif
  184. ifdef DEBUG
  185. CXXFLAGS+= -O0 -g
  186. else
  187. CXXFLAGS+= -O3
  188. CPPFLAGS+= -DNDEBUG
  189. endif
  190. endif
  191. ######### C and C++ #########
  192. ifeq ($(BUILD_FOR),OS/390)
  193. CPPFLAGS=-W "l,xplink,dll" -W "c,float(ieee),xplink,dll,exportall"
  194. else ifeq ($(BUILD_FOR),Darwin)
  195. CPPFLAGS=-D_DARWIN_C_SOURCE
  196. else
  197. LDLIBS+=-luuid
  198. endif
  199. ######### YML2 #########
  200. YML2_PATH=$(HOME)/yml2
  201. YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
  202. YML2_OPTS=--encoding=utf8
  203. ######### asn1c #########
  204. # asn1c binary
  205. ASN1C=asn1c
  206. # asn1c include search flag
  207. ASN1C_INC=
  208. #ASN1C_INC=-I$(HOME)/include
  209. ######### sqlite3 #########
  210. # If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
  211. # Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
  212. SQLITE3_FROM_OS=placeholder
  213. ######### MIME #########
  214. ######### pEp MIME #########
  215. # Set pEpMIME= anything (there are ifdefs on it) in your local.conf if you want
  216. # to compile built-in pEpMIME (requires a separate libppEpMIME source repo to be
  217. # checked out elsewhere on the system - define or redefine these in local.conf
  218. # if you want to use it; otherwise, we default to etpan. (This will eventually
  219. # become the default, but not yet.
  220. #
  221. PEP_MIME=
  222. PEP_MIME_SRC=$(HOME)/src/pEpMIME/src
  223. ######### libetpan #########
  224. # libetpan library search flag
  225. #
  226. ETPAN_LIB=
  227. #ETPAN_LIB=-L$(HOME)/lib
  228. # libetpan include search flag
  229. ETPAN_INC=
  230. #ETPAN_INC=-I$(HOME)/include
  231. ######### OpenPGP #########
  232. # Selects OpenPGP implementation. must be `SEQUOIA`
  233. ifeq ($(BUILD_FOR),OS/390)
  234. OPENPGP=NETPGP
  235. else
  236. OPENPGP=SEQUOIA
  237. endif
  238. # Sequoia-specific variables
  239. SEQUOIA_CFLAGS+=
  240. SEQUOIA_LDFLAGS+=
  241. SEQUOIA_LIB=
  242. SEQUOIA_INC=
  243. ######### Engine internals #########
  244. # C macros (not environment variables) that can be overridden:
  245. # DEFAULT_KEYSERVER - string with default keyserver
  246. # CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
  247. # Example:
  248. # EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
  249. EXTRA_MACROS=
  250. ifdef PER_USER_DIRECTORY
  251. EXTRA_MACROS+= -DPER_USER_DIRECTORY=\"$(PER_USER_DIRECTORY)\"
  252. endif
  253. ifdef PER_MACHINE_DIRECTORY
  254. EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=\"$(PER_MACHINE_DIRECTORY)\"
  255. endif
  256. CFLAGS+=$(EXTRA_MACROS)
  257. CXXFLAGS+=$(EXTRA_MACROS)
  258. ######### Misc #########
  259. # FIXME Maybe include these variables here.
  260. # Check how they are used throughout the project before setting them here
  261. #LLDB_BIN
  262. # Add this for running tests in debugger
  263. #TEST_DEBUGGER=lldb --batch -o r
  264. # comma-separated list of tests to exclude from gensuite (relevant for running tests only)
  265. EXCLUDE=
  266. ######### Footer #########
  267. ################################
  268. # Include local.conf for any overrides and additional flags
  269. ################################
  270. -include $(HERE)/local.conf
  271. ifdef BUILD_CONFIG
  272. include $(BUILD_CONFIG)
  273. endif
  274. ######### Post processing assignments ########
  275. # If sequoia has been set up and the SEQUOIA flags aren't defined, set them up.
  276. # Otherwise, add them to the CFLAGS/CXXFLAGS/LDFLAGS and library/include variables
  277. ifeq ($(OPENPGP),SEQUOIA)
  278. ifeq ($(SEQUOIA_CFLAGS),)
  279. SEQUOIA_CFLAGS+=$(shell pkg-config --cflags-only-other sequoia-openpgp)
  280. endif
  281. ifeq ($(SEQUOIA_LDFLAGS),)
  282. SEQUOIA_LDFLAGS+=$(shell pkg-config --libs-only-l sequoia-openpgp)
  283. endif
  284. ifeq ($(SEQUOIA_LIB),)
  285. SEQUOIA_LIB=$(shell pkg-config --libs-only-L --libs-only-other sequoia-openpgp)
  286. endif
  287. ifeq ($(SEQUOIA_INC),)
  288. SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
  289. endif
  290. CFLAGS+= $(SEQUOIA_CFLAGS)
  291. CXXFLAGS+= $(SEQUOIA_CFLAGS)
  292. LD_FLAGS+= $(SEQUOIA_LDFLAGS)
  293. endif
  294. # YML_PATH is needed in the environment of every call to a program of the YML2 distribution
  295. export YML_PATH=$(YML2_PATH)
  296. # Postprocess for pEpMIME
  297. ifdef PEP_MIME
  298. # Replace c++11 with c++14 for now (limiting the subst to the ++11 means it doesn't matter if gnu or not)
  299. CXXFLAGS:=$(subst ++11,++14,$(CXXFLAGS)) -fPIC -fvisibility=hidden
  300. endif
  301. ifdef PEP_MIME
  302. ifndef PEP_MIME_SRC
  303. $(error "Compiling with the PEP_MIME option set requires the value of PEP_MIME_SRC to be set to the source directory for libpEpMIME")
  304. else
  305. CPPFLAGS+=-DPEP_BUILTIN_MIME
  306. ifneq ($(BUILD_ON),OS/390)
  307. LDLIBS+=-lstdc++
  308. endif
  309. ETPAN_LIB=
  310. ETPAN_INC=
  311. endif
  312. endif