bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 1 | package twrp |
| 2 | |
| 3 | import ( |
| 4 | "android/soong/android" |
| 5 | "android/soong/cc" |
| 6 | "fmt" |
| 7 | "path/filepath" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | func globalFlags(ctx android.BaseContext) []string { |
| 12 | var cflags []string |
| 13 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 14 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 15 | cflags = append(cflags, "-DUSE_QTI_HAPTICS") |
| 16 | } |
| 17 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 18 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" { |
| 19 | cflags = append(cflags, "-DUSE_QTI_AIDL_HAPTICS") |
| 20 | } |
| 21 | |
sekaiacg | 38d6efd | 2022-06-25 13:41:54 +0800 | [diff] [blame] | 22 | 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 | |
sekaiacg | acc522f | 2022-06-25 13:45:17 +0800 | [diff] [blame] | 26 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS_FIX_OFF") == "true" { |
| 27 | cflags = append(cflags, "-DUSE_QTI_AIDL_HAPTICS_FIX_OFF") |
| 28 | } |
| 29 | |
soulr344 | f831bff | 2021-08-16 09:46:38 +0500 | [diff] [blame] | 30 | if getMakeVars(ctx, "TW_USE_SAMSUNG_HAPTICS") == "true" { |
| 31 | cflags = append(cflags, "-DUSE_SAMSUNG_HAPTICS") |
| 32 | } |
| 33 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 34 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 35 | cflags = append(cflags, "-DMSM_BSP") |
| 36 | } |
| 37 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 38 | if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 39 | cflags = append(cflags, "-DNEW_ION_HEAP") |
| 40 | } |
| 41 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 42 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 43 | _ = matches |
| 44 | if err == nil { |
| 45 | cflags = append(cflags, "-DHAS_DRM") |
| 46 | } |
| 47 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 48 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 49 | cflags = append(cflags, "-DTW_INCLUDE_JPEG") |
| 50 | } |
| 51 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 52 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 53 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY") |
| 54 | } |
| 55 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 56 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 57 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X") |
| 58 | } |
| 59 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 60 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 61 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y") |
| 62 | } |
| 63 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 64 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 65 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") |
| 66 | } |
| 67 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 68 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 69 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") |
| 70 | } |
| 71 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 72 | if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 73 | cflags = append(cflags, "-D_EVENT_LOGGING") |
| 74 | } |
| 75 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 76 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 77 | |
| 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 105 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 106 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 120 | if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" { |
Tommaso Fonda | 3b494b7 | 2022-09-29 15:10:29 +0200 | [diff] [blame] | 121 | cflags = append(cflags, "-DOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 122 | } else { |
| 123 | cflags = append(cflags, "-DOVERSCAN_PERCENT=0") |
| 124 | } |
| 125 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 126 | if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 127 | cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT") |
| 128 | } |
| 129 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 130 | if getMakeVars(ctx, "TW_FBIOPAN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 131 | cflags = append(cflags, "-DTW_FBIOPAN") |
| 132 | } |
| 133 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 134 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 135 | switch tw_rotation { |
| 136 | case "0": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 137 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 138 | case "90": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 139 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 140 | case "180": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 141 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 142 | case "270": |
| 143 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 144 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 145 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 146 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 147 | } else { |
| 148 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 149 | } |
| 150 | } |
| 151 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 152 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 153 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 154 | } |
| 155 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 156 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 157 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 158 | } |
| 159 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 160 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 161 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 162 | } |
| 163 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 164 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 165 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 166 | } |
| 167 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 168 | if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" { |
| 169 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 170 | } |
| 171 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 172 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 173 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 174 | } |
| 175 | |
| 176 | return cflags |
| 177 | } |
| 178 | |
| 179 | func globalSrcs(ctx android.BaseContext) []string { |
| 180 | var srcs []string |
| 181 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 182 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 183 | srcs = append(srcs, "graphics_overlay.cpp") |
| 184 | } |
| 185 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 186 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 187 | _ = matches |
| 188 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 189 | srcs = append(srcs, "graphics_drm.cpp") |
| 190 | } |
| 191 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 192 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 193 | srcs = append(srcs, "tspdrv.cpp") |
| 194 | } |
| 195 | return srcs |
| 196 | } |
| 197 | |
| 198 | func globalIncludes(ctx android.BaseContext) []string { |
| 199 | var includes []string |
| 200 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 201 | 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") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 204 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 205 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 206 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 207 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 208 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } else { |
| 212 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 213 | } |
| 214 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 215 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 216 | includes = append(includes, "external/jpeg") |
| 217 | } |
| 218 | |
| 219 | return includes |
| 220 | } |
| 221 | |
| 222 | func globalStaticLibs(ctx android.BaseContext) []string { |
| 223 | var staticLibs []string |
| 224 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 225 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 226 | _ = matches |
| 227 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 228 | 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 | |
| 239 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 240 | var sharedLibs []string |
| 241 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 242 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 243 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 244 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 245 | } |
| 246 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 247 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" { |
Woomymy | fb8aff5 | 2022-08-03 18:34:59 +0200 | [diff] [blame] | 248 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-ndk_platform") |
| 249 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-cpp") |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 250 | } |
| 251 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 252 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 253 | sharedLibs = append(sharedLibs, "libjpeg") |
| 254 | } |
| 255 | return sharedLibs |
| 256 | } |
| 257 | |
| 258 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 259 | var requiredModules []string |
| 260 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 261 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 262 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 263 | requiredModules = append(requiredModules, kernelDir) |
| 264 | } |
| 265 | return requiredModules |
| 266 | } |
| 267 | |
| 268 | func 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 | |
| 299 | func init() { |
| 300 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 301 | } |
| 302 | |
| 303 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 304 | module := cc.DefaultsFactory() |
| 305 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 306 | |
| 307 | return module |
| 308 | } |