forked from g7/mce-plugin-libhybris
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
189 lines (142 loc) · 5.21 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# ----------------------------------------------------------- -*- mode: sh -*-
# Installation directories etc
# ----------------------------------------------------------------------------
NAME ?= mce-plugin-libhybris
DESTDIR ?= /tmp/test-install-$(NAME)
_LIBDIR ?= /usr/lib
# ----------------------------------------------------------------------------
# List of targets to build
# ----------------------------------------------------------------------------
TARGETS += hybris.so
# ----------------------------------------------------------------------------
# Top level targets
# ----------------------------------------------------------------------------
.PHONY: build install clean distclean mostlyclean
build:: $(TARGETS)
install:: build
clean:: mostlyclean
$(RM) $(TARGETS)
distclean:: clean
$(RM) *.so *.p *.q *.i
mostlyclean::
$(RM) *.o *~ *.bak
# ----------------------------------------------------------------------------
# Default flags
# ----------------------------------------------------------------------------
CPPFLAGS += -D_GNU_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64
CPPFLAGS += -D_THREAD_SAFE
CPPFLAGS += -DMCE_HYBRIS_INTERNAL=2
COMMON += -Wall
COMMON += -Wextra
COMMON += -Wmissing-prototypes
COMMON += -Os
COMMON += -g
COMMON += -fvisibility=hidden
CFLAGS += $(COMMON)
CFLAGS += -std=c99
CXXFLAGS += $(COMMON)
LDFLAGS += -g
LDLIBS += -Wl,--as-needed
LDLIBS += -lpthread
# ----------------------------------------------------------------------------
# Flags from pkg-config
# ----------------------------------------------------------------------------
PKG_NAMES += glib-2.0
PKG_NAMES += libhardware
PKG_NAMES += android-headers
maintenance = normalize clean distclean mostlyclean
intersection = $(strip $(foreach w,$1, $(filter $w,$2)))
ifneq ($(call intersection,$(maintenance),$(MAKECMDGOALS)),)
PKG_CONFIG ?= true
endif
ifneq ($(strip $(PKG_NAMES)),)
PKG_CONFIG ?= pkg-config
PKG_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PKG_NAMES))
PKG_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PKG_NAMES))
PKG_CPPFLAGS := $(filter -D%,$(PKG_CFLAGS)) $(filter -I%,$(PKG_CFLAGS))
PKG_CFLAGS := $(filter-out -I%, $(filter-out -D%, $(PKG_CFLAGS)))
endif
CPPFLAGS += $(PKG_CPPFLAGS)
CFLAGS += $(PKG_CFLAGS)
LDLIBS += $(PKG_LDLIBS)
# ----------------------------------------------------------------------------
# Implicit rules
# ----------------------------------------------------------------------------
.SUFFIXES: %.pic.o
.PRECIOUS: %.pic.o
%.so :
$(CC) -o $@ -shared $^ $(LDFLAGS) $(LDLIBS)
%.pic.o : %.c
$(CC) -c -o $@ $< -fPIC $(CPPFLAGS) $(CFLAGS)
%.q : %.c
$(CC) -E -o $@ $(CPPFLAGS) $<
%.p : %.q
cat $< | cproto | prettyproto.py > $@
%.i : %.q
cat $< | cproto -s | prettyproto.py > $@
preprocess: $(patsubst %.c,%.q,$(wildcard *.c))
prototypes: $(patsubst %.c,%.p,$(wildcard *.c))
locals: $(patsubst %.c,%.i,$(wildcard *.c))
# ----------------------------------------------------------------------------
# Explicit dependencies
# ----------------------------------------------------------------------------
hybris_OBJS += hybris-fb.pic.o
hybris_OBJS += hybris-lights.pic.o
hybris_OBJS += hybris-sensors.pic.o
hybris_OBJS += hybris-thread.pic.o
hybris_OBJS += plugin-api.pic.o
hybris_OBJS += plugin-config.pic.o
hybris_OBJS += plugin-logging.pic.o
hybris_OBJS += plugin-quirks.pic.o
hybris_OBJS += sysfs-led-bacon.pic.o
hybris_OBJS += sysfs-led-binary.pic.o
hybris_OBJS += sysfs-led-f5121.pic.o
hybris_OBJS += sysfs-led-hammerhead.pic.o
hybris_OBJS += sysfs-led-htcvision.pic.o
hybris_OBJS += sysfs-led-main.pic.o
hybris_OBJS += sysfs-led-redgreen.pic.o
hybris_OBJS += sysfs-led-util.pic.o
hybris_OBJS += sysfs-led-vanilla.pic.o
hybris_OBJS += sysfs-led-white.pic.o
hybris_OBJS += sysfs-val.pic.o
hybris.so : LDLIBS += -lhardware -lm
hybris.so : $(hybris_OBJS)
install:: hybris.so
install -d -m755 $(DESTDIR)$(_LIBDIR)/mce/modules
install -m644 hybris.so $(DESTDIR)$(_LIBDIR)/mce/modules/
# ----------------------------------------------------------------------------
# Source code normalization
# ----------------------------------------------------------------------------
.PHONY: normalize
normalize::
normalize_whitespace -M Makefile
normalize_whitespace -a $(wildcard *.[ch] *.cc *.cpp)
# ----------------------------------------------------------------------------
# AUTOMATIC HEADER DEPENDENCIES
# ----------------------------------------------------------------------------
.PHONY: depend
depend::
@echo "Updating .depend"
$(CC) -MM $(CPPFLAGS) $(MCE_CFLAGS) $(wildcard *.c) |\
./depend_filter.py > .depend
ifneq ($(MAKECMDGOALS),depend) # not while: make depend
ifneq (,$(wildcard .depend)) # not if .depend does not exist
include .depend
endif
endif
# ----------------------------------------------------------------------------
# Hunt for excess include statements
# ----------------------------------------------------------------------------
.PHONY: headers
.SUFFIXES: %.checked
headers:: c_headers c_sources
%.checked : %
find_unneeded_includes.py $(CPPFLAGS) $(CFLAGS) -- $<
@touch $@
clean::
$(RM) *.checked *.order
c_headers:: $(patsubst %,%.checked,$(wildcard *.h))
c_sources:: $(patsubst %,%.checked,$(wildcard *.c))
order::
find_unneeded_includes.py -- $(wildcard *.h) $(wildcard *.c)