2

I would like to create a makefile for LaTeX documents (in this minimal example). When there is no file "makeindexstyle.ist", it should be created (by running make makeindexstyle.ist) and used for formatting the index. The rule for %.pdf reflects this. However, it is not working yet, I receive the error

ifneq (, ) {
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
make: *** [master.pdf] Error 2

What's wrong?

Parts from Makefile:

MASTER = master
TEX = slave

TEXI = texi2dvi -p

all: $(MASTER:=.pdf)

%.pdf: %.tex $(TEX:=.tex)
    ifneq ($(wildcard makeindexstyle.ist), ) { # if makeindexstyle.ist exists, compile and build index
        $(TEXI) $<
        make makeindexstyle.ist
        makeindex -c -s makeindexstyle.ist $(MASTER:=.idx)
    }
    endif
    $(TEXI) $<

makeindexstyle.ist:
    @(echo "...") > makeindexstyle.ist

UPDATE: I tried to make it as simple as possible to see where the error comes from. Among other things (like quoting), I tried this:

%.pdf: %.tex $(TEX:=.tex)
    exist := $(wildcard "absolute-path-to-makeindexstyle.ist")
    ifneq ($strip $(exist)),)
             echo "foo"
    endif
    $(TEXI) $<

but the result is

exists := 
make: exists: Command not found
make: *** [book.pdf] Error 127
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102

2 Answers2

2

In the meanwhile, I could solve it on the shell side:

IDX = "makeindexstyle.ist"
%.pdf: %.tex $(TEX:=.tex)
    @if test -f $(IDX); then \
        echo "foo"; \
    fi
    $(TEXI) $<
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
-1

This sounds like a duplicate of How do I check if file exists in Makefile? or How to conditional set up a Makefile variable by testing if a file exists.

Try

ifneq ($(wildcard makeindexstyle.ist),)

without the space. Alternatively, throw "" around the arguments?

Community
  • 1
  • 1
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
  • Thanks, Quuxplusone. I knew the two links (and many others). Still, this does not solve the problem. I also tried the quoting (although I think it's not necessary), as described here: http://www.humbug.in/2012/makefile-check-if-a-file-exists-using-wildcard-function/. Still no luck. I'll post an update soon which also failed, maybe that reveals my wrong way of thinking here. – Marius Hofert Oct 09 '12 at 05:18