clawpack / clawutil

General utility programs
BSD 3-Clause "New" or "Revised" License
10 stars 31 forks source link

recursive $(MAKE) doesn't find right Makefile #38

Open rjleveque opened 11 years ago

rjleveque commented 11 years ago

I've got a directory with a file setrun_restart.py but no setrun.py and Makefile_restart sets SETRUN_FILE=setrun_restart.py

I modified the Makefile.common to print out what setrun file it's using...

----------------------------------------------------------------------------

Make data files needed by Fortran code:

.data: $(SETRUN_FILE) $(MAKEFILE_LIST) ; @echo Using setrun from $(SETRUN_FILE) $(MAKE) data

data: $(MAKEFILE_LIST); -rm -f .data @echo Using setrun from $(SETRUN_FILE) $(CLAW_PYTHON) $(SETRUN_FILE) $(CLAW_PKG) touch .data

----------------------------------------------------------------------------

It works as expected if I do $ make data -f Makefile_restart

but here's what happens if I "make .data..."

$ make .data -f Makefile_restart Using setrun from setrun_restart.py make data rm -f .data Using setrun from setrun.py python setrun.py amrclaw
python: can't open file 'setrun.py': [Errno 2] No such file or directory

The $(MAKE) data command is to blame -- it's not using the right version of the Makefile for this recursive call. (I also have a Makefile in the directory and if I remove that then it says it doesn't know how to make data at all.)

My GNU Make book doesn't tell how to fix this. It says there's a variable $(MAKEFLAGS) that should be passed but say that this does not contain the -f flag in particular.

mandli commented 11 years ago

So it's not keeping track of the correct Makefile?

rjleveque commented 11 years ago

That's right - The $(MAKE) call from Makefile.common uses the Makefile in the apps directory rather than Makefile_restart (which did the "include Makefile.common").

rjleveque commented 10 years ago

I'm running into this problem again, e.g. if there's a Makefile2 with

EXE = xclaw2
OUTDIR = _output2

then Make .exe -f Makefile2 creates xclaw2 fine but Make .output -f Makefile2 uses xclaw and writes to _output, taken from the original Makefile.

mandli commented 10 years ago

Does adding a conditional to the makefile variables work for what you are trying to do?

ifdef test1
    EXE = xclaw
    OUTDIR = _output
else
    EXE = xclaw2
    OUTDIR = _output2
fi