Compile all C files in a directory into separate programs

Martin Broadhurst picture Martin Broadhurst · Apr 24, 2010 · Viewed 24k times · Source

Is there a way using GNU Make of compiling all of the C files in a directory into separate programs, with each program named as the source file without the .c extension?

Answer

Martin Broadhurst picture Martin Broadhurst · Apr 24, 2010
SRCS = $(wildcard *.c)

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

all: $(PROGS)

%: %.c

        $(CC) $(CFLAGS)  -o $@ $<