Makefile Directory List and Dependency List

In the makefile, I create all my .o files in the build directory:

program: class1.o class2.o class3.o
    g++ $(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.o -o $@

It would be great to create $(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.ofrom a list of dependencies ...

I know that it $^will provide me with a list of all the dependencies, separated by spaces, but I cannot deal with a subdirectory.

Is it possible?

And if I have program: class1.o class2.o class3.o configure, can I remove configurefrom the list?

Thank:)

Edit: Michael solutions work well, but makefind no dependencies and must build anything every time ... Is there no simpler way to create implicit rules, for example program: class1.o class2.o class3.o, to say to put binary files in the assembly directory?

+3
2

g++ $(addprefix $(BUILDDIR), $^) -o $@

.

8.3.

+5

(, , ) Make. there, , , , - ( , ). , .

Make , Michael Kohne, class1.o, $(BUILDDIR) class1.o. ( , $(BUILDDIR) VPATH, .)

, ( , ) - :

NAMES = class1 class2  
OBJECTS = $(patsubst %,$(BUILDDIR)%.o,$(NAMES))

program: $(OBJECTS) configure
    g++ $(OBJECTS) -o $@

$(OBJECTS):$(BUILDDIR)%.o:%.cc
    g++ -c $^ -o $@

, , .

+5

Source: https://habr.com/ru/post/1735312/


All Articles