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 | |
soulr344 | f831bff | 2021-08-16 09:46:38 +0500 | [diff] [blame] | 22 | if getMakeVars(ctx, "TW_USE_SAMSUNG_HAPTICS") == "true" { |
| 23 | cflags = append(cflags, "-DUSE_SAMSUNG_HAPTICS") |
| 24 | } |
| 25 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 26 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 27 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 36 | if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 37 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 46 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 47 | cflags = append(cflags, "-DTW_INCLUDE_JPEG") |
| 48 | } |
| 49 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 50 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 51 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY") |
| 52 | } |
| 53 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 54 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 55 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X") |
| 56 | } |
| 57 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 58 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 59 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y") |
| 60 | } |
| 61 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 62 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 63 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") |
| 64 | } |
| 65 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 66 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 67 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") |
| 68 | } |
| 69 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 70 | if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 71 | cflags = append(cflags, "-D_EVENT_LOGGING") |
| 72 | } |
| 73 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 74 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 75 | |
| 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 103 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 104 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 118 | if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" { |
| 119 | cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 120 | } else { |
| 121 | cflags = append(cflags, "-DOVERSCAN_PERCENT=0") |
| 122 | } |
| 123 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 124 | if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 125 | cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT") |
| 126 | } |
| 127 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 128 | if getMakeVars(ctx, "TW_FBIOPAN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 129 | cflags = append(cflags, "-DTW_FBIOPAN") |
| 130 | } |
| 131 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 132 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 133 | switch tw_rotation { |
| 134 | case "0": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 135 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 136 | case "90": |
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 "180": |
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 "270": |
| 141 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 142 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 143 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 144 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 145 | } else { |
| 146 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 147 | } |
| 148 | } |
| 149 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 150 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 151 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 152 | } |
| 153 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 154 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 155 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 156 | } |
| 157 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 158 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 159 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 160 | } |
| 161 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 162 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 163 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 164 | } |
| 165 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 166 | if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" { |
| 167 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 168 | } |
| 169 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 170 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 171 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 172 | } |
| 173 | |
| 174 | return cflags |
| 175 | } |
| 176 | |
| 177 | func globalSrcs(ctx android.BaseContext) []string { |
| 178 | var srcs []string |
| 179 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 180 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 181 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 195 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 196 | srcs = append(srcs, "tspdrv.cpp") |
| 197 | } |
| 198 | return srcs |
| 199 | } |
| 200 | |
| 201 | func globalIncludes(ctx android.BaseContext) []string { |
| 202 | var includes []string |
| 203 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 204 | if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 205 | includes = append(includes, "bootable/recovery/crypto/fscrypt") |
| 206 | } |
| 207 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 208 | 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") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 211 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 212 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 213 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 214 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 215 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | } else { |
| 219 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 220 | } |
| 221 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 222 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 223 | includes = append(includes, "external/jpeg") |
| 224 | } |
| 225 | |
| 226 | return includes |
| 227 | } |
| 228 | |
| 229 | func 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 | |
| 251 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 252 | var sharedLibs []string |
| 253 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 254 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 255 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 256 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 257 | } |
| 258 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 259 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 264 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 265 | sharedLibs = append(sharedLibs, "libjpeg") |
| 266 | } |
| 267 | return sharedLibs |
| 268 | } |
| 269 | |
| 270 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 271 | var requiredModules []string |
| 272 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 273 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 274 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 275 | requiredModules = append(requiredModules, kernelDir) |
| 276 | } |
| 277 | return requiredModules |
| 278 | } |
| 279 | |
| 280 | func 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 | |
| 311 | func init() { |
| 312 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 313 | } |
| 314 | |
| 315 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 316 | module := cc.DefaultsFactory() |
| 317 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 318 | |
| 319 | return module |
| 320 | } |