Unix Programming - [make] can make do this?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > [make] can make do this?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [make] can make do this?
Arun Dev

2004-01-23, 5:35 pm

Hello everybody

I am a beginner to make.

For my work with LaTeX I need a few targets to achive
the following:

My "source" file mysource.tex has various forms like
either \documentclass[pdf,nocolor]..
or \documentclass[ps,nocolor]..
or ...

depending on the target, say "make pdf", latex should
run on the first version of the tex file, the second
line will be commented out (or cut out).

Similarly "make ps".

Can make do this? How?

Arun

Zoran Cutura

2004-01-23, 5:35 pm

Arun Dev <nospam@pleaz.xy> wrote:
quote:

> Hello everybody
>
> I am a beginner to make.
>
> For my work with LaTeX I need a few targets to achive
> the following:
>
> My "source" file mysource.tex has various forms like
> either \documentclass[pdf,nocolor]..
> or \documentclass[ps,nocolor]..
> or ...
>
> depending on the target, say "make pdf", latex should
> run on the first version of the tex file, the second
> line will be commented out (or cut out).
>
> Similarly "make ps".
>
> Can make do this? How?



make cannot do this magically, but you can have to PHONY rules:

..PHONY: ps pdf

ps:
sed -e 's/documentclass\[p.*,nocolor]/documentclass\[ps,nocolor]/'
latex mysource.tex

pdf:
sed -e 's/documentclass\[p.*,nocolor]/documentclass\[pdf,nocolor]/'
latex mysource.tex


Note, that this is by no means a complete makefile, but just a pointer
in the direction you're heading to.
--
Z (Zoran.Cutura@daimlerchrysler.com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Arun Dev

2004-01-23, 5:35 pm

Hi Zoran

Thanks for quick reply!

Zoran Cutura wrote:
quote:

>
> make cannot do this magically, but you can have to PHONY rules:
>
> .PHONY: ps pdf
>
> ps:
> sed -e 's/documentclass\[p.*,nocolor]/documentclass\[ps,nocolor]/'
> latex mysource.tex
>
> pdf:
> sed -e 's/documentclass\[p.*,nocolor]/documentclass\[pdf,nocolor]/'
> latex mysource.tex
>
>
> Note, that this is by no means a complete makefile, but just a pointer
> in the direction you're heading to.



I guess, the idea is clear to me.

Unfortunately the example I've given misled you to
assume this is the _only_ difference between the
two versions of the tex-file.

It is not so. There are other blocks of TeX-source within
the document, which have to be added or removed according
to the target.

IMHO, either something like a preprocessor directive
to the C-compiler (-d name=val) or some if-then somewhere
is necessary.

Hope the question is clear ;)

Arun

Zoran Cutura

2004-01-23, 5:35 pm

Arun Dev <nospam@pleaz.xy> wrote:
quote:

> Hi Zoran
>
> Thanks for quick reply!
>
> Zoran Cutura wrote:
....[QUOTE][color=darkred]
>
> I guess, the idea is clear to me.
>
> Unfortunately the example I've given misled you to
> assume this is the _only_ difference between the
> two versions of the tex-file.
>
> It is not so. There are other blocks of TeX-source within
> the document, which have to be added or removed according
> to the target.
>
> IMHO, either something like a preprocessor directive
> to the C-compiler (-d name=val) or some if-then somewhere
> is necessary.
>
> Hope the question is clear ;)



Well, that isn't what you asked in your first posting, and it is hardly
solved with make only. What I've shown so far is how to write your
rules in the makefile such that you can differ between the two ways of
processing your source. But you've not asked how to process your source
until now.

For preprocessing text-files you may want to try the m4-preprocessor
instead of the simple sed-command I presented in my previous reply.

I don't konw which changes actually need to be done, so I cannot present
you with a concrete sollution.

--
Z (Zoran.Cutura@daimlerchrysler.com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Tristan Miller

2004-01-23, 5:35 pm

Greetings.

In article <4003e6c9$1_2@news.tiscalinet.ch>, Arun Dev wrote:
quote:

> For my work with LaTeX I need a few targets to achive
> the following:
>
> My "source" file mysource.tex has various forms like
> either \documentclass[pdf,nocolor]..
> or \documentclass[ps,nocolor]..
> or ...



Wouldn't it simply be easier to use conditionals within the LaTeX file
itself to determine which arguments are used depending on whether it's
being processed by latex or pdflatex? This way user intervention is not
required to switch output modes.

For example, you could put the following at the top of the file:

\newif\ifpdf
\ifx\pdfoutput\undefined
\documentclass[ps,nocolor]{article}
\usepackage{graphicx}
\pdffalse
\else
\pdfoutput=1
\pdfcompresslevel=9
\documentclass[pdf,nocolor]{article}
\usepackage[pdftex]{graphicx}
\pdftrue
\fi

Later on in the document when you need to chose between Postscript- and
PDF-specific code you can use the folowing:

\ifpdf
I am running pdflatex! Hooray!
\else
I am not running pdflatex! Hooray!
\fi

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Arun Dev

2004-01-23, 5:35 pm

Hello Zoran

Zoran Cutura wrote:
quote:

>
> Well, that isn't what you asked in your first posting, and it is hardly
> solved with make only. What I've shown so far is how to write your
> rules in the makefile such that you can differ between the two ways of
> processing your source. But you've not asked how to process your source
> until now.



Sorry, if I haven't formulated my problem clearly.
I'm myself "searching in the dark".
quote:

> For preprocessing text-files you may want to try the m4-preprocessor
> instead of the simple sed-command I presented in my previous reply.
>
> I don't konw which changes actually need to be done, so I cannot present
> you with a concrete sollution.



It is not necessary. You have been helpful already.

In fact, I've found a LaTeX Macro which does this.
It works fine. Still I would like to understand
how it works. I will try the line presented by
the other poster Tristan Miller in this thread.

Thanks for taking your time.

Arun.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com