23,125
社区成员
发帖
与我相关
我的任务
分享
################################################################################
# File: Makefile
# Description:
# Author: Xiaoyong Wen <wen_kernel@163.com>, 20120523, PM.
#
# Fix hisoty:
#
################################################################################
debug := 1
ifdef debug
CFLAGS += -g
else
CFLAGS += -O2
endif
CC := gcc
CFLAGS += -I.
LDFLAGS += -L.
bin := main
obj := main.o a.o b.o
#src := a.c b.c main.c a.h b.h
src := $(wildcard *.c) $(wildcard *.h)
.PHONY : clean all debug
all : $(bin)
# @-ls -al $(bin)
$(bin) : $(obj)
$(obj) : $(src)
debug:
@echo $(src)
@echo $(obj)
@echo $(CFLAGS)
@echo $(LDFLAGS)
@echo $(Q)
clean:
rm -f $(bin) $(obj)
#####################################################################
## file : test makefile for build current dir .c ##
## author : jernymy ##
## date-time : 05/06/2010 ##
#####################################################################
CC = gcc
CPP = g++
RM = rm -rf
## debug flag
DBG_ENABLE = 1
## source file path
SRC_PATH := .
## target exec file name
TARGET := test
## get all source files
SRCS += $(wildcard $(SRC_PATH)/*.c)
## all .o based on all .c
OBJS := $(SRCS:.c=.o)
## need libs, add at here
LIBS :=
## used headers file path
INCLUDE_PATH := .
## used include librarys file path
LIBRARY_PATH := /lib
## debug for debug info, when use gdb to debug
ifeq (1, ${DBG_ENABLE})
CFLAGS += -D_DEBUG -O0 -g -DDEBUG=1
endif
## get all include path
CFLAGS += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
## get all library path
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
## get all librarys
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))
all: clean build
build:
$(CC) -c $(CFLAGS) $(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
$(RM) $(OBJS)
clean:
$(RM) $(OBJS) $(TARGET)