Makefile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. override CPPFLAGS += --std=c++1z
  2. override CPPFLAGS += -MMD -MP
  3. override CPPFLAGS += $(shell cat .cxxflags 2> /dev/null | xargs)
  4. override CPPFLAGS += -I./include -I./source
  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. override LDLIBS += -lSDL2 -lpthread
  9. ifdef ENABLE_THEORA_RECORDER
  10. override CPPFLAGS += -DENABLE_THEORA_RECORDER
  11. override LDLIBS += -ltheoraenc -ltheoradec -logg
  12. endif
  13. PREFIX ?= $(DESTDIR)/usr/local
  14. BINDIR := $(PREFIX)/bin
  15. NAME := neogol
  16. SRCDIR := ./source
  17. TEMPDIR := temp
  18. DISTDIR := out
  19. SOURCES := $(shell find -wholename "$(SRCDIR)/*.cpp")
  20. HEADERS := $(shell find -wholename "$(SRCDIR)/*.hpp" && find -wholename "$(SRCDIR)/*.h")
  21. OUT := $(DISTDIR)/$(NAME)
  22. TARGET := $(OUT:$(DISTDIR)/%=$(BINDIR)/%)
  23. OBJECTS := $(SOURCES:%.cpp=$(TEMPDIR)/%.o)
  24. OBJDIRS := $(shell dirname $(OBJECTS))
  25. LOCALIB := $(wildcard lib/*.a)
  26. DEPENDS := $(OBJECTS:.o=.d)
  27. INSTALL_SRCDIR := $(PREFIX)/source
  28. INSTALL_SOURCES := $(SOURCES:$(SRCDIR)/%=$(INSTALL_SRCDIR)/%) $(HEADERS:$(SRCDIR)/%=$(INSTALL_SRCDIR)/%)
  29. INSTALL_SRCDIRS := $(shell dirname $(INSTALL_SOURCES))
  30. build: $(OUT)
  31. $(OUT): $(OBJECTS) $(LOCALIB) | $(DISTDIR)
  32. $(CXX) $(LDFLAGS) $(OBJECTS) $(LOCALIB) $(LDLIBS) -o $@
  33. $(TEMPDIR)/%.o: %.cpp | $(TEMPDIR)
  34. @mkdir -p $(@D)
  35. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
  36. $(TEMPDIR):
  37. @mkdir -p $@
  38. $(DISTDIR):
  39. @mkdir -p $@
  40. clean:
  41. @rm $(DEPENDS) 2> /dev/null || true
  42. @rm $(OBJECTS) 2> /dev/null || true
  43. @rmdir -p $(OBJDIRS) 2> /dev/null || true
  44. @rmdir -p $(TEMPDIR) 2> /dev/null || true
  45. @echo Temporaries cleaned!
  46. distclean: clean
  47. @rm $(OUT) 2> /dev/null || true
  48. @rmdir -p $(DISTDIR) 2> /dev/null || true
  49. @echo All clean!
  50. install: $(TARGET)
  51. $(BINDIR)/%: $(DISTDIR)/% | $(BINDIR)
  52. install --strip $< $@
  53. $(BINDIR):
  54. @mkdir $@
  55. uninstall:
  56. -rm $(TARGET)
  57. @rmdir -p $(BINDIR) 2> /dev/null || true
  58. @echo Uninstall complete!
  59. install_source: $(INSTALL_SOURCES)
  60. $(INSTALL_SRCDIR)/%: $(SRCDIR)/% ./COPYRIGHT
  61. @mkdir -p $(@D)
  62. cat ./COPYRIGHT > $@
  63. cat $< >> $@
  64. uninstall_source:
  65. -rm $(INSTALL_SOURCES)
  66. @rmdir -p $(INSTALL_SRCDIRS) 2> /dev/null || true
  67. @echo Source code uninstalled!
  68. -include $(DEPENDS)
  69. .PRECIOUS : $(OBJECTS)
  70. .PHONY : clean distclean uninstall uninstall_source