用cc -MM替换makedepend

时间:2011-06-15 18:45:31

标签: c gcc makefile

我目前使用的是makedepend,但是我遇到了一些问题和库,并决定我也可以切换到cc -MM。我当前的makefile是以this建模的。

我将如何进行更改?


当前Makefile

NAME := engine
C_SRCS := $(wildcard *.c) $(wildcard */*.c)
H_SRCS := $(wildcard *.h) $(wildcard */*.h)
C_OBJS := ${C_SRCS:.c=.o}
INCLUDE_DIRS := .
LIBRARY_DIRS :=
LIBRARIES := event

CFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L($librarydir))
LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library))

.PHONY: all clean depend

all: $(NAME)

$(NAME): $(C_OBJS)
    $(LINK.cc) $(C_OBJS) -o $(NAME)

clean:
    @- $(RM) $(NAME)
    @- $(RM) $(OBJS)

distclean: clean

depend:
    makedepend -- $(CFLAGS) $(CFLAGS) -- $(C_SRCS)

# makedepend after this line
# DO NOT DELETE THIS LINE

engine.o: util/std.h /usr/include/stdlib.h /usr/include/Availability.h
engine.o: /usr/include/AvailabilityInternal.h /usr/include/_types.h
engine.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
engine.o: /usr/include/machine/_types.h /usr/include/i386/_types.h
engine.o: /usr/include/sys/wait.h /usr/include/sys/signal.h
engine.o: /usr/include/sys/appleapiopts.h /usr/include/machine/signal.h
engine.o: /usr/include/i386/signal.h /usr/include/i386/_structs.h
engine.o: /usr/include/sys/_structs.h /usr/include/machine/_structs.h
engine.o: /usr/include/sys/resource.h /usr/include/machine/endian.h
engine.o: /usr/include/i386/endian.h /usr/include/sys/_endian.h
engine.o: /usr/include/libkern/_OSByteOrder.h
engine.o: /usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h
engine.o: /usr/include/machine/types.h /usr/include/i386/types.h util/out.h
engine.o: /usr/include/stdio.h /usr/include/secure/_stdio.h
engine.o: /usr/include/secure/_common.h /usr/include/errno.h
engine.o: /usr/include/sys/errno.h /usr/include/string.h
engine.o: /usr/include/secure/_string.h util/lvl.h conf.h http/server.h
http/server.o: /usr/include/errno.h /usr/include/sys/errno.h
http/server.o: /usr/include/sys/cdefs.h /usr/include/stdlib.h
http/server.o: /usr/include/Availability.h
http/server.o: /usr/include/AvailabilityInternal.h /usr/include/_types.h
http/server.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
http/server.o: /usr/include/i386/_types.h /usr/include/sys/wait.h
http/server.o: /usr/include/sys/signal.h /usr/include/sys/appleapiopts.h
http/server.o: /usr/include/machine/signal.h /usr/include/i386/signal.h
http/server.o: /usr/include/i386/_structs.h /usr/include/sys/_structs.h
http/server.o: /usr/include/machine/_structs.h /usr/include/sys/resource.h
http/server.o: /usr/include/machine/endian.h /usr/include/i386/endian.h
http/server.o: /usr/include/sys/_endian.h /usr/include/libkern/_OSByteOrder.h
http/server.o: /usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h
http/server.o: /usr/include/machine/types.h /usr/include/i386/types.h
http/server.o: /usr/include/unistd.h /usr/include/sys/unistd.h
http/server.o: /usr/include/sys/select.h /usr/include/sys/_select.h
http/server.o: /usr/include/sys/socket.h /usr/include/sys/types.h
http/server.o: /usr/include/machine/_param.h /usr/include/i386/_param.h
http/server.o: /usr/include/netdb.h /usr/include/stdint.h
http/server.o: /usr/include/netinet/in.h /usr/include/netinet6/in6.h
http/server.o: /usr/include/arpa/inet.h /usr/include/fcntl.h
http/server.o: /usr/include/sys/fcntl.h http/request.h conf.h util/out.h
http/server.o: /usr/include/stdio.h /usr/include/secure/_stdio.h
http/server.o: /usr/include/secure/_common.h /usr/include/string.h
http/server.o: /usr/include/secure/_string.h util/lvl.h util/buf.h
http/server.o: /usr/include/stddef.h
util/buf.o: /usr/include/stdlib.h /usr/include/Availability.h
util/buf.o: /usr/include/AvailabilityInternal.h /usr/include/_types.h
util/buf.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
util/buf.o: /usr/include/machine/_types.h /usr/include/i386/_types.h
util/buf.o: /usr/include/sys/wait.h /usr/include/sys/signal.h
util/buf.o: /usr/include/sys/appleapiopts.h /usr/include/machine/signal.h
util/buf.o: /usr/include/i386/signal.h /usr/include/i386/_structs.h
util/buf.o: /usr/include/sys/_structs.h /usr/include/machine/_structs.h
util/buf.o: /usr/include/sys/resource.h /usr/include/machine/endian.h
util/buf.o: /usr/include/i386/endian.h /usr/include/sys/_endian.h
util/buf.o: /usr/include/libkern/_OSByteOrder.h
util/buf.o: /usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h
util/buf.o: /usr/include/machine/types.h /usr/include/i386/types.h util/buf.h
util/buf.o: /usr/include/stddef.h util/std.h util/out.h /usr/include/stdio.h
util/buf.o: /usr/include/secure/_stdio.h /usr/include/secure/_common.h
util/buf.o: /usr/include/errno.h /usr/include/sys/errno.h
util/buf.o: /usr/include/string.h /usr/include/secure/_string.h util/lvl.h
util/buf.o: conf.h

1 个答案:

答案 0 :(得分:3)

auto-dependencies上查看本页的最后一部分。

如果您的编译器支持-MMD选项(如gcc那样),那么您只需在编译器标志中包含-MMD(make dependencies)和-MP(为.d文件中的每个prereq制作假目标),并添加以下是Makefile的结尾:

# Use the dependency files created by the -MMD option to gcc.
-include $(SRCS:.c=.d)  

我一直在使用Cygwin / gcc一段时间,并对结果感到满意。