Regis Santos
Regis Santos

Reputation: 3749

Sending parameters to make (Linux or other *nix flavor)

See the code below: How do I send a parameter BASE_NAME = myfile to the command line without typing BASE_NAME. I want to enter only

$make pdf myfile

BASE_NAME = myfile

LATEX     = latex
PDFLATEX  = pdflatex
BIBTEX    = bibtex
MAKEINDEX = makeindex
DVIPS     = dvips
PS2PDF    = ps2pdf

pdf: $(BASE_NAME).pdf
ps: $(BASE_NAME).ps

$(BASE_NAME).ps: $(BASE_NAME).tex 
    $(LATEX) $<
    $(BIBTEX) $(BASE_NAME) 
    $(LATEX) $< 
    $(LATEX) $<
    $(DVIPS) -Ppdf $(BASE_NAME)

$(BASE_NAME).pdf: $(BASE_NAME).tex
    $(PDFLATEX) $<

clean:
    rm -f $(BASE_NAME)*.ps $(BASE_NAME)*.dvi *.log \
          *.aux *.blg *.toc \
          missfont.log $(BASE_NAME)*.bbl $(BASE_NAME)*.out \
          $(BASE_NAME)*.lof $(BASE_NAME)*.lot

open:
    acroread $(BASE_NAME).pdf

Also, how do I use an option-type

$make pdf -o myfile

to generate the PDF and then open it from the option -o?

Upvotes: 3

Views: 277

Answers (2)

Boris
Boris

Reputation: 301

This is not a TeX question per se, but nevertheless...

You are much better if you specifiy generic rules instead of specific ones. Besides, if you want to open your files, Makefile conventions suggest the command make open rather than make -o.

I usually do it like this

# The only thing that changes!
TEXFILES = firstfile.tex secondfile.tex  

PDFS = ${TEXFILES:%.tex=%.pdf}

all: $(PDFS)

open: all
    for x in ${PDFS}; do (xpdf $$x &); done

# You can write a similar rule for ps...
%.pdf: %.tex  
    pdflatex $*
    -bibtex $*
    pdflatex $*
    - while ( grep -q '^LaTeX Warning: Label(s) may have changed' $*.log || \
    grep -q '^Package natbib Warning: Citation(s) may have changed' $*.log ) \
    do pdflatex $*; done


clean:
   $(RM) *.aux *.bbl *.dvi *.log *.out *.toc *.blg *.lof *.lot

distclean: clean
       $(RM) $(PDFS)

Upvotes: 2

uzsolt
uzsolt

Reputation: 6027

I think you should change your Makefile as Boris wrote:

%.pdf: %.tex
     pdflatex $<

After you can run make myfile.pdf or make foo.pdf or anything else.

Upvotes: 1

Related Questions