Makefile 918 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. PACKAGES = armadillo
  2. CXXFLAGS = -std=c++11 -Wall -Wextra
  3. LDFLAGS = -larmadillo
  4. LIBS =
  5. MAINSRC = ./src/main.cpp
  6. ifeq ($(DEBUG), 1)
  7. CXXFLAGS += -DDEBUG -O0
  8. else
  9. CXXFLAGS += -DNDEBUG -O2
  10. endif
  11. CXXFLAGS += `pkg-config --cflags $(PACKAGES)`
  12. LDFLAGS +=`pkg-config --libs-only-L --libs-only-other $(PACKAGES)`
  13. LIBS +=`pkg-config --libs-only-l $(PACKAGES)`
  14. BINDIR = ./bin
  15. OBJDIR = ./obj
  16. SRCDIR = ./src
  17. SRC = $(filter-out $(MAINSRC), $(shell find $(SRCDIR) -name *.cpp))
  18. OBJ = $(subst $(SRCDIR)/, $(OBJDIR)/, $(SRC:.cpp=.o))
  19. BIN = $(subst $(SRCDIR)/, $(BINDIR)/, $(MAINSRC:.cpp=.out))
  20. .PHONY: all clean
  21. .SECONDARY:
  22. all: ctags $(BIN)
  23. $(BINDIR)/%.out: $(OBJ) $(OBJDIR)/%.o
  24. mkdir -p $(@D)
  25. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
  26. $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
  27. mkdir -p $(@D)
  28. $(CXX) $(CXXFLAGS) -c $< -o $@
  29. clean:
  30. find $(OBJDIR) -name "*.o" | xargs rm
  31. rm $(BIN)
  32. ctags: $(SRC) $(MAINSRC)
  33. ctags -R $(SRCDIR)