Note that there are some explanatory texts on larger screens.

plurals
  1. POGnu Makefile, compile should fail
    primarykey
    data
    text
    <p>I have a collection of examples that I want to <strong>make sure they fail to compile</strong>. What is the best way to to that with a *<em>GNU Makefile</em>?</p> <pre><code>test_nocompile: $(NOCOMPILE_CPP) for cpp in $(NOCOMPILE_CPP) ; do \ echo === $$cpp === ; \ if $(CXX) $(CXXFLAGS) -c -o fail.o $$cpp ; then echo ok ; else exit 1; fi ; \ done </code></pre> <p>As you can see, I have several difficulties here:</p> <ul> <li>Accessing the shell-for variable <code>cpp</code>: <code>$cpp</code>, <code>\$cpp</code> and <code>$$cpp</code> both do not work.</li> <li>Even with my <code>if</code> the make stops after the first g++-compile fails. But thats exactly what I want. I want failing to g++-compile to be considered the correct behaviour.</li> <li>Shell-for-loops in Makefiles are not the best idea. Is there a better way? I can not think of one, because since I expect the compiles to fail, I do not have a correct target, right?</li> </ul> <p>Advanced and optional:</p> <ul> <li>If I could manage to have the <em>fail-check</em> above working, I could try a second pass of compilation, this time with an additional <code>-DEXCLUDE_FAIL</code>, which takes out the offending line from my examples, and then the code should compile. Any idea?</li> <li>or should write a Python script for that...? ;-)</li> </ul> <p><strong>Edit:</strong></p> <p>I think my "advanced and optional" gave me a very good idea right now. I could use makes dependency checking again. Just a rough sketch here:</p> <pre><code> NOCOMPILE_CPP := $(wildcard nocompile/ *.cpp) NOCOMPILE_XFAILS := $(addsuffix .xfail,$(basename $(NOCOMPILE_CPP))) %.xfail: %.cpp if $(CXX) $(CXXFLAGS) -o $@ $&lt; ; then exit 1 ; else echo OK ; fi $(CXX) $(CXXFLAGS) -DEXCLUDE_FAILCODE -o $@ $&lt; test_nocompile: $(NOCOMPILE_XFAILS) </code></pre> <p>Is this elegant? Then I only have to work out how <code>-DEXCLUDE_FAILCODE</code> can make the failing tests work.... Non-trivial, but doable. I think that could do it, right?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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