Shejo284
Shejo284

Reputation: 4771

Makefile command modification

I would like to modify a Makefile command:

-rm -f $(OBJS)
-rm -f $(OBJS:.o=.mod)

The first removes all filenames.o and the second removes all filenames.mod. However, I would like to modify the second such that I get: mod_filenames.mod, i.e., add the string "mod_".

I tried: -rm -f mod_$(OBJS:.o=.mod), but this only affected the first file in the list. But I'm jet guessing here. If anyone could suggest a wide site where such programming is explained, I would grateful.

Upvotes: 2

Views: 80

Answers (2)

xaizek
xaizek

Reputation: 5252

GNU Make Manual.

There is also GNU Make Unleased book and GNU Make Standard Library.

See 8.3 Functions for File Names of the manual, you can use $(addprefix ...) (there are other ways) to get:

-rm -f $(OBJS)
-rm -f $(addprefix mod_,$(OBJS:.o=.mod))

It would be even better to use $(RM) (it's usually rm -f):

-$(RM) $(OBJS)
-$(RM) $(addprefix mod_,$(OBJS:.o=.mod))

Upvotes: 2

MadScientist
MadScientist

Reputation: 101051

The GNU make manual describes all these things.

You can use patterns to get what you want:

-rm -f $(OBJS:%.o=mod_%.mod)

Writing $(OBJS:.o=.mod) is just shorthand for $(OBJS:%.o=%.mod).

Upvotes: 1

Related Questions