0

I have a makefile which is supposed to compile all my programs in a folder individually. The makefile content is :

SRCS = $(wildcard *.c)

PROGS = $(patsubst %.c,%,$(SRCS))

all: $(PROGS)

%: %.c
        $(CC) $(CFLAGS) -o $@ $<
clean: 
        rm -f $(PROGS)

and my files are named :

d744eb7b-350a-11e5-b84e-0242ac110011_2015-08-17_11:04:23.c

d746064f-350a-11e5-b84e-0242ac110011_2015-08-17_11:03:37.c

and so on.

When I run the makefile, it shows the following error :

makefile:5: *** target pattern contains no '%'.  Stop.

Can someone please tell me what is wrong? Thanks for your time.

  • The issue is the colons in your long filenames. There seems to be ways to escape these, but it looks really problematic. Can you change the structure of the dot-C filenames? – Steve Friedl Dec 02 '19 at 16:01
  • See also https://stackoverflow.com/questions/2052406/escaping-colons-in-filenames-in-a-makefile – AProgrammer Dec 02 '19 at 16:05
  • 1
    I read the same page that @AProgrammer did; it might be possible to work around this, but it's going to seriously suck, and your time will be much better spent figuring out how to use different filenames. – Steve Friedl Dec 02 '19 at 16:08
  • I agree with @SteveFriedl, especially if you want any assurance that it will continue to work when updating your `make` program, without speaking using an alternative one. – AProgrammer Dec 02 '19 at 16:10
  • AProgrammer, SteveFriedl Thanks a lot for your inputs. I dont think I will add any other complications, cause as of now, I dont even know how the makefile is working here ( Please explain it to me ? ). I am just going to rename all the files. – Richi Dubey Dec 02 '19 at 16:15

1 Answers1

2

I'm going to enter this as an answer: the problem is caused by the colons in the filenames, the parts that form the timestamp. The use of colons is so deeply embedded in how make works that it's going to be a nightmare to get it to take these names even if you somehow figure it out.

@AProgrammer has noted the page Escaping colons in filenames in a Makefile that essentially deals with the same thing, and the clear consensus is: don't do that.

Even this trivial makefile:

SRCS = 744eb7b-350a-11e5-b84e-0242ac110011_2015-08-17_11:04:23.c \
       d746064f-350a-11e5-b84e-0242ac110011_2015-08-17_11:03:37.c

foo : $(SRCS)
        echo $^

fails on my Linux system with the same "target pattern contains no %" error.

Yes, you can put a \ in front front of the colons if you enter them directly, and that might work, but when you start feeding these into other things, you end up in backslash hell due to the the various macro expansions.

It might be possible to solve this, but it would be a mess of a makefile, and your successor who has to maintain this will hate you forever, and probably be back here with "How do I fix this mess?" :-)

Renaming the files to change the colons to (say) underscores will make this problem go away.

Good luck.

Steve Friedl
  • 3,929
  • 1
  • 23
  • 30