Makefile 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Utilities
  2. RM := rm -rf
  3. CHDIR := cd
  4. EXEC := exec
  5. # Test artifacts
  6. TEST_DIR := tests
  7. TEST_OUT := $(TEST_DIR)/all
  8. TEST_SRCS := all.cpp types.cpp stack.cpp functions.cpp
  9. TEST_DEPS := $(TEST_SRCS:%.cpp=$(TEST_DIR)/%.d)
  10. TEST_OBJS := $(TEST_SRCS:%.cpp=$(TEST_DIR)/%.o)
  11. # Example artifacts
  12. EXAMPLE_DIR := examples
  13. EXAMPLE_SRCS := types.cpp stack.cpp functions.cpp usertypes.cpp
  14. EXAMPLE_DEPS := $(EXAMPLE_SRCS:%.cpp=$(EXAMPLE_DIR)/%.d)
  15. EXAMPLE_OBJS := $(EXAMPLE_SRCS:%.cpp=$(EXAMPLE_DIR)/%.out)
  16. # Compiler
  17. CXX ?= clang++
  18. CXXFLAGS += -std=c++14 -O2 -g -DDEBUG -fmessage-length=0 -Wall -Wextra -pedantic -Ilib
  19. LDLIBS += -llua
  20. # Default targets
  21. all: test examples
  22. clean:
  23. $(RM) $(EXAMPLE_OBJS) $(EXAMPLE_DEPS) $(TEST_OUT) $(TEST_OBJS) $(TEST_DEPS)
  24. # Tests
  25. test: $(TEST_OUT)
  26. ./$(TEST_OUT)
  27. -include $(TEST_DEPS)
  28. $(TEST_OUT): $(TEST_OBJS)
  29. $(CXX) $(LDFLAGS) -o$@ $(TEST_OBJS) $(LDLIBS)
  30. $(TEST_DIR)/%.o: $(TEST_DIR)/%.cpp Makefile
  31. echo Compile test
  32. $(CXX) -c $(CXXFLAGS) -MMD -MF$(@:%.o=%.d) -MT$@ -o$@ $<
  33. # Examples
  34. examples: $(EXAMPLE_OBJS)
  35. @for ex in $(EXAMPLE_OBJS); do echo "> Example '$$ex'"; ./$$ex; done
  36. -include $(EXAMPLE_DEPS)
  37. $(EXAMPLE_DIR)/%.out: $(EXAMPLE_DIR)/%.cpp Makefile
  38. $(CXX) $(CXXFLAGS) -MMD -MF$(<:%.cpp=%.d) -MT$@ -o$@ $< $(LDLIBS)
  39. # Phony
  40. .PHONY: all clean test examples