Discussion:
Get the directory of the Makefile
Victor Porton
2017-09-19 22:05:56 UTC
Permalink
I want to pass absolute (or relative with possible ../../..) path of
certain file (for example, laying in the same directory as Makefile or
in its subdirectory or its superdirectory) to my application.

For example, consider that I created application run-tests in a direct
subdirectory of the Makefile and I want to run

./run-tests ../data.txt

when I am in a direct subdirectory of the directory with the Makefile,
because data.txt lies in the same directory as the Makefile.

That is I want Automake to add the correct ../ prefix to data.txt.

How to get the path to my data.txt?
Mathieu Lirzin
2017-09-19 22:22:35 UTC
Permalink
Hello Victor,
Post by Victor Porton
I want to pass absolute (or relative with possible ../../..) path of
certain file (for example, laying in the same directory as Makefile or
in its subdirectory or its superdirectory) to my application.
For example, consider that I created application run-tests in a direct
subdirectory of the Makefile and I want to run
./run-tests ../data.txt
when I am in a direct subdirectory of the directory with the Makefile,
because data.txt lies in the same directory as the Makefile.
That is I want Automake to add the correct ../ prefix to data.txt.
How to get the path to my data.txt?
I am not sure to understand what you are trying to do.

A minimal example of a 'configure.ac' and a 'Makefile.am' building
'run-tests' would make easier for us to understand and help you.

Thanks.
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Victor Porton
2017-09-19 22:29:22 UTC
Permalink
Post by Mathieu Lirzin
Hello Victor,
Post by Victor Porton
I want to pass absolute (or relative with possible ../../..) path of
certain file (for example, laying in the same directory as Makefile or
in its subdirectory or its superdirectory) to my application.
For example, consider that I created application run-tests in a direct
subdirectory of the Makefile and I want to run
./run-tests ../data.txt
when I am in a direct subdirectory of the directory with the
Makefile,
because data.txt lies in the same directory as the Makefile.
That is I want Automake to add the correct ../ prefix to data.txt.
How to get the path to my data.txt?
I am not sure to understand what you are trying to do.
A minimal example of a 'configure.ac' and a 'Makefile.am' building
'run-tests' would make easier for us to understand and help you.
Thanks.
It seems I found a solution myself. It can be done like:

check-local: $(builddir)/obj-static/test/run_all_tests
$(builddir)/obj-static/test/run_all_tests $(srcdir)/../data.txt

Loading...