28

I am trying to understand a Makefile, but I don't understand the recipe line with the comment.

...
...
sample.a:
    cd ../$(basename $(notdir $@)) && make    ##i don't understand this
...
...

I'm still a newbie at this. Can you give me a very simple explanation about:

$(basename $(notdir $@))

1 Answers1

53

If you break it down:

$(notdir $@) takes away the path from the file name leaving just the file name (so /x/y/foo.a becomes foo.a) $(basename ...) takes away the extension (so foo.a becomes foo)

There's a decent reference here: http://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

lurker
  • 56,987
  • 9
  • 69
  • 103
  • Excellent answer. Also I use directory name as prefix for `$(notdir $@)`. For example: `@echo "Building source file: " $< $(CC) $(CFLAGS) -c $< -o $(OBJECT-DIR)/$(notdir $@)` And before define `OBJECT-DIR = obj` – EsmaeelE Apr 04 '20 at 22:39