4600-project-1/Makefile

63 lines
1.4 KiB
Makefile
Raw Permalink Normal View History

2022-04-06 06:45:57 +00:00
# +-------------+---------+-----------------------+
# | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
# +-------------+---------+-----------------------+
# | 2022-04-04 |
# +-----------------------------------------------+
2022-04-06 04:53:57 +00:00
# ---------- Variables listed below --------- #
# Executable
TARGET := main.out
2022-04-05 23:06:52 +00:00
# Paths to source, include, dependency, and object files
SPATH = src
IPATH = inc
DPATH = dep
OPATH = obj
2022-04-05 23:06:52 +00:00
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)))
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
all: $(DPATH) $(OPATH) $(TARGET)
dump:
@echo SOURCES: $(SOURCES)
@echo OBJECTS: $(OBJECTS)
@echo TARGET: $(TARGET)
@echo VPATH: $(VPATH)
clean:
-rm $(TARGET)
-rm -r dep obj
2022-04-06 04:53:57 +00:00
run:
-$(addprefix ./,$(addsuffix ;,$(TARGET)))
$(DPATH) $(OPATH):
mkdir -p $@
# Make the executable(s)
%.out: $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^
# Make the object and dependency files
2022-04-05 23:06:52 +00:00
$(OPATH)/%.o: $(SPATH)/%.cpp
$(CC) $(CFLAGS) -MMD -MF $(DPATH)/$(@F:.o=.d) -o $@ -c $<
2022-04-06 04:53:57 +00:00
# --------- Inclusions listed below --------- #
# use dependencies when rebuilding
2022-04-05 23:06:52 +00:00
-include $(wildcard $(DPATH)/*.d)