-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathandroidmk_solution.lua
175 lines (147 loc) · 4.61 KB
/
androidmk_solution.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
--
-- androidmk_solution.lua
-- Generator for Application.mk and Android.mk solution files
-- Author : Bastien Brunnenstein
--
local androidmk = premake.extensions.androidmk
local solution = premake.solution
local project = premake.project
local make = premake.make
local p = premake
function androidmk.generate_applicationmk(sln)
premake.eol("\n")
androidmk.slnBuildScript(sln)
p.w('PM5_HELP := true')
for cfg in solution.eachconfig(sln) do
p.w('')
p.x('ifeq ($(%s),%s)', androidmk.CONFIG_OPTION, cfg.shortname)
androidmk.slnOptim(sln, cfg)
androidmk.slnAbi(sln, cfg)
androidmk.slnPlatform(sln, cfg)
androidmk.slnStl(sln, cfg)
androidmk.slnToolchainVersion(sln, cfg)
p.w(' PM5_HELP := false')
p.w('endif')
end
androidmk.slnPremakeHelp(sln)
end
function androidmk.generate_androidmk(sln)
premake.eol("\n")
local curpath = 'SOLUTION_'..sln.name:upper()..'_PATH'
p.w('%s := $(call my-dir)', curpath)
p.w('')
for prj in solution.eachproject(sln) do
local prjpath = premake.filename(prj, androidmk.prjFile(prj))
local prjrelpath = path.getrelative(sln.location, prjpath)
p.x('include $(%s)/%s', curpath, prjrelpath)
end
for cfg in solution.eachconfig(sln) do
local existingmklist = {}
local moduleslist = {}
-- Agregate existing Android.mk files for each project per configuration
for prj in solution.eachproject(sln) do
for prjcfg in project.eachconfig(prj) do
if prjcfg.shortname == cfg.shortname then
for _, mkpath in ipairs(prj.amk_includes) do
local mkrelpath = path.getrelative(sln.location, mkpath)
if not table.contains(existingmklist, mkrelpath) then
table.insert(existingmklist, mkrelpath)
end
end
for _, mod in ipairs(prj.amk_importmodules) do
if not table.contains(moduleslist, mod) then
table.insert(moduleslist, mod)
end
end
end
end
end
if #existingmklist > 0 or #moduleslist > 0 then
p.w('')
p.x('ifeq ($(%s),%s)', androidmk.CONFIG_OPTION, cfg.shortname)
for _, mkpath in ipairs(existingmklist) do
p.x(' include $(%s)/%s', curpath, mkpath)
end
for _, mod in ipairs(moduleslist) do
p.x(' $(call import-module,%s)', mod)
end
p.w('endif')
end
end
end
function androidmk.slnBuildScript(sln)
p.x('APP_BUILD_SCRIPT := $(call my-dir)/%s', androidmk.slnAndroidFile(sln))
end
function androidmk.slnPremakeHelp(sln)
p.w('')
p.w('ifeq ($(PM5_HELP),true)')
p.w(' $(info )')
p.w(' $(info Usage:)')
p.w(' $(info $() ndk-build %s=<config>)', androidmk.CONFIG_OPTION)
p.w(' $(info )')
p.w(' $(info CONFIGURATIONS:)')
for cfg in solution.eachconfig(sln) do
p.w(' $(info $() %s)', cfg.shortname)
end
p.w(' $(info )')
p.w(' $(info For more ndk-build options, see https://developer.android.com/ndk/guides/ndk-build.html)')
p.w(' $(info )')
p.w(' $(error Set %s and try again)', androidmk.CONFIG_OPTION)
p.w('endif')
end
-- Function to make sure that an option in a given config is the same for every project
-- Additionnaly, replace "default" with "nil"
local function agregateOption(sln, cfg, option)
local first = true
local val
for prj in solution.eachproject(sln) do
for prjcfg in project.eachconfig(prj) do
if prjcfg.shortname == cfg.shortname then
if first then
first = false
val = prjcfg[option]
else
if prjcfg[option] ~= val then
error("Value for "..option.." must be the same on every project for configuration "..cfg.longname.." in solution "..sln.name)
end
end
end
end
end
if val == "default" then
return nil
end
return val
end
function androidmk.slnOptim(sln, cfg)
local optim = agregateOption(sln, cfg, "optimize")
if optim == p.OFF or optim == "Debug" then
p.w(' APP_OPTIM := debug')
elseif optim ~= nil then
p.w(' APP_OPTIM := release')
end
end
function androidmk.slnAbi(sln, cfg)
local abi = agregateOption(sln, cfg, "ndkabi")
if abi then
p.w(' APP_ABI := %s', abi)
end
end
function androidmk.slnPlatform(sln, cfg)
local plat = agregateOption(sln, cfg, "ndkplatform")
if plat then
p.w(' APP_PLATFORM := %s', plat)
end
end
function androidmk.slnStl(sln, cfg)
local stl = agregateOption(sln, cfg, "ndkstl")
if stl then
p.w(' APP_STL := %s', stl)
end
end
function androidmk.slnToolchainVersion(sln, cfg)
local toolchain = agregateOption(sln, cfg, "ndktoolchainversion")
if toolchain then
p.w(' NDK_TOOLCHAIN_VERSION := %s', toolchain)
end
end