Search code examples
makefiledirectory

How to get the basename of the current folder as variable in a makefile?


I want to copy a file to a server using scp. But I want to use my current folder name in my makefile as variable.

I know I get my current path using $(CURDIR) but my local path isn't the same on my remote server.

E.g. my path is /Users/obstschale/Documents/Lab2/ and I want to copy Lab2.tar to [email protected]:/home/path/Lab2/.

copy2server:
    echo $(CURDIR)
    scp Lab2.tar [email protected]:/home/path/{folder}

I probably have to pipe $(CURDIR) into something and find my last folder.

Update: $(CURDIR) is the right variable. $(CURID) is the wrong one at least it didn't work for me.


Solution

  • I didn't have luck with the backtick syntax in makefiles (GNU Make 3.81) as Sylvain describes it. If it doesn't work for you either, use

    $(shell basename $(CURDIR))
    

    instead of

    `basename $(CURDIR)`