Makefile 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
  2. #
  3. # smartdns is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # smartdns is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. PKG_CONFIG := pkg-config
  16. DESTDIR :=
  17. PREFIX := /usr
  18. SBINDIR := $(PREFIX)/sbin
  19. SLIBDIR := $(PREFIX)/lib
  20. SYSCONFDIR := /etc
  21. RUNSTATEDIR := /run
  22. SYSTEMDSYSTEMUNITDIR := $(shell ${PKG_CONFIG} --variable=systemdsystemunitdir systemd)
  23. SMARTDNS_SYSTEMD = systemd/smartdns.service
  24. ifneq ($(strip $(DESTDIR)),)
  25. $(shell mkdir -p $(DESTDIR) -m 0755)
  26. override DESTDIR := $(realpath $(DESTDIR))
  27. endif
  28. PLUGINS :=
  29. WITH_UI ?= 0
  30. ifeq ($(WITH_UI), 1)
  31. PLUGINS += plugin/smartdns-ui
  32. endif
  33. define PLUGINS_TARGETS
  34. $(foreach plugin,$(PLUGINS),$(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) -C $(plugin) $(1);)
  35. endef
  36. .PHONY: all clean install help SMARTDNS_BIN
  37. all: SMARTDNS_BIN
  38. SMARTDNS_BIN: $(SMARTDNS_SYSTEMD)
  39. $(MAKE) $(MFLAGS) -C src all
  40. $(call PLUGINS_TARGETS, all)
  41. $(SMARTDNS_SYSTEMD): systemd/smartdns.service.in
  42. cp $< $@
  43. sed -i 's|@SBINDIR@|$(SBINDIR)|' $@
  44. sed -i 's|@SYSCONFDIR@|$(SYSCONFDIR)|' $@
  45. sed -i 's|@RUNSTATEDIR@|$(RUNSTATEDIR)|' $@
  46. help:
  47. @echo "Options:"
  48. @echo " WITH_UI=1: Build with smartdns-ui plugin"
  49. @echo " OPTIMIZE_SIZE=1: Optimize size of the smartdns-ui plugin (only for smartdns-ui)"
  50. @echo " DESTDIR: Specify the installation directory prefix"
  51. clean:
  52. $(MAKE) $(MFLAGS) -C src clean
  53. $(RM) $(SMARTDNS_SYSTEMD)
  54. $(call PLUGINS_TARGETS, clean)
  55. install: SMARTDNS_BIN
  56. install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/default etc/default/smartdns
  57. install -v -m 0755 -D -t $(DESTDIR)$(SYSCONFDIR)/init.d etc/init.d/smartdns
  58. install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/smartdns etc/smartdns/smartdns.conf
  59. install -v -m 0755 -D -t $(DESTDIR)$(SBINDIR) src/smartdns
  60. install -v -m 0644 -D -t $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) systemd/smartdns.service
  61. $(call PLUGINS_TARGETS, install)