Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182341
  • 博文数量: 37
  • 博客积分: 1110
  • 博客等级: 少尉
  • 技术积分: 395
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-29 22:01
文章分类

全部博文(37)

文章存档

2013年(10)

2011年(2)

2010年(25)

我的朋友

分类: LINUX

2010-11-23 20:17:22

# Readme:
# use: make config
# use: make dir
# use: make GlobalClean
# use: make clean
# use: make rebuild
# use: make cleanall
# use: make test
# use: make
# firs of all, use "make config" or "make dir" to
# build a source files struct. and then,
# put your source files into the DIR src
# link libs to the DIR lib
# set as a C++ Makefile
# use: ":1,$ s/\.c/\.cpp/g" in vi

SHELL=/bin/sh
CC=gcc
MAKE=make
MAKE_DIR=$(PWD)
SRC_DIR=$(MAKE_DIR)/src/
OBJ_DIR=$(MAKE_DIR)/obj/
LIB_DIR=$(MAKE_DIR)/lib/
INCLUDE_DIR=$(MAKE_DIR)/include
DEBUG_DIR=$(MAKE_DIR)/debug/
RELEASE_DIR=$(MAKE_DIR)/release/
OUTPUT_DIR=
INCLUDE=-I$(INCLUDE_DIR) -I$(SRC_DIR)
LIB=-L$(LIB_DIR) -L$(OBJ_DIR)
OUTPUT_FILE=out
vpath %.c $(SRC_DIR)
vpath %.o $(OBJ_DIR)
vpath %.d $(OBJ_DIR)
SRC_FILES:=$(wildcard $(SRC_DIR)*.c)
SRC_FILES:=$(notdir $(SRC_FILES))
OBJ_FILES:=$(patsubst %.c,%.o,$(SRC_FILES) )
DEP_FILES:=$(patsubst %.c,%.d,$(SRC_FILES) )
FLAG_DEBUG=-g
FLAG_COMPLE=-c
FLAG_LINK=
DEBUG=1
ifeq ($(DEBUG),1)
OUTPUT_DIR:=$(DEBUG_DIR)
FLAG_COMPLE:=$(FLAG_COMPLE) $(FLAG_DEBUG)
FLAG_LINK:=
else
OUTPUT_DIR:=$(RELEASE_DIR)
FLAG_COMPLE:=$(FLAG_COMPLE)
FLAG_LINK:=
endif
OUT=$(OUTPUT_DIR)$(OUTPUT_FILE)
$(OUT): $(OBJ_FILES)
 @echo -e "building: $(notdir $@) \n\t please wait ...\n"
 @$(CC) $(FLAG_LINK) $(addprefix $(OBJ_DIR),$(notdir $^)) $(LIB) -o $@
%.o:%.c %.d
 @echo -e "building: $(notdir $@) \n\t please wait ...\n"
 @$(CC) $(FLAG_COMPLE) $< $(INCLUDE) -o $(OBJ_DIR)$@
$(OBJ_DIR)%.d:%.c
 @echo -e "building: $(notdir $@) \n\t please wait ...\n"
 @$(CC) $< $(INCLUDE) -MM -MD -o $@
-include $(addprefix $(OBJ_DIR),$(DEP_FILES))
config: dir
dir:
 mkdir -p $(SRC_DIR)
 mkdir -p $(OBJ_DIR)
 mkdir -p $(LIB_DIR)
 mkdir -p $(INCLUDE_DIR)
 mkdir -p $(DEBUG_DIR)
 mkdir -p $(RELEASE_DIR)
clean:
 @rm -f $(OBJ_DIR)* *.d *.o
 @rm -f $(OUT)
 @clear
rebuild: clean all
cleanall:
 @rm -f $(OBJ_DIR)*
 @rm -f $(RELEASE_DIR)*
 @rm -f $(DEBUG_DIR)*
test:
 $(OUT)
.PHONY: all config rebuild test cleanall
.SUFFIXES:
GlobalClean:
 @find . -type f -name "Makefile" |sed -n '2,$$p'\
 |sed s/Makefile/\ \`pwd\`/g|awk ' {ECHO="echo"};{CD="cd "};\
  {MAKE="&& make clean&&"};{print ECHO,CD,$$1,MAKE,CD,$$2  } ' |sh
阅读(2148) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2010-11-24 13:05:29

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com