0

I have a make file that has two includes like this :

$ cat /src/Makefile
include ../rules.mk

Test:
    echo $(DIST_ROOT)

include src.base.mk

Test2: 
     echo $(DIST_ROOT)

. PHONY: Test Test2

$ cat /rules.mk
DIST_ROOT = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))

$ cat /src/src.base.mk
srcdir = $(DIST_ROOT)/src

The issue is that the output of both is /src but it should be /.

How does this happen and how can I fix this?

Thaodan
  • 107
  • 1
  • 3
  • 10
  • In `Test2` recipe do you really echo `$(DIST_ROOT)`? Isn't it `$(srcdir)`, instead? And when you write `/src`, isn't it `/src/src.base.mk`? And (it seems obvious but you did not specify this) do you invoke make from `/src`? And your` `Phony`, isn't it `.PHONY`? – Renaud Pacalet Dec 06 '17 at 13:32
  • @RenaudPacalet yes sorry. I tiped this on my smartphone. But the 2nd recipe is really "echo $(DIST_ROOT)". – Thaodan Dec 06 '17 at 13:35
  • 1
    Cannot reproduce this. `make Test` outputs `/src` and `make Test2` also outputs `/src`. And this is not surprising at all. – Renaud Pacalet Dec 06 '17 at 13:46
  • Sorry for the late answer. But thats exactly the isue the output should be / not /src. – Thaodan Dec 31 '17 at 04:11

1 Answers1

0

I found the issue and a fix.
To answer my own question:
When assigning a variable with just equal sign, the variable gets cast everytime its just.
What I needed to add was ":" so it gets casted once and is set as wanted.
Based on this question.

Thaodan
  • 107
  • 1
  • 3
  • 10