Makefile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. CPPFLAGS += --std=c++1z
  2. override CPPFLAGS += -MMD -MP
  3. override CPPFLAGS += -I./include
  4. override CPPFLAGS += $(shell cat .cxxflags 2> /dev/null | xargs)
  5. override LDFLAGS += $(shell cat .ldflags 2> /dev/null | xargs)
  6. override LDLIBS += $(shell cat .ldlibs 2> /dev/null | xargs)
  7. ifneq ($(shell cat COPYRIGHT 2> /dev/null),)
  8. COPYRIGHT ?= COPYRIGHT
  9. else
  10. COPYRIGHT ?= /dev/null
  11. endif
  12. PREFIX ?= $(DESTDIR)/usr/local
  13. INCDIR := $(PREFIX)/include
  14. BINDIR := $(PREFIX)/bin
  15. SOURCES := $(wildcard *.cpp)
  16. SCRIPTS := $(shell find -name *.sh)
  17. MAKETMP := $(wildcard make_templates/*)
  18. INCLUDE := $(MAKETMP:%=$(INCDIR)/%)
  19. TEMPDIR := temp
  20. DISTDIR := out
  21. OUT := $(SOURCES:%.cpp=$(DISTDIR)/%)
  22. TARGET := $(OUT:$(DISTDIR)/%=$(BINDIR)/%)
  23. TARGET += $(SCRIPTS:%.sh=$(BINDIR)/%)
  24. OBJECTS := $(SOURCES:%.cpp=$(TEMPDIR)/%.o)
  25. DEPENDS := $(OBJECTS:.o=.d)
  26. build: $(OUT)
  27. $(DISTDIR)/%: $(TEMPDIR)/%.o | $(DISTDIR)
  28. $(CXX) $(LDFLAGS) $< $(LDLIBS) -o $@
  29. $(TEMPDIR)/%.o: %.cpp | $(TEMPDIR)
  30. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
  31. $(TEMPDIR):
  32. @mkdir -p $@
  33. $(DISTDIR):
  34. @mkdir -p $@
  35. clean:
  36. @rm $(DEPENDS) 2> /dev/null || true
  37. @rm $(OBJECTS) 2> /dev/null || true
  38. @rmdir -p $(TEMPDIR) 2> /dev/null || true
  39. @echo Temporaries cleaned!
  40. distclean: clean
  41. @rm $(OUT) 2> /dev/null || true
  42. @rmdir -p $(DISTDIR) 2> /dev/null || true
  43. @echo All clean!
  44. install-includes: $(INCLUDE)
  45. @echo Includes installed!
  46. install: $(TARGET) install-includes
  47. @echo Install complete!
  48. $(INCDIR)/make_templates/%: ./make_templates/% $(COPYRIGHT)
  49. @mkdir -p $(@D)
  50. cat $(COPYRIGHT) > $@ 2> /dev/null || true
  51. cat $< >> $@
  52. $(BINDIR)/%: $(DISTDIR)/% | $(BINDIR)
  53. install --strip $< $@
  54. $(BINDIR)/%: ./%.sh | $(BINDIR)
  55. install $< $@
  56. $(BINDIR):
  57. @mkdir -p $@
  58. uninstall-includes:
  59. -rm $(INCLUDE)
  60. @rmdir -p $(shell dirname $(INCLUDE)) 2> /dev/null || true
  61. @echo Includes uninstalled!
  62. uninstall: uninstall-includes
  63. -rm $(TARGET)
  64. @rmdir -p $(BINDIR) 2> /dev/null || true
  65. @rmdir -p $(shell dirname $(INCLUDE)) 2> /dev/null || true
  66. @echo Uninstall complete!
  67. -include $(DEPENDS)
  68. .PRECIOUS : $(OBJECTS)
  69. .PHONY : clean distclean uninstall uninstall-includes