Advertisement
microwerx

Generic C++ Makefile

Aug 28th, 2019
1,328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 0.73 KB | None | 0 0
  1. CXX = g++
  2. CXXFLAGS = -std=c++14 -g -Wall
  3. LDFLAGS =
  4.  
  5. # We use this to
  6. SOURCES = $(wildcard *.cpp)
  7. HEADERS = $(wildcard *.hpp) $(wildcard *.h)
  8. OBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))
  9.  
  10. # Write the name of your program here
  11. TARGET = hello
  12.  
  13. .PHONY: all clean
  14.  
  15. # This "phony" target says we want the target to be built
  16. all: $(TARGET)
  17.  
  18. # This "phony" target removes all built files
  19. clean:
  20.     $(RM) *.o
  21.     $(RM) $(TARGET)
  22.  
  23. # Tells make how to make target out of objects
  24. $(TARGET): $(OBJECTS)
  25.     $(CXX) -o $@ $(OBJECTS) $(LDFLAGS)
  26.  
  27. # Tells make how to make objects out of source code
  28. # It also says when we change a header, recompile
  29. # $< is the input, $@ is the output
  30. %.o: %.cpp $(HEADERS)
  31.     $(CXX) $(CXXFLAGS) -c $< -o $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement