0

This is a kind of silly question, but this is first time I am using Makefile. I am having trouble with selecting files. When I used this command,

target1:

     $(CC) -o target *.c

it worked well. But this doesn't work,

SRCS = dir1/*.c
target1:

     $(CC) -o target $(SRCS)

and spits this error.

clang: error: no such file or directory: 'dir1/*.c'

Obviously this because my variable SRCS is escaped before passed. How can I make Makefile pass the string as is? Or is there another conventional/designed way to do this? (selecting file by pattern)

eonil
  • 83,476
  • 81
  • 317
  • 516
  • you might find your answer here http://stackoverflow.com/questions/1139271/makefiles-with-source-files-in-different-directories – A4L Mar 03 '13 at 00:09

2 Answers2

3

You can use the wildcard keyword to select all the files matching a certain pattern like this:

SRCS = $(wildcard dir1/*.c)
target1:

     $(CC) -o target $(SRCS)
Tuxdude
  • 47,485
  • 15
  • 109
  • 110
1
SRCS := $(shell echo dir1/*.c)
target1:
    $(CC) -o target $(SRCS)
suspectus
  • 16,548
  • 8
  • 49
  • 57