2022-04-06 04:53:57 +00:00
|
|
|
# ---------- Variables listed below --------- #
|
|
|
|
|
2022-04-05 22:56:11 +00:00
|
|
|
# Executable
|
|
|
|
TARGET := main.out
|
2022-04-03 16:39:40 +00:00
|
|
|
|
2022-04-05 23:06:52 +00:00
|
|
|
# Paths to source, include, dependency, and object files
|
2022-04-05 22:56:11 +00:00
|
|
|
SPATH = src
|
|
|
|
IPATH = inc
|
|
|
|
DPATH = dep
|
|
|
|
OPATH = obj
|
|
|
|
|
2022-04-05 23:06:52 +00:00
|
|
|
VPATH = $(SPATH) $(IPATH) $(DPATH) $(OPATH)
|
2022-04-05 22:56:11 +00:00
|
|
|
|
|
|
|
# compiler and compiler flags
|
2022-04-03 16:39:40 +00:00
|
|
|
CC = g++
|
2022-04-05 23:07:58 +00:00
|
|
|
CFLAGS = -I$(IPATH) -pthread -lrt
|
2022-04-05 22:56:11 +00:00
|
|
|
|
|
|
|
# list of object files
|
|
|
|
SOURCES = $(wildcard $(SPATH)/*.cpp)
|
|
|
|
OBJECTS = $(addprefix $(OPATH)/,$(notdir $(SOURCES:.cpp=.o)))
|
2022-04-03 16:39:40 +00:00
|
|
|
|
2022-04-06 04:53:57 +00:00
|
|
|
|
|
|
|
# ----------- Targets listed below ---------- #
|
|
|
|
# Some targets aren't real
|
|
|
|
.PHONY: all clean run dump
|
|
|
|
# Don't autodelete object files:
|
|
|
|
.PRECIOUS: $(OPATH)/%.o
|
2022-04-03 16:39:40 +00:00
|
|
|
|
2022-04-05 22:56:11 +00:00
|
|
|
all: $(DPATH) $(OPATH) $(TARGET)
|
2022-04-03 16:39:40 +00:00
|
|
|
|
2022-04-05 22:56:11 +00:00
|
|
|
dump:
|
|
|
|
@echo SOURCES: $(SOURCES)
|
|
|
|
@echo OBJECTS: $(OBJECTS)
|
|
|
|
@echo TARGET: $(TARGET)
|
|
|
|
@echo VPATH: $(VPATH)
|
2022-04-03 16:39:40 +00:00
|
|
|
|
|
|
|
clean:
|
2022-04-05 22:56:11 +00:00
|
|
|
-rm $(TARGET)
|
|
|
|
-rm -r dep obj
|
2022-04-03 16:39:40 +00:00
|
|
|
|
2022-04-06 04:53:57 +00:00
|
|
|
run:
|
|
|
|
-$(addprefix ./,$(addsuffix ;,$(TARGET)))
|
|
|
|
|
2022-04-05 22:56:11 +00:00
|
|
|
$(DPATH) $(OPATH):
|
|
|
|
mkdir -p $@
|
|
|
|
|
|
|
|
# Make the executable(s)
|
2022-04-03 16:39:40 +00:00
|
|
|
%.out: $(OBJECTS)
|
|
|
|
$(CC) $(CFLAGS) -o $@ $^
|
2022-04-05 22:56:11 +00:00
|
|
|
# Make the object and dependency files
|
2022-04-05 23:06:52 +00:00
|
|
|
$(OPATH)/%.o: $(SPATH)/%.cpp
|
2022-04-05 23:07:58 +00:00
|
|
|
$(CC) $(CFLAGS) -MMD -MF $(DPATH)/$(@F:.o=.d) -o $@ -c $<
|
2022-04-05 22:56:11 +00:00
|
|
|
|
2022-04-06 04:53:57 +00:00
|
|
|
# --------- Inclusions listed below --------- #
|
2022-04-05 22:56:11 +00:00
|
|
|
# use dependencies when rebuilding
|
2022-04-05 23:06:52 +00:00
|
|
|
-include $(wildcard $(DPATH)/*.d)
|