You haven't given us many details, so I'll suppose you have two source files, foo.c
and bar.c
, and you're building in two directories, red/
and blue/
. Here is a crude makefile that will do the job:
OBJS := foo.o bar.o
RED_OBJS := $(addprefix red/,$(OBJS))
BLUE_OBJS := $(addprefix blue/,$(OBJS))
$(RED_OBJS): red/%.o : %.c
$(CC) -c $< -o $@
$(BLUE_OBJS): blue/%.o : %.c
$(CC) -c $< -o $@
red/red_exec: $(RED_OBJS)
$(CC) $< -o $@
blue/blue_exec: $(BLUE_OBJS)
$(CC) $< -o $@