Assuming you use GNU make, something like:
O ?= build
OBJS := $(patsubst %.c,$(O)/%.o,$(wildcard *.c))
SOS := $(O)/<you know better than me>
EXECS := $(O)/<you know better than me>
all: $(OBJS) $(SOS) $(EXECS)
$(OBJS): $(O)/%.o: %.c
mkdir -p $(O); \
$(CC) $(CFLAGS) -c $< -o $@
$(SOS): ...
$(EXECS): ...
should be close to what you want. As I do not know which *.so
and executables you want to build and how, I just indicate a possibility for the rule that builds the *.o
. It should be easy to adapt to the other targets.
If you type make
, the build
sub-directory will be created if it does not exist. If you type make O=foo
, the foo
sub-directory will be created (if it does not exist) and be used instead of build
.
$(OBJS): $(O)/%.o: %.c
is a static pattern rule. In case it is not clear enough, the GNU make documentation will tell you everything about them.