Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my makefile target-specific variable work?
    text
    copied!<p>I am trying to make a makefile which does the following:</p> <ul> <li>gets source files from the <strong>src</strong> directory</li> <li>puts object files in the <strong>obj</strong> directory</li> <li>puts binary files in the <strong>bin</strong> directory</li> <li>puts release targets in the <strong>rel</strong> directory</li> <li>puts debug targets in the <strong>dbg</strong> directory</li> </ul> <p>The first problem i'm having is that my target-specific variables don't seem to be working here is the makefile:</p> <pre><code># Build Directories src_dir=src obj_dir=obj bin_dir=bin cc=cl cc_flags= # create the directory for the current target. dir_guard=@mkdir -p $(@D) # source files src = MainTest.cpp # object files - replace .cpp on source files with .o and add the temp directory prefix obj = $(addprefix $(obj_dir)/$(cfg_dir)/, $(addsuffix .obj, $(basename $(src)))) release: cfg_dir = rel release: executable debug: cfg_dir = dbg debug: cc_flags += -Yd -ZI debug: executable executable: $(bin_dir)/$(cfg_dir)/MainTest.exe # build TwoDee.exe from all of the object files. $(bin_dir)/$(cfg_dir)/MainTest.exe : $(obj) $(dir_guard) $(cc) -out:$@ $(obj) -link # build all of the object files in the temp directory from their corresponding cpp files. $(obj_dir)/$(cfg_dir)/%.obj : $(source_dir)/%.cpp $(dir_guard) $(cc) $(cc_flags) -Fo$(obj_dir)/$(cfg_dir) -c $&lt; </code></pre> <p>When I run make debug I get:</p> <pre><code>make: *** No rule to make target `obj//MainTest.obj', needed by `bin//MainTest.exe'. </code></pre> <p>There is also something else wrong because if I remove the debug and release variables and hardcode <strong>cfg_dir to rel</strong> I then get:</p> <pre><code>make: *** No rule to make target `obj/rel/MainTest.obj', needed by `bin/rel/MainTest.exe'. Stop. </code></pre> <p>So my object rule must also be wrong. I am new to make files so if anyone sees other things which are wrong, comments are welcome.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload