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.
You can use shell function: current_dir = $(shell pwd) .
$@ 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.
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.
That's what abspath does. It creates an absolute path. That means it must be anchored at the root.
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)`
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With