源文件 ./src/main.c ./src/foo.c ./src/foo.h
执行结果 在
$(DIR_DEPS)/%.dep:$(DIR_DEPS) $(DIR_SRCS)/%.c
@echo "Making $@..."
@set -e;\
$(RM) $(RMFLAGS) $@.tmp;\
$(CC) -E -MM $(filter %.c,$^) > $@.tmp;\
sed 's,\(.*\)\.o[:]*,$(DIR_OBJS)/\1.o:,g' < $@.tmp > $@;\
$(RM) $(RMFLAGS) $@.tmp
这里死循环了。。。Makefile源文件如下
Makefile[/color]
.PHONY:all clean
CC = gcc
RM = rm
RMFLAGS = -fr
MKDIR = mkdir
DIR_OBJS = objs
DIR_EXES = exes
DIR_SRCS = src
DIR_DEPS = deps
DIRS = $(DIR_OBJS) $(DIR_EXES) $(DIR_DEPS)
EXE = exe
EXE := $(addprefix $(DIR_EXES)/, $(EXE))
SRCS := $(wildcard $(DIR_SRCS)/*.c)
OBJS := $(patsubst $(DIR_SRCS)/%.c,$(DIR_OBJS)/%.o,$(SRCS))
DEPS := $(patsubst $(DIR_SRCS)/%.c,$(DIR_DEPS)/%.dep,$(SRCS))
all: $(EXE)
-include $(DEPS)
-include $(DEPS)
$(DIRS):
$(MKDIR) $@
$(EXE): $(DIR_EXES) $(OBJS)
@echo "This is EXE"
@echo $@
$(CC) -o $@ $(filter %.o,$^)
$(DIR_OBJS)/%.o:$(DIR_OBJS) $(DIR_SRCS)/%.c
$(CC) -o $@ -c $(filter %.c,$^)
$(DIR_DEPS)/%.dep:$(DIR_DEPS) $(DIR_SRCS)/%.c
@echo "Making $@..."
@set -e;\
$(RM) $(RMFLAGS) $@.tmp;\
$(CC) -E -MM $(filter %.c,$^) > $@.tmp;\
sed 's,\(.*\)\.o[:]*,$(DIR_OBJS)/\1.o:,g' < $@.tmp > $@;\
$(RM) $(RMFLAGS) $@.tmp
clean:
$(RM) $(RMFLAGS) $(DIRS)