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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 22 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 23 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 32 | if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 33 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 42 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 43 | cflags = append(cflags, "-DTW_INCLUDE_JPEG") |
| 44 | } |
| 45 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 46 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 47 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY") |
| 48 | } |
| 49 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 50 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 51 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X") |
| 52 | } |
| 53 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 54 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 55 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y") |
| 56 | } |
| 57 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 58 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 59 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") |
| 60 | } |
| 61 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 62 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 63 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") |
| 64 | } |
| 65 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 66 | if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 67 | cflags = append(cflags, "-D_EVENT_LOGGING") |
| 68 | } |
| 69 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 70 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 71 | |
| 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 99 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 100 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 114 | if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" { |
| 115 | cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 116 | } else { |
| 117 | cflags = append(cflags, "-DOVERSCAN_PERCENT=0") |
| 118 | } |
| 119 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 120 | if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 121 | cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT") |
| 122 | } |
| 123 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 124 | if getMakeVars(ctx, "TW_FBIOPAN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 125 | cflags = append(cflags, "-DTW_FBIOPAN") |
| 126 | } |
| 127 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 128 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 129 | 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: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 136 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 137 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 138 | } else { |
| 139 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 140 | } |
| 141 | } |
| 142 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 143 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 144 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 145 | } |
| 146 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 147 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 148 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 149 | } |
| 150 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 151 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 152 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 153 | } |
| 154 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 155 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 156 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 157 | } |
| 158 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 159 | if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" { |
| 160 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 161 | } |
| 162 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 163 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 164 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 165 | } |
| 166 | |
| 167 | return cflags |
| 168 | } |
| 169 | |
| 170 | func globalSrcs(ctx android.BaseContext) []string { |
| 171 | var srcs []string |
| 172 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 173 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 174 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 188 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 189 | srcs = append(srcs, "tspdrv.cpp") |
| 190 | } |
| 191 | return srcs |
| 192 | } |
| 193 | |
| 194 | func globalIncludes(ctx android.BaseContext) []string { |
| 195 | var includes []string |
| 196 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 197 | if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 198 | includes = append(includes, "bootable/recovery/crypto/fscrypt") |
| 199 | } |
| 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 | |
| 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 | |
| 244 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 245 | var sharedLibs []string |
| 246 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 247 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 248 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 249 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 250 | } |
| 251 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 252 | 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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 257 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 258 | sharedLibs = append(sharedLibs, "libjpeg") |
| 259 | } |
| 260 | return sharedLibs |
| 261 | } |
| 262 | |
| 263 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 264 | var requiredModules []string |
| 265 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 266 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 267 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 268 | requiredModules = append(requiredModules, kernelDir) |
| 269 | } |
| 270 | return requiredModules |
| 271 | } |
| 272 | |
| 273 | func 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 | |
| 304 | func init() { |
| 305 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 306 | } |
| 307 | |
| 308 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 309 | module := cc.DefaultsFactory() |
| 310 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 311 | |
| 312 | return module |
| 313 | } |