I have this directory structure.
app/
src
include
lib/
src
maincode/
main.cc
Makefile
I want to generate automatic target from the source list in makefile. So I don't have to write rule for each file.
Example
source=\
../src/a.cpp
../src/ab.cpp
../lib/src/b.cpp
I want to write rule like
%.o:%.cpp
so that I don't have to repeat rule for each file. How I can achieve this ?
Edit: the find command should be inside a shell variable
If you are using Linux, I think you can use:
SOURCES=$(shell find . -name *.cpp)
OBJECTS=$(SOURCES:%.cpp=%.o)
%.o: %.cpp
<command to compile>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With