#####################################################################
# @file Makefile
# @brief My Makefile for resolving bugs in makefiles
#
# @version 0.4
# @author yangyoufa
#####################################################################
# Include your own makefiles
# include def.mk
TOOLPREFIX =
AT = @
RM = rm
CP = cp
LN = ln
SED = sed
SET = set
MAKE = make
RMDIR = rmdir
MKDIR = mkdir
TOUCH = touch
INSTALL = install -m644
CC = $(TOOLPREFIX)cc
GCC = $(TOOLPREFIX)gcc
CPP = $(TOOLPREFIX)cpp
CXX = $(TOOLPREFIX)g++
LD = $(TOOLPREFIX)ld
AR = $(TOOLPREFIX)ar
AS = $(TOOLPREFIX)as
STRIP = $(TOOLPREFIX)strip
RANDLIB = $(TOOLPREFIX)randlib
INCLS +=
LIBS +=
CFLAGS +=
CPPFLAGS +=
OBJS +=
.PHONY : all install clean distclean
all : $(OBJS)
install : $(OBJS)
clean :
$(AT)$(RM) -f *.o
distclean : clean
$(AT)$(RM) -f *.d
%.o : %.c
$(AT)$(GCC) $(CFLAGS) $(INCLS) -o $@ -c $<
%.o : %.cpp
$(AT)$(CPP) $(CPPFLAGS) $(INCLS) -o $@ -c $<
%.d : %.c
$(AT)$(GCC) $(CFLAGS) $(INCLS) -MM -MP -MF $@.$$$$ $<; \
$(SED) 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
$(RM) -f $@.$$$$
%.d : %.cpp
$(AT)$(CPP) $(CPPFLAGS) $(INCLS) -MM -MP -MF $@.$$$$ $<;\
$(SED) 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
$(RM) -f $@.$$$$
# Includes all generated makefiles
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), distclean)
# -include $(patsubst %.c,%.d,"$(SRCS)")
# -include $(patsubst %.cpp,%.d,"$(SRCS)")
-include $(OBJS:.o=.d)
endif
endif
文章来源:
http://fengqing888.blog.163.com/blog/static/33011416201171234417301