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.

378 lines
11 KiB

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