My question is deceptively simple, but I have lost several hours of study trying to get the solution. I'm trying to create a Makefile that builds an executable for each .c file in a directory.
I have tried the following:
CC = gcc
SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c,%.o,$(SRCS))
all: $(OBJS)
$(CC) $< -o $@
%.o: %.c
$(CC) $(CPFLAGS) -c $<
but this way it is creating only .o
files, and not any executables. I need a rule that makes an executable for each of these .o
files. Something like the following:
gcc src.o -o src