Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # libdatachannel
  2. NAME=libdatachannel
  3. CXX=$(CROSS)g++
  4. AR=$(CROSS)ar
  5. RM=rm -f
  6. CXXFLAGS=-std=c++17
  7. CPPFLAGS=-O2 -pthread -fPIC -Wall
  8. LDFLAGS=-pthread
  9. LIBS=
  10. LOCALLIBS=libusrsctp.a
  11. USRSCTP_DIR=deps/usrsctp
  12. SRTP_DIR=deps/libsrtp
  13. SRTP_CONFIGURE_FLAGS=
  14. JUICE_DIR=deps/libjuice
  15. PLOG_DIR=deps/plog
  16. INCLUDES=-Isrc -Iinclude/rtc -Iinclude -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib
  17. LDLIBS=
  18. USE_GNUTLS ?= 0
  19. ifneq ($(USE_GNUTLS), 0)
  20. CPPFLAGS+=-DUSE_GNUTLS=1
  21. LIBS+=gnutls
  22. else
  23. CPPFLAGS+=-DUSE_GNUTLS=0
  24. LIBS+=openssl
  25. SRTP_CONFIGURE_FLAGS+=--enable-openssl
  26. endif
  27. USE_NICE ?= 0
  28. ifneq ($(USE_NICE), 0)
  29. CPPFLAGS+=-DUSE_NICE=1
  30. LIBS+=glib-2.0 gobject-2.0 nice
  31. else
  32. CPPFLAGS+=-DUSE_NICE=0
  33. INCLUDES+=-I$(JUICE_DIR)/include
  34. LOCALLIBS+=libjuice.a
  35. ifneq ($(USE_GNUTLS), 0)
  36. LIBS+=nettle
  37. endif
  38. endif
  39. NO_MEDIA ?= 0
  40. USE_SYSTEM_SRTP ?= 0
  41. ifeq ($(NO_MEDIA), 0)
  42. CPPFLAGS+=-DRTC_ENABLE_MEDIA=1
  43. ifneq ($(USE_SYSTEM_SRTP), 0)
  44. CPPFLAGS+=-DRTC_SYSTEM_SRTP=1
  45. LIBS+=srtp
  46. else
  47. CPPFLAGS+=-DRTC_SYSTEM_SRTP=0
  48. INCLUDES+=-I$(SRTP_DIR)/include
  49. LOCALLIBS+=libsrtp2.a
  50. endif
  51. else
  52. CPPFLAGS+=-DRTC_ENABLE_MEDIA=0
  53. endif
  54. NO_WEBSOCKET ?= 0
  55. ifeq ($(NO_WEBSOCKET), 0)
  56. CPPFLAGS+=-DRTC_ENABLE_WEBSOCKET=1
  57. else
  58. CPPFLAGS+=-DRTC_ENABLE_WEBSOCKET=0
  59. endif
  60. CPPFLAGS+=-DRTC_EXPORTS
  61. INCLUDES+=$(if $(LIBS),$(shell pkg-config --cflags $(LIBS)),)
  62. LDLIBS+=$(LOCALLIBS) $(if $(LIBS),$(shell pkg-config --libs $(LIBS)),)
  63. SRCS=$(shell printf "%s " src/*.cpp src/impl/*.cpp)
  64. OBJS=$(subst .cpp,.o,$(SRCS))
  65. TEST_SRCS=$(shell printf "%s " test/*.cpp)
  66. TEST_OBJS=$(subst .cpp,.o,$(TEST_SRCS))
  67. all: $(NAME).a $(NAME).so tests
  68. src/%.o: src/%.cpp
  69. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -MMD -MP -o $@ -c $<
  70. test/%.o: test/%.cpp
  71. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -Iinclude -Isrc -MMD -MP -o $@ -c $<
  72. -include $(subst .cpp,.d,$(SRCS))
  73. $(NAME).a: $(LOCALLIBS) $(OBJS)
  74. $(AR) crf $@ $(OBJS)
  75. $(NAME).so: $(LOCALLIBS) $(OBJS)
  76. $(CXX) $(LDFLAGS) -shared -o $@ $(OBJS) $(LDLIBS)
  77. tests: $(NAME).a $(TEST_OBJS)
  78. $(CXX) $(LDFLAGS) -o $@ $(TEST_OBJS) $(NAME).a $(LDLIBS)
  79. clean:
  80. -$(RM) include/rtc/*.d *.d
  81. -$(RM) src/*.o src/*.d
  82. -$(RM) src/impl/*.o src/impl/*.d
  83. -$(RM) test/*.o test/*.d
  84. dist-clean: clean
  85. -$(RM) $(NAME).a
  86. -$(RM) $(NAME).so
  87. -$(RM) libusrsctp.a
  88. -$(RM) libjuice.a
  89. -$(RM) libsrtp2.a
  90. -$(RM) tests
  91. -$(RM) include/*~
  92. -$(RM) src/*~
  93. -$(RM) test/*~
  94. -cd $(USRSCTP_DIR) && make clean
  95. -cd $(SRTP_DIR) && make clean
  96. -cd $(JUICE_DIR) && make clean
  97. libusrsctp.a:
  98. cd $(USRSCTP_DIR) && \
  99. ./bootstrap && \
  100. ./configure --enable-static --disable-programs --disable-debug \
  101. --disable-inet --disable-inet6 CFLAGS="-fPIC" && \
  102. make
  103. cp $(USRSCTP_DIR)/usrsctplib/.libs/libusrsctp.a .
  104. libsrtp2.a:
  105. cd $(SRTP_DIR) && \
  106. ./configure $(SRTP_CONFIGURE_FLAGS) && \
  107. make
  108. cp $(SRTP_DIR)/libsrtp2.a .
  109. libjuice.a:
  110. ifneq ($(USE_GNUTLS), 0)
  111. cd $(JUICE_DIR) && make USE_NETTLE=1
  112. else
  113. cd $(JUICE_DIR) && make USE_NETTLE=0
  114. endif
  115. cp $(JUICE_DIR)/libjuice.a .