tags:

views:

125

answers:

2

I am distributing my cpp files along with a makefile. Now the makefile is located in the same directory as the cpp file.

What is the variable ( if any) in makefile that allows me to retrieve the current directory with the makefile is located? In this way I can use that variable to specify my cpp path for compilation.

My makefile is as follows:

all:
    g++ ($makeFileDir)/main.cpp ($makeFileDir)/hello.cpp ($makeFileDir)/factorial.cpp -o ($makeFileDir)/hello.exe

Edit: I am running my makefiles on Windows

A: 

you can use $(srcdir)

then ./configure --srcdir="/your/path/to/the/source/directory"

Tommy
+1  A: 

I remember I had the exact same problem. It's not possible, as far as I remember. The best bet you can have is to pass it as a variable. That is both cross platform and guaranteed to work, as you know the makefile dir at invoke time (otherwise you can't invoke it).

In alternative, you can do a very dirty trick, meaning you try to combine your current path (you can obtain with $(CURDIR) in gnu make) with the path of the invocation of the makefile (which can be tricky, and depends on your make)

Stefano Borini