blob: 29170987609b3ae33e227e84c4291ce42e2a762b [file] [log] [blame]
bigbiff673c7ae2020-12-02 19:44:56 -05001package libminui_defaults
2
3import (
4 "android/soong/android"
5 "android/soong/cc"
6 "fmt"
7 "path/filepath"
8 "strings"
9)
10
11func globalFlags(ctx android.BaseContext) []string {
12 var cflags []string
13
14 if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
15 cflags = append(cflags, "-DUSE_QTI_HAPTICS")
16 }
17
18 if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
19 cflags = append(cflags, "-DMSM_BSP")
20 }
21
22 matches, err := filepath.Glob("system/core/adf/Android.*")
23 _ = matches
24 if err == nil {
25 cflags = append(cflags, "-DHAS_ADF")
26 }
27
28 if ctx.AConfig().Getenv("TW_NEW_ION_HEAP") == "true" {
29 cflags = append(cflags, "-DNEW_ION_HEAP")
30 }
31
32 matches, err = filepath.Glob("external/libdrm/Android.*")
33 if err == nil {
34 cflags = append(cflags, "-DHAS_DRM")
35 }
36
37 if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
38 cflags = append(cflags, "-DTW_INCLUDE_JPEG")
39 }
40
41 if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
42 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
43 }
44
45 if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
46 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
47 }
48
49 if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
50 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
51 }
52
53 if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
54 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
55 }
56
57 if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
58 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
59 }
60
61 if ctx.AConfig().Getenv("TWRP_EVENT_LOGGING") == "true" {
62 cflags = append(cflags, "-D_EVENT_LOGGING")
63 }
64
65 var pixelFormat = strings.Replace(ctx.AConfig().Getenv("TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
66
67 switch pixelFormat {
68 case "RGBA_8888":
69 fmt.Println("****************************************************************************)")
70 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
71 fmt.Println("****************************************************************************)")
72 cflags = append(cflags, "-DRECOVERY_RGBA")
73 break
74
75 case "RGBX_8888":
76 fmt.Println("****************************************************************************)")
77 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
78 fmt.Println("****************************************************************************)")
79 cflags = append(cflags, "-DRECOVERY_RGBX")
80 break
81
82 case "BGRA_8888":
83 fmt.Println("****************************************************************************)")
84 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
85 fmt.Println("****************************************************************************)")
86 cflags = append(cflags, "-DRECOVERY_BGRA")
87 break
88
89 case "RGB_565":
90 cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
91 break
92 }
93
94 pixelFormat = strings.Replace(ctx.AConfig().Getenv("TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
95 switch pixelFormat {
96 case "ABGR_8888":
97 cflags = append(cflags, "-DRECOVERY_ABGR")
98 break
99
100 case "RGBX_8888":
101 cflags = append(cflags, "-DRECOVERY_RGBX")
102 break
103
104 case "BGRA_8888":
105 cflags = append(cflags, "-DRECOVERY_BGRA")
106 break
107 }
108
109 if ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
110 cflags = append(cflags, "-DDOVERSCAN_PERCENT="+ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT"))
111 } else {
112 cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
113 }
114
115 if ctx.AConfig().Getenv("TW_SCREEN_BLANK_ON_BOOT") == "true" {
116 cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
117 }
118
119 if ctx.AConfig().Getenv("TW_FBIOPAN") == "true" {
120 cflags = append(cflags, "-DTW_FBIOPAN")
121 }
122
123 var tw_rotation = ctx.AConfig().Getenv("TW_ROTATION")
124 switch tw_rotation {
125 case "0":
126 case "90":
127 case "180":
128 case "270":
129 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
130 default:
131 if ctx.AConfig().Getenv("BOARD_HAS_FLIPPED_SCREEN") == "true" {
132 cflags = append(cflags, "-DTW_ROTATION=180")
133 } else {
134 cflags = append(cflags, "-DTW_ROTATION=0")
135 }
136 }
137
138 if ctx.AConfig().Getenv("TW_IGNORE_MAJOR_AXIS_0") == "true" {
139 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
140 }
141
142 if ctx.AConfig().Getenv("TW_IGNORE_MT_POSITION_0") == "true" {
143 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
144 }
145
146 if ctx.AConfig().Getenv("TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
147 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
148 }
149
150 if ctx.AConfig().Getenv("TW_INPUT_BLACKLIST") != "" {
151 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+ctx.AConfig().Getenv("TW_INPUT_BLACKLIST"))
152 }
153
154 if ctx.AConfig().Getenv("TW_WHITELIST_INPUT") != "" {
155 cflags = append(cflags, "-DWHITELIST_INPUT="+ctx.AConfig().Getenv("TW_WHITELIST_INPUT"))
156 }
157
158 if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
159 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
160 }
161
162 cflags = append(cflags, "-DTWRES="+ctx.AConfig().Getenv("TWRES_PATH"))
163 return cflags
164}
165
166func globalSrcs(ctx android.BaseContext) []string {
167 var srcs []string
168
169 if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
170 srcs = append(srcs, "graphics_overlay.cpp")
171 }
172
173 matches, err := filepath.Glob("system/core/adf/Android.*")
174 _ = matches
175 if err == nil {
176 srcs = append(srcs, "graphics_adf.cpp")
177 }
178
179 matches, err = filepath.Glob("external/libdrm/Android.*")
180 if err == nil {
181 srcs = append(srcs, "graphics_drm.cpp")
182 }
183
184 if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
185 srcs = append(srcs, "tspdrv.cpp")
186 }
187 return srcs
188}
189
190func globalIncludes(ctx android.BaseContext) []string {
191 var includes []string
192
193 if ctx.AConfig().Getenv("TW_INCLUDE_CRYPTO") != "" {
194 includes = append(includes, "bootable/recovery/crypto/fscrypt")
195 }
196
197 if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
198 if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
199 includes = append(includes, ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
200 } else {
201 if ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS") != "" {
202 includes = append(includes, "bootable/recovery/minuitwrp")
203 } else {
204 includes = append(includes, ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS"))
205 }
206 }
207 } else {
208 includes = append(includes, "bootable/recovery/minuitwrp")
209 }
210
211 if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
212 includes = append(includes, "external/jpeg")
213 }
214
215 return includes
216}
217
218func globalStaticLibs(ctx android.BaseContext) []string {
219 var staticLibs []string
220
221 matches, err := filepath.Glob("system/core/adf/Android.*")
222 _ = matches
223 if err == nil {
224 staticLibs = append(staticLibs, "libadf")
225 }
226
227 matches, err = filepath.Glob("external/libdrm/Android.*")
228 if err == nil {
229 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
230 if err != nil {
231 staticLibs = append(staticLibs, "libdrm_platform")
232 } else {
233 staticLibs = append(staticLibs, "libdrm")
234 }
235 }
236
237 return staticLibs
238}
239
240func globalSharedLibs(ctx android.BaseContext) []string {
241 var sharedLibs []string
242
243 if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
244 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
245 sharedLibs = append(sharedLibs, "libhidlbase")
246 }
247
248 if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
249 sharedLibs = append(sharedLibs, "libjpeg")
250 }
251 return sharedLibs
252}
253
254func globalRequiredModules(ctx android.BaseContext) []string {
255 var requiredModules []string
256
257 if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
258 var kernelDir = ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
259 requiredModules = append(requiredModules, kernelDir)
260 }
261 return requiredModules
262}
263
264func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
265 type props struct {
266 Target struct {
267 Android struct {
268 Cflags []string
269 Enabled *bool
270 }
271 }
272 Cflags []string
273 Srcs []string
274 Include_dirs []string
275 Static_libs []string
276 Shared_libs []string
277 Required []string
278 }
279
280 p := &props{}
281 p.Cflags = globalFlags(ctx)
282 s := globalSrcs(ctx)
283 p.Srcs = s
284 i := globalIncludes(ctx)
285 p.Include_dirs = i
286 staticLibs := globalStaticLibs(ctx)
287 p.Static_libs = staticLibs
288 sharedLibs := globalSharedLibs(ctx)
289 p.Shared_libs = sharedLibs
290 requiredModules := globalRequiredModules(ctx)
291 p.Required = requiredModules
292 ctx.AppendProperties(p)
293}
294
295func init() {
296 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
297}
298
299func libMinuiTwrpDefaultsFactory() android.Module {
300 module := cc.DefaultsFactory()
301 android.AddLoadHook(module, libMinuiTwrpDefaults)
302
303 return module
304}