Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 776
Hans-Helge Avatar asked Mar 17 '13 10:03

Hans-Helge


People also ask

How do I get the current relative directory of my makefile?

You can use shell function: current_dir = $(shell pwd) .

What is $@ in makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.

How do I print a variable in makefile?

To use it, just set the list of variables to print on the command line, and include the debug target: $ make V="USERNAME SHELL" debug makefile:2: USERNAME = Owner makefile:2: SHELL = /bin/sh.exe make: debug is up to date. Now you can print variables by simply listing them on the command line.

What is Abspath in makefile?

That's what abspath does. It creates an absolute path. That means it must be anchored at the root.


2 Answers

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)`
like image 174
firefrorefiddle Avatar answered Sep 20 '22 06:09

firefrorefiddle


I tried this rule:

test:
    @echo $(CURDIR)           # e.g. /tmp/foobar/blafoor/baz
    @echo $(notdir $(CURDIR))  # gives "baz" here.

which worked fine for me.

maybe this is not intended to work, because notdir should

Extract the non-directory part of each file name.

like image 27
reox Avatar answered Sep 22 '22 06:09

reox