主目录下的makefile
CC := gcc
SUBDIRS := lib src obj
BIN := main
PWD := $(shell pwd)
OBJS_DIR := $(PWD)/obj
BIN_DIR := $(PWD)/bin
export CC PWD BIN OBJS_DIR BIN_DIR
all : CHECK_DIR $(SUBDIRS)
CHECK_DIR :
mkdir -p $(BIN_DIR)
$(SUBDIRS) : ECHO
make -C $@
ECHO :
@echo $(SUBDIRS)
@echo begin complie
CLEAN :
@rm -rf $(OBJS_DIR)/*.o
@rm -rf $(BIN_DIR)
lib 目录下的makefile
AR := ar rc
LOCAL_SRC := $(wildcard *.c)
LOCAL_OBJ := $(patsubst %.c,%.o,$(LOCAL_SRC))
CFLAGS := -c
LIB := libxid.a
.PHONY : all
all : ECHO $(LIB)
ECHO :
@echo $(LOCAL_OBJ)
$(LIB) : $(LOCAL_OBJ)
$(AR) $(LIB) $^
#mv $(LIB) $(LIB_DIR)
$(LOCAL_OBJ) : $(LOCAL_SRC)
$(CC) $(CFLAGS) $(LOCAL_SRC) -I$(INCLUDE_DIR)
src目录下的makefile
CFLAGS = -c
LOCAL_SRC := $(wildcard *.c)
LOCAL_OBJ := $(patsubst %.c,%.o,$(LOCAL_SRC))
#$(BIN) : $(LOCAL_OBJ)
#$(CC) $(CFLAGS) $(BIN) $(LOCAL_OBJ) -L$(LIB_DIR) -lxid
$(LOCAL_OBJ) : $(LOCAL_SRC)
$(CC) $(CFLAGS) $(LOCAL_SRC) -I$(INCLUDE_DIR) -I$(LIB_DIR)
-mv $(LOCAL_OBJ) $(OBJS_DIR)
clean :
-rm -rf *.o
obj目录下的makefile
LOCAL_OBJ := $(wildcard *.o)
CFLAGS = -o
$(BIN) : $(LOCAL_OBJ)
$(CC) $(CFLAGS) $@ $^ -L$(LIB_DIR) -lxid -lpthread
-mv $(BIN) $(BIN_DIR)