forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
136 lines (110 loc) · 3.38 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
###############################################################################
# Copyright (C) 2014-2015
# file: Makefile
# author: gozfree <[email protected]>
# created: 2015-12-16 00:18
# updated: 2015-12-16 00:18
###############################################################################
###############################################################################
# common
###############################################################################
#ARCH: linux/pi/android/ios/
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)g++
CXX = $(CROSS_PREFIX)g++
LD = $(CROSS_PREFIX)ld
AR = $(CROSS_PREFIX)ar
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 = libconfig
VERSION_SH = $(shell pwd)/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}
TGT_UNIT_TEST = test_$(LIBNAME)
OBJS_INI = ini/iniparser.o \
ini/dictionary.o \
ini/ini_config.o
OBJS_JSON = json/json_config.o
OBJS_LUA = lua/luatables.o \
lua/lua_config.o
OBJS_LIB = $(LIBNAME).o \
$(OBJS_INI) \
$(OBJS_JSON) \
$(OBJS_LUA)
OBJS_UNIT_TEST = test_$(LIBNAME).o
###############################################################################
# cflags and ldflags
###############################################################################
CFLAGS_LUA = `pkg-config --cflags lua5.2`
CFLAGS := -g -Wall -Werror -fPIC
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include
CFLAGS += $(CFLAGS_LUA)
SHARED := -shared
LDFLAGS_LUA = `pkg-config --libs lua5.2`
LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -L$(OUTPUT)/lib -llog
LDFLAGS += -lc
LDFLAGS += -pthread
LDFLAGS += -ljansson
LDFLAGS += $(LDFLAGS_LUA)
###############################################################################
# target
###############################################################################
.PHONY : all clean
TGT := $(TGT_LIB_A)
TGT += $(TGT_LIB_SO)
TGT += $(TGT_UNIT_TEST)
OBJS := $(OBJS_LIB) $(OBJS_UNIT_TEST)
all: $(TGT)
%.o:%.c
$(CC_V) -c $(CFLAGS) $< -o $@
%.o:%.cc
$(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)
$(TGT_UNIT_TEST): $(OBJS_UNIT_TEST) $(ANDROID_MAIN_OBJ)
$(CC_V) -o $@ $^ $(TGT_LIB_A) $(LDFLAGS)
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)
$(CP_V) -r $(TGT_LIB_H) $(OUTPUT)/include
$(CP_V) -r $(TGT_LIB_A) $(OUTPUT)/lib
$(CP_V) -r $(TGT_LIB_SO) $(OUTPUT)/lib
$(CP_V) -r $(TGT_LIB_SO_VER) $(OUTPUT)/lib
uninstall:
$(RM_V) -f $(OUTPUT)/include/$(TGT_LIB_H)
$(RM_V) -f $(OUTPUT)/lib/$(TGT_LIB_A)
$(RM_V) -f $(OUTPUT)/lib/$(TGT_LIB_SO)
$(RM_V) -f $(OUTPUT)/lib/$(TGT_LIB_SO_VER)