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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 18 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 19 | cflags = append(cflags, "-DMSM_BSP") |
| 20 | } |
| 21 | |
| 22 | matches, err := filepath.Glob("system/core/adf/Android.*") |
| 23 | _ = matches |
| 24 | if err == nil { |
| 25 | cflags = append(cflags, "-DHAS_ADF") |
| 26 | } |
| 27 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 28 | if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 29 | cflags = append(cflags, "-DNEW_ION_HEAP") |
| 30 | } |
| 31 | |
| 32 | matches, err = filepath.Glob("external/libdrm/Android.*") |
| 33 | _ = matches |
| 34 | if err == nil { |
| 35 | cflags = append(cflags, "-DHAS_DRM") |
| 36 | } |
| 37 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 38 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 39 | cflags = append(cflags, "-DTW_INCLUDE_JPEG") |
| 40 | } |
| 41 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 42 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 43 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY") |
| 44 | } |
| 45 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 46 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 47 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X") |
| 48 | } |
| 49 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 50 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 51 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y") |
| 52 | } |
| 53 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 54 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 55 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") |
| 56 | } |
| 57 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 58 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 59 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") |
| 60 | } |
| 61 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 62 | if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 63 | cflags = append(cflags, "-D_EVENT_LOGGING") |
| 64 | } |
| 65 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 66 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 67 | |
| 68 | switch pixelFormat { |
| 69 | case "RGBA_8888": |
| 70 | fmt.Println("****************************************************************************)") |
| 71 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)") |
| 72 | fmt.Println("****************************************************************************)") |
| 73 | cflags = append(cflags, "-DRECOVERY_RGBA") |
| 74 | break |
| 75 | |
| 76 | case "RGBX_8888": |
| 77 | fmt.Println("****************************************************************************)") |
| 78 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)") |
| 79 | fmt.Println("****************************************************************************)") |
| 80 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 81 | break |
| 82 | |
| 83 | case "BGRA_8888": |
| 84 | fmt.Println("****************************************************************************)") |
| 85 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)") |
| 86 | fmt.Println("****************************************************************************)") |
| 87 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 88 | break |
| 89 | |
| 90 | case "RGB_565": |
| 91 | cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565") |
| 92 | break |
| 93 | } |
| 94 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 95 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 96 | switch pixelFormat { |
| 97 | case "ABGR_8888": |
| 98 | cflags = append(cflags, "-DRECOVERY_ABGR") |
| 99 | break |
| 100 | |
| 101 | case "RGBX_8888": |
| 102 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 103 | break |
| 104 | |
| 105 | case "BGRA_8888": |
| 106 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 107 | break |
| 108 | } |
| 109 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 110 | if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" { |
| 111 | cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 112 | } else { |
| 113 | cflags = append(cflags, "-DOVERSCAN_PERCENT=0") |
| 114 | } |
| 115 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 116 | if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 117 | cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT") |
| 118 | } |
| 119 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 120 | if getMakeVars(ctx, "TW_FBIOPAN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 121 | cflags = append(cflags, "-DTW_FBIOPAN") |
| 122 | } |
| 123 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 124 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 125 | switch tw_rotation { |
| 126 | case "0": |
| 127 | case "90": |
| 128 | case "180": |
| 129 | case "270": |
| 130 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 131 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 132 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 133 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 134 | } else { |
| 135 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 136 | } |
| 137 | } |
| 138 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 139 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 140 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 141 | } |
| 142 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 143 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 144 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 145 | } |
| 146 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 147 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 148 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 149 | } |
| 150 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 151 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 152 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 153 | } |
| 154 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 155 | if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" { |
| 156 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
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_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 160 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 161 | } |
| 162 | |
| 163 | return cflags |
| 164 | } |
| 165 | |
| 166 | func globalSrcs(ctx android.BaseContext) []string { |
| 167 | var srcs []string |
| 168 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 169 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 170 | srcs = append(srcs, "graphics_overlay.cpp") |
| 171 | } |
| 172 | |
| 173 | matches, err := filepath.Glob("system/core/adf/Android.*") |
| 174 | _ = matches |
| 175 | if err == nil { |
| 176 | srcs = append(srcs, "graphics_adf.cpp") |
| 177 | } |
| 178 | |
| 179 | matches, err = filepath.Glob("external/libdrm/Android.*") |
| 180 | if err == nil { |
| 181 | srcs = append(srcs, "graphics_drm.cpp") |
| 182 | } |
| 183 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 184 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 185 | srcs = append(srcs, "tspdrv.cpp") |
| 186 | } |
| 187 | return srcs |
| 188 | } |
| 189 | |
| 190 | func globalIncludes(ctx android.BaseContext) []string { |
| 191 | var includes []string |
| 192 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 193 | if getMakeVars(ctx, "TW_INCLUDE_CRYPTO") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 194 | includes = append(includes, "bootable/recovery/crypto/fscrypt") |
| 195 | } |
| 196 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 197 | 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") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 200 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 201 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 202 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 203 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 204 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | } else { |
| 208 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 209 | } |
| 210 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 211 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 212 | includes = append(includes, "external/jpeg") |
| 213 | } |
| 214 | |
| 215 | return includes |
| 216 | } |
| 217 | |
| 218 | func globalStaticLibs(ctx android.BaseContext) []string { |
| 219 | var staticLibs []string |
| 220 | |
| 221 | matches, err := filepath.Glob("system/core/adf/Android.*") |
| 222 | _ = matches |
| 223 | if err == nil { |
| 224 | staticLibs = append(staticLibs, "libadf") |
| 225 | } |
| 226 | |
| 227 | matches, err = filepath.Glob("external/libdrm/Android.*") |
| 228 | if err == nil { |
| 229 | matches, err = filepath.Glob("external/libdrm/Android.common.mk") |
| 230 | if err != nil { |
| 231 | staticLibs = append(staticLibs, "libdrm_platform") |
| 232 | } else { |
| 233 | staticLibs = append(staticLibs, "libdrm") |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return staticLibs |
| 238 | } |
| 239 | |
| 240 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 241 | var sharedLibs []string |
| 242 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 243 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 244 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 245 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 246 | } |
| 247 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 248 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 249 | sharedLibs = append(sharedLibs, "libjpeg") |
| 250 | } |
| 251 | return sharedLibs |
| 252 | } |
| 253 | |
| 254 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 255 | var requiredModules []string |
| 256 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 257 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 258 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 259 | requiredModules = append(requiredModules, kernelDir) |
| 260 | } |
| 261 | return requiredModules |
| 262 | } |
| 263 | |
| 264 | func 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 | |
| 295 | func init() { |
| 296 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 297 | } |
| 298 | |
| 299 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 300 | module := cc.DefaultsFactory() |
| 301 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 302 | |
| 303 | return module |
| 304 | } |