1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| CXX = g++
CXXFLAGS = -O3 -g -Wall -Wextra
LDFLAGS =
# name of the executable that will be created
TARGET = Main
# directory of the source files .cpp and .h
SRCDIR = .
# directory of the binary files .o
BINDIR = ./bin
# directory of the dependency files .d
DEPDIR = ./dep
# directory used by 'tarball' target to store archives .tar.gz
ARCHIVESDIR = .
# name of the makefile
MAKEFILE = Makefile
SRC = $(wildcard $(SRCDIR)/*.cc)
OBJ = $(patsubst $(SRCDIR)/%.cc,$(BINDIR)/%.o,$(SRC))
DEP = $(patsubst $(SRCDIR)/%.cc,$(DEPDIR)/%.d,$(SRC))
all: $(TARGET)
# link
$(TARGET): $(OBJ)
$(CXX) -o $@ $^ $(LDFLAGS)
# pull in dependency info for existing .o files
-include $(DEP)
# compile and generate dependency info
$(BINDIR)/%.o: $(SRCDIR)/%.cc $(MAKEFILE)
@mkdir -p $(BINDIR) $(DEPDIR)
$(CXX) -c $< $(CXXFLAGS) -o $@
@$(CXX) -MM $(CXXFLAGS) -MT $(BINDIR)/$*.o $< > $(DEPDIR)/$*.d
.PHONY: tarball temprm clean mrproper
tarball: $(MAKEFILE) $(SRCDIR) README
@mkdir -p $(ARCHIVESDIR)
tar zcf $(ARCHIVESDIR)/$(shell basename $(shell pwd))-$(shell date +%Y%m%d-%Hh%Mm).tar.gz $^
# cleaners
temprm:
@rm -f $(SRCDIR)/*~ *~
clean: temprm
@rm -f $(OBJ) $(DEP)
mrproper: clean
@rm -f $(TARGET)
@rm -rf $(BINDIR) $(DEPDIR) |