-
Notifications
You must be signed in to change notification settings - Fork 25
/
make_one_lib
70 lines (52 loc) · 1.96 KB
/
make_one_lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# 本软件为免费、开源软件。
# 本软件的版权(包括源码及二进制发布版本)归一切公众所有。
# 您可以自由使用、传播本软件。
# 您也可以以任何形式、任何目的使用本软件(包括源码及二进制发布版本),而不受任何版权限制。
# =====================
# 作者: 孙明保
# 邮箱: [email protected]
#
TARGET_PATH=$(lib_target_root)
LIB_FILE_STATIC=$(addprefix $(lib_target_root)/lib, $(addsuffix .a, $(LIB_NAME)))
LIB_FILE_DYNAMIC=$(addprefix $(lib_target_root)/lib, $(addsuffix .so, $(LIB_NAME)))
OBJ_PATH=$(TARGET_PATH)/$(LIB_NAME)_tmp
DEP_PATH=$(OBJ_PATH)
__dummy:=$(shell $(MKDIR) $(OBJ_PATH))
SRC_PATH=$(lib_root)/$(LIB_NAME)/src
SRC_FILES=$(wildcard $(SRC_PATH)/*.c)
SRC_FILES_BASE_NAMES=$(basename $(notdir $(SRC_FILES)))
OBJ_FILES=$(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(SRC_FILES_BASE_NAMES)))
SOBJ_FILES=$(addprefix $(OBJ_PATH)/, $(addsuffix .sobj, $(SRC_FILES_BASE_NAMES)))
DEP_FILES=$(addprefix $(DEP_PATH)/, $(addsuffix .d, $(SRC_FILES_BASE_NAMES)))
#you can change CFLAGS/INC_DIRS according to lib name
INC_DIRS+=-I$(lib_root)/$(LIB_NAME)/api \
-I$(lib_root)/$(LIB_NAME)/inc \
-I$(lib_root)/$(LIB_NAME)/src
#all: $(LIB_FILE_STATIC) $(LIB_FILE_DYNAMIC)
all: $(LIB_FILE_STATIC)
.PHONY:all
$(LIB_FILE_STATIC): $(OBJ_FILES)
@echo -n Making $@ ...
@$(AR) -rcs $@ $^
@echo done!
$(LIB_FILE_DYNAMIC): $(SOBJ_FILES)
@echo -n Making $@ ...
@$(CC) -shared -o $@ $^
@echo done!
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(DEP_PATH)/%.d
@echo -n Making $@ ...
@$(CC) -c $(CFLAGS) $(INC_DIRS) $< -o $@
@echo done!
$(OBJ_PATH)/%.sobj: $(SRC_PATH)/%.c $(DEP_PATH)/%.d
@echo -n Making $@ ...
@$(CC) -c -fPIC $(CFLAGS) $(INC_DIRS) $< -o $@
@echo done!
$(DEP_PATH)/%.d: $(SRC_PATH)/%.c
# $(CC) -MM $(CFLAGS) $(INC_DIRS) $< | \
# sed "s/$*\.o[ :]*/$(subst /,\/, $(OBJ_PATH))\/$*.o $(subst /,\/, $(DEP_PATH))\/$*.d : /g"> $@
@echo -n Making $@ ...
@$(CC) -MM $(CFLAGS) $(INC_DIRS) $< | \
sed "s|$*\.o[ :]*|$(DEP_PATH)/$*.d : |g"> $@
@echo done!
-include $(DEP_FILES)