EXE := purge
TST_EXE := testPurge
SRCS := $(wildcard *.cpp)
EXE_SRCS := $(filter-out testPurge.cpp, $(SRCS))
TST_SRCS := $(filter-out purge.cpp, $(SRCS))
OBJS := $(SRCS:.cpp=.o)
EXE_OBJS := $(EXE_SRCS:.cpp=.o)
TST_OBJS := $(TST_SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
CFLAGS += -std=c++11 -g
INCLUDE += -I../common
LIBS += -lpthread -lboost_filesystem -lboost_system
.PHONY : all clean run test
all : $(EXE) $(TST_EXE)
# Create executable
$(EXE) : $(EXE_OBJS)
g++ -o $(EXE) $(EXE_OBJS) $(LIBS)
$(TST_EXE) : $(TST_OBJS)
g++ -o $(TST_EXE) $(TST_OBJS) $(LIBS)
# Compile source files
.cpp.o :
g++ $(CFLAGS) -MMD -MP $(INCLUDE) -c $<
# Clean up
clean :
rm -f $(OBJS) $(EXE) $(TST_EXE) $(DEPS) journal.log journal.txt
# Run executable
run : $(EXE)
cp journal.purge journal.txt
./$(EXE)
# Run tests
test : $(TST_EXE)
./$(TST_EXE)
# Include generated dependencies
-include $(DEPS)
# GNU make wildcard function
# objects := $(wildcard *.o)
# change the list of C source files into a list of object files
# $(patsubst %.c,%.o,$(wildcard *.c))
# $(CC) -c $(CFLAGS) $(CPPFLAGS) < -o $@
# GNU make Automatic Variables
# $@ = The file name of the target of the rule.
# < = The name of the first prerequisite.
# $^ = The names of all the prerequisites, with spaces between them.
# GNU compiler
# -c = Compile or assemble the source files, but do not link.
# -o file = Place output in file file.
# -g = Produce debugging information in the operating system's native format.
# -Wall = Enables all the warnings about constructions that some users consider questionable, and that are easy to avoid.
# -D name = Predefine name as a macro, with definition 1.
# -I dir = Add the directory dir to the list of directories to be searched for header files.
# -llibrary = Search the library named library when linking.
# -Ldir = Add directory dir to the list of directories to be searched for -l.
.PHONY : clean wipe
# link Executable
$(executable) : $(objects)
g++ -o $@ $^ -lpthread -ludev
# Pattern rule to compile '.cpp' files into '.o' files
%.o : %.cpp
g++ -Wall -c < -o $@
# additional prerequisite to each object file
$(objects) : CUsbManager.h