Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. SYS := $(shell $(CXX) -dumpmachine)
  2. SHLIB := libi2pd.so
  3. ARLIB := libi2pd.a
  4. SHLIB_CLIENT := libi2pdclient.so
  5. ARLIB_CLIENT := libi2pdclient.a
  6. I2PD := i2pd
  7. GREP := grep
  8. DEPS := obj/make.dep
  9. LIB_SRC_DIR := libi2pd
  10. LIB_CLIENT_SRC_DIR := libi2pd_client
  11. DAEMON_SRC_DIR := daemon
  12. include filelist.mk
  13. USE_AESNI := yes
  14. USE_AVX := yes
  15. USE_STATIC := no
  16. USE_MESHNET := no
  17. USE_UPNP := no
  18. DEBUG := yes
  19. ifeq ($(DEBUG),yes)
  20. CXX_DEBUG = -g
  21. else
  22. CXX_DEBUG = -Os
  23. LD_DEBUG = -s
  24. endif
  25. ifeq ($(WEBSOCKETS),1)
  26. NEEDED_CXXFLAGS += -DWITH_EVENTS
  27. endif
  28. ifneq (, $(findstring darwin, $(SYS)))
  29. DAEMON_SRC += $(DAEMON_SRC_DIR)/UnixDaemon.cpp
  30. ifeq ($(HOMEBREW),1)
  31. include Makefile.homebrew
  32. else
  33. include Makefile.osx
  34. endif
  35. else ifneq (, $(findstring linux, $(SYS))$(findstring gnu, $(SYS)))
  36. DAEMON_SRC += $(DAEMON_SRC_DIR)/UnixDaemon.cpp
  37. include Makefile.linux
  38. else ifneq (, $(findstring freebsd, $(SYS))$(findstring openbsd, $(SYS)))
  39. DAEMON_SRC += $(DAEMON_SRC_DIR)/UnixDaemon.cpp
  40. include Makefile.bsd
  41. else ifneq (, $(findstring mingw, $(SYS))$(findstring cygwin, $(SYS)))
  42. DAEMON_SRC += Win32/DaemonWin32.cpp Win32/Win32Service.cpp Win32/Win32App.cpp
  43. include Makefile.mingw
  44. else # not supported
  45. $(error Not supported platform)
  46. endif
  47. ifeq ($(USE_MESHNET),yes)
  48. NEEDED_CXXFLAGS += -DMESHNET
  49. endif
  50. NEEDED_CXXFLAGS += -I$(LIB_SRC_DIR) -I$(LIB_CLIENT_SRC_DIR)
  51. all: mk_obj_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD)
  52. mk_obj_dir:
  53. @mkdir -p obj
  54. @mkdir -p obj/Win32
  55. @mkdir -p obj/$(LIB_SRC_DIR)
  56. @mkdir -p obj/$(LIB_CLIENT_SRC_DIR)
  57. @mkdir -p obj/$(DAEMON_SRC_DIR)
  58. api: mk_obj_dir $(SHLIB) $(ARLIB)
  59. api_client: mk_obj_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT)
  60. ## NOTE: The NEEDED_CXXFLAGS are here so that CXXFLAGS can be specified at build time
  61. ## **without** overwriting the CXXFLAGS which we need in order to build.
  62. ## For example, when adding 'hardening flags' to the build
  63. ## (e.g. -fstack-protector-strong -Wformat -Werror=format-security), we do not want to remove
  64. ## -std=c++11. If you want to remove this variable please do so in a way that allows setting
  65. ## custom FLAGS to work at build-time.
  66. deps: mk_obj_dir
  67. $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS)
  68. @sed -i -e '/\.o:/ s/^/obj\//' $(DEPS)
  69. obj/%.o: %.cpp
  70. $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $<
  71. # '-' is 'ignore if missing' on first run
  72. -include $(DEPS)
  73. DAEMON_OBJS += $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC))
  74. $(I2PD): $(DAEMON_OBJS) $(ARLIB) $(ARLIB_CLIENT)
  75. $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS)
  76. $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC))
  77. ifneq ($(USE_STATIC),yes)
  78. $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^
  79. endif
  80. $(SHLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC))
  81. $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^
  82. $(ARLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC))
  83. $(AR) -r $@ $^
  84. $(ARLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC))
  85. $(AR) -r $@ $^
  86. clean:
  87. $(RM) -r obj
  88. $(RM) -r docs/generated
  89. $(RM) $(I2PD) $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT)
  90. strip: $(I2PD) $(SHLIB_CLIENT) $(SHLIB)
  91. strip $^
  92. LATEST_TAG=$(shell git describe --tags --abbrev=0 openssl)
  93. BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
  94. dist:
  95. git archive --format=tar.gz -9 --worktree-attributes \
  96. --prefix=i2pd_$(LATEST_TAG)/ $(LATEST_TAG) -o i2pd_$(LATEST_TAG).tar.gz
  97. last-dist:
  98. git archive --format=tar.gz -9 --worktree-attributes \
  99. --prefix=i2pd_$(LATEST_TAG)/ $(BRANCH) -o ../i2pd_$(LATEST_TAG).orig.tar.gz
  100. doxygen:
  101. doxygen -s docs/Doxyfile
  102. .PHONY: all
  103. .PHONY: clean
  104. .PHONY: deps
  105. .PHONY: doxygen
  106. .PHONY: dist
  107. .PHONY: last-dist
  108. .PHONY: api
  109. .PHONY: api_client
  110. .PHONY: mk_obj_dir
  111. .PHONY: install