# pmake can't find include file, .CURDIR not getting expanded.



## Maelstorm (Aug 27, 2014)

I've run into a somewhat baffling problem with FreeBSD's pmake.  I'm working on a software project that uses multiple source files and thus include files which are scattered among a directory tree.  If you are in the top directory and type `make`, everything works fine.  However, if you go into one of the directories and type `make`, then it cannot find one of the files.  I figured it is a directory reference problem, but I can't seem to locate where the problem is.

Makefile

```
#
# Makefile
#



# Set PROG to the executable program name.  No .o or .c extension.
# Set OBJS to name.o for each obj file used.  Do not include program obj.
# Set HEADS to the name of the local header files.
# Set DIRS to any subdir's used that make should recusively execute in.
# Set LEVEL to the level number of the subtree.  Top level is 1.
#
# Command Line Options
#   -DTHREADING  Use pthread(3) threading library.
#   -DDEBUG      Enable debugging code
#   XCC          Set C compiler
#   XCOPTS       Additional Compiler Options
#
# Note that these variables can also be specified here if those options are
# always required.
#


PROG    = crand.test
OBJS    = crand.o
HEADS   = ctypesx.h crand.h crandp.h
DIRS    =
LEVEL   = 2


.include "mk.inc"
```

mk.inc is symlinked from the make directory.

```
# Base Directory

CDIR = ${.CURDIR}
.if empty(BASEDIR)
TBDIR = ${.CURDIR}
.else
TBDIR = ${BASEDIR}
.endif
BASEDIR = ${TBDIR}
.if defined(LEVEL) && !empty(LEVEL)
.if ${LEVEL} == "2"
BASEDIR = ${TBDIR}/..
.endif
.if ${LEVEL} == "3"
BASEDIR = ${TBDIR}/../..
.endif
.if ${LEVEL} == "4"
BASEDIR = ${TBDIR}/../../..
.endif
.if ${LEVEL} == "5"
BASEDIR = ${TBDIR}/../../../..
.endif
.if ${LEVEL} == "6"
BASEDIR = ${TBDIR}/../../../../..
.endif
.if ${LEVEL} == "7"
BASEDIR = ${TBDIR}/../../../../../..
.endif
.if ${LEVEL} == "8"
BASEDIR = ${TBDIR}/../../../../../../..
.endif
.if ${LEVEL} == "9"
BASEDIR = ${TBDIR}/../../../../../../../..
.endif
.else
.error LEVEL not set or is empty.
LEVEL = 1
.endif
.undef TBDIR

.include "$(BASEDIR)/make/mk.main.inc"
```

The last line with 
	
	



```
.include "$(BASEDIR)/make/mk.main.inc"
```
 is not being picked up for some reason.  It's almost like the .CURDIR variable isn't getting expanded.  Look here:

```
strata:/home/dr2867/c/m3/crand 351 $$$ ->make
"/home/dr2867/c/m3/crand/mk.inc", line 41: Could not find /../make/mk.main.inc
make: fatal errors encountered -- cannot continue
strata:/home/dr2867/c/m3/crand 352 $$$ ->
```

It picked up BASEDIR but it didn't pickup .CURDIR.  Anyone know why?


----------

