14

I want to write a make file to compile my source code. I have to put in my make file the includes paths but i have a lot of folders with source codes. In make file i have a list with all .c files like this :

__MDA_SRC = \
$(__VIEWPATH)\f_03\test\mda\src\mda.c

now i need to find out the path of this file.

I tried this one :

__PATHS_FEATURE = \
$(dir $(__MDA_SRC ))

__INCLUDE_PATHES := \
-I$(__PATHS_FEATURE)

but i have an error F100: cannot open ...bla bla..

i supposed that the problem is on the path, because the path is extructed with the last backslash like: ..\..\..\..\..\f_03\test\mda\src\

How could i have the path without the last backslash like this : ..\..\..\..\..\f_02\hydraulic\btc\src

2 Answers 2

17

That seems unlikely to be the problem to me but you can remove it with

$(__PATHS_FEATURE:\=)

or

$(patsubst %\,%,$(__PATHS_FEATURE))
Sign up to request clarification or add additional context in comments.

4 Comments

it looks to me like you are you are missing a percent there: $(patsubst %\,%,$(__PATHS_FEATURE))
@Compholio Indeed. Good catch.
Heh. I approached this like "first copy/paste and see if it works, then try to understand". But it was working. Then I realized I was on a UNIX-based system where the "trailing slash" is a forward slash. Oof. +1.
3

This may not work for your problem since your path is not absolute, however the 'abspath' and 'realpath' indirectly do what you are looking for. 'realpath' will remove the last forward slash as well as any . .. or repeated /

pathwslash=/dirs/and/more/dirs/
path=$(realpath $(pathwslash))

echo $(path) # /dirs/and/more/dirs

Here is some documentation for some other functions that may be helpful: https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.