blob: a6497a275672c195da5b31ee1842661253d5ff8b [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
bigbiff6e0ca7d2021-02-06 19:15:16 -050030 if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050031 cflags = append(cflags, "-DNEW_ION_HEAP")
32 }
33
nebrassy0c3533f2021-11-14 16:05:51 +010034 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -050035 _ = matches
36 if err == nil {
37 cflags = append(cflags, "-DHAS_DRM")
38 }
39
bigbiff6e0ca7d2021-02-06 19:15:16 -050040 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -050041 cflags = append(cflags, "-DTW_INCLUDE_JPEG")
42 }
43
bigbiff6e0ca7d2021-02-06 19:15:16 -050044 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050045 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
46 }
47
bigbiff6e0ca7d2021-02-06 19:15:16 -050048 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050049 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
50 }
51
bigbiff6e0ca7d2021-02-06 19:15:16 -050052 if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050053 cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
54 }
55
bigbiff6e0ca7d2021-02-06 19:15:16 -050056 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050057 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
58 }
59
bigbiff6e0ca7d2021-02-06 19:15:16 -050060 if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050061 cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
62 }
63
bigbiff6e0ca7d2021-02-06 19:15:16 -050064 if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050065 cflags = append(cflags, "-D_EVENT_LOGGING")
66 }
67
bigbiff6e0ca7d2021-02-06 19:15:16 -050068 var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050069
70 switch pixelFormat {
71 case "RGBA_8888":
72 fmt.Println("****************************************************************************)")
73 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
74 fmt.Println("****************************************************************************)")
75 cflags = append(cflags, "-DRECOVERY_RGBA")
76 break
77
78 case "RGBX_8888":
79 fmt.Println("****************************************************************************)")
80 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
81 fmt.Println("****************************************************************************)")
82 cflags = append(cflags, "-DRECOVERY_RGBX")
83 break
84
85 case "BGRA_8888":
86 fmt.Println("****************************************************************************)")
87 fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
88 fmt.Println("****************************************************************************)")
89 cflags = append(cflags, "-DRECOVERY_BGRA")
90 break
91
92 case "RGB_565":
93 cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
94 break
95 }
96
bigbiff6e0ca7d2021-02-06 19:15:16 -050097 pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050098 switch pixelFormat {
99 case "ABGR_8888":
100 cflags = append(cflags, "-DRECOVERY_ABGR")
101 break
102
103 case "RGBX_8888":
104 cflags = append(cflags, "-DRECOVERY_RGBX")
105 break
106
107 case "BGRA_8888":
108 cflags = append(cflags, "-DRECOVERY_BGRA")
109 break
110 }
111
bigbiff6e0ca7d2021-02-06 19:15:16 -0500112 if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
113 cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT"))
bigbiffd81833a2021-01-17 11:06:57 -0500114 } else {
115 cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
116 }
117
bigbiff6e0ca7d2021-02-06 19:15:16 -0500118 if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500119 cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
120 }
121
bigbiff6e0ca7d2021-02-06 19:15:16 -0500122 if getMakeVars(ctx, "TW_FBIOPAN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500123 cflags = append(cflags, "-DTW_FBIOPAN")
124 }
125
bigbiff6e0ca7d2021-02-06 19:15:16 -0500126 var tw_rotation = getMakeVars(ctx, "TW_ROTATION")
bigbiffd81833a2021-01-17 11:06:57 -0500127 switch tw_rotation {
128 case "0":
bigbiffdd161232021-11-08 19:00:33 -0500129 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500130 case "90":
bigbiffdd161232021-11-08 19:00:33 -0500131 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500132 case "180":
bigbiffdd161232021-11-08 19:00:33 -0500133 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -0500134 case "270":
135 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
136 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -0500137 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500138 cflags = append(cflags, "-DTW_ROTATION=180")
139 } else {
140 cflags = append(cflags, "-DTW_ROTATION=0")
141 }
142 }
143
bigbiff6e0ca7d2021-02-06 19:15:16 -0500144 if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500145 cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
146 }
147
bigbiff6e0ca7d2021-02-06 19:15:16 -0500148 if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500149 cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
150 }
151
bigbiff6e0ca7d2021-02-06 19:15:16 -0500152 if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500153 cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
154 }
155
bigbiff6e0ca7d2021-02-06 19:15:16 -0500156 if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" {
157 cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST"))
bigbiffd81833a2021-01-17 11:06:57 -0500158 }
159
bigbiff6e0ca7d2021-02-06 19:15:16 -0500160 if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" {
161 cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT"))
bigbiffd81833a2021-01-17 11:06:57 -0500162 }
163
bigbiff6e0ca7d2021-02-06 19:15:16 -0500164 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500165 cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
166 }
167
168 return cflags
169}
170
171func globalSrcs(ctx android.BaseContext) []string {
172 var srcs []string
173
bigbiff6e0ca7d2021-02-06 19:15:16 -0500174 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500175 srcs = append(srcs, "graphics_overlay.cpp")
176 }
177
nebrassy0c3533f2021-11-14 16:05:51 +0100178 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -0500179 _ = matches
180 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -0500181 srcs = append(srcs, "graphics_drm.cpp")
182 }
183
bigbiff6e0ca7d2021-02-06 19:15:16 -0500184 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500185 srcs = append(srcs, "tspdrv.cpp")
186 }
187 return srcs
188}
189
190func globalIncludes(ctx android.BaseContext) []string {
191 var includes []string
192
bigbiff6e0ca7d2021-02-06 19:15:16 -0500193 if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500194 includes = append(includes, "bootable/recovery/crypto/fscrypt")
195 }
196
bigbiff6e0ca7d2021-02-06 19:15:16 -0500197 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
198 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
199 includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
bigbiffd81833a2021-01-17 11:06:57 -0500200 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500201 if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500202 includes = append(includes, "bootable/recovery/minuitwrp")
203 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500204 includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS"))
bigbiffd81833a2021-01-17 11:06:57 -0500205 }
206 }
207 } else {
208 includes = append(includes, "bootable/recovery/minuitwrp")
209 }
210
bigbiff6e0ca7d2021-02-06 19:15:16 -0500211 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500212 includes = append(includes, "external/jpeg")
213 }
214
215 return includes
216}
217
218func globalStaticLibs(ctx android.BaseContext) []string {
219 var staticLibs []string
220
nebrassy0c3533f2021-11-14 16:05:51 +0100221 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -0500222 _ = matches
223 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -0500224 matches, err = filepath.Glob("external/libdrm/Android.common.mk")
225 if err != nil {
226 staticLibs = append(staticLibs, "libdrm_platform")
227 } else {
228 staticLibs = append(staticLibs, "libdrm")
229 }
230 }
231
232 return staticLibs
233}
234
235func globalSharedLibs(ctx android.BaseContext) []string {
236 var sharedLibs []string
237
bigbiff6e0ca7d2021-02-06 19:15:16 -0500238 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500239 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
240 sharedLibs = append(sharedLibs, "libhidlbase")
241 }
242
nebrassy76224bd2021-04-05 11:52:44 +0200243 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
nebrassy204e36e2021-11-14 23:27:51 +0100244 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-ndk_platform")
245 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-cpp")
nebrassy76224bd2021-04-05 11:52:44 +0200246 }
247
bigbiff6e0ca7d2021-02-06 19:15:16 -0500248 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500249 sharedLibs = append(sharedLibs, "libjpeg")
250 }
251 return sharedLibs
252}
253
254func globalRequiredModules(ctx android.BaseContext) []string {
255 var requiredModules []string
256
bigbiff6e0ca7d2021-02-06 19:15:16 -0500257 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
258 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500259 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}