GOST public key algorithm ENGINE donated to the OpenSSL by Cryptocom.
[oweals/openssl.git] / engines / ccgost / Makefile
1 # OPENSSL_DIR is a root directory of openssl sources
2 THISDIR?=$(shell perl -MCwd -e 'print getcwd')
3 OPENSSL_DIR?=$(THISDIR)/../openssl
4 ENGINE_ID?=gost
5 TESTSUITE_DIR?=$(THISDIR)/test-suite
6 FOR?=$(HOST)
7 CC=gcc
8 CFLAGS=-fPIC -g -Wall -I$(OPENSSL_DIR)/include
9 LDFLAGS=-g -L $(OPENSSL_DIR) -static-libgcc
10 ifeq "$(FOR)" "s64"
11 CFLAGS+=-m64
12 LDFLAGS+=-m64
13 endif
14 OS:=$(shell uname -s)
15 ifeq "$(OS)" "FreeBSD" 
16 LIBDIR:=$(shell LD_LIBRARY_PATH=$(OPENSSL_DIR) $(OPENSSL_DIR)/apps/openssl version -d|sed -e 's/^[^"]*"//' -e 's/".*$$//')/lib
17 LDFLAGS+=-rpath $(LIBDIR)
18 endif
19
20
21 ifeq "$(FOR)" "w32"
22 ENGINE_LIB?=$(ENGINE_ID)$(DLLSUFFIX)
23 DLLSUFFIX=.dll
24 EXESUFFIX=.exe
25 CFLAGS+=-mno-cygwin
26 LDFLAGS+=-mno-cygwin
27 ifeq "$(OS)" "Linux"
28 CC=i586-mingw32msvc-gcc
29 endif
30 LIBS=-lcrypto.dll 
31 else
32 ENGINE_LIB?=lib$(ENGINE_ID)$(DLLSUFFIX)
33 LIBS=-lcrypto 
34 DLLSUFFIX=.so
35 endif
36 export DLLSUFFIX
37 export EXESUFFIX
38 ifneq "$(FOR)" ""
39 export FOR
40 endif
41 CFLAGS+=$(DEBUG_FLAGS)
42 export ENGINE_LIB
43 ENG_SOURCES=md_gost.c  gost_crypt.c  gost_asn1.c ameth.c pmeth.c\
44         gost_crypt.c gost_sign.c gost2001.c md_gost.c gost_crypt.c\
45         engine.c gost94_keyx.c keywrap.c gost2001_keyx.c
46 all: $(ENGINE_LIB) openssl.cnf
47 buildtests:
48 $(ENGINE_LIB): e_gost_err.o engine.o ameth.o pmeth.o params.o md_gost.o gosthash.o gost89.o gost_sign.o gost_crypt.o  keywrap.o  gost2001.o gost94_keyx.o gost2001_keyx.o gost_asn1.o
49         $(CC) $(LDFLAGS) -shared -o $@ $+ $(LIBS) $(LDFLAGS)
50 openssl.cnf: openssl.cnf.1 openssl.cnf.2
51         cat $+ > $@
52 openssl.cnf.1:
53         echo "openssl_conf = openssl_def" > $@
54 openssl.cnf.2:
55         echo "[openssl_def]" > $@
56         echo "engines = engine_section" >> $@
57         echo "[engine_section]" >> $@
58         echo "$(ENGINE_ID) = $(ENGINE_ID)_section" >> $@
59         echo "[$(ENGINE_ID)_section]" >> $@
60         echo "dynamic_path = $(THISDIR)/$(ENGINE_LIB)" >> $@
61         echo "engine_id = $(ENGINE_ID)" >> $@
62         echo "default_algorithms = ALL" >> $@
63 gosthash1.o: gosthash.c
64         $(CC) -c $(CFLAGS) -o $@ -DOPENSSL_BUILD $+
65 gostsum: gostsum.o gosthash.o gost89.o
66 inttests: gosttest$(EXESUFFIX) etalon wraptest$(EXESUFFIX) etalon.wrap ectest$(EXESUFFIX) etalon.ec
67         ./gosttest${EXESUFFIX} > gost_test
68         diff -uw gost_test etalon
69         ./wraptest$(EXESUFFIX) > wrap_test
70         diff -uw wrap_test etalon.wrap
71         ./ectest$(EXESUFFIX) > ec_test 2>&1
72         diff -uw ec_test etalon.ec
73 ectest$(EXESUFFIX): ectest.o gost2001_dbg.o gost_sign_dbg.o params.o e_gost_err.o
74         $(CC) -o $@ $(LDFLAGS) $+ -lcrypto 
75 %_dbg.o: %.c    
76         $(CC) -c $(CFLAGS) -DDEBUG_SIGN -DDEBUG_KEYS -o $@ $+
77 gosttest$(EXESUFFIX): gosttest.o gosthash.o gost89.o
78         $(CC) $(LDFLAGS) -o $@ $+
79 wraptest$(EXESUFFIX): wraptest.c keywrap.c gost89.c     
80         $(CC) -DDEBUG_DH $(LDFLAGS) -o $@ $+
81 sign_ex: LOADLIBES=-lcrypto
82 sign_ex: sign_ex.o
83 clean:
84         rm -f core gosttest gostsum *.o gost_test openssl.cnf* $(ENGINE_LIB)
85         if [ -f t/Makefile ]; then $(MAKE) -C t clean; fi
86         if [ -f $(TESTSUITE_DIR)/Makefile ]; then $(MAKE) -C $(TESTSUITE_DIR) clean; fi
87 e_gost_err.c e_gost_err.h: $(ENG_SOURCES) gost.ec e_gost_err.proto
88         perl $(OPENSSL_DIR)/util/mkerr.pl -conf gost.ec -nostatic -debug -write $(ENG_SOURCES)
89
90 tests: openssl.cnf.2
91         OPENSSL_DIR=$(OPENSSL_DIR) $(MAKE) -C $(TESTSUITE_DIR) CONFADD=$(THISDIR)/openssl.cnf.2
92
93 # depedencies
94 #
95 #
96 gost_sign.o: gost_sign.c sign.h paramset.h tools.h e_gost_err.h
97
98 pmeth.o: pmeth.c meth.h pmeth.h sign.h paramset.h e_gost_err.h
99
100 ameth.o: ameth.c tools.h meth.h pmeth.h gost_asn1.h crypt.h e_gost_err.h paramset.h
101
102 keywrap.o: keywrap.c gost89.h keywrap.h
103
104 gost2001.o: gost2001.c tools.h sign.h paramset.h e_gost_err.h
105
106 engine.o: engine.c md.h crypt.h meth.h e_gost_err.h
107
108 gost89.o: gost89.c gost89.h
109
110 gost_asn1.o: gost_asn1.c gost_asn1.h
111
112 gost_crypt.o: gost_crypt.c crypt.h gost89.h e_gost_err.h gost_asn1.h
113
114 gosthash.o: gosthash.c gost89.h gosthash.h
115
116 md_gost.o: md_gost.c md.h gosthash.h e_gost_err.h
117
118 params.o: params.c paramset.h
119
120 gost94_keyx.o: gost94_keyx.c  gost_asn1.h gost89.h gosthash.h crypt.h pmeth.h keywrap.h e_gost_err.h gostkeyx.h
121
122 gost2001_keyx.o: gost2001_keyx.c gost89.h gost_asn1.h e_gost_err.h keywrap.h crypt.h sign.h gostkeyx.h pmeth.h gosthash.h tools.h