分为makefile 和makefile.env 两个文件,其中makefile.env存放公共部门的编译指令,makefile 中针对个人设置单独的路径。 这个可以适用多个目录,多个文件的编译。
#
# Makefile.env exmaple
#
# by Jiffy.He
#
DIR_INC = ./include
DIR_OBJ = ./obj
DIR_BIN = ./bin
DIR_SRC = ./src
TARGET = $(DIR_BIN)/main
CC = gcc
CFLAGS = -g -Wall -I${DIR_INC} -I${EXT_DIR}
SRC = $(wildcard ${DIR_SRC}/*.c) \
$(wildcard ${DIR_SRC}/def/*.c) \
$(wildcard ${DIR_SRC}/test/*.c)
DIR = $(notdir $(SRC))
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) -o $@ $^
${DIR_OBJ}/%.o: ${DIR_SRC}/%.c
$(CC) $(CFLAGS) -o $@ -c $<
${DIR_OBJ}/%.o: ${DIR_SRC}/def/%.c
$(CC) $(CFLAGS) -o $@ -c $<
${DIR_OBJ}/%.o: ${DIR_SRC}/test/%.c
$(CC) $(CFLAGS) -o $@ -c $<
clean:
rm -rf $(OBJ) $(TARGET)
makefile文件:
#
# Makefile exmaple
#
# by Jiffy.He
#
TOPDIR=./
EXT_DIR = /usr/include
include $(TOPDIR)/Makefile.env
附件为tgz格式,在linux 下用tar zxf 解压
makefile.rar
阅读(5569) | 评论(0) | 转发(0) |