Code:
CXXFLAGS = -O2 -pipe -march=pentium3 -fomit-frame-pointer -c
CXX = g++
SRCS = $(wildcard *.cpp)
OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
HDRS = $(patsubst %.h,%.o,$(wildcard *.h))
mylib.a: $(OBJS)
ar cr mylib.a ${OBJS}
clean:
-rm *.o
-rm *.a
Problem: When changing .h files the affected .cpp files won't be recompiled.
The .cpp files dependencies on .h files could obviously be pretty hard to resolve and probably includes writing rules "by hand" or using a tool to actually automate the task by scanning the .cpp files.
Is there an elegant solution to rewrite this makefile so that it will take care of all the .h and .cpp files in the directory? Either by using some - for me - unknown feature of make, or by using some other tool?
I don't want to write individual rules for all my files as it's error-prone and time-consuming.