blob: bbd66242098ba7334b236f4a01bd644dc80641a9 [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
sekaiacg38d6efd2022-06-25 13:41:54 +080022 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS_FQNAME") != "" {
23 cflags = append(cflags, "-DUSE_QTI_AIDL_HAPTICS_FQNAME="+getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS_FQNAME"))
24 }
25
sekaiacgacc522f2022-06-25 13:45:17 +080026 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS_FIX_OFF") == "true" {
27 cflags = append(cflags, "-DUSE_QTI_AIDL_HAPTICS_FIX_OFF")
28 }
29
soulr344f831bff2021-08-16 09:46:38 +050030 if getMakeVars(ctx, "TW_USE_SAMSUNG_HAPTICS") == "true" {
31 cflags = append(cflags, "-DUSE_SAMSUNG_HAPTICS")
32 }
33
bigbiff6e0ca7d2021-02-06 19:15:16 -050034 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050035 cflags = append(cflags, "-DMSM_BSP")
36 }
37
bigbiff6e0ca7d2021-02-06 19:15:16 -050038 if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050039 cflags = append(cflags, "-DNEW_ION_HEAP")
40 }
41
nebrassy0c3533f2021-11-14 16:05:51 +010042 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -050043 _ = matches
44 if err == nil {
45 cflags = append(cflags, "-DHAS_DRM")
46 }
47
bigbiff6e0ca7d2021-02-06 19:15:16 -050048 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -050049 cflags = append(cflags, "-DTW_INCLUDE_JPEG")
50 }
51
bigbiff6e0ca7d2021-02-06 19:15:16 -050052 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050053 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
54 }
55
bigbiff6e0ca7d2021-02-06 19:15:16 -050056 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050057 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
58 }
59
bigbiff6e0ca7d2021-02-06 19:15:16 -050060 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050061 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
62 }
63
bigbiff6e0ca7d2021-02-06 19:15:16 -050064 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050065 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
66 }
67
bigbiff6e0ca7d2021-02-06 19:15:16 -050068 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050069 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
70 }
71
bigbiff6e0ca7d2021-02-06 19:15:16 -050072 if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050073 cflags = append(cflags, "-D_EVENT_LOGGING")
74 }
75
bigbiff6e0ca7d2021-02-06 19:15:16 -050076 var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050077
78 switch pixelFormat {
79 case "RGBA_8888":
80 fmt.Println("****************************************************************************)")
81 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
82 fmt.Println("****************************************************************************)")
83 cflags = append(cflags, "-DRECOVERY_RGBA")
84 break
85
86 case "RGBX_8888":
87 fmt.Println("****************************************************************************)")
88 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
89 fmt.Println("****************************************************************************)")
90 cflags = append(cflags, "-DRECOVERY_RGBX")
91 break
92
93 case "BGRA_8888":
94 fmt.Println("****************************************************************************)")
95 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
96 fmt.Println("****************************************************************************)")
97 cflags = append(cflags, "-DRECOVERY_BGRA")
98 break
99
100 case "RGB_565":
101 cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
102 break
103 }
104
bigbiff6e0ca7d2021-02-06 19:15:16 -0500105 pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -0500106 switch pixelFormat {
107 case "ABGR_8888":
108 cflags = append(cflags, "-DRECOVERY_ABGR")
109 break
110
111 case "RGBX_8888":
112 cflags = append(cflags, "-DRECOVERY_RGBX")
113 break
114
115 case "BGRA_8888":
116 cflags = append(cflags, "-DRECOVERY_BGRA")
117 break
118 }
119
bigbiff6e0ca7d2021-02-06 19:15:16 -0500120 if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
Tommaso Fonda3b494b72022-09-29 15:10:29 +0200121 cflags = append(cflags, "-DOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT"))
bigbiffd81833a2021-01-17 11:06:57 -0500122 } else {
123 cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
124 }
125
bigbiff6e0ca7d2021-02-06 19:15:16 -0500126 if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500127 cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
128 }
129
bigbiff6e0ca7d2021-02-06 19:15:16 -0500130 if getMakeVars(ctx, "TW_FBIOPAN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500131 cflags = append(cflags, "-DTW_FBIOPAN")
132 }
133
bigbiff6e0ca7d2021-02-06 19:15:16 -0500134 var tw_rotation = getMakeVars(ctx, "TW_ROTATION")
bigbiffd81833a2021-01-17 11:06:57 -0500135 switch tw_rotation {
136 case "0":
bigbiffdd161232021-11-08 19:00:33 -0500137 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500138 case "90":
bigbiffdd161232021-11-08 19:00:33 -0500139 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500140 case "180":
bigbiffdd161232021-11-08 19:00:33 -0500141 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500142 case "270":
143 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
144 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -0500145 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500146 cflags = append(cflags, "-DTW_ROTATION=180")
147 } else {
148 cflags = append(cflags, "-DTW_ROTATION=0")
149 }
150 }
151
bigbiff6e0ca7d2021-02-06 19:15:16 -0500152 if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500153 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
154 }
155
bigbiff6e0ca7d2021-02-06 19:15:16 -0500156 if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500157 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
158 }
159
bigbiff6e0ca7d2021-02-06 19:15:16 -0500160 if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500161 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
162 }
163
bigbiff6e0ca7d2021-02-06 19:15:16 -0500164 if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" {
165 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST"))
bigbiffd81833a2021-01-17 11:06:57 -0500166 }
167
bigbiff6e0ca7d2021-02-06 19:15:16 -0500168 if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" {
169 cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT"))
bigbiffd81833a2021-01-17 11:06:57 -0500170 }
171
bigbiff6e0ca7d2021-02-06 19:15:16 -0500172 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500173 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
174 }
175
176 return cflags
177}
178
179func globalSrcs(ctx android.BaseContext) []string {
180 var srcs []string
181
bigbiff6e0ca7d2021-02-06 19:15:16 -0500182 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500183 srcs = append(srcs, "graphics_overlay.cpp")
184 }
185
nebrassy0c3533f2021-11-14 16:05:51 +0100186 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -0500187 _ = matches
188 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -0500189 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_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
nebrassy0c3533f2021-11-14 16:05:51 +0100225 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -0500226 _ = matches
227 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -0500228 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
229 if err != nil {
230 staticLibs = append(staticLibs, "libdrm_platform")
231 } else {
232 staticLibs = append(staticLibs, "libdrm")
233 }
234 }
235
236 return staticLibs
237}
238
239func globalSharedLibs(ctx android.BaseContext) []string {
240 var sharedLibs []string
241
bigbiff6e0ca7d2021-02-06 19:15:16 -0500242 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500243 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
244 sharedLibs = append(sharedLibs, "libhidlbase")
245 }
246
nebrassy76224bd2021-04-05 11:52:44 +0200247 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
nebrassy204e36e2021-11-14 23:27:51 +0100248 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-ndk_platform")
249 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-cpp")
nebrassy76224bd2021-04-05 11:52:44 +0200250 }
251
bigbiff6e0ca7d2021-02-06 19:15:16 -0500252 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500253 sharedLibs = append(sharedLibs, "libjpeg")
254 }
255 return sharedLibs
256}
257
258func globalRequiredModules(ctx android.BaseContext) []string {
259 var requiredModules []string
260
bigbiff6e0ca7d2021-02-06 19:15:16 -0500261 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
262 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500263 requiredModules = append(requiredModules, kernelDir)
264 }
265 return requiredModules
266}
267
268func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
269 type props struct {
270 Target struct {
271 Android struct {
272 Cflags []string
273 Enabled *bool
274 }
275 }
276 Cflags []string
277 Srcs []string
278 Include_dirs []string
279 Static_libs []string
280 Shared_libs []string
281 Required []string
282 }
283
284 p := &props{}
285 p.Cflags = globalFlags(ctx)
286 s := globalSrcs(ctx)
287 p.Srcs = s
288 i := globalIncludes(ctx)
289 p.Include_dirs = i
290 staticLibs := globalStaticLibs(ctx)
291 p.Static_libs = staticLibs
292 sharedLibs := globalSharedLibs(ctx)
293 p.Shared_libs = sharedLibs
294 requiredModules := globalRequiredModules(ctx)
295 p.Required = requiredModules
296 ctx.AppendProperties(p)
297}
298
299func init() {
300 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
301}
302
303func libMinuiTwrpDefaultsFactory() android.Module {
304 module := cc.DefaultsFactory()
305 android.AddLoadHook(module, libMinuiTwrpDefaults)
306
307 return module
308}