Search code examples
makefilecommand-line-arguments

Issue with passing environment variable to make file


In my make file I have 2 parameters defined as below with default values. PARAM1 ?= 2 PARAM2 ?= 11 I am using these parameters in my target cpp_run.

cpp_run:
    ./dig_vr_App $(PARAM1) $(PARAM2) |& tee run_Cpp.log

However if I pass the parameters from the command line for example

make cpp_run PARAM1=102 PARAM2=0

the make file still picks up the default values, i.e., 2 and 11 (from the log file run_cpp.log). I followed other posts which says use PARAM1=num1 and PARAM2=num2 in the command line as shown above but it doesn't work.


Solution

  • As I said in my comments, you are not telling us something. I created this test:

    $ cat Makefile
    PARAM1 ?= 2
    PARAM2 ?= 11
    
    cpp_run:
             @echo ./dig_vr_App $(PARAM1) $(PARAM2)
    

    and it works exactly how I'd expect:

    $ make --version | head -n2
    GNU Make 4.3
    Built for x86_64-pc-linux-gnu
    
    $ make cpp_run
    ./dig_vr_App 2 11
    
    $ make cpp_run PARAM1=102 PARAM2=0
    ./dig_vr_App 102 0
    

    So there's something about your environment or makefile that you haven't explained to us.