-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathandroidmk_project.lua
243 lines (193 loc) · 5.93 KB
/
androidmk_project.lua
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
--
-- androidmk_project.lua
-- Generator for Android.mk project files
-- Author : Bastien Brunnenstein
--
local androidmk = premake.extensions.androidmk
local make = premake.make
local project = premake.project
local p = premake
function androidmk.generate_projectmk(prj)
premake.eol("\n")
androidmk.prjHeader(prj)
-- Prepare the list of files
local rootFiles, cfgFiles = androidmk.prepareSrcFiles(prj)
androidmk.prjSrcFiles(rootFiles)
for cfg in project.eachconfig(prj) do
p.w('')
p.x('ifeq ($(%s),%s)', androidmk.CONFIG_OPTION, cfg.shortname)
androidmk.prjIncludes(prj, cfg)
androidmk.prjCppFeatures(prj, cfg)
androidmk.prjCfgSrcFiles(cfgFiles[cfg])
androidmk.prjDependencies(prj, cfg)
androidmk.prjLdFlags(prj, cfg)
androidmk.prjCFlags(prj, cfg)
-- Always last
androidmk.prjKind(prj, cfg)
p.w('endif')
end
end
function androidmk.prjHeader(prj)
p.w('LOCAL_PATH := $(call my-dir)')
p.w('include $(CLEAR_VARS)')
p.w('LOCAL_MODULE := %s', prj.name)
if prj.targetname then
p.w('LOCAL_MODULE_FILENAME := %s', prj.targetname)
end
p.w('')
end
function androidmk.prjKind(prj, cfg)
if cfg.kind == premake.STATICLIB then
p.w(' include $(BUILD_STATIC_LIBRARY)')
else -- cfg.kind == premake.SHAREDLIB
p.w(' include $(BUILD_SHARED_LIBRARY)')
end
end
function androidmk.prjIncludes(prj, cfg)
if cfg.includedirs then
p.w(' LOCAL_C_INCLUDES := %s',
table.implode(
table.translate(
table.translate(cfg.includedirs,
function(d)
return "$(LOCAL_PATH)/"..project.getrelative(prj, d)
end)
, p.esc)
, '', '', ' '))
end
end
function androidmk.prjCppFeatures(prj, cfg)
local features = {}
if cfg.rtti == p.ON then
table.insert(features, "rtti")
end
if cfg.exceptionhandling == p.ON then
table.insert(features, "exceptions")
end
if #features > 0 then
p.w(' LOCAL_CPP_FEATURES := %s', table.implode(features, '', '', ' '))
end
end
function androidmk.prepareSrcFiles(prj)
local root = {}
local configs = {}
for cfg in project.eachconfig(prj) do
configs[cfg] = {}
end
local tr = project.getsourcetree(prj)
premake.tree.traverse(tr, {
onleaf = function(node, depth)
-- Figure out what configurations contain this file
local incfg = {}
local inall = true
for cfg in project.eachconfig(prj) do
local filecfg = premake.fileconfig.getconfig(node, cfg)
if filecfg and not filecfg.flags.ExcludeFromBuild then
incfg[cfg] = filecfg
else
inall = false
end
end
-- Allow .arm, .neon and .arm.neon files
if not path.iscppfile(node.abspath) and
path.getextension(node.abspath) ~= "arm" and
path.getextension(node.abspath) ~= "neon" then
return
end
local filename = project.getrelative(prj, node.abspath)
-- If this file exists in all configurations, write it to
-- the project's list of files, else add to specific cfgs
if inall then
table.insert(root, filename)
else
for cfg in project.eachconfig(prj) do
if incfg[cfg] then
table.insert(configs[cfg], filename)
end
end
end
end
})
return root, configs
end
function androidmk.prjSrcFiles(files)
p.w('LOCAL_SRC_FILES := %s', table.implode(table.translate(files, p.esc), '', '', ' '))
end
function androidmk.prjCfgSrcFiles(files)
if #files > 0 then
p.w(' LOCAL_SRC_FILES += %s', table.implode(table.translate(files, p.esc), '', '', ' '))
end
end
function androidmk.prjDependencies(prj, cfg)
local staticdeps = {}
local shareddeps = {}
local dependencies = premake.config.getlinks(cfg, "dependencies", "object")
for _, dep in ipairs(dependencies) do
if dep.kind == premake.STATICLIB then
table.insert(staticdeps, dep.filename)
else
table.insert(shareddeps, dep.filename)
end
end
for _, v in ipairs(cfg.amk_staticlinks) do
table.insert(staticdeps, v)
end
for _, v in ipairs(cfg.amk_sharedlinks) do
table.insert(shareddeps, v)
end
if #staticdeps > 0 then
p.w(' LOCAL_STATIC_LIBRARIES := %s', table.implode(staticdeps, '', '', ' '))
end
if #shareddeps > 0 then
p.w(' LOCAL_SHARED_LIBRARIES := %s', table.implode(shareddeps, '', '', ' '))
end
end
function androidmk.prjLdFlags(prj, cfg)
-- LDLIBS
local flags = {}
for _, dir in ipairs(premake.config.getlinks(cfg, "system", "directory")) do
table.insert(flags, '-L' .. premake.quoted(dir))
end
for _, name in ipairs(premake.config.getlinks(cfg, "system", "basename")) do
table.insert(flags, "-l" .. name)
end
if #flags > 0 then
p.w(' LOCAL_LDLIBS := %s', table.implode(table.translate(flags, p.esc), '', '', ' '))
end
--LDFLAGS
flags = premake.config.mapFlags(cfg, androidmk.ldflags)
for _, opt in ipairs(cfg.linkoptions) do
table.insert(flags, opt)
end
if #flags > 0 then
p.w(' LOCAL_LDFLAGS := %s', table.implode(table.translate(flags, p.esc), '', '', ' '))
end
end
function androidmk.prjCFlags(prj, cfg)
local flags = premake.config.mapFlags(cfg, androidmk.cflags)
-- Defines
for _, def in ipairs(cfg.defines) do
table.insert(flags, '-D' .. def)
end
-- Warnings
for _, enable in ipairs(cfg.enablewarnings) do
table.insert(flags, '-W' .. enable)
end
for _, disable in ipairs(cfg.disablewarnings) do
table.insert(flags, '-Wno-' .. disable)
end
for _, fatal in ipairs(cfg.fatalwarnings) do
table.insert(flags, '-Werror=' .. fatal)
end
-- Build options
for _, opt in ipairs(cfg.buildoptions) do
table.insert(flags, opt)
end
if #flags > 0 then
p.w(' LOCAL_CFLAGS := %s', table.implode(table.translate(flags, p.esc), '', '', ' '))
end
local cppflags = premake.config.mapFlags(cfg, androidmk.cppflags)
if #cppflags > 0 then
p.w(' LOCAL_CPPFLAGS := %s', table.implode(table.translate(cppflags, p.esc), '', '', ' '))
end
end