My makefile will not check if there has been any updates and just compiles if it has more than a single source file added in. It works fine with just a single source file.
It seems that it's any source file that's not listed as the first one will always be recompiled and linked.
SOURCES=myclass.cpp mylock.cpp
EXECUTABLE=locktest
LIBRARIES=-pthread
CFLAGS=-Wall
CXX=g++
DIR=host/
EXE=$(EXECUTABLE)
OBJECTS=$(SOURCES:%.cpp=$(DIR)%.o)
$(EXE): $(OBJECTS)
$(CXX) -o $@ $(OBJECTS) $(LIBRARIES)
$(DIR)%.o: %.cpp $(DIR)
$(CXX) $(CFLAGS) -c $< -o $@
$(DIR):
@mkdir $(DIR)
clean:
@rm $(OBJECTS) $(EXE)
@rmdir $(DIR)
Output shows problem:
stud@pc:~/Desktop/Locktest$ make
g++ -Wall -c myclass.cpp -o host/myclass.o
g++ -Wall -c mylock.cpp -o host/mylock.o
g++ -o locktest host/myclass.o host/mylock.o -pthread
stud@pc:~/Desktop/Locktest$ make
g++ -Wall -c myclass.cpp -o host/myclass.o
g++ -o locktest host/myclass.o host/mylock.o -pthread