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 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 30 | if getMakeVars(ctx, "TW_NEW_ION_HEAP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 31 | cflags = append(cflags, "-DNEW_ION_HEAP") |
| 32 | } |
| 33 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 34 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 35 | _ = matches |
| 36 | if err == nil { |
| 37 | cflags = append(cflags, "-DHAS_DRM") |
| 38 | } |
| 39 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 40 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 41 | cflags = append(cflags, "-DTW_INCLUDE_JPEG") |
| 42 | } |
| 43 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 44 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 45 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY") |
| 46 | } |
| 47 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 48 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_X") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 49 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X") |
| 50 | } |
| 51 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 52 | if getMakeVars(ctx, "RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 53 | cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y") |
| 54 | } |
| 55 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 56 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 57 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") |
| 58 | } |
| 59 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 60 | if getMakeVars(ctx, "RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 61 | cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") |
| 62 | } |
| 63 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 64 | if getMakeVars(ctx, "TWRP_EVENT_LOGGING") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 65 | cflags = append(cflags, "-D_EVENT_LOGGING") |
| 66 | } |
| 67 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 68 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 69 | |
| 70 | switch pixelFormat { |
| 71 | case "RGBA_8888": |
| 72 | fmt.Println("****************************************************************************)") |
| 73 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)") |
| 74 | fmt.Println("****************************************************************************)") |
| 75 | cflags = append(cflags, "-DRECOVERY_RGBA") |
| 76 | break |
| 77 | |
| 78 | case "RGBX_8888": |
| 79 | fmt.Println("****************************************************************************)") |
| 80 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)") |
| 81 | fmt.Println("****************************************************************************)") |
| 82 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 83 | break |
| 84 | |
| 85 | case "BGRA_8888": |
| 86 | fmt.Println("****************************************************************************)") |
| 87 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)") |
| 88 | fmt.Println("****************************************************************************)") |
| 89 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 90 | break |
| 91 | |
| 92 | case "RGB_565": |
| 93 | cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565") |
| 94 | break |
| 95 | } |
| 96 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 97 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 98 | switch pixelFormat { |
| 99 | case "ABGR_8888": |
| 100 | cflags = append(cflags, "-DRECOVERY_ABGR") |
| 101 | break |
| 102 | |
| 103 | case "RGBX_8888": |
| 104 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 105 | break |
| 106 | |
| 107 | case "BGRA_8888": |
| 108 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 109 | break |
| 110 | } |
| 111 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 112 | if getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT") != "" { |
| 113 | cflags = append(cflags, "-DDOVERSCAN_PERCENT="+getMakeVars(ctx, "TARGET_RECOVERY_OVERSCAN_PERCENT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 114 | } else { |
| 115 | cflags = append(cflags, "-DOVERSCAN_PERCENT=0") |
| 116 | } |
| 117 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 118 | if getMakeVars(ctx, "TW_SCREEN_BLANK_ON_BOOT") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 119 | cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT") |
| 120 | } |
| 121 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 122 | if getMakeVars(ctx, "TW_FBIOPAN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 123 | cflags = append(cflags, "-DTW_FBIOPAN") |
| 124 | } |
| 125 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 126 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 127 | switch tw_rotation { |
| 128 | case "0": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 129 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 130 | case "90": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 131 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 132 | case "180": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 133 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 134 | case "270": |
| 135 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 136 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 137 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 138 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 139 | } else { |
| 140 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 141 | } |
| 142 | } |
| 143 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 144 | if getMakeVars(ctx, "TW_IGNORE_MAJOR_AXIS_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 145 | cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0") |
| 146 | } |
| 147 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 148 | if getMakeVars(ctx, "TW_IGNORE_MT_POSITION_0") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 149 | cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0") |
| 150 | } |
| 151 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 152 | if getMakeVars(ctx, "TW_IGNORE_ABS_MT_TRACKING_ID") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 153 | cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID") |
| 154 | } |
| 155 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 156 | if getMakeVars(ctx, "TW_INPUT_BLACKLIST") != "" { |
| 157 | cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+getMakeVars(ctx, "TW_INPUT_BLACKLIST")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 158 | } |
| 159 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 160 | if getMakeVars(ctx, "TW_WHITELIST_INPUT") != "" { |
| 161 | cflags = append(cflags, "-DWHITELIST_INPUT="+getMakeVars(ctx, "TW_WHITELIST_INPUT")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 162 | } |
| 163 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 164 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 165 | cflags = append(cflags, "-DTW_HAPTICS_TSPDRV") |
| 166 | } |
| 167 | |
| 168 | return cflags |
| 169 | } |
| 170 | |
| 171 | func globalSrcs(ctx android.BaseContext) []string { |
| 172 | var srcs []string |
| 173 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 174 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 175 | srcs = append(srcs, "graphics_overlay.cpp") |
| 176 | } |
| 177 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 178 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 179 | _ = matches |
| 180 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 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_TARGET_USES_QCOM_BSP") == "true" { |
| 194 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 195 | includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 196 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 197 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 198 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 199 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 200 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | } else { |
| 204 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 205 | } |
| 206 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 207 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 208 | includes = append(includes, "external/jpeg") |
| 209 | } |
| 210 | |
| 211 | return includes |
| 212 | } |
| 213 | |
| 214 | func globalStaticLibs(ctx android.BaseContext) []string { |
| 215 | var staticLibs []string |
| 216 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 217 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 218 | _ = matches |
| 219 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 220 | matches, err = filepath.Glob("external/libdrm/Android.common.mk") |
| 221 | if err != nil { |
| 222 | staticLibs = append(staticLibs, "libdrm_platform") |
| 223 | } else { |
| 224 | staticLibs = append(staticLibs, "libdrm") |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return staticLibs |
| 229 | } |
| 230 | |
| 231 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 232 | var sharedLibs []string |
| 233 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 234 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 235 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 236 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 237 | } |
| 238 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 239 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" { |
nebrassy | 204e36e | 2021-11-14 23:27:51 +0100 | [diff] [blame] | 240 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-ndk_platform") |
| 241 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V1-cpp") |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 242 | } |
| 243 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 244 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 245 | sharedLibs = append(sharedLibs, "libjpeg") |
| 246 | } |
| 247 | return sharedLibs |
| 248 | } |
| 249 | |
| 250 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 251 | var requiredModules []string |
| 252 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 253 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 254 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 255 | requiredModules = append(requiredModules, kernelDir) |
| 256 | } |
| 257 | return requiredModules |
| 258 | } |
| 259 | |
| 260 | func libMinuiTwrpDefaults(ctx android.LoadHookContext) { |
| 261 | type props struct { |
| 262 | Target struct { |
| 263 | Android struct { |
| 264 | Cflags []string |
| 265 | Enabled *bool |
| 266 | } |
| 267 | } |
| 268 | Cflags []string |
| 269 | Srcs []string |
| 270 | Include_dirs []string |
| 271 | Static_libs []string |
| 272 | Shared_libs []string |
| 273 | Required []string |
| 274 | } |
| 275 | |
| 276 | p := &props{} |
| 277 | p.Cflags = globalFlags(ctx) |
| 278 | s := globalSrcs(ctx) |
| 279 | p.Srcs = s |
| 280 | i := globalIncludes(ctx) |
| 281 | p.Include_dirs = i |
| 282 | staticLibs := globalStaticLibs(ctx) |
| 283 | p.Static_libs = staticLibs |
| 284 | sharedLibs := globalSharedLibs(ctx) |
| 285 | p.Shared_libs = sharedLibs |
| 286 | requiredModules := globalRequiredModules(ctx) |
| 287 | p.Required = requiredModules |
| 288 | ctx.AppendProperties(p) |
| 289 | } |
| 290 | |
| 291 | func init() { |
| 292 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 293 | } |
| 294 | |
| 295 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 296 | module := cc.DefaultsFactory() |
| 297 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 298 | |
| 299 | return module |
| 300 | } |