Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1511262
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: LINUX

2012-12-21 20:42:48

//--- Makefile范本, 简洁
CC = gcc
CFLAGS += -Wall -g

OBJ := smtpclient.o xucommon.o owtest.o xuudp.o

world: compile
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

xucommon.o:
$(CC) $(CFLAGS) -c ../xucommon/xucommon.c

xuudp.o:
$(CC) $(CFLAGS) -c ../xucommon/xuudp.c

compile: $(OBJ)
$(CC) $(CFLAGS) -o smtptest $(OBJ)

clean:
@echo "cleanning project"
$(RM) *.o smtptest
@echo "clean completed"

.PHONY: clean

----------------------------------------------------------------------------------------
# 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
 --------------------------------------------------------------------------------------------------------------


阅读(1031) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~