Makefile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. JUICE_DIR=deps/libjuice
  13. PLOG_DIR=deps/plog
  14. INCLUDES=-Iinclude/rtc -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib
  15. LDLIBS=
  16. USE_GNUTLS ?= 0
  17. ifneq ($(USE_GNUTLS), 0)
  18. CPPFLAGS+=-DUSE_GNUTLS=1
  19. LIBS+=gnutls
  20. else
  21. CPPFLAGS+=-DUSE_GNUTLS=0
  22. LIBS+=openssl
  23. endif
  24. USE_JUICE ?= 0
  25. ifneq ($(USE_JUICE), 0)
  26. CPPFLAGS+=-DUSE_JUICE=1
  27. INCLUDES+=-I$(JUICE_DIR)/include
  28. LOCALLIBS+=libjuice.a
  29. ifneq ($(USE_GNUTLS), 0)
  30. LIBS+=nettle
  31. endif
  32. else
  33. CPPFLAGS+=-DUSE_JUICE=0
  34. LIBS+=glib-2.0 gobject-2.0 nice
  35. endif
  36. INCLUDES+=$(shell pkg-config --cflags $(LIBS))
  37. LDLIBS+=$(LOCALLIBS) $(shell pkg-config --libs $(LIBS))
  38. SRCS=$(shell printf "%s " src/*.cpp)
  39. OBJS=$(subst .cpp,.o,$(SRCS))
  40. TEST_SRCS=$(shell printf "%s " test/*.cpp)
  41. TEST_OBJS=$(subst .cpp,.o,$(TEST_SRCS))
  42. all: $(NAME).a $(NAME).so tests
  43. src/%.o: src/%.cpp
  44. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -MMD -MP -o $@ -c $<
  45. test/%.o: test/%.cpp
  46. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -Iinclude -Isrc -MMD -MP -o $@ -c $<
  47. -include $(subst .cpp,.d,$(SRCS))
  48. $(NAME).a: $(OBJS)
  49. $(AR) crf $@ $(OBJS)
  50. $(NAME).so: $(LOCALLIBS) $(OBJS)
  51. $(CXX) $(LDFLAGS) -shared -o $@ $(OBJS) $(LDLIBS)
  52. tests: $(NAME).a $(TEST_OBJS)
  53. $(CXX) $(LDFLAGS) -o $@ $(TEST_OBJS) $(NAME).a $(LDLIBS)
  54. clean:
  55. -$(RM) include/rtc/*.d *.d
  56. -$(RM) src/*.o src/*.d
  57. -$(RM) test/*.o test/*.d
  58. dist-clean: clean
  59. -$(RM) $(NAME).a
  60. -$(RM) $(NAME).so
  61. -$(RM) libusrsctp.a
  62. -$(RM) libjuice.a
  63. -$(RM) tests
  64. -$(RM) include/*~
  65. -$(RM) src/*~
  66. -$(RM) test/*~
  67. -cd $(USRSCTP_DIR) && make clean
  68. -cd $(JUICE_DIR) && make clean
  69. libusrsctp.a:
  70. cd $(USRSCTP_DIR) && \
  71. ./bootstrap && \
  72. ./configure --enable-static --disable-debug CFLAGS="$(CPPFLAGS) -Wno-error=format-truncation" && \
  73. make
  74. cp $(USRSCTP_DIR)/usrsctplib/.libs/libusrsctp.a .
  75. libjuice.a:
  76. ifneq ($(USE_GNUTLS), 0)
  77. cd $(JUICE_DIR) && make USE_NETTLE=1
  78. else
  79. cd $(JUICE_DIR) && make USE_NETTLE=0
  80. endif
  81. cp $(JUICE_DIR)/libjuice.a .