forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
119 lines (97 loc) · 2.97 KB
/
Makefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
###############################################################################
# common
###############################################################################
#ARCH: linux/arm/android/ios/win
ARCH ?= linux
CROSS_PREFIX ?=
OUTPUT ?= /usr/local
BUILD_DIR := $(shell pwd)/../build/
ARCH_INC := $(BUILD_DIR)/$(ARCH).inc
COLOR_INC := $(BUILD_DIR)/color.inc
ifeq ($(ARCH_INC), $(wildcard $(ARCH_INC)))
include $(ARCH_INC)
endif
CC = $(CROSS_PREFIX)gcc
CXX = $(CROSS_PREFIX)g++
LD = $(CROSS_PREFIX)ld
AR = $(CROSS_PREFIX)ar
STRIP = $(CROSS_PREFIX)strip
ifeq ($(COLOR_INC), $(wildcard $(COLOR_INC)))
include $(COLOR_INC)
else
CC_V = $(CC)
CXX_V = $(CXX)
LD_V = $(LD)
AR_V = $(AR)
CP_V = $(CP)
RM_V = $(RM)
endif
###############################################################################
# target and object
###############################################################################
LIBNAME = libgear
VERSION_SH = $(shell pwd)/src/version.sh $(LIBNAME)
VER = $(shell $(VERSION_SH); awk '/define\ $(LIBNAME)_version/{print $$3}' version.h)
TGT_LIB_H = $(LIBNAME).h
TGT_LIB_A = $(LIBNAME).a
TGT_LIB_SO = $(LIBNAME).so
TGT_LIB_SO_VER = $(TGT_LIB_SO).${VER}
OBJS_LIB := $(patsubst %.c,%.o,$(wildcard src/*.c))
###############################################################################
# cflags and ldflags
###############################################################################
ifeq ($(MODE), release)
CFLAGS := -O2 -Wall -Werror -fPIC
LTYPE := release
else
CFLAGS := -g -Wall -Werror -fPIC
LTYPE := debug
endif
ifeq ($(OUTPUT),/usr/local)
OUTLIBPATH := /usr/local
else
OUTLIBPATH := $(OUTPUT)/$(LTYPE)
endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I./include
CFLAGS += -I$(OUTPUT)/include
CFLAGS += -DNO_CRYPTO
SHARED := -shared
LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -pthread
###############################################################################
# target
###############################################################################
.PHONY : all clean
TGT := $(TGT_LIB_A)
TGT += $(TGT_LIB_SO)
OBJS := $(OBJS_LIB)
all: $(TGT)
%.o:%.c
$(CC_V) -c $(CFLAGS) $< -o $@
$(TGT_LIB_A): $(OBJS_LIB)
$(AR_V) rcs $@ $^
$(TGT_LIB_SO): $(OBJS_LIB)
$(CC_V) -o $@ $^ $(SHARED)
@mv $(TGT_LIB_SO) $(TGT_LIB_SO_VER)
@ln -sf $(TGT_LIB_SO_VER) $(TGT_LIB_SO)
clean:
$(RM_V) -f $(OBJS)
$(RM_V) -f $(TGT)
$(RM_V) -f version.h
$(RM_V) -f $(TGT_LIB_SO)*
$(RM_V) -f $(TGT_LIB_SO_VER)
install:
$(MAKEDIR_OUTPUT)
@if [ "$(MODE)" = "release" ];then $(STRIP) $(TGT); fi
@mkdir -p ${OUTPUT}/include/gear-lib
@mkdir -p ${OUTPUT}/lib/gear-lib
$(CP_V) -r include/$(TGT_LIB_H) $(OUTPUT)/include/gear-lib
$(CP_V) -r $(TGT_LIB_A) $(OUTLIBPATH)/lib/gear-lib
$(CP_V) -r $(TGT_LIB_SO) $(OUTLIBPATH)/lib/gear-lib
$(CP_V) -r $(TGT_LIB_SO_VER) $(OUTLIBPATH)/lib/gear-lib
uninstall:
cd $(OUTPUT)/include/gear-lib && rm -f $(TGT_LIB_H)
$(RM_V) -f $(OUTLIBPATH)/lib/gear-lib/$(TGT_LIB_A)
$(RM_V) -f $(OUTLIBPATH)/lib/gear-lib/$(TGT_LIB_SO)
$(RM_V) -f $(OUTLIBPATH)/lib/gear-lib/$(TGT_LIB_SO_VER)