blob: 802533a18cf19a75666347d5623b31ec8758aa98 [file] [log] [blame]
bigbiffd81833a2021-01-17 11:06:57 -05001package twrp
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
bigbiff6e0ca7d2021-02-06 19:15:16 -050014 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050015 cflags = append(cflags, "-DUSE_QTI_HAPTICS")
16 }
17
nebrassy76224bd2021-04-05 11:52:44 +020018 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
19 cflags = append(cflags, "-DUSE_QTI_AIDL_HAPTICS")
20 }
21
soulr344f831bff2021-08-16 09:46:38 +050022 if getMakeVars(ctx, "TW_USE_SAMSUNG_HAPTICS") == "true" {
23 cflags = append(cflags, "-DUSE_SAMSUNG_HAPTICS")
24 }
25
bigbiff6e0ca7d2021-02-06 19:15:16 -050026 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050027 cflags = append(cflags, "-DMSM_BSP")
28 }
29
30 matches, err := filepath.Glob("system/core/adf/Android.*")
31 _ = matches
32 if err == nil {
33 cflags = append(cflags, "-DHAS_ADF")
34 }
35
bigbiff6e0ca7d2021-02-06 19:15:16 -050036 if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050037 cflags = append(cflags, "-DNEW_ION_HEAP")
38 }
39
40 matches, err = filepath.Glob("external/libdrm/Android.*")
41 _ = matches
42 if err == nil {
43 cflags = append(cflags, "-DHAS_DRM")
44 }
45
bigbiff6e0ca7d2021-02-06 19:15:16 -050046 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -050047 cflags = append(cflags, "-DTW_INCLUDE_JPEG")
48 }
49
bigbiff6e0ca7d2021-02-06 19:15:16 -050050 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050051 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
52 }
53
bigbiff6e0ca7d2021-02-06 19:15:16 -050054 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050055 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
56 }
57
bigbiff6e0ca7d2021-02-06 19:15:16 -050058 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050059 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
60 }
61
bigbiff6e0ca7d2021-02-06 19:15:16 -050062 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050063 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
64 }
65
bigbiff6e0ca7d2021-02-06 19:15:16 -050066 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050067 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
68 }
69
bigbiff6e0ca7d2021-02-06 19:15:16 -050070 if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050071 cflags = append(cflags, "-D_EVENT_LOGGING")
72 }
73
bigbiff6e0ca7d2021-02-06 19:15:16 -050074 var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050075
76 switch pixelFormat {
77 case "RGBA_8888":
78 fmt.Println("****************************************************************************)")
79 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
80 fmt.Println("****************************************************************************)")
81 cflags = append(cflags, "-DRECOVERY_RGBA")
82 break
83
84 case "RGBX_8888":
85 fmt.Println("****************************************************************************)")
86 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
87 fmt.Println("****************************************************************************)")
88 cflags = append(cflags, "-DRECOVERY_RGBX")
89 break
90
91 case "BGRA_8888":
92 fmt.Println("****************************************************************************)")
93 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
94 fmt.Println("****************************************************************************)")
95 cflags = append(cflags, "-DRECOVERY_BGRA")
96 break
97
98 case "RGB_565":
99 cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
100 break
101 }
102
bigbiff6e0ca7d2021-02-06 19:15:16 -0500103 pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -0500104 switch pixelFormat {
105 case "ABGR_8888":
106 cflags = append(cflags, "-DRECOVERY_ABGR")
107 break
108
109 case "RGBX_8888":
110 cflags = append(cflags, "-DRECOVERY_RGBX")
111 break
112
113 case "BGRA_8888":
114 cflags = append(cflags, "-DRECOVERY_BGRA")
115 break
116 }
117
bigbiff6e0ca7d2021-02-06 19:15:16 -0500118 if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
119 cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT"))
bigbiffd81833a2021-01-17 11:06:57 -0500120 } else {
121 cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
122 }
123
bigbiff6e0ca7d2021-02-06 19:15:16 -0500124 if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500125 cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
126 }
127
bigbiff6e0ca7d2021-02-06 19:15:16 -0500128 if getMakeVars(ctx, "TW_FBIOPAN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500129 cflags = append(cflags, "-DTW_FBIOPAN")
130 }
131
bigbiff6e0ca7d2021-02-06 19:15:16 -0500132 var tw_rotation = getMakeVars(ctx, "TW_ROTATION")
bigbiffd81833a2021-01-17 11:06:57 -0500133 switch tw_rotation {
134 case "0":
135 case "90":
136 case "180":
137 case "270":
138 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
139 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -0500140 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500141 cflags = append(cflags, "-DTW_ROTATION=180")
142 } else {
143 cflags = append(cflags, "-DTW_ROTATION=0")
144 }
145 }
146
bigbiff6e0ca7d2021-02-06 19:15:16 -0500147 if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500148 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
149 }
150
bigbiff6e0ca7d2021-02-06 19:15:16 -0500151 if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500152 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
153 }
154
bigbiff6e0ca7d2021-02-06 19:15:16 -0500155 if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500156 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
157 }
158
bigbiff6e0ca7d2021-02-06 19:15:16 -0500159 if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" {
160 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST"))
bigbiffd81833a2021-01-17 11:06:57 -0500161 }
162
bigbiff6e0ca7d2021-02-06 19:15:16 -0500163 if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" {
164 cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT"))
bigbiffd81833a2021-01-17 11:06:57 -0500165 }
166
bigbiff6e0ca7d2021-02-06 19:15:16 -0500167 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500168 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
169 }
170
171 return cflags
172}
173
174func globalSrcs(ctx android.BaseContext) []string {
175 var srcs []string
176
bigbiff6e0ca7d2021-02-06 19:15:16 -0500177 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500178 srcs = append(srcs, "graphics_overlay.cpp")
179 }
180
181 matches, err := filepath.Glob("system/core/adf/Android.*")
182 _ = matches
183 if err == nil {
184 srcs = append(srcs, "graphics_adf.cpp")
185 }
186
187 matches, err = filepath.Glob("external/libdrm/Android.*")
188 if err == nil {
189 srcs = append(srcs, "graphics_drm.cpp")
190 }
191
bigbiff6e0ca7d2021-02-06 19:15:16 -0500192 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500193 srcs = append(srcs, "tspdrv.cpp")
194 }
195 return srcs
196}
197
198func globalIncludes(ctx android.BaseContext) []string {
199 var includes []string
200
bigbiff6e0ca7d2021-02-06 19:15:16 -0500201 if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500202 includes = append(includes, "bootable/recovery/crypto/fscrypt")
203 }
204
bigbiff6e0ca7d2021-02-06 19:15:16 -0500205 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
206 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
207 includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
bigbiffd81833a2021-01-17 11:06:57 -0500208 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500209 if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500210 includes = append(includes, "bootable/recovery/minuitwrp")
211 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500212 includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS"))
bigbiffd81833a2021-01-17 11:06:57 -0500213 }
214 }
215 } else {
216 includes = append(includes, "bootable/recovery/minuitwrp")
217 }
218
bigbiff6e0ca7d2021-02-06 19:15:16 -0500219 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500220 includes = append(includes, "external/jpeg")
221 }
222
223 return includes
224}
225
226func globalStaticLibs(ctx android.BaseContext) []string {
227 var staticLibs []string
228
229 matches, err := filepath.Glob("system/core/adf/Android.*")
230 _ = matches
231 if err == nil {
232 staticLibs = append(staticLibs, "libadf")
233 }
234
235 matches, err = filepath.Glob("external/libdrm/Android.*")
236 if err == nil {
237 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
238 if err != nil {
239 staticLibs = append(staticLibs, "libdrm_platform")
240 } else {
241 staticLibs = append(staticLibs, "libdrm")
242 }
243 }
244
245 return staticLibs
246}
247
248func globalSharedLibs(ctx android.BaseContext) []string {
249 var sharedLibs []string
250
bigbiff6e0ca7d2021-02-06 19:15:16 -0500251 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500252 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
253 sharedLibs = append(sharedLibs, "libhidlbase")
254 }
255
nebrassy76224bd2021-04-05 11:52:44 +0200256 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
257 sharedLibs = append(sharedLibs, "android.hardware.vibrator-ndk_platform")
258 sharedLibs = append(sharedLibs, "android.hardware.vibrator-cpp")
259 }
260
bigbiff6e0ca7d2021-02-06 19:15:16 -0500261 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500262 sharedLibs = append(sharedLibs, "libjpeg")
263 }
264 return sharedLibs
265}
266
267func globalRequiredModules(ctx android.BaseContext) []string {
268 var requiredModules []string
269
bigbiff6e0ca7d2021-02-06 19:15:16 -0500270 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
271 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500272 requiredModules = append(requiredModules, kernelDir)
273 }
274 return requiredModules
275}
276
277func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
278 type props struct {
279 Target struct {
280 Android struct {
281 Cflags []string
282 Enabled *bool
283 }
284 }
285 Cflags []string
286 Srcs []string
287 Include_dirs []string
288 Static_libs []string
289 Shared_libs []string
290 Required []string
291 }
292
293 p := &props{}
294 p.Cflags = globalFlags(ctx)
295 s := globalSrcs(ctx)
296 p.Srcs = s
297 i := globalIncludes(ctx)
298 p.Include_dirs = i
299 staticLibs := globalStaticLibs(ctx)
300 p.Static_libs = staticLibs
301 sharedLibs := globalSharedLibs(ctx)
302 p.Shared_libs = sharedLibs
303 requiredModules := globalRequiredModules(ctx)
304 p.Required = requiredModules
305 ctx.AppendProperties(p)
306}
307
308func init() {
309 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
310}
311
312func libMinuiTwrpDefaultsFactory() android.Module {
313 module := cc.DefaultsFactory()
314 android.AddLoadHook(module, libMinuiTwrpDefaults)
315
316 return module
317}