0

I'm writing a Makefile to ease latex file compilation. I am trying to create a clean target to delete all files produced by pdflatex, and I wrote this:

SHELL := /bin/bash
name = mydocument

all: show

$(name).pdf: $(name).tex
    # We need to run it twice to update the TOC
    pdflatex $<
    pdflatex $<

show: $(name).pdf
    gnome-open $<

clean:
    ls -l $(name)!(.tex)

.PHONY: all clean show

The problem is the command ls -l $(name)!(.tex). If I run it from the terminal I get the list of files to delete (i.e. all files called "mydocument" that have an extension different from ".tex"), but if I run it with make clean I get the following error:

ls -l mydocument!(.tex)
/bin/bash: -c: line 0: syntax error near unexpected token "("
/bin/bash: -c: line 0: `ls -l mydocument!(.tex)'
make: *** [clean] Error 1

Does anyone know how to fix this?

user2340612
  • 10,053
  • 4
  • 41
  • 66
  • on the cmdline, what does 'shopt extglob' output? – bgarcia Jan 30 '16 at 12:23
  • 1
    Well actually it's on on a regular shell, but it's off inside the Makefile! I should enable it inside the Makefile – user2340612 Jan 30 '16 at 12:28
  • 2
    I found the answer here: http://stackoverflow.com/questions/6922187/how-to-fix-makefile-syntax-error-when-using-wildcard-on-make-clean – user2340612 Jan 30 '16 at 12:32
  • 3
    You should seriously think of using `latexmk`. It will handle (optimally) several LaTeX passes (unlike yours, that always processes twice). It also handles cleaning very nicely (with the `-c` or `-C` switches): it will really clean all auxilliary files (and only them). – gniourf_gniourf Jan 30 '16 at 12:37
  • Thank you, I didn't know it, I'll give a look at it! – user2340612 Jan 30 '16 at 12:41
  • 1
    @gniourf_gniourf I will definitely switch to `latexmk` since it can perform all building phases automatically. It also has a "preview-continuous" option that can be very useful. Thanks again for making me discover this tool! – user2340612 Jan 30 '16 at 13:45

0 Answers0