4600-project-2/Makefile

66 lines
1.5 KiB
Makefile
Raw Normal View History

2022-04-17 00:03:38 +00:00
# +-------------+---------+-----------------------+
# | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
# +-------------+---------+-----------------------+
# | Created 2022-04-04 Edited 2022-04-16 |
# +-----------------------------------------------+
# ---------- Variables listed below --------- #
# Executable
TARGET := main.out
# Paths to source, include, dependency, and object files
SPATH = src
IPATH = inc
DPATH = dep
OPATH = obj
# File type of source file
2022-04-17 23:29:32 +00:00
STYPE = cpp
2022-04-17 00:03:38 +00:00
VPATH = $(SPATH) $(IPATH) $(DPATH) $(OPATH)
# compiler and compiler flags
2022-04-17 23:29:32 +00:00
CC = g++
2022-04-23 02:06:30 +00:00
CFLAGS = -I$(IPATH) -std=c++11
2022-04-17 00:03:38 +00:00
# list of object files
SOURCES = $(wildcard $(SPATH)/*.$(STYPE))
OBJECTS = $(addprefix $(OPATH)/,$(notdir $(SOURCES:.$(STYPE)=.o)))
# ----------- 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
run:
-$(addprefix ./,$(addsuffix ;,$(TARGET)))
$(DPATH) $(OPATH):
mkdir -p $@
# Make the executable(s)
%.out: $(OBJECTS)
2022-04-23 02:06:30 +00:00
$(CC) $(CFLAGS) -o "$@" $^
2022-04-17 00:03:38 +00:00
# Make the object and dependency files
$(OPATH)/%.o: $(SPATH)/%.$(STYPE)
$(CC) $(CFLAGS) -MMD -MF "$(DPATH)/$(@F:.o=.d)" -o "$@" -c "$<"
# --------- Inclusions listed below --------- #
# use dependencies when rebuilding
-include $(wildcard $(DPATH)/*.d)