Makefile.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. # Makefile for secure rtp
  2. #
  3. # David A. McGrew
  4. # Cisco Systems, Inc.
  5. # targets:
  6. #
  7. # runtest runs test applications
  8. # runtest-valgrind runs test applications with valgrind
  9. # test builds test applications
  10. # libsrtp2.a static library implementing srtp
  11. # libsrtp2.so shared 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. DYNAMIC_PATH_VAR = @DYNAMIC_PATH_VAR@
  16. CRYPTO_LIBDIR = @CRYPTO_LIBDIR@
  17. USE_EXTERNAL_CRYPTO = @USE_EXTERNAL_CRYPTO@
  18. HAVE_PCAP = @HAVE_PCAP@
  19. # Specify how tests should find shared libraries on macOS and Linux
  20. #
  21. # macOS purges DYLD_LIBRARY_PATH when spawning subprocesses, so it's
  22. # not possible to pass this in from the outside; we have to specify
  23. # it for any subprocesses we call. No support for dynamic linked
  24. # tests on Windows.
  25. ifneq ($(strip $(CRYPTO_LIBDIR)),)
  26. ifneq ($(OS),Windows_NT)
  27. UNAME_S = $(shell uname -s)
  28. ifeq ($(UNAME_S),Linux)
  29. FIND_LIBRARIES = LD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
  30. endif
  31. ifeq ($(UNAME_S),Darwin)
  32. FIND_LIBRARIES = DYLD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
  33. endif
  34. CRYPTO_LIBDIR_FORWARD = CRYPTO_LIBDIR=$(CRYPTO_LIBDIR)
  35. endif
  36. endif
  37. .PHONY: all shared_library test
  38. all: test
  39. runtest: test
  40. @echo "running libsrtp2 test applications..."
  41. $(FIND_LIBRARIES) crypto/test/cipher_driver$(EXE) -v >/dev/null
  42. $(FIND_LIBRARIES) crypto/test/kernel_driver$(EXE) -v >/dev/null
  43. $(FIND_LIBRARIES) test/test_srtp$(EXE) >/dev/null
  44. $(FIND_LIBRARIES) test/rdbx_driver$(EXE) -v >/dev/null
  45. $(FIND_LIBRARIES) test/srtp_driver$(EXE) -v >/dev/null
  46. $(FIND_LIBRARIES) test/roc_driver$(EXE) -v >/dev/null
  47. $(FIND_LIBRARIES) test/replay_driver$(EXE) -v >/dev/null
  48. $(FIND_LIBRARIES) test/dtls_srtp_driver$(EXE) >/dev/null
  49. cd test; $(CRYPTO_LIBDIR_FORWARD) $(abspath $(srcdir))/test/rtpw_test.sh -w $(abspath $(srcdir))/test/words.txt >/dev/null
  50. ifeq (1, $(USE_EXTERNAL_CRYPTO))
  51. cd test; $(CRYPTO_LIBDIR_FORWARD) $(abspath $(srcdir))/test/rtpw_test_gcm.sh -w $(abspath $(srcdir))/test/words.txt >/dev/null
  52. endif
  53. @echo "libsrtp2 test applications passed."
  54. $(MAKE) -C crypto runtest
  55. runtest-valgrind: test
  56. @echo "running libsrtp2 test applications... (valgrind)"
  57. valgrind --error-exitcode=1 --leak-check=full test/test_srtp$(EXE) -v >/dev/null
  58. valgrind --error-exitcode=1 --leak-check=full test/srtp_driver$(EXE) -v >/dev/null
  59. @echo "libsrtp2 test applications passed. (valgrind)"
  60. # makefile variables
  61. CC = @CC@
  62. CXX = @CXX@
  63. INCDIR = -Icrypto/include -I$(srcdir)/include -I$(srcdir)/crypto/include
  64. DEFS = @DEFS@
  65. CPPFLAGS= @CPPFLAGS@
  66. CFLAGS = @CFLAGS@
  67. CXXFLAGS= @CXXFLAGS@
  68. srtp-fuzzer: CFLAGS += -g
  69. srtp-fuzzer: CXXFLAGS += -g
  70. LIBS = @LIBS@
  71. LDFLAGS = -L. @LDFLAGS@
  72. COMPILE = $(CC) $(DEFS) $(INCDIR) $(CPPFLAGS) $(CFLAGS)
  73. SRTPLIB = -lsrtp2
  74. PCAP_LIB = @PCAP_LIB@
  75. AR = @AR@
  76. RANLIB = @RANLIB@
  77. INSTALL = @INSTALL@
  78. # EXE defines the suffix on executables - it's .exe for Windows, and
  79. # null on linux, bsd, and OS X and other OSes.
  80. EXE = @EXE@
  81. HMAC_OBJS = @HMAC_OBJS@
  82. AES_ICM_OBJS = @AES_ICM_OBJS@
  83. srcdir = @srcdir@
  84. top_srcdir = @top_srcdir@
  85. top_builddir = @top_builddir@
  86. VPATH = @srcdir@
  87. prefix = @prefix@
  88. exec_prefix = @exec_prefix@
  89. includedir = @includedir@
  90. libdir = @libdir@
  91. bindir = @bindir@
  92. pkgconfigdir = $(libdir)/pkgconfig
  93. pkgconfig_DATA = libsrtp2.pc
  94. SHAREDLIBVERSION = 1
  95. ifneq (,$(or $(findstring linux,@host@), $(findstring gnu,@host@)))
  96. SHAREDLIB_DIR = $(libdir)
  97. SHAREDLIB_LDFLAGS = -shared -Wl,-soname,$@
  98. SHAREDLIBSUFFIXNOVER = so
  99. SHAREDLIBSUFFIX = $(SHAREDLIBSUFFIXNOVER).$(SHAREDLIBVERSION)
  100. else ifneq (,$(or $(findstring cygwin,@host@), $(findstring mingw,@host@)))
  101. SHAREDLIB_DIR = $(bindir)
  102. SHAREDLIB_LDFLAGS = -shared -Wl,--out-implib,libsrtp2.dll.a
  103. SHAREDLIBVERSION =
  104. SHAREDLIBSUFFIXNOVER = dll
  105. SHAREDLIBSUFFIX = $(SHAREDLIBSUFFIXNOVER)
  106. else ifeq (darwin,$(findstring darwin,@host@))
  107. SHAREDLIB_DIR = $(libdir)
  108. SHAREDLIB_LDFLAGS = -dynamiclib -twolevel_namespace \
  109. -fno-common -headerpad_max_install_names -install_name $(libdir)/$@
  110. SHAREDLIBSUFFIXNOVER = dylib
  111. SHAREDLIBSUFFIX = $(SHAREDLIBVERSION).$(SHAREDLIBSUFFIXNOVER)
  112. endif
  113. # implicit rules for object files and test apps
  114. %.o: %.c
  115. $(COMPILE) -c $< -o $@
  116. %$(EXE): %.c
  117. $(COMPILE) $(LDFLAGS) $< -o $@ $(SRTPLIB) $(LIBS)
  118. ciphers = crypto/cipher/cipher.o crypto/cipher/null_cipher.o \
  119. $(AES_ICM_OBJS)
  120. hashes = crypto/hash/null_auth.o crypto/hash/auth.o \
  121. $(HMAC_OBJS)
  122. replay = crypto/replay/rdb.o crypto/replay/rdbx.o \
  123. crypto/replay/ut_sim.o
  124. math = crypto/math/datatypes.o crypto/math/stat.o
  125. ust = crypto/ust/ust.o
  126. err = crypto/kernel/err.o
  127. kernel = crypto/kernel/crypto_kernel.o crypto/kernel/alloc.o \
  128. crypto/kernel/key.o $(err) # $(ust)
  129. cryptobj = $(ciphers) $(hashes) $(math) $(kernel) $(replay)
  130. # libsrtp2.a (implements srtp processing)
  131. srtpobj = srtp/srtp.o srtp/ekt.o
  132. libsrtp2.a: $(srtpobj) $(cryptobj) $(gdoi)
  133. $(AR) cr libsrtp2.a $^
  134. $(RANLIB) libsrtp2.a
  135. libsrtp2.$(SHAREDLIBSUFFIX): $(srtpobj) $(cryptobj) $(gdoi)
  136. $(CC) -shared -o $@ $(SHAREDLIB_LDFLAGS) \
  137. $^ $(LDFLAGS) $(LIBS)
  138. if [ -n "$(SHAREDLIBVERSION)" ]; then \
  139. ln -sfn $@ libsrtp2.$(SHAREDLIBSUFFIXNOVER); \
  140. fi
  141. shared_library: libsrtp2.$(SHAREDLIBSUFFIX)
  142. libsrtp2.so: $(srtpobj) $(cryptobj)
  143. $(CC) -shared -Wl,-soname,libsrtp2.so \
  144. -o libsrtp2.so $^ $(LDFLAGS)
  145. # test applications
  146. ifneq (1, $(USE_EXTERNAL_CRYPTO))
  147. AES_CALC = crypto/test/aes_calc$(EXE)
  148. endif
  149. crypto_testapp = $(AES_CALC) crypto/test/cipher_driver$(EXE) \
  150. crypto/test/datatypes_driver$(EXE) crypto/test/kernel_driver$(EXE) \
  151. crypto/test/sha1_driver$(EXE) crypto/test/stat_driver$(EXE) \
  152. crypto/test/env$(EXE)
  153. testapp = $(crypto_testapp) test/srtp_driver$(EXE) test/replay_driver$(EXE) \
  154. test/roc_driver$(EXE) test/rdbx_driver$(EXE) test/rtpw$(EXE) \
  155. test/dtls_srtp_driver$(EXE) test/test_srtp$(EXE)
  156. ifeq (1, $(HAVE_PCAP))
  157. testapp += test/rtp_decoder$(EXE)
  158. endif
  159. $(testapp): libsrtp2.a
  160. test/rtpw$(EXE): test/rtpw.c test/rtp.c test/util.c test/getopt_s.c \
  161. crypto/math/datatypes.c
  162. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  163. ifeq (1, $(HAVE_PCAP))
  164. test/rtp_decoder$(EXE): test/rtp_decoder.c test/rtp.c test/util.c test/getopt_s.c \
  165. crypto/math/datatypes.c
  166. $(COMPILE) $(LDFLAGS) -o $@ $^ $(PCAP_LIB) $(LIBS) $(SRTPLIB)
  167. endif
  168. crypto/test/aes_calc$(EXE): crypto/test/aes_calc.c test/util.c
  169. $(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  170. test/test_srtp$(EXE): test/test_srtp.c
  171. $(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  172. crypto/test/datatypes_driver$(EXE): crypto/test/datatypes_driver.c test/util.c
  173. $(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  174. crypto/test/sha1_driver$(EXE): crypto/test/sha1_driver.c test/util.c
  175. $(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  176. test/srtp_driver$(EXE): test/srtp_driver.c test/util.c test/getopt_s.c
  177. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  178. test/rdbx_driver$(EXE): test/rdbx_driver.c test/getopt_s.c
  179. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  180. test/dtls_srtp_driver$(EXE): test/dtls_srtp_driver.c test/getopt_s.c test/util.c
  181. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  182. crypto/test/cipher_driver$(EXE): crypto/test/cipher_driver.c test/getopt_s.c
  183. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  184. crypto/test/kernel_driver$(EXE): crypto/test/kernel_driver.c test/getopt_s.c
  185. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  186. crypto/test/env$(EXE): crypto/test/env.c test/getopt_s.c
  187. $(COMPILE) $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
  188. test: $(testapp)
  189. @echo "Build done. Please run '$(MAKE) runtest' to run self tests."
  190. memtest: test/srtp_driver
  191. @test/srtp_driver -v -d "alloc" > tmp
  192. @grep freed tmp | wc -l > freed
  193. @grep allocated tmp | wc -l > allocated
  194. @echo "checking for memory leaks (only works with --enable-stdout)"
  195. cmp -s allocated freed
  196. @echo "passed (same number of alloc() and dealloc() calls found)"
  197. @rm freed allocated tmp
  198. # the target 'plot' runs the timing test (test/srtp_driver -t) then
  199. # uses gnuplot to produce plots of the results - see the script file
  200. # 'timing'
  201. plot: test/srtp_driver
  202. test/srtp_driver -t > timing.dat
  203. # bookkeeping: tags, clean, and distribution
  204. tags:
  205. etags */*.[ch] */*/*.[ch]
  206. # documentation - the target libsrtp2doc builds html documentation
  207. libsrtp2doc:
  208. $(MAKE) -C doc
  209. # fuzzer
  210. srtp-fuzzer: libsrtp2.a
  211. $(MAKE) -C fuzzer
  212. .PHONY: clean superclean distclean install
  213. install:
  214. $(INSTALL) -d $(DESTDIR)$(includedir)/srtp2
  215. $(INSTALL) -d $(DESTDIR)$(libdir)
  216. cp $(srcdir)/include/srtp.h $(DESTDIR)$(includedir)/srtp2
  217. cp $(srcdir)/crypto/include/cipher.h $(DESTDIR)$(includedir)/srtp2
  218. cp $(srcdir)/crypto/include/auth.h $(DESTDIR)$(includedir)/srtp2
  219. cp $(srcdir)/crypto/include/crypto_types.h $(DESTDIR)$(includedir)/srtp2
  220. if [ -f libsrtp2.a ]; then cp libsrtp2.a $(DESTDIR)$(libdir)/; fi
  221. if [ -f libsrtp2.dll.a ]; then cp libsrtp2.dll.a $(DESTDIR)$(libdir)/; fi
  222. if [ -f libsrtp2.$(SHAREDLIBSUFFIX) ]; then \
  223. $(INSTALL) -d $(DESTDIR)$(SHAREDLIB_DIR); \
  224. cp libsrtp2.$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR)/; \
  225. cp libsrtp2.$(SHAREDLIBSUFFIXNOVER) $(DESTDIR)$(SHAREDLIB_DIR)/; \
  226. if [ -n "$(SHAREDLIBVERSION)" ]; then \
  227. ln -sfn libsrtp2.$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR)/libsrtp2.$(SHAREDLIBSUFFIXNOVER); \
  228. fi; \
  229. fi
  230. $(INSTALL) -d $(DESTDIR)$(pkgconfigdir)
  231. cp $(top_builddir)/$(pkgconfig_DATA) $(DESTDIR)$(pkgconfigdir)/
  232. uninstall:
  233. rm -f $(DESTDIR)$(includedir)/srtp2/*.h
  234. rm -f $(DESTDIR)$(libdir)/libsrtp2.*
  235. -rmdir $(DESTDIR)$(includedir)/srtp2
  236. rm -f $(DESTDIR)$(pkgconfigdir)/$(pkgconfig_DATA)
  237. clean:
  238. rm -rf $(cryptobj) $(srtpobj) TAGS \
  239. libsrtp2.a libsrtp2.so libsrtp2.dll.a core *.core test/core
  240. for a in * */* */*/*; do \
  241. if [ -f "$$a~" ] ; then rm -f $$a~; fi; \
  242. done;
  243. for a in $(testapp); do rm -rf $$a$(EXE); done
  244. rm -rf *.pict *.jpg *.dat
  245. rm -rf freed allocated tmp
  246. $(MAKE) -C doc clean
  247. $(MAKE) -C fuzzer clean
  248. superclean: clean
  249. rm -rf crypto/include/config.h config.log config.cache config.status \
  250. Makefile crypto/Makefile doc/Makefile \
  251. .gdb_history test/.gdb_history .DS_Store
  252. rm -rf autom4te.cache
  253. distclean: superclean
  254. distname = libsrtp-$(shell cat VERSION)
  255. distribution: runtest superclean
  256. if ! [ -f VERSION ]; then exit 1; fi
  257. if [ -f ../$(distname).tgz ]; then \
  258. mv ../$(distname).tgz ../$(distname).tgz.bak; \
  259. fi
  260. cd ..; tar cvzf $(distname).tgz libsrtp
  261. # EOF