forked from cossacklabs/themis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
1060 lines (911 loc) · 33.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2015 Cossack Labs Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#===== Early setup =============================================================
# Set default goal for "make"
.DEFAULT_GOAL := all
# Set shell for target commands
SHELL = bash
# Disable built-in rules
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
## build directory
BUILD_PATH ?= build
# Include system configuration file, creating it if necessary
-include $(BUILD_PATH)/configure.mk
$(BUILD_PATH)/configure.mk:
@./configure
#===== Variables ===============================================================
#----- Versioning --------------------------------------------------------------
# Increment VERSION when making a new release of Themis.
#
# If you make breaking (backwards-incompatible) changes to API or ABI
# then increment LIBRARY_SO_VERSION as well, and update package names.
VERSION := $(shell test -d .git && git describe --tags || cat VERSION)
LIBRARY_SO_VERSION = 0
# Version in format X.Y.Z, without build number and commit hash
VERSION_SHORT := $(shell cat VERSION)
#----- Toolchain ---------------------------------------------------------------
CMAKE ?= cmake
GO ?= go
CLANG_FORMAT ?= clang-format
CLANG_TIDY ?= clang-tidy
INSTALL ?= install
INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
#----- Build directories -------------------------------------------------------
INC_PATH = include
SRC_PATH = src
BIN_PATH = $(BUILD_PATH)
OBJ_PATH = $(BIN_PATH)/obj
AUD_PATH = $(BIN_PATH)/for_audit
TEST_SRC_PATH = tests
TEST_BIN_PATH = $(BIN_PATH)/tests
#----- Installation paths ------------------------------------------------------
## installation prefix
PREFIX ?= /usr/local
# Advanced variables for fine-tuning installation paths
prefix ?= $(PREFIX)
exec_prefix ?= $(prefix)
bindir ?= $(prefix)/bin
includedir ?= $(prefix)/include
libdir ?= $(exec_prefix)/lib
jnidir ?= $(libdir)
pkgconfigdir ?= $(libdir)/pkgconfig
#----- Basic compiler flags ----------------------------------------------------
# Add Themis source directory to search paths
CFLAGS += -I$(INC_PATH) -I$(SRC_PATH) -I$(SRC_PATH)/wrappers/themis/
LDFLAGS += -L$(BIN_PATH)
# Build shared libraries
CFLAGS += -fPIC
########################################################################
#
# Pretty-printing utilities
#
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
RIGHT_EDGE:=$(shell cols=$$(($$(tput cols) - 12)); cols=$$((cols > 68 ? 68 : cols)); echo $$cols)
MOVE_COLUMN=\033[$(RIGHT_EDGE)G
OK_STRING=$(MOVE_COLUMN)$(OK_COLOR)[OK]$(NO_COLOR)
ERROR_STRING=$(MOVE_COLUMN)$(ERROR_COLOR)[ERRORS]$(NO_COLOR)
WARN_STRING=$(MOVE_COLUMN)$(WARN_COLOR)[WARNINGS]$(NO_COLOR)
ifeq ($(VERBOSE),)
PRINT_OK = printf "$@ $(OK_STRING)\n"
PRINT_OK_ = printf "$(OK_STRING)\n"
else
PRINT_OK = printf "$@ $(OK_STRING)\n" && printf "$(CMD)\n"
PRINT_OK_ = printf "$(OK_STRING)\n" && printf "$(CMD)\n"
endif
PRINT_ERROR = printf "$@ $(ERROR_STRING)\n" && printf "$(CMD)\n$$LOG\n" && false
PRINT_ERROR_ = printf "$(ERROR_STRING)\n" && printf "$(CMD)\n$$LOG\n" && false
PRINT_WARNING = printf "$@ $(WARN_STRING)\n" && printf "$(CMD)\n$$LOG\n"
PRINT_WARNING_ = printf "$(WARN_STRING)\n" && printf "$(CMD)\n$$LOG\n"
BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -ne 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
BUILD_CMD_ = LOG=$$($(CMD) 2>&1) ; if [ $$? -ne 0 ]; then $(PRINT_ERROR_); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_); else $(PRINT_OK_); fi;
########################################################################
#
# Select and configure cryptographic engine
#
ifdef IS_EMSCRIPTEN
ENGINE ?= boringssl
else
ENGINE ?= libressl
endif
ifeq ($(ENGINE),openssl)
CRYPTO_ENGINE_DEF = OPENSSL
CRYPTO_ENGINE_PATH = openssl
else ifeq ($(ENGINE),libressl)
CRYPTO_ENGINE_DEF = LIBRESSL
CRYPTO_ENGINE_PATH = openssl
else ifeq ($(ENGINE),boringssl)
CRYPTO_ENGINE_DEF = BORINGSSL
CRYPTO_ENGINE_PATH = boringssl
else
$(error engine $(ENGINE) is not supported)
endif
CRYPTO_ENGINE = $(SRC_PATH)/soter/$(CRYPTO_ENGINE_PATH)
CFLAGS += -D$(CRYPTO_ENGINE_DEF) -DCRYPTO_ENGINE_PATH=$(CRYPTO_ENGINE_PATH)
CFLAGS += $(CRYPTO_ENGINE_CFLAGS)
# If we're building for macOS and there's Homebrew installed then prefer
# Homebrew's OpenSSL instead of the system one by default.
ifdef IS_MACOS
ifeq ($(CRYPTO_ENGINE_PATH),openssl)
ifneq ($(HOMEBREW_OPENSSL_PATH),)
CRYPTO_ENGINE_INCLUDE_PATH = $(HOMEBREW_OPENSSL_PATH)/include
CRYPTO_ENGINE_LIB_PATH = $(HOMEBREW_OPENSSL_PATH)/lib
endif
endif
endif
ifneq ($(ENGINE_INCLUDE_PATH),)
CRYPTO_ENGINE_INCLUDE_PATH = $(ENGINE_INCLUDE_PATH)
endif
ifneq ($(ENGINE_LIB_PATH),)
CRYPTO_ENGINE_LIB_PATH = $(ENGINE_LIB_PATH)
endif
# Basic compiler flags (lower priority than selected engine)
# We got /usr/local as default PREFIX and not all platforms include that path in default search path.
# Make sure whatever PREFIX is used, includes and libs are searched there.
#
# These two additional flags, -I and -L, need to be _after_ engine flags to not override it.
# CFLAGS is populated with CRYPTO_ENGINE_CFLAGS few lines above, so we could add -I to CFLAGS.
# LDFLAGS and CRYPTO_ENGINE_LDFLAGS are used separately, in this same order, so new macro was
# introduced, ADDITIONAL_LDFLAGS, to be used after CRYPTO_ENGINE_LDFLAGS, so that LDFLAGS remain
# at the beginning of linker flags.
CFLAGS += -I$(includedir)
ADDITIONAL_LDFLAGS += -L$(libdir)
ifneq ($(AUTH_SYM_ALG),)
CFLAGS += -D$(AUTH_SYM_ALG)
endif
ifneq ($(SYM_ALG),)
CFLAGS += -D$(SYM_ALG)
endif
ifeq ($(RSA_KEY_LENGTH),1024)
CFLAGS += -DTHEMIS_RSA_KEY_LENGTH=RSA_KEY_LENGTH_1024
endif
ifeq ($(RSA_KEY_LENGTH),2048)
CFLAGS += -DTHEMIS_RSA_KEY_LENGTH=RSA_KEY_LENGTH_2048
endif
ifeq ($(RSA_KEY_LENGTH),4096)
CFLAGS += -DTHEMIS_RSA_KEY_LENGTH=RSA_KEY_LENGTH_4096
endif
ifeq ($(RSA_KEY_LENGTH),8192)
CFLAGS += -DTHEMIS_RSA_KEY_LENGTH=RSA_KEY_LENGTH_8192
endif
########################################################################
#
# Compilation flags for C/C++ code
#
# Some build systems may call C compilers themselves. We don't want to leak
# our compilation flags there, so do not export these variables.
unexport CFLAGS LDFLAGS
# Prevent undefined symbols in produced binaries, but allow them for sanitizers
# which expect the libraries linked into the main executable to be underlinked.
ifndef WITH_ASAN
ifndef WITH_MSAN
ifndef WITH_TSAN
ifndef WITH_UBSAN
# Not all Emscripten toolchains support these flags so leave them out as well.
ifndef IS_EMSCRIPTEN
ifdef IS_MACOS
LDFLAGS += -Wl,-undefined,error
endif
ifdef IS_LINUX
LDFLAGS += -Wl,--no-undefined
endif
endif
endif
endif
endif
endif
CFLAGS += -O2 -g
# Get better runtime backtraces by preserving the frame pointer. This eats
# one of seven precious registers on x86, but our functions are quite large
# so they almost always use stack and need the frame pointer anyway.
CFLAGS += -fno-omit-frame-pointer
# Enable runtime stack canaries for functions to guard for buffer overflows.
# FIXME(ilammy, 2020-10-29): enable stack canaries for WasmThemis too
# Currently, stack protector is not supported by the "upstream" flavor
# of Emscripten toolchain. Tracking issue is here:
# https://github.com/emscripten-core/emscripten/issues/9780
ifndef IS_EMSCRIPTEN
ifeq (yes,$(call supported,-fstack-protector-strong))
CFLAGS += -fstack-protector-strong
else
CFLAGS += -fstack-protector
endif
endif
# Enable miscellaneous compile-time checks in standard library usage.
CFLAGS += -D_FORTIFY_SOURCE=2
# Prevent global offset table overwrite attacks.
ifdef IS_LINUX
LDFLAGS += -Wl,-z,relro -Wl,-z,now
endif
ifdef COVERAGE
CFLAGS += -O0 --coverage
LDFLAGS += --coverage
endif
ifdef DEBUG
CFLAGS += -O0 -DDEBUG
endif
ifneq ($(GEM_INSTALL_OPTIONS),)
_GEM_INSTALL_OPTIONS = $(GEM_INSTALL_OPTIONS)
endif
define supported =
$(shell if echo "int main(void){}" | $(if $(AFL_CC),$(AFL_CC),$(CC)) -x c -fsyntax-only -Werror $(1) - >/dev/null 2>&1; then echo "yes"; fi)
endef
ifeq (yes,$(WITH_FATAL_WARNINGS))
CFLAGS += -Werror
endif
# We are security-oriented so we use a pretty paranoid^W comprehensive set
# of compiler flags. Some of them are not available for all compilers, so
# we have to check if we can use them first.
CFLAGS += -Wall -Wextra
CFLAGS += -Wformat
CFLAGS += -Wformat-nonliteral
ifeq (yes,$(call supported,-Wformat-overflow))
CFLAGS += -Wformat-overflow
endif
CFLAGS += -Wformat-security
ifeq (yes,$(call supported,-Wformat-signedness))
CFLAGS += -Wformat-signedness
endif
ifeq (yes,$(call supported,-Wformat-truncation))
CFLAGS += -Wformat-truncation
endif
ifeq (yes,$(call supported,-Wnull-dereference))
CFLAGS += -Wnull-dereference
endif
ifeq (yes,$(call supported,-Wshift-overflow))
CFLAGS += -Wshift-overflow
endif
ifeq (yes,$(call supported,-Wshift-negative-value))
CFLAGS += -Wshift-negative-value
endif
CFLAGS += -Wstrict-overflow
CFLAGS += -Wswitch
ifeq (yes,$(call supported,-Walloca))
CFLAGS += -Walloca
endif
CFLAGS += -Wvla
CFLAGS += -Wpointer-arith
# Forbid old-style C function prototypes
# (skip for C++ files as older g++ complains about it)
ifeq (yes,$(call supported,-Wstrict-prototypes))
CFLAGS += $(if $(findstring .cpp,$(suffix $<)),,-Wstrict-prototypes)
endif
CFLAGS += -fvisibility=hidden
#
# Enable code sanitizers on demand and if supported by compiler
#
ifdef WITH_ASAN
CFLAGS += -DWITH_ASAN
ifeq (yes,$(call supported,-fsanitize=address))
SANITIZERS += -fsanitize=address
else
$(error -fsanitize=address requested but $(CC) does not seem to support it)
endif
endif
ifdef WITH_MSAN
CFLAGS += -DWITH_MSAN
ifeq (yes,$(call supported,-fsanitize=memory))
SANITIZERS += -fsanitize=memory -fsanitize-memory-track-origins=2
else
$(error -fsanitize=memory requested but $(CC) does not seem to support it)
endif
endif
ifdef WITH_TSAN
CFLAGS += -DWITH_TSAN
ifeq (yes,$(call supported,-fsanitize=thread))
SANITIZERS += -fsanitize=thread
else
$(error -fsanitize=thread requested but $(CC) does not seem to support it)
endif
endif
ifdef WITH_UBSAN
CFLAGS += -DWITH_UBSAN
ifeq (yes,$(call supported,-fsanitize=undefined))
SANITIZERS += -fsanitize=undefined
else
$(error -fsanitize=undefined requested but $(CC) does not seem to support it)
endif
ifeq (yes,$(call supported,-fsanitize=integer))
SANITIZERS += -fsanitize=integer
else
$(warning -fsanitize=integer not supported by $(CC), skipping...)
endif
ifeq (yes,$(call supported,-fsanitize=nullability))
SANITIZERS += -fsanitize=nullability
else
$(warning -fsanitize=nullability not supported by $(CC), skipping...)
endif
endif
ifeq (yes,$(WITH_FATAL_SANITIZERS))
SANITIZERS += -fno-sanitize-recover=all
endif
CFLAGS += $(SANITIZERS)
LDFLAGS += $(SANITIZERS)
# Binary format compatibility with Themis 0.9.6 on x86_64 architecture.
# https://github.com/cossacklabs/themis/pull/279
# Themis 0.9.6 is going EOL on 2020-12-13 so it can be removed after that.
ifneq ($(WITH_SCELL_COMPAT),)
CFLAGS += -DSCELL_COMPAT
endif
########################################################################
include src/soter/soter.mk
include src/themis/themis.mk
ifndef CARGO
include src/wrappers/themis/jsthemis/jsthemis.mk
include src/wrappers/themis/themispp/themispp.mk
include src/wrappers/themis/wasm/wasmthemis.mk
include jni/themis_jni.mk
include tests/test.mk
include tools/afl/fuzzy.mk
endif
########################################################################
#
# Principal Makefile targets
#
all: themis_static soter_static themis_shared soter_shared themis_pkgconfig soter_pkgconfig
@echo $(VERSION)
soter_static: $(BIN_PATH)/$(LIBSOTER_A)
soter_shared: $(BIN_PATH)/$(LIBSOTER_SO)
themis_static: $(BIN_PATH)/$(LIBTHEMIS_A)
themis_shared: $(BIN_PATH)/$(LIBTHEMIS_SO)
themis_jni: $(BIN_PATH)/$(LIBTHEMISJNI_SO)
soter_pkgconfig: $(BIN_PATH)/libsoter.pc
themis_pkgconfig: $(BIN_PATH)/libthemis.pc
fmt: $(FMT_FIXUP)
fmt_check: $(FMT_CHECK)
clean: CMD = rm -rf $(BIN_PATH)
clean: nist_rng_test_suite_clean clean_rust clean_python
@$(BUILD_CMD)
clean_rust:
ifdef RUST_VERSION
@cargo clean
@rm -f tools/rust/*.rust
endif
clean_python:
ifdef PYTHON3_VERSION
@rm -rf src/wrappers/themis/python/dist
@rm -rf src/wrappers/themis/python/pythemis.egg-info
endif
get_version:
@echo $(VERSION)
for-audit: $(SOTER_AUD) $(THEMIS_AUD)
########################################################################
#
# Common build rules
#
$(OBJ_PATH)/%.c.o: CMD = $(CC) -c -o $@ $< $(CFLAGS)
$(OBJ_PATH)/%.c.o: %.c
@mkdir -p $(@D)
@echo -n "compile "
@$(BUILD_CMD)
$(OBJ_PATH)/%.cpp.o: CMD = $(CXX) -c -o $@ $< $(CFLAGS)
$(OBJ_PATH)/%.cpp.o: %.cpp
@mkdir -p $(@D)
@echo -n "compile "
@$(BUILD_CMD)
$(OBJ_PATH)/%.c.fmt_fixup $(OBJ_PATH)/%.h.fmt_fixup $(OBJ_PATH)/%.cpp.fmt_fixup $(OBJ_PATH)/%.hpp.fmt_fixup: \
CMD = $(CLANG_TIDY) -fix $< -- $(CFLAGS) 2>/dev/null && $(CLANG_FORMAT) -i $< && touch $@
$(OBJ_PATH)/%.c.fmt_check $(OBJ_PATH)/%.h.fmt_check $(OBJ_PATH)/%.cpp.fmt_check $(OBJ_PATH)/%.hpp.fmt_check: \
CMD = $(CLANG_FORMAT) $< | diff -u $< - && $(CLANG_TIDY) $< -- $(CFLAGS) 2>/dev/null && touch $@
$(OBJ_PATH)/%.fmt_fixup: %
@mkdir -p $(@D)
@echo -n "fixup $< "
@$(BUILD_CMD_)
$(OBJ_PATH)/%.fmt_check: %
@mkdir -p $(@D)
@echo -n "check $< "
@$(BUILD_CMD_)
#$(AUD_PATH)/%: CMD = $(CC) $(CFLAGS) -E -dI -dD $< -o $@
$(AUD_PATH)/%: CMD = ./scripts/pp.sh $< $@
$(AUD_PATH)/%: $(SRC_PATH)/%
@mkdir -p $(@D)
@echo -n "compile "
@$(BUILD_CMD)
########################################################################
#
# Themis Core installation
#
# Red Hat systems usually do not have "lsb_release" in their default setup
# so we look into the release version files from "centos-release" package.
ifdef IS_LINUX
ifeq ($(shell . /etc/os-release; echo $$ID),centos)
IS_CENTOS := true
LD_SO_CONF = $(DESTDIR)/etc/ld.so.conf.d/themis.conf
endif
endif
install: all install_soter install_themis
@echo -n "Themis installed to $(PREFIX)"
@$(PRINT_OK_)
# CentOS does not have /usr/local/lib in the default search path, add it there.
ifeq ($(IS_CENTOS),true)
-@mkdir -p "$$(dirname "$(LD_SO_CONF)")"
-@echo "$(libdir)" > "$(LD_SO_CONF)" && echo "Added $(libdir) to $(LD_SO_CONF)"
endif
ifdef IS_LINUX
-@ldconfig
endif
@if [ -e /usr/include/themis/themis.h ] && [ -e /usr/local/include/themis/themis.h ]; then \
echo ""; \
echo "Multiple Themis installations detected in standard system paths:"; \
echo ""; \
echo " - /usr"; \
echo " - /usr/local"; \
echo ""; \
echo "This may lead to surprising behaviour when building and using software"; \
echo "which depends on Themis."; \
echo ""; \
echo "If you previously had Themis installed from source to \"/usr\","; \
echo "consider uninstalling the old version with"; \
echo ""; \
echo " sudo $(MAKE) uninstall PREFIX=/usr"; \
echo ""; \
echo "and keep the new version in \"/usr/local\"."; \
echo ""; \
fi
uninstall: uninstall_themis uninstall_soter
@echo -n "Themis uninstalled from $(PREFIX) "
@$(PRINT_OK_)
# Remove non-standard library search path created by "install" for CentOS.
ifeq ($(IS_CENTOS),true)
@rm -f "$(LD_SO_CONF)"
endif
########################################################################
#
# Themis distribution tarball
#
DIST_DIR = themis_$(VERSION)
# Themis Core source code, tests, docs
DIST_FILES += docs src tests Makefile VERSION
DIST_FILES += README.md CHANGELOG.md LICENSE
DIST_FILES += PKGBUILD.MSYS2 Themis.nsi
# Supporting files for language wrappers
DIST_FILES += Cargo.toml
DIST_FILES += CMakeLists.txt
DIST_FILES += gothemis
DIST_FILES += jni
DIST_FILES += scripts tools
dist:
@mkdir -p $(DIST_DIR)
@rsync -a $(DIST_FILES) $(DIST_DIR)
@tar czf $(DIST_DIR).tar.gz $(DIST_DIR)
@rm -rf $(DIST_DIR)
@echo $(DIST_DIR).tar.gz
unpack_dist:
@tar -xf $(DIST_DIR).tar.gz
########################################################################
#
# Themis wrapper installation
#
## PHP #########################
ifeq ($(PHP_VERSION),5)
PHP_FOLDER = php
else
PHP_FOLDER = php7
endif
phpthemis_install: CMD = cd src/wrappers/themis/$(PHP_FOLDER) && phpize && ./configure && make install
phpthemis_install:
ifdef PHP_VERSION
@echo -n "phpthemis install "
@$(BUILD_CMD_)
else
@echo "Error: php not found"
@exit 1
endif
ifneq ("$(wildcard src/wrappers/themis/php/Makefile)","")
PHP_THEMIS_INSTALL = 1
endif
phpthemis_uninstall: CMD = if [ -e src/wrappers/themis/php/Makefile ]; then cd src/wrappers/themis/php && make distclean ; fi;
phpthemis_uninstall:
ifdef PHP_THEMIS_INSTALL
@echo -n "phpthemis uninstall "
@$(BUILD_CMD_)
endif
uninstall: phpthemis_uninstall
## Ruby ########################
rbthemis_install: CMD = cd src/wrappers/themis/ruby && gem build rbthemis.gemspec && gem install ./*.gem $(_GEM_INSTALL_OPTIONS)
rbthemis_install:
ifdef RUBY_GEM_VERSION
@echo -n "rbthemis install "
@$(BUILD_CMD_)
else
@echo "Error: ruby gem not found"
@exit 1
endif
rbthemis_uninstall: CMD = gem uninstall rbthemis
rbthemis_uninstall:
ifdef RUBY_GEM_VERSION
@echo -n "rbthemis uninstall "
@$(BUILD_CMD_)
endif
uninstall: rbthemis_uninstall
## Python ######################
ifdef PIP_VERSION
PIP_THEMIS_INSTALL := $(shell pip freeze |grep themis)
endif
pythemis_install: CMD = cd src/wrappers/themis/python/ && pip3 install .
pythemis_install:
ifeq ($(PYTHON3_VERSION),)
@echo "python3 not found"
@exit 1
endif
@echo -n "pythemis install "
@$(BUILD_CMD_)
########################################################################
#
# Packaging Themis Core: Linux distributions
#
ifeq ($(ENGINE),boringssl)
ifeq ($(CRYPTO_ENGINE_LIB_PATH),)
PACKAGE_EMBEDDED_BORINGSSL := yes
endif
endif
COSSACKLABS_URL = https://www.cossacklabs.com
MAINTAINER = "Cossack Labs Limited <dev@cossacklabs.com>"
LICENSE_NAME = "Apache License Version 2.0"
DEB_CODENAME := $(shell lsb_release -cs 2> /dev/null)
DEB_ARCHITECTURE = `dpkg --print-architecture 2>/dev/null`
ifeq ($(PACKAGE_EMBEDDED_BORINGSSL),yes)
# fpm has "--provides" option, but it eats package versions when we need to
# preserve them for correct dependency resolution. Insert fields directly.
DEB_DEPENDENCIES += --deb-field "Provides: $(CANONICAL_PACKAGE_NAME) (= $(VERSION)+$(OS_CODENAME))"
DEB_DEPENDENCIES += --conflicts $(CANONICAL_PACKAGE_NAME)
DEB_DEPENDENCIES += --replaces $(CANONICAL_PACKAGE_NAME)
DEB_DEPENDENCIES_DEV += --deb-field "Provides: $(DEB_CANONICAL_DEV_PACKAGE_NAME) (= $(VERSION)+$(OS_CODENAME))"
DEB_DEPENDENCIES_DEV += --conflicts $(DEB_CANONICAL_DEV_PACKAGE_NAME)
DEB_DEPENDENCIES_DEV += --replaces $(DEB_CANONICAL_DEV_PACKAGE_NAME)
else
# If we were using native Debian packaging, dpkg-shlibdeps could supply us with
# accurate dependency information. However, we build packages manually, so we
# use dependencies of "libssl-dev" as a proxy. Typically this is "libssl1.1".
#
# Example output of "apt-cache depends" (from Ubuntu 16.04):
#
# libssl-dev
# Depends: libssl1.0.0
# Depends: zlib1g-dev
# Recommends: libssl-doc
DEB_DEPENDENCIES += $(shell apt-cache depends libssl-dev | awk '$$1 == "Depends:" && $$2 ~ /^libssl/ { print "--depends", $$2 }' )
DEB_DEPENDENCIES_DEV += --depends libssl-dev
endif
DEB_DEPENDENCIES_DEV += --depends "$(PACKAGE_NAME) = $(VERSION)+$(OS_CODENAME)"
DEB_DEPENDENCIES_THEMISPP = --depends "$(DEB_CANONICAL_DEV_PACKAGE_NAME) = $(VERSION)+$(OS_CODENAME)"
DEB_DEPENDENCIES_JNI += --depends "$(CANONICAL_PACKAGE_NAME) >= $(VERSION)+$(OS_CODENAME)"
ifeq ($(PACKAGE_EMBEDDED_BORINGSSL),yes)
RPM_DEPENDENCIES += --provides $(CANONICAL_PACKAGE_NAME)
RPM_DEPENDENCIES += --conflicts $(CANONICAL_PACKAGE_NAME)
RPM_DEPENDENCIES += --replaces $(CANONICAL_PACKAGE_NAME)
RPM_DEPENDENCIES_DEV += --provides $(RPM_CANONICAL_DEV_PACKAGE_NAME)
RPM_DEPENDENCIES_DEV += --conflicts $(RPM_CANONICAL_DEV_PACKAGE_NAME)
RPM_DEPENDENCIES_DEV += --replaces $(RPM_CANONICAL_DEV_PACKAGE_NAME)
else
RPM_DEPENDENCIES += --depends openssl-libs
RPM_DEPENDENCIES_DEV += --depends openssl-devel
endif
RPM_DEPENDENCIES_DEV += --depends "$(PACKAGE_NAME) = $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_DEPENDENCIES_THEMISPP = --depends "$(RPM_CANONICAL_DEV_PACKAGE_NAME) = $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_DEPENDENCIES_JNI += --depends "$(CANONICAL_PACKAGE_NAME) >= $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_RELEASE_NUM = 1
OS_NAME := $(shell lsb_release -is 2>/dev/null || printf 'unknown')
ifeq ($(OS_NAME),$(filter $(OS_NAME),Debian Ubuntu))
#0.9.4-153-g9915004+jessie_amd64.deb.
NAME_SUFFIX = $(VERSION)+$(DEB_CODENAME)_$(DEB_ARCHITECTURE).deb
OS_CODENAME = $(shell lsb_release -cs)
DEB_LIBDIR := /lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
else ifeq ($(OS_NAME),$(filter $(OS_NAME),RedHatEnterpriseServer CentOS))
OS_NAME = $(shell cat /etc/os-release | grep -e "^ID=\".*\"" | cut -d'"' -f2)
OS_VERSION = $(shell cat /etc/os-release | grep -i version_id|cut -d'"' -f2)
ARCHITECTURE = $(shell arch)
RPM_VERSION = $(shell echo -n "$(VERSION)"|sed s/-/_/g)
NAME_SUFFIX = $(RPM_VERSION).$(OS_NAME)$(OS_VERSION).$(ARCHITECTURE).rpm
RPM_LIBDIR := /$(shell [ $$(arch) == "x86_64" ] && echo "lib64" || echo "lib")
endif
CANONICAL_PACKAGE_NAME = libthemis
DEB_CANONICAL_DEV_PACKAGE_NAME = $(CANONICAL_PACKAGE_NAME)-dev
RPM_CANONICAL_DEV_PACKAGE_NAME = $(CANONICAL_PACKAGE_NAME)-devel
ifeq ($(PACKAGE_EMBEDDED_BORINGSSL),yes)
PACKAGE_NAME = libthemis-boringssl
else
PACKAGE_NAME = libthemis
endif
DEB_DEV_PACKAGE_NAME = $(PACKAGE_NAME)-dev
RPM_DEV_PACKAGE_NAME = $(PACKAGE_NAME)-devel
DEB_THEMISPP_PACKAGE_NAME = libthemispp-dev
RPM_THEMISPP_PACKAGE_NAME = libthemispp-devel
JNI_PACKAGE_NAME = libthemis-jni
PACKAGE_CATEGORY = security
SHORT_DESCRIPTION = Data security library for network communication and data storage
RPM_SUMMARY = Data security library for network communication and data storage. \
Themis is a data security library, providing users with high-quality security \
services for secure messaging of any kinds and flexible data storage. Themis \
is aimed at modern developers, with high level OOP wrappers for Ruby, Python, \
PHP, Java / Android and iOS / OSX. It is designed with ease of use in mind, \
high security and cross-platform availability.
POST_INSTALL_SCRIPT := $(BIN_PATH)/post_install.sh
POST_UNINSTALL_SCRIPT := $(BIN_PATH)/post_uninstall.sh
DEV_PACKAGE_FILES += $(includedir)/soter/
DEV_PACKAGE_FILES += $(includedir)/themis/
DEV_PACKAGE_FILES += $(pkgconfigdir)/
DEV_PACKAGE_FILES += $(libdir)/$(LIBSOTER_A)
DEV_PACKAGE_FILES += $(libdir)/$(LIBSOTER_LINK)
DEV_PACKAGE_FILES += $(libdir)/$(LIBTHEMIS_A)
DEV_PACKAGE_FILES += $(libdir)/$(LIBTHEMIS_LINK)
LIB_PACKAGE_FILES += $(libdir)/$(LIBSOTER_SO)
LIB_PACKAGE_FILES += $(libdir)/$(LIBTHEMIS_SO)
THEMISPP_PACKAGE_FILES += $(includedir)/themispp/
JNI_PACKAGE_FILES += $(jnidir)/$(LIBTHEMISJNI_SO)
deb: MODE_PACKAGING = 1
deb: DESTDIR = $(BIN_PATH)/deb/root
deb: PREFIX = /usr
deb: libdir = $(PREFIX)$(DEB_LIBDIR)
deb: jnidir = $(PREFIX)$(DEB_LIBDIR)/jni
deb: install $(if $(WITHOUT_THEMISPP), , themispp_install) $(if $(WITHOUT_JAVA), , themis_jni_install)
@printf "ldconfig" > $(POST_INSTALL_SCRIPT)
@printf "ldconfig" > $(POST_UNINSTALL_SCRIPT)
@find $(DESTDIR) -name '*.$(SHARED_EXT)*' -type f -exec strip -o {} {} \;
@fpm --input-type dir \
--output-type deb \
--name $(DEB_DEV_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/$(DEB_DEV_PACKAGE_NAME)_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
$(DEB_DEPENDENCIES_DEV) \
--deb-priority optional \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--category $(PACKAGE_CATEGORY) \
--force \
$(foreach file,$(DEV_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
@fpm --input-type dir \
--output-type deb \
--name $(PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/$(PACKAGE_NAME)_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
$(DEB_DEPENDENCIES) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--deb-priority optional \
--category $(PACKAGE_CATEGORY) \
--force \
$(foreach file,$(LIB_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
ifndef WITHOUT_THEMISPP
@fpm --input-type dir \
--output-type deb \
--name $(DEB_THEMISPP_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/$(DEB_THEMISPP_PACKAGE_NAME)_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
$(DEB_DEPENDENCIES_THEMISPP) \
--deb-priority optional \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--category $(PACKAGE_CATEGORY) \
--force \
$(foreach file,$(THEMISPP_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
endif
ifndef WITHOUT_JAVA
@fpm --input-type dir \
--output-type deb \
--name $(JNI_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/$(JNI_PACKAGE_NAME)_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
$(DEB_DEPENDENCIES_JNI) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--deb-priority optional \
--category $(PACKAGE_CATEGORY) \
--force \
$(foreach file,$(JNI_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
endif
@find $(BIN_PATH) -name \*.deb
# Use builtin feature of fpm to create a .deb package from a Python package dir.
# Dependencies are automatically added, i.e. PyThemis depends on `six`, so fpm will add `python3-six` to deps.
deb_python: DEB_ARCHITECTURE = all
deb_python: DESTDIR = $(BIN_PATH)/deb/pythemis_root
deb_python:
@mkdir -p $(BIN_PATH)/deb
@fpm --input-type python \
--output-type deb \
--python-bin=python3 \
--python-package-name-prefix=python3 \
--name python3-pythemis \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/python3-pythemis_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
--depends python3 --depends libthemis \
--deb-priority optional \
--category $(PACKAGE_CATEGORY) \
--force \
src/wrappers/themis/python
@echo $(BIN_PATH)/deb/python3-pythemis_$(NAME_SUFFIX)
# Using `apt` since it could install dependencies (we depend on python3-six),
# while dpkg would just complain about missing dependency and fail
pythemis_install_deb: DEB_ARCHITECTURE = all
pythemis_install_deb: deb_python
apt install ./$(BIN_PATH)/deb/python3-pythemis_$(NAME_SUFFIX)
rpm: MODE_PACKAGING = 1
rpm: DESTDIR = $(BIN_PATH)/rpm/root
rpm: PREFIX = /usr
rpm: libdir = $(PREFIX)$(RPM_LIBDIR)
rpm: install themispp_install themis_jni_install
@printf "ldconfig" > $(POST_INSTALL_SCRIPT)
@printf "ldconfig" > $(POST_UNINSTALL_SCRIPT)
@find $(DESTDIR) -name '*.$(SHARED_EXT)*' -type f -exec strip -o {} {} \;
@fpm --input-type dir \
--output-type rpm \
--name $(RPM_DEV_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
$(RPM_DEPENDENCIES_DEV) \
--maintainer $(MAINTAINER) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--package $(BIN_PATH)/rpm/$(RPM_DEV_PACKAGE_NAME)-$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(DEV_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
@fpm --input-type dir \
--output-type rpm \
--name $(PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
--maintainer $(MAINTAINER) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
$(RPM_DEPENDENCIES) \
--package $(BIN_PATH)/rpm/$(PACKAGE_NAME)-$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(LIB_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
@fpm --input-type dir \
--output-type rpm \
--name $(RPM_THEMISPP_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
--maintainer $(MAINTAINER) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
$(RPM_DEPENDENCIES_THEMISPP) \
--package $(BIN_PATH)/rpm/$(RPM_THEMISPP_PACKAGE_NAME)-$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(THEMISPP_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
@fpm --input-type dir \
--output-type rpm \
--name $(JNI_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
--maintainer $(MAINTAINER) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
$(RPM_DEPENDENCIES_JNI) \
--package $(BIN_PATH)/rpm/$(JNI_PACKAGE_NAME)-$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(JNI_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))
@find $(BIN_PATH) -name \*.rpm
rpm_python: ARCHITECTURE = all
rpm_python:
@mkdir -p $(BIN_PATH)/rpm
@fpm --input-type python \
--output-type rpm \
--python-bin=python3 \
--python-package-name-prefix=python3 \
--name python3-pythemis \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/rpm/python3-pythemis_$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--depends python3 --depends libthemis \
--category $(PACKAGE_CATEGORY) \
--force \
src/wrappers/themis/python
@echo $(BIN_PATH)/rpm/python3-pythemis_$(NAME_SUFFIX)
pythemis_install_rpm: ARCHITECTURE = all
pythemis_install_rpm: rpm_python
yum install ./$(BIN_PATH)/rpm/python3-pythemis_$(NAME_SUFFIX)
########################################################################
#
# Packaging Themis Core: Windows (NSIS)
#
nsis_installer: $(BIN_PATH)/InstallThemis.exe
$(BIN_PATH)/InstallThemis.exe: FORCE
ifdef IS_MSYS
@$(MAKE) install PREFIX=/ DESTDIR="$(BIN_PATH)/install"
@ldd "$(BIN_PATH)/install/bin"/*.dll | \
awk '$$3 ~ "^/usr/bin" { print $$3}' | sort --uniq | \
xargs -I % cp % "$(BIN_PATH)/install/bin"
@makensis Themis.nsi
@rm -r "$(BIN_PATH)/install"
else
@echo "NSIS installers can only be build in MSYS environment on Windows."
@echo
@echo "Please make sure that you are using MSYS terminal session which"
@echo "is usually available as 'MSYS2 MSYS' shortcut in the MSYS group"
@echo "of the Start menu."
@exit 1
endif
FORCE:
########################################################################