Makefile 死循环
来源: 互联网 发布时间:2017-05-25
本文导语: 模仿 李云的Makefile写的,添加include后死循环, 源文件 ./src/main.c ./src/foo.c ./src/foo.h 执行结果 在 $(DIR_DEPS)/%.dep:$(DIR_DEPS) $(DIR_SRCS)/%.c @echo "Making $@..." @set -e; $(RM) $(RMFLA...
模仿 李云的Makefile写的,添加include后死循环,
源文件 ./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' $@;
$(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' $@;
$(RM) $(RMFLAGS) $@.tmp
clean:
$(RM) $(RMFLAGS) $(DIRS)
源文件 ./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' $@;
$(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' $@;
$(RM) $(RMFLAGS) $@.tmp
clean:
$(RM) $(RMFLAGS) $(DIRS)
|
把DIR_DEPS从条件中去掉,手工建立该目录