help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditional file parameters in make command?


From: Mike Shal
Subject: Re: conditional file parameters in make command?
Date: Thu, 26 Mar 2009 14:54:18 -0400

On 3/26/09, Erik <address@hidden> wrote:
> I need to generate a PDF-file from subdocuments. I have this Makefile:
>  whole.pdf: 1.pdf 2.pdf 3.pdf 4.pdf 5.pdf 6.pdf 7.pdf 8.pdf 9.pdf
>    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$@ -dBATCH $^
>
>  The problem is that a subdocument may begin on the backside of the last
>  page of the previous subdocument. This is bad if the printed document
>  should be divided into subdocuments. Therefore I need to make sure that
>  every subdocument begins on a new paper. A way to do this would be to
>  insert an empty 1-page document (empty.pdf) after each document that has
>  an odd number of pages:
>  whole.pdf: 1.pdf 2.pdf 3.pdf empty.pdf 4.pdf 5.pdf 6.pdf 7.pdf empty.pdf
>  8.pdf empty.pdf 9.pdf
>    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$@ -dBATCH $^
>
>  That is certainly not the right way to do it. It will fail if I change
>  any subdocument so that its page count modulo 2 is changed.
>
>  By using pdfinfo (in the poppler package) I can find out whether a
>  particular PDF-file has an odd number of pages:
>    echo $(pdfinfo file.pdf|egrep "^Pages: *[[:digit:]]+$"|sed "address@hidden:
>  *\([[:digit:]]\+\)address@hidden@")%2|bc
>
>  But which is the right way to build that into the Makefile?

Maybe you would be better off doing this in the shell rather than in
make? Something like:

whole.pdf: 1.pdf 2.pdf 3.pdf ...
   files=`for i in $^; do echo $$i; if echo $$(pdfinfo ...); then echo
empty.pdf; fi; done`; \
   gs -dNOPAUSE ... $$files

Here is a working example with some phony targets to give you a better
idea of what I mean. Basically I just test if the file is "4", and if
so then add in an extra file.

$ cat Makefile
.PHONY: 1 2 3 4 5 whole
whole: 1 2 3 4 5
        @files=`for i in $^; do echo $$i; if [ "$$i" == "4" ]; then
echo extra; fi; done`; \
        echo "Run command on $$files"

$ make
Run command on 1
2
3
4
extra
5

May require some additional tweaking to get what you want - hope it helps!
-Mike




reply via email to

[Prev in Thread] Current Thread [Next in Thread]