##################################################################### ## 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, ( I N C L U D E P A T H ) , − I (INCLUDE_PATH), -I (INCLUDEPATH),−I(dir))
get all library path
LDFLAGS += $(foreach lib, ( L I B R A R Y P A T H ) , − L (LIBRARY_PATH), -L (LIBRARYPATH),−L(lib))
get all librarys
LDFLAGS += $(foreach lib, ( L I B S ) , − l (LIBS), -l (LIBS),−l(lib))
all: clean build
build:
$(CC) -c $(CFLAGS) $(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
$(RM) $(OBJS)
clean:
$(RM) $(OBJS) $(TARGET)