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": |
| 135 | case "90": |
| 136 | case "180": |
| 137 | case "270": |
| 138 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 139 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 140 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 141 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 142 | } else { |
| 143 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 144 | } |
| 145 | } |
| 146 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 147 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 148 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 149 | } |
| 150 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 151 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 152 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 153 | } |
| 154 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 155 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 156 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 157 | } |
| 158 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 159 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 160 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
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_WHITELIST_INPUT") != "" { |
| 164 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 165 | } |
| 166 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 167 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 168 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 169 | } |
| 170 | |
| 171 | return cflags |
| 172 | } |
| 173 | |
| 174 | func globalSrcs(ctx android.BaseContext) []string { |
| 175 | var srcs []string |
| 176 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 177 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 178 | srcs = append(srcs, "graphics_overlay.cpp") |
| 179 | } |
| 180 | |
| 181 | matches, err := filepath.Glob("system/core/adf/Android.*") |
| 182 | _ = matches |
| 183 | if err == nil { |
| 184 | srcs = append(srcs, "graphics_adf.cpp") |
| 185 | } |
| 186 | |
| 187 | matches, err = filepath.Glob("external/libdrm/Android.*") |
| 188 | if err == nil { |
| 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_INCLUDE_CRYPTO") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 202 | includes = append(includes, "bootable/recovery/crypto/fscrypt") |
| 203 | } |
| 204 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 205 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
| 206 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 207 | includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 208 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 209 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 210 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 211 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 212 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | } else { |
| 216 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 217 | } |
| 218 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 219 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 220 | includes = append(includes, "external/jpeg") |
| 221 | } |
| 222 | |
| 223 | return includes |
| 224 | } |
| 225 | |
| 226 | func globalStaticLibs(ctx android.BaseContext) []string { |
| 227 | var staticLibs []string |
| 228 | |
| 229 | matches, err := filepath.Glob("system/core/adf/Android.*") |
| 230 | _ = matches |
| 231 | if err == nil { |
| 232 | staticLibs = append(staticLibs, "libadf") |
| 233 | } |
| 234 | |
| 235 | matches, err = filepath.Glob("external/libdrm/Android.*") |
| 236 | if err == nil { |
| 237 | matches, err = filepath.Glob("external/libdrm/Android.common.mk") |
| 238 | if err != nil { |
| 239 | staticLibs = append(staticLibs, "libdrm_platform") |
| 240 | } else { |
| 241 | staticLibs = append(staticLibs, "libdrm") |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return staticLibs |
| 246 | } |
| 247 | |
| 248 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 249 | var sharedLibs []string |
| 250 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 251 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 252 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 253 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 254 | } |
| 255 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 256 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" { |
| 257 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-ndk_platform") |
| 258 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-cpp") |
| 259 | } |
| 260 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 261 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 262 | sharedLibs = append(sharedLibs, "libjpeg") |
| 263 | } |
| 264 | return sharedLibs |
| 265 | } |
| 266 | |
| 267 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 268 | var requiredModules []string |
| 269 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 270 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 271 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 272 | requiredModules = append(requiredModules, kernelDir) |
| 273 | } |
| 274 | return requiredModules |
| 275 | } |
| 276 | |
| 277 | func libMinuiTwrpDefaults(ctx android.LoadHookContext) { |
| 278 | type props struct { |
| 279 | Target struct { |
| 280 | Android struct { |
| 281 | Cflags []string |
| 282 | Enabled *bool |
| 283 | } |
| 284 | } |
| 285 | Cflags []string |
| 286 | Srcs []string |
| 287 | Include_dirs []string |
| 288 | Static_libs []string |
| 289 | Shared_libs []string |
| 290 | Required []string |
| 291 | } |
| 292 | |
| 293 | p := &props{} |
| 294 | p.Cflags = globalFlags(ctx) |
| 295 | s := globalSrcs(ctx) |
| 296 | p.Srcs = s |
| 297 | i := globalIncludes(ctx) |
| 298 | p.Include_dirs = i |
| 299 | staticLibs := globalStaticLibs(ctx) |
| 300 | p.Static_libs = staticLibs |
| 301 | sharedLibs := globalSharedLibs(ctx) |
| 302 | p.Shared_libs = sharedLibs |
| 303 | requiredModules := globalRequiredModules(ctx) |
| 304 | p.Required = requiredModules |
| 305 | ctx.AppendProperties(p) |
| 306 | } |
| 307 | |
| 308 | func init() { |
| 309 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 310 | } |
| 311 | |
| 312 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 313 | module := cc.DefaultsFactory() |
| 314 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 315 | |
| 316 | return module |
| 317 | } |