Makefile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. override 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. override LDFLAGS += -L./lib
  8. PREFIX ?= $(DESTDIR)/usr/local
  9. BINDIR := $(PREFIX)/bin
  10. SOURCES := $(shell echo *.cpp)
  11. SCRIPTS := $(shell echo *.sh)
  12. TEMPDIR := temp
  13. DISTDIR := out
  14. OUT := $(SOURCES:%.cpp=$(DISTDIR)/f%)
  15. TARGET := $(OUT:$(DISTDIR)/%=$(BINDIR)/%)
  16. TARGET += $(SCRIPTS:%.sh=$(BINDIR)/%)
  17. OBJECTS := $(SOURCES:%.cpp=$(TEMPDIR)/%.o)
  18. LOCALIB := $(wildcard lib/*.a)
  19. DEPENDS := $(OBJECTS:.o=.d)
  20. build: $(OUT)
  21. test: build
  22. ./tests/basic.sh
  23. $(DISTDIR)/f%: $(TEMPDIR)/%.o $(LOCALIB) | $(DISTDIR)
  24. $(CXX) $(LDFLAGS) $< $(LOCALIB) $(LDLIBS) -o $@
  25. $(TEMPDIR)/%.o: %.cpp | $(TEMPDIR)
  26. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
  27. $(TEMPDIR):
  28. @mkdir $@
  29. $(DISTDIR):
  30. @mkdir $@
  31. clean:
  32. @rm $(DEPENDS) 2> /dev/null || true
  33. @rm $(OBJECTS) 2> /dev/null || true
  34. @rmdir $(TEMPDIR) 2> /dev/null || true
  35. @echo Temporaries cleaned!
  36. distclean: clean
  37. @rm $(OUT) 2> /dev/null || true
  38. @rmdir $(DISTDIR) 2> /dev/null || true
  39. @echo All clean!
  40. install: $(TARGET)
  41. @echo Install complete!
  42. $(BINDIR)/%: $(DISTDIR)/% | $(BINDIR)
  43. install --strip $< $@
  44. $(BINDIR)/%: ./%.sh | $(BINDIR)
  45. install $< $@
  46. $(BINDIR):
  47. @mkdir $@
  48. uninstall:
  49. -rm $(TARGET)
  50. @rmdir -p $(BINDIR) 2> /dev/null || true
  51. @echo Uninstall complete!
  52. -include $(DEPENDS)
  53. .PRECIOUS : $(OBJECTS)
  54. .PHONY : test clean distclean uninstall