一个简单的Makefile

前期将 FreeBSD 的 TCP 栈移到用户态的时候没有参考项目已有的 Makefile,主要是项目的 Makefile 写的太复杂,看上去有点晕,而且前期也基本上不需要依赖已有 Makefile 定义的变量,因此单独弄了个 Makefile,自我感觉良好:),以后一些小东西也可以继续用~

关于 Makefile 可以参考:http://www.gnu.org/software/make/manual/

# author: runsisi AT hust.edu.cn
# date: 2013/08/24

.PHONY : all clean
 
CC := /opt/xxx/x86_64_gcc4.5.2_glibc2.13.0/bin/x86_64-pc-linux-gnu-gcc
AR := /opt/xxx/x86_64_gcc4.5.2_glibc2.13.0/bin/x86_64-pc-linux-gnu-ar
 
CODE_DIR := $(CURDIR)/../../..
ROOT_DIR := $(CURDIR)
TARGET := $(ROOT_DIR)/libbsdtcp.a

INC_DIRS := $(ROOT_DIR)/include \
			$(ROOT_DIR)/include/opt \
			$(ROOT_DIR)/include/amd64 \
			$(ROOT_DIR)/include/x86 \
			$(ROOT_DIR)/include/contrib/altq \
			$(CODE_DIR)/dps/pub/include
		 
SRC_DIRS := $(ROOT_DIR)/source/kern \
			$(ROOT_DIR)/source/libkern \
			$(ROOT_DIR)/source/net \
			$(ROOT_DIR)/source/netinet \
			$(ROOT_DIR)/source/vm
			
INCS := $(addprefix -I, $(INC_DIRS))
SRCS := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.c))
OBJS := $(SRCS:.c=.o)
DEPS := $(OBJS:.o=.d)

MACROS := -D_KERNEL
CFLAGS := -MD -MP $(INCS) $(MACROS)

all : $(TARGET)
	@printf "Compilation done:)\n"
	
$(TARGET) : $(OBJS)
	$(AR) -crs $@ $^

%.o : %.c
	$(CC) -c $(CFLAGS) -o $@ $<
	
-include $(DEPS)

clean:
	@rm -f $(OBJS) $(DEPS) $(TARGET)

最后修改于 2014-08-18