Search code examples
makefile

How to figure out which makefile in a chain of makefiles is overwriting a variable?


I would like to know how to find out where a variable is being overwritten when trying to "make" my program. Here is the compiler error:

Loading /home/tyler/Software/Cpp/Cpp_Libraries/PelePhysics/Submodules/amrex/Tools/GNUMake/comps/gnu.mak...
Loading /home/tyler/Software/Cpp/Cpp_Libraries/PelePhysics/Submodules/amrex/Tools/GNUMake/sites/Make.unknown...
Loading /home/tyler/Software/Cpp/Cpp_Libraries/PelePhysics/Submodules/amrex/Tools/GNUMake/packages/Make.sundials...
make: /home/tyler/Software/Cpp/Cpp_Libraries/PelePhysics/Submodules/amrex/Tools/F_scripts/findparams.py: No such file or directory
make: Warning: File 'tmp_build_dir/o/2d.gnu.EXE/AMReX_buildInfo.d' has modification time 26084 s in the future
make: *** No rule to make target '/Users/tfara/amrex/Src/Extern/SUNDIALS/AMReX_NVector_MultiFab.cpp', needed by 'tmp_build_dir/o/2d.gnu.EXE/AMReX_NVector_MultiFab.o'.  Stop.

I believe I can tell you precisely the problem: I worked on this piece of software previously and, on that machine, a variable called AMREX_HOME was set to /Users/tfara/amrex/. Now I am on a different machine and AMREX_HOME should be set to /home/tyler/Software/Cpp/Cpp_Libraries/PelePhysics/Submodules/amrex/. The issue is that the programs PelePhysics and AMREX are enormous, professionally developed packages and when they are made, there is a huge chain of intermediate makefiles that get included, which I cannot begin to fully understand.

So you can see from the compiler error that the first three "loads" use the correct AMREX_HOME variable. This is because I set that variable in my own makefile. But somewhere along the way, the AMREX_HOME variable gets overwritten. I'd like to have the compiler tell me who is trying to make the target /Users/tfara/amrex/Src/Extern/(etc) so that I can go to that makefile and update the path variable appropriately.


Solution

  • The .d timestamp warning suggests that you copied the source directory along with the build artefacts in tmp_build_dir in it onto the new machine. Your makefiles end up including the auto-generated header dependencies .d files from that build directory, .d files contain paths to header files on the machine that produced these files and those paths don't match your new build environment.

    To fix the problem do either of:

    • Remove all these build artefacts. make clean should normally do that, otherwise rm -rf tmp_build_dir is drastically robust.
    • Remove only .d files and keep the the rest of the build artefacts with find tmp_build_dir -name '*.d' -delete. Other build artefacts may still contain full paths from original build environment, though.