Using cmdstan makefile from another directory


#1

I am using Linux (Ubuntu 18.10), cmdstan 2.18.1, with the usual gcc and GNU make setup.

I am aware that one should use the provided makefile to compile programs as

cd cmdstan_location
make /some_other_path/model

but I am wondering if I could call it in the directory of the model file somehow, as it would make my workflow more convenient.

So far I tried

make -C cmdstan_location -f cmdstan_location/makefile model

but got an error, eg

$ make -C ~/src/cmdstan-2.18.1/ -f ~/src/cmdstan-2.18.1/makefile model
make: Entering directory '/home/tamas/src/cmdstan-2.18.1'
make: *** No rule to make target 'model'.  Stop.
make: Leaving directory '/home/tamas/src/cmdstan-2.18.1'

#2

I’ve been working, for a while now, on a bash script that does this. Omitting the extra bits, these lines from this script file work on macOS 10.13.6.

cwd="$(pwd)"
cmdstan="$HOME/cmdstan"
make "$cwd/$1" -C "$cmdstan"

#3

Here are some instructions, that I did a while ago. (On some system there might be problems, not sure why.)

ps. Don’t have spaces in your path.


#4

Yes, that’s crucial. There’s no way to have make treat spaces properly.

I’m not sure if this will work with the current develop makefiles, but please report if it does work.


#5

@syclik the following bash script works for me (macOS 10.13) with a fresh clone of cmdstan. It’s certainly a work in progress, but lines 8, 9, and 94 are what I posted above.