Search code examples
makefiletargets

Using multiple and combinable makefile targets


I have a latex project containing at least two options: printable (witch put clickable link on footnote) and monochrome (witch put the wool document on black). This options could be used as single option or, it could be used at the same time (if I want a monochrome document with the links in footnotes).

So, this is the skeleton of my makefile:

 printable:
     ${TEX} -jobname=${NAME} "\def\isprintable{1} \input{main.tex}"

 monochrome:
     ${TEX} -jobname=${NAME} "\def\ismonochrome{1} \input{main.tex}"

This code only permit me to get a document on a printable format Xor a monochrome document. But not twice on the same time.

I tried the target printable monochrome: but in this case, I always get a a printable and monochrome document, also when I invoke make with only on of printable or monochrome target. I can’t get an only monochrome document or an only printable document.

So, is it possible to make an ifthen structure before the targets on the makefile to evaluate the targets pasted to make before execute it?

Something like:

if targets contain monochrome
     then: ARG=${ARG} "\def\ismonochrome{1}"

if tragets contain printable
     then: ARG=${ARG} "\def\isprintable{1}"

${TEX} -jobname=${NAME} "${ARG} \input{main.tex}"

Is it possible to do this with a makefile or I have to develop another way?


Solution

  • ifdef MONOCHROME
    ARGS += \\def\\ismonochrome{1}
    endif
    
    ifdef PRINTABLE
    ARGS += \\def\\isprintable{1}
    endif
    
    project:
        ${TEX} -jobname=${NAME} \"$(ARGS)\"
    

    You can invoke this with, e.g.

    make MONOCHROME=true PRINTABLE=yes
    

    Notice that some "escaping" may be necessary to deal with double-quotes, back-slashes and other special characters; this may require some fine-tuning on your system.