-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
152 lines (113 loc) · 2.7 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- Mode: makefile-gmake -*-
.PHONY: clean all debug release install
#
# Required packages
#
LDPKGS = libncicore libnciplugin libgbinder libglibutil gobject-2.0 glib-2.0
PKGS = $(LDPKGS) nfcd-plugin
#
# Default target
#
all: debug release
#
# Library name
#
NAME = binder
LIB_NAME = $(NAME)
LIB_SONAME = $(LIB_NAME).so
LIB = $(LIB_SONAME)
#
# Sources
#
SRC = \
binder_nfc_adapter.c \
binder_nfc_plugin.c
#
# Directories
#
SRC_DIR = src
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall
BASE_FLAGS = -fPIC -fvisibility=hidden
DEFINES = -DNFC_PLUGIN_EXTERNAL
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) -MMD -MP \
$(shell pkg-config --cflags $(PKGS))
FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared
DEBUG_FLAGS = -g
RELEASE_FLAGS =
DISABLE_HEXDUMP ?= 0
ifneq ($(DISABLE_HEXDUMP),0)
DEFINES += -DDISABLE_HEXDUMP
endif
KEEP_SYMBOLS ?= 0
ifneq ($(KEEP_SYMBOLS),0)
RELEASE_FLAGS += -g
endif
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
LIBS = $(shell pkg-config --libs $(LDPKGS))
DEBUG_LIBS = $(LIBS)
RELEASE_LIBS = $(LIBS)
#
# Files
#
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
#
# Dependencies
#
DEPS = \
$(DEBUG_OBJS:%.o=%.d) \
$(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif
DEBUG_DEPS =
RELEASE_DEPS =
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
#
# Rules
#
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
debug: $(DEBUG_LIB)
release: $(RELEASE_LIB)
clean:
rm -f *~ rpm/*~ $(SRC_DIR)/*~
rm -fr $(BUILD_DIR)
$(DEBUG_BUILD_DIR):
mkdir -p $@
$(RELEASE_BUILD_DIR):
mkdir -p $@
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(DEBUG_LIB): $(DEBUG_OBJS) $(DEBUG_DEPS)
$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) $(DEBUG_LIBS) -o $@
$(RELEASE_LIB): $(RELEASE_OBJS) $(RELEASE_DEPS)
$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) $(RELEASE_LIBS) -o $@
#
# Install
#
PLUGIN_DIR ?= usr/lib/nfcd/plugins
ABS_PLUGIN_DIR := $(shell echo /$(PLUGIN_DIR) | sed -r 's|/+|/|g')
INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
INSTALL_PLUGIN_DIR = $(DESTDIR)$(ABS_PLUGIN_DIR)
install: $(INSTALL_PLUGIN_DIR)
$(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_PLUGIN_DIR)
$(INSTALL_PLUGIN_DIR):
$(INSTALL_DIRS) $@