blob: 2f82c6ebacfcdc343093ebeb607340912f5d7dd8 [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":
bigbiffdd161232021-11-08 19:00:33 -0500135 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500136 case "90":
bigbiffdd161232021-11-08 19:00:33 -0500137 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500138 case "180":
bigbiffdd161232021-11-08 19:00:33 -0500139 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500140 case "270":
141 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
142 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -0500143 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500144 cflags = append(cflags, "-DTW_ROTATION=180")
145 } else {
146 cflags = append(cflags, "-DTW_ROTATION=0")
147 }
148 }
149
bigbiff6e0ca7d2021-02-06 19:15:16 -0500150 if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500151 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
152 }
153
bigbiff6e0ca7d2021-02-06 19:15:16 -0500154 if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500155 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
156 }
157
bigbiff6e0ca7d2021-02-06 19:15:16 -0500158 if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500159 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
160 }
161
bigbiff6e0ca7d2021-02-06 19:15:16 -0500162 if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" {
163 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST"))
bigbiffd81833a2021-01-17 11:06:57 -0500164 }
165
bigbiff6e0ca7d2021-02-06 19:15:16 -0500166 if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" {
167 cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT"))
bigbiffd81833a2021-01-17 11:06:57 -0500168 }
169
bigbiff6e0ca7d2021-02-06 19:15:16 -0500170 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500171 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
172 }
173
174 return cflags
175}
176
177func globalSrcs(ctx android.BaseContext) []string {
178 var srcs []string
179
bigbiff6e0ca7d2021-02-06 19:15:16 -0500180 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500181 srcs = append(srcs, "graphics_overlay.cpp")
182 }
183
184 matches, err := filepath.Glob("system/core/adf/Android.*")
185 _ = matches
186 if err == nil {
187 srcs = append(srcs, "graphics_adf.cpp")
188 }
189
190 matches, err = filepath.Glob("external/libdrm/Android.*")
191 if err == nil {
192 srcs = append(srcs, "graphics_drm.cpp")
193 }
194
bigbiff6e0ca7d2021-02-06 19:15:16 -0500195 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500196 srcs = append(srcs, "tspdrv.cpp")
197 }
198 return srcs
199}
200
201func globalIncludes(ctx android.BaseContext) []string {
202 var includes []string
203
bigbiff6e0ca7d2021-02-06 19:15:16 -0500204 if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500205 includes = append(includes, "bootable/recovery/crypto/fscrypt")
206 }
207
bigbiff6e0ca7d2021-02-06 19:15:16 -0500208 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
209 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
210 includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
bigbiffd81833a2021-01-17 11:06:57 -0500211 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500212 if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500213 includes = append(includes, "bootable/recovery/minuitwrp")
214 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500215 includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS"))
bigbiffd81833a2021-01-17 11:06:57 -0500216 }
217 }
218 } else {
219 includes = append(includes, "bootable/recovery/minuitwrp")
220 }
221
bigbiff6e0ca7d2021-02-06 19:15:16 -0500222 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500223 includes = append(includes, "external/jpeg")
224 }
225
226 return includes
227}
228
229func globalStaticLibs(ctx android.BaseContext) []string {
230 var staticLibs []string
231
232 matches, err := filepath.Glob("system/core/adf/Android.*")
233 _ = matches
234 if err == nil {
235 staticLibs = append(staticLibs, "libadf")
236 }
237
238 matches, err = filepath.Glob("external/libdrm/Android.*")
239 if err == nil {
240 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
241 if err != nil {
242 staticLibs = append(staticLibs, "libdrm_platform")
243 } else {
244 staticLibs = append(staticLibs, "libdrm")
245 }
246 }
247
248 return staticLibs
249}
250
251func globalSharedLibs(ctx android.BaseContext) []string {
252 var sharedLibs []string
253
bigbiff6e0ca7d2021-02-06 19:15:16 -0500254 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500255 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
256 sharedLibs = append(sharedLibs, "libhidlbase")
257 }
258
nebrassy76224bd2021-04-05 11:52:44 +0200259 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
260 sharedLibs = append(sharedLibs, "android.hardware.vibrator-ndk_platform")
261 sharedLibs = append(sharedLibs, "android.hardware.vibrator-cpp")
262 }
263
bigbiff6e0ca7d2021-02-06 19:15:16 -0500264 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500265 sharedLibs = append(sharedLibs, "libjpeg")
266 }
267 return sharedLibs
268}
269
270func globalRequiredModules(ctx android.BaseContext) []string {
271 var requiredModules []string
272
bigbiff6e0ca7d2021-02-06 19:15:16 -0500273 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
274 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500275 requiredModules = append(requiredModules, kernelDir)
276 }
277 return requiredModules
278}
279
280func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
281 type props struct {
282 Target struct {
283 Android struct {
284 Cflags []string
285 Enabled *bool
286 }
287 }
288 Cflags []string
289 Srcs []string
290 Include_dirs []string
291 Static_libs []string
292 Shared_libs []string
293 Required []string
294 }
295
296 p := &props{}
297 p.Cflags = globalFlags(ctx)
298 s := globalSrcs(ctx)
299 p.Srcs = s
300 i := globalIncludes(ctx)
301 p.Include_dirs = i
302 staticLibs := globalStaticLibs(ctx)
303 p.Static_libs = staticLibs
304 sharedLibs := globalSharedLibs(ctx)
305 p.Shared_libs = sharedLibs
306 requiredModules := globalRequiredModules(ctx)
307 p.Required = requiredModules
308 ctx.AppendProperties(p)
309}
310
311func init() {
312 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
313}
314
315func libMinuiTwrpDefaultsFactory() android.Module {
316 module := cc.DefaultsFactory()
317 android.AddLoadHook(module, libMinuiTwrpDefaults)
318
319 return module
320}