49 lines
948 B
Makefile
49 lines
948 B
Makefile
# Executable
|
|
TARGET := main.out
|
|
|
|
# Paths to source, include, dependency, and object files
|
|
SPATH = src
|
|
IPATH = inc
|
|
DPATH = dep
|
|
OPATH = obj
|
|
|
|
VPATH = $(SPATH) $(IPATH) $(DPATH) $(OPATH)
|
|
|
|
# compiler and compiler flags
|
|
CC = g++
|
|
CFLAGS = -I$(IPATH) -pthread -lrt
|
|
|
|
# list of object files
|
|
SOURCES = $(wildcard $(SPATH)/*.cpp)
|
|
OBJECTS = $(addprefix $(OPATH)/,$(notdir $(SOURCES:.cpp=.o)))
|
|
|
|
.PHONY: all clean dump
|
|
|
|
all: $(DPATH) $(OPATH) $(TARGET)
|
|
|
|
dump:
|
|
@echo SOURCES: $(SOURCES)
|
|
@echo OBJECTS: $(OBJECTS)
|
|
@echo TARGET: $(TARGET)
|
|
@echo VPATH: $(VPATH)
|
|
|
|
clean:
|
|
-rm $(TARGET)
|
|
-rm -r dep obj
|
|
|
|
$(DPATH) $(OPATH):
|
|
mkdir -p $@
|
|
|
|
# Make the executable(s)
|
|
%.out: $(OBJECTS)
|
|
$(CC) $(CFLAGS) -o $@ $^
|
|
# Make the object and dependency files
|
|
$(OPATH)/%.o: $(SPATH)/%.cpp
|
|
$(CC) $(CFLAGS) -MMD -MF $(DPATH)/$(@F:.o=.d) -o $@ -c $<
|
|
|
|
# Don't autodelete object files:
|
|
.SECONDARY: $(OPATH)/%.o
|
|
|
|
# use dependencies when rebuilding
|
|
-include $(wildcard $(DPATH)/*.d)
|