blob: 92be0a09f400020624f6e2c00034ffebff717136 [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
bigbiff6e0ca7d2021-02-06 19:15:16 -050022 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050023 cflags = append(cflags, "-DMSM_BSP")
24 }
25
26 matches, err := filepath.Glob("system/core/adf/Android.*")
27 _ = matches
28 if err == nil {
29 cflags = append(cflags, "-DHAS_ADF")
30 }
31
bigbiff6e0ca7d2021-02-06 19:15:16 -050032 if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050033 cflags = append(cflags, "-DNEW_ION_HEAP")
34 }
35
36 matches, err = filepath.Glob("external/libdrm/Android.*")
37 _ = matches
38 if err == nil {
39 cflags = append(cflags, "-DHAS_DRM")
40 }
41
bigbiff6e0ca7d2021-02-06 19:15:16 -050042 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -050043 cflags = append(cflags, "-DTW_INCLUDE_JPEG")
44 }
45
bigbiff6e0ca7d2021-02-06 19:15:16 -050046 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050047 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
48 }
49
bigbiff6e0ca7d2021-02-06 19:15:16 -050050 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050051 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
52 }
53
bigbiff6e0ca7d2021-02-06 19:15:16 -050054 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050055 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
56 }
57
bigbiff6e0ca7d2021-02-06 19:15:16 -050058 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050059 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
60 }
61
bigbiff6e0ca7d2021-02-06 19:15:16 -050062 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050063 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
64 }
65
bigbiff6e0ca7d2021-02-06 19:15:16 -050066 if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050067 cflags = append(cflags, "-D_EVENT_LOGGING")
68 }
69
bigbiff6e0ca7d2021-02-06 19:15:16 -050070 var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050071
72 switch pixelFormat {
73 case "RGBA_8888":
74 fmt.Println("****************************************************************************)")
75 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
76 fmt.Println("****************************************************************************)")
77 cflags = append(cflags, "-DRECOVERY_RGBA")
78 break
79
80 case "RGBX_8888":
81 fmt.Println("****************************************************************************)")
82 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
83 fmt.Println("****************************************************************************)")
84 cflags = append(cflags, "-DRECOVERY_RGBX")
85 break
86
87 case "BGRA_8888":
88 fmt.Println("****************************************************************************)")
89 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
90 fmt.Println("****************************************************************************)")
91 cflags = append(cflags, "-DRECOVERY_BGRA")
92 break
93
94 case "RGB_565":
95 cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
96 break
97 }
98
bigbiff6e0ca7d2021-02-06 19:15:16 -050099 pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -0500100 switch pixelFormat {
101 case "ABGR_8888":
102 cflags = append(cflags, "-DRECOVERY_ABGR")
103 break
104
105 case "RGBX_8888":
106 cflags = append(cflags, "-DRECOVERY_RGBX")
107 break
108
109 case "BGRA_8888":
110 cflags = append(cflags, "-DRECOVERY_BGRA")
111 break
112 }
113
bigbiff6e0ca7d2021-02-06 19:15:16 -0500114 if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
115 cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT"))
bigbiffd81833a2021-01-17 11:06:57 -0500116 } else {
117 cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
118 }
119
bigbiff6e0ca7d2021-02-06 19:15:16 -0500120 if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500121 cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
122 }
123
bigbiff6e0ca7d2021-02-06 19:15:16 -0500124 if getMakeVars(ctx, "TW_FBIOPAN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500125 cflags = append(cflags, "-DTW_FBIOPAN")
126 }
127
bigbiff6e0ca7d2021-02-06 19:15:16 -0500128 var tw_rotation = getMakeVars(ctx, "TW_ROTATION")
bigbiffd81833a2021-01-17 11:06:57 -0500129 switch tw_rotation {
130 case "0":
131 case "90":
132 case "180":
133 case "270":
134 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
135 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -0500136 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500137 cflags = append(cflags, "-DTW_ROTATION=180")
138 } else {
139 cflags = append(cflags, "-DTW_ROTATION=0")
140 }
141 }
142
bigbiff6e0ca7d2021-02-06 19:15:16 -0500143 if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500144 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
145 }
146
bigbiff6e0ca7d2021-02-06 19:15:16 -0500147 if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500148 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
149 }
150
bigbiff6e0ca7d2021-02-06 19:15:16 -0500151 if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500152 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
153 }
154
bigbiff6e0ca7d2021-02-06 19:15:16 -0500155 if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" {
156 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST"))
bigbiffd81833a2021-01-17 11:06:57 -0500157 }
158
bigbiff6e0ca7d2021-02-06 19:15:16 -0500159 if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" {
160 cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT"))
bigbiffd81833a2021-01-17 11:06:57 -0500161 }
162
bigbiff6e0ca7d2021-02-06 19:15:16 -0500163 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500164 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
165 }
166
167 return cflags
168}
169
170func globalSrcs(ctx android.BaseContext) []string {
171 var srcs []string
172
bigbiff6e0ca7d2021-02-06 19:15:16 -0500173 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500174 srcs = append(srcs, "graphics_overlay.cpp")
175 }
176
177 matches, err := filepath.Glob("system/core/adf/Android.*")
178 _ = matches
179 if err == nil {
180 srcs = append(srcs, "graphics_adf.cpp")
181 }
182
183 matches, err = filepath.Glob("external/libdrm/Android.*")
184 if err == nil {
185 srcs = append(srcs, "graphics_drm.cpp")
186 }
187
bigbiff6e0ca7d2021-02-06 19:15:16 -0500188 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500189 srcs = append(srcs, "tspdrv.cpp")
190 }
191 return srcs
192}
193
194func globalIncludes(ctx android.BaseContext) []string {
195 var includes []string
196
bigbiff6e0ca7d2021-02-06 19:15:16 -0500197 if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500198 includes = append(includes, "bootable/recovery/crypto/fscrypt")
199 }
200
bigbiff6e0ca7d2021-02-06 19:15:16 -0500201 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
202 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
203 includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
bigbiffd81833a2021-01-17 11:06:57 -0500204 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500205 if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500206 includes = append(includes, "bootable/recovery/minuitwrp")
207 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500208 includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS"))
bigbiffd81833a2021-01-17 11:06:57 -0500209 }
210 }
211 } else {
212 includes = append(includes, "bootable/recovery/minuitwrp")
213 }
214
bigbiff6e0ca7d2021-02-06 19:15:16 -0500215 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500216 includes = append(includes, "external/jpeg")
217 }
218
219 return includes
220}
221
222func globalStaticLibs(ctx android.BaseContext) []string {
223 var staticLibs []string
224
225 matches, err := filepath.Glob("system/core/adf/Android.*")
226 _ = matches
227 if err == nil {
228 staticLibs = append(staticLibs, "libadf")
229 }
230
231 matches, err = filepath.Glob("external/libdrm/Android.*")
232 if err == nil {
233 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
234 if err != nil {
235 staticLibs = append(staticLibs, "libdrm_platform")
236 } else {
237 staticLibs = append(staticLibs, "libdrm")
238 }
239 }
240
241 return staticLibs
242}
243
244func globalSharedLibs(ctx android.BaseContext) []string {
245 var sharedLibs []string
246
bigbiff6e0ca7d2021-02-06 19:15:16 -0500247 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500248 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
249 sharedLibs = append(sharedLibs, "libhidlbase")
250 }
251
nebrassy76224bd2021-04-05 11:52:44 +0200252 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
253 sharedLibs = append(sharedLibs, "android.hardware.vibrator-ndk_platform")
254 sharedLibs = append(sharedLibs, "android.hardware.vibrator-cpp")
255 }
256
bigbiff6e0ca7d2021-02-06 19:15:16 -0500257 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500258 sharedLibs = append(sharedLibs, "libjpeg")
259 }
260 return sharedLibs
261}
262
263func globalRequiredModules(ctx android.BaseContext) []string {
264 var requiredModules []string
265
bigbiff6e0ca7d2021-02-06 19:15:16 -0500266 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
267 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500268 requiredModules = append(requiredModules, kernelDir)
269 }
270 return requiredModules
271}
272
273func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
274 type props struct {
275 Target struct {
276 Android struct {
277 Cflags []string
278 Enabled *bool
279 }
280 }
281 Cflags []string
282 Srcs []string
283 Include_dirs []string
284 Static_libs []string
285 Shared_libs []string
286 Required []string
287 }
288
289 p := &props{}
290 p.Cflags = globalFlags(ctx)
291 s := globalSrcs(ctx)
292 p.Srcs = s
293 i := globalIncludes(ctx)
294 p.Include_dirs = i
295 staticLibs := globalStaticLibs(ctx)
296 p.Static_libs = staticLibs
297 sharedLibs := globalSharedLibs(ctx)
298 p.Shared_libs = sharedLibs
299 requiredModules := globalRequiredModules(ctx)
300 p.Required = requiredModules
301 ctx.AppendProperties(p)
302}
303
304func init() {
305 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
306}
307
308func libMinuiTwrpDefaultsFactory() android.Module {
309 module := cc.DefaultsFactory()
310 android.AddLoadHook(module, libMinuiTwrpDefaults)
311
312 return module
313}