skip to Main Content

I have an rm command that does not work in a Makefile but when I copy it to the shell it works:

$ make clean
rm paper.{abs,blg,pdf,aux,log,bbl,out,xmpdata}
rm: cannot remove 'paper.{abs,blg,pdf,aux,log,bbl,out,xmpdata}': No such file or directory
make: *** [Makefile:8: clean] Error 1
$ rm paper.{abs,blg,pdf,aux,log,bbl,out,xmpdata}
$

What can cause this? The file rights seem to be OK. I tried using double quotes and apostrophes around the filename expression but neither worked.

UPDATE: I run GNU Make 4.3 on Ubuntu 22.04

2

Answers


  1. Chosen as BEST ANSWER

    Following this answer: https://unix.stackexchange.com/a/270799/46710

    I was able to do this within classic shell:

    define clean_aux_files =
    
            for e in abs blg pdf aux log bbl out xmpdata
            do 
              rm "paper.$e"
            done
    endef
    
    .ONESHELL:
    
    clean:  
            $(value clean_aux_files)
            rm pdfa.xmpi texput.log
    

    I tested this and it worked.


  2. GNU Make runs the POSIX-compliant /bin/sh for a shell. It would be a disaster for portability if it invoked whatever shell the user was using.

    The {} form you’re using is not a POSIX-conforming syntax: POSIX does not define any special behavior for {}. You are trying to take advantage of a capability of your personal shell (likely bash) which is non-standard.

    You either need to write out the multiple filenames or use standard POSIX globbing, or else add a line to your makefile to force it to use bash instead of /bin/sh, like:

    SHELL := /bin/bash
    

    Note then your makefile will not work properly on any system where /bin/bash is not present.

    You could also use a GNU Make function, such as:

    clean:
            rm $(addprefix paper.,abs,blg,pdf,aux,log,bbl,out,xmpdata)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search