makefile 编译c语言,一个简单的makefile的实现,编译当前目录下所有的.c文件

#####################################################################

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值