1 # Makefile for secure rtp 2 # 3 # David A. McGrew 4 # Cisco Systems, Inc. 5 6 # targets: 7 # 8 # runtest runs test applications 9 # test builds test applications 10 # libcrypt.a static library implementing crypto engine 11 # libsrtp.a static library implementing srtp 12 # clean removes objects, libs, and executables 13 # distribution cleans and builds a .tgz 14 # tags builds etags file from all .c and .h files 15 16 .PHONY: all test build_table_apps 17 18 all: test 19 20 runtest: build_table_apps test 21 @echo "running libsrtp test applications..." 22 crypto/test/cipher_driver$(EXE) -v >/dev/null 23 crypto/test/kernel_driver$(EXE) -v >/dev/null 24 test/rdbx_driver$(EXE) -v >/dev/null 25 test/srtp_driver$(EXE) -v >/dev/null 26 test/roc_driver$(EXE) -v >/dev/null 27 test/replay_driver$(EXE) -v >/dev/null 28 test/dtls_srtp_driver$(EXE) >/dev/null 29 cd test; $(abspath $(srcdir))/test/rtpw_test.sh >/dev/null 30 @echo "libsrtp test applications passed." 31 $(MAKE) -C crypto runtest 32 33 # makefile variables 34 35 CC = gcc 36 INCDIR = -Icrypto/include -I$(srcdir)/include -I$(srcdir)/crypto/include 37 DEFS = -DHAVE_CONFIG_H 38 CPPFLAGS= 39 CFLAGS = -Wall -O4 -fexpensive-optimizations -funroll-loops 40 LIBS = 41 LDFLAGS = -L. 42 COMPILE = $(CC) $(DEFS) $(INCDIR) $(CPPFLAGS) $(CFLAGS) 43 SRTPLIB = -lsrtp 44 45 RANLIB = ranlib 46 INSTALL = /usr/bin/install -c 47 48 # EXE defines the suffix on executables - it's .exe for Windows, and 49 # null on linux, bsd, and OS X and other OSes. 50 EXE = 51 # gdoi is the group domain of interpretation for isakmp, a group key 52 # management system which can provide keys for srtp 53 gdoi = 54 # Random source. 55 RNG_OBJS = rand_source.o 56 57 srcdir = . 58 top_srcdir = . 59 top_builddir = 60 61 prefix = /usr/local 62 exec_prefix = ${prefix} 63 includedir = ${prefix}/include 64 libdir = ${exec_prefix}/lib 65 66 67 # implicit rules for object files and test apps 68 69 %.o: %.c 70 $(COMPILE) -c $< -o $@ 71 72 %$(EXE): %.c 73 $(COMPILE) $(LDFLAGS) $< -o $@ $(SRTPLIB) $(LIBS) 74 75 76 # libcrypt.a (the crypto engine) 77 ciphers = crypto/cipher/cipher.o crypto/cipher/null_cipher.o \ 78 crypto/cipher/aes.o crypto/cipher/aes_icm.o \ 79 crypto/cipher/aes_cbc.o 80 81 hashes = crypto/hash/null_auth.o crypto/hash/sha1.o \ 82 crypto/hash/hmac.o crypto/hash/auth.o # crypto/hash/tmmhv2.o 83 84 replay = crypto/replay/rdb.o crypto/replay/rdbx.o \ 85 crypto/replay/ut_sim.o 86 87 math = crypto/math/datatypes.o crypto/math/stat.o 88 89 ust = crypto/ust/ust.o 90 91 rng = crypto/rng/$(RNG_OBJS) crypto/rng/prng.o crypto/rng/ctr_prng.o 92 93 err = crypto/kernel/err.o 94 95 kernel = crypto/kernel/crypto_kernel.o crypto/kernel/alloc.o \ 96 crypto/kernel/key.o $(rng) $(err) # $(ust) 97 98 cryptobj = $(ciphers) $(hashes) $(math) $(stat) $(kernel) $(replay) 99 100 # libsrtp.a (implements srtp processing) 101 102 srtpobj = srtp/srtp.o srtp/ekt.o 103 104 libsrtp.a: $(srtpobj) $(cryptobj) $(gdoi) 105 ar cr libsrtp.a $^ 106 $(RANLIB) libsrtp.a 107 108 # libcryptomath.a contains general-purpose routines that are used to 109 # generate tables and verify cryptoalgorithm implementations - this 110 # library is not meant to be included in production code 111 112 cryptomath = crypto/math/math.o crypto/math/gf2_8.o 113 114 libcryptomath.a: $(cryptomath) 115 ar cr libcryptomath.a $(cryptomath) 116 $(RANLIB) libcryptomath.a 117 118 119 # test applications 120 121 crypto_testapp = crypto/test/aes_calc$(EXE) crypto/test/cipher_driver$(EXE) \ 122 crypto/test/datatypes_driver$(EXE) crypto/test/kernel_driver$(EXE) \ 123 crypto/test/rand_gen$(EXE) crypto/test/sha1_driver$(EXE) \ 124 crypto/test/stat_driver$(EXE) 125 126 testapp = $(crypto_testapp) test/srtp_driver$(EXE) test/replay_driver$(EXE) \ 127 test/roc_driver$(EXE) test/rdbx_driver$(EXE) test/rtpw$(EXE) \ 128 test/dtls_srtp_driver$(EXE) 129 130 $(testapp): libsrtp.a 131 132 test/rtpw$(EXE): test/rtpw.c test/rtp.c test/getopt_s.c 133 $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB) 134 135 test/srtp_driver$(EXE): test/srtp_driver.c test/getopt_s.c 136 $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB) 137 138 test/rdbx_driver$(EXE): test/rdbx_driver.c test/getopt_s.c 139 $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB) 140 141 test/dtls_srtp_driver$(EXE): test/dtls_srtp_driver.c test/getopt_s.c 142 $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB) 143 144 test: $(testapp) 145 @echo "Build done. Please run '$(MAKE) runtest' to run self tests." 146 147 memtest: test/srtp_driver 148 @test/srtp_driver -v -d "alloc" > tmp 149 @grep freed tmp | wc -l > freed 150 @grep allocated tmp | wc -l > allocated 151 @echo "checking for memory leaks (only works with --enable-stdout)" 152 cmp -s allocated freed 153 @echo "passed (same number of alloc() and dealloc() calls found)" 154 @rm freed allocated tmp 155 156 # tables_apps are used to generate the tables used in the crypto 157 # implementations; these need only be generated during porting, not 158 # for building libsrtp or the test applications 159 160 table_apps = tables/aes_tables 161 162 build_table_apps: $(table_apps) 163 164 # in the tables/ subdirectory, we use libcryptomath instead of libsrtp 165 166 tables/%: tables/%.c libcryptomath.a 167 $(COMPILE) $(LDFLAGS) $< -o $@ $(LIBS) libcryptomath.a 168 169 # the target 'plot' runs the timing test (test/srtp_driver -t) then 170 # uses gnuplot to produce plots of the results - see the script file 171 # 'timing' 172 173 plot: test/srtp_driver 174 test/srtp_driver -t > timing.dat 175 176 177 # bookkeeping: tags, clean, and distribution 178 179 tags: 180 etags */*.[ch] */*/*.[ch] 181 182 183 # documentation - the target libsrtpdoc builds a PDF file documenting 184 # libsrtp 185 186 libsrtpdoc: 187 $(MAKE) -C doc 188 189 .PHONY: clean superclean distclean install 190 191 install: 192 @if [ -r $(DESTDIR)$(includedir)/srtp/srtp.h ]; then \ 193 echo "you should run 'make uninstall' first"; exit 1; \ 194 fi 195 $(INSTALL) -d $(DESTDIR)$(includedir)/srtp 196 $(INSTALL) -d $(DESTDIR)$(libdir) 197 cp $(srcdir)/include/*.h $(DESTDIR)$(includedir)/srtp 198 cp $(srcdir)/crypto/include/*.h $(DESTDIR)$(includedir)/srtp 199 if [ "$(srcdir)" != "." ]; then cp crypto/include/*.h $(DESTDIR)$(includedir)/srtp; fi 200 if [ -f libsrtp.a ]; then cp libsrtp.a $(DESTDIR)$(libdir)/; fi 201 202 uninstall: 203 rm -f $(DESTDIR)$(includedir)/srtp/*.h 204 rm -f $(DESTDIR)$(libdir)/libsrtp.a 205 -rmdir $(DESTDIR)$(includedir)/srtp 206 207 clean: 208 rm -rf $(cryptobj) $(srtpobj) $(cryptomath) TAGS \ 209 libcryptomath.a libsrtp.a core *.core test/core 210 for a in * */* */*/*; do \ 211 if [ -f "$$a~" ] ; then rm -f $$a~; fi; \ 212 done; 213 for a in $(testapp) $(table_apps); do rm -rf $$a$(EXE); done 214 rm -rf *.pict *.jpg *.dat 215 rm -rf freed allocated tmp 216 $(MAKE) -C doc clean 217 $(MAKE) -C crypto clean 218 219 220 superclean: clean 221 rm -rf crypto/include/config.h config.log config.cache config.status \ 222 Makefile crypto/Makefile doc/Makefile \ 223 .gdb_history test/.gdb_history .DS_Store 224 rm -rf autom4te.cache 225 226 distclean: superclean 227 228 distname = srtp-$(shell cat VERSION) 229 230 distribution: runtest superclean 231 if ! [ -f VERSION ]; then exit 1; fi 232 if [ -f ../$(distname).tgz ]; then \ 233 mv ../$(distname).tgz ../$(distname).tgz.bak; \ 234 fi 235 cd ..; tar cvzf $(distname).tgz srtp 236 237 # EOF 238