#compiler
CC := gcc
#generate target file
TARGET := main.o
#source file path
SUBDIRS := ./
SUBDIRS += demo/aa/
SUBDIRS += bb/
SUBDIRS += cc/
#header file path
INCLUDES := -I ./
INCLUDES += -I ./demo/aa/
INCLUDES += -I ./bb
INCLUDES += -I ./cc
INCLUDES += -I ./dd
#corresponding target file
C_OBJS := aa/bb.o
C_OBJS += demo/aa/bb.o
C_OBJS += cc/xbc.o
#.so file
LDFLAGS += ./lib/yy.so
LDFLAGS += ./lib/zz.so
#pthread compile link
LIB := -lm
LIB += -lpthread
#.PHONY: subdirs ${SUBDIRS} cleansubdirs
#subdirs: ${SUBDIRS}
#${SUBDIRS}:
# ${MAKE} -C $@ all
#%.o: %.c
# ${CC} ${INCLUDES} -c $< -o $@
#cleansubdirs:
# @for dir in ${SUBDIRS}; do \
# ${MAKE} -C $$dir clean; \
# done
#all:subdirs ${C_OBJS}
# ${CC} -o ${TARGET} $$(find ${SUBDIRS} -name '*.o') ${INCLUDES} ${LIB}
all: $(TARGET)
$(TARGET):$(C_OBJS)
$(CC) -o $@ $^ $(INCLUDES) $(LIB) $(LDFLAGS)
$(C_OBJS):%o:%c
$(CC) -o $@ -c $< $(INCLUDES) $(LIB)
clean:
rm -f ${TARGET} ${C_OBJS}

此博客给出了C语言代码编译的makefile模板。定义了编译器为gcc,目标文件为main.o,指定了源文件和头文件路径,列出了对应的目标文件、.so文件,还包含pthread编译链接相关内容,最后给出了编译和清理的规则。
1139

被折叠的 条评论
为什么被折叠?



