5

I have a Makefile, and I want make to run automatically when I double-click it (from the Ubuntu file manager). So, I made this Makefile executable, and added at its top the following shebang line:

#!/usr/bin/make -f

When I run /usr/bin/make -f Makefile, I get the desired result.

However, when I double-click the Makefile, or just run ./Makefile, I get an error:

: No such file or directory
clang-9      -o .o
clang: error: no input files
make: *** [<builtin>: .o] Error 1

What is the correct way to make my Makefile executable?

Here are the entire contents of my makefile:

#!/usr/bin/make -f

# A makefile for building pdf files from the text (odt files) and slides (odp files).
# Author: Erel Segal-Halevi
# Since: 2019-02

SOURCES_ODP=$(shell find . -name '*.odp')
TARGETS_ODP=$(subst .odp,.pdf,$(SOURCES_ODP))
SOURCES_ODT=$(shell find . -name '*.odt')
TARGETS_ODT=$(subst .odt,.pdf,$(SOURCES_ODT))
SOURCES_DOC=$(shell find . -name '*.doc*')
TARGETS_DOC=$(subst .doc,.pdf,$(subst .docx,.pdf,$(SOURCES_DOC)))
SOURCES_ODS=$(shell find . -name '*.ods')
TARGETS_XSLX=$(subst .ods,.xlsx,$(SOURCES_ODS))

all: $(TARGETS_ODP) $(TARGETS_ODT) $(TARGETS_DOC) $(TARGETS_XSLX)
    #
    -git commit -am "update pdf files"
    -git push
    echo Done!
    sleep 86400

%.pdf: %.odt
    #
    libreoffice --headless --convert-to pdf $< --outdir $(@D)
    -git add $@
    -git add $<
    
%.pdf: %.doc*
    #
    libreoffice --headless --convert-to pdf $< --outdir $(@D)
    -git add $@
    -git add $<

%.pdf: %.odp
    #
    libreoffice --headless --convert-to pdf $< --outdir $(@D)
    -git add $@
    -git add $<

%.xlsx: %.ods
    #
    libreoffice --headless --convert-to xlsx $< --outdir $(@D)
    -git add $@
    -git add $<

clean:
    rm -f *.pdf
0

1 Answer 1

8

#!/usr/bin/make -f is a valid shebang to allow execution of a Makefile. The problem with your Makefile isn’t its shebang, it’s that it uses Windows line-endings; if you fix that, e.g. with

sed -i $'s/\r$//' Makefile

your Makefile will run correctly.

The difference between using make to run such a Makefile, and running it directly, is that in the latter case, because of the Windows line endings, make is invoked as

make -f $'\r'Makefile

This produces the “No such file or directory” error, since there is no file with a name consisting of a single carriage return. When Make is asked to process a file as a Makefile, it tries to produce it or update it if necessary; since the file that Make is looking for here is missing, it tries to create it. This invokes Make’s built-in rules, which is where the C compiler invocation comes from.

3
  • 2
    dos2unix is frequently available as a tool to fix this. Commented Oct 20, 2022 at 15:24
  • @Barmar not as frequently as sed ;-). Commented Oct 20, 2022 at 16:20
  • Some systems have fromdos instead of dos2unix. Commented Oct 20, 2022 at 20:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.