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

3 Answers 3

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) $<
0

I'm answering this for anyone who experiences this error as I did. This site is what I stumbled upon after this post and it explains it is a problem with indentation.

This code causes the error

target : dependencies
    ifneq (condition)
        body1
    else
        body2
    endif

But this code functions as expected

target : dependecies
ifneq (condition)
    body1
else
    body2
endif

Makefiles are wierd.

-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?

1
  • 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: humbug.in/2012/…. Still no luck. I'll post an update soon which also failed, maybe that reveals my wrong way of thinking here. Oct 9, 2012 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.