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.

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