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 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 14 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 15 | _ = matches |
| 16 | if err == nil { |
| 17 | cflags = append(cflags, "-DHAS_DRM") |
| 18 | } |
| 19 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 20 | var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 21 | |
| 22 | switch pixelFormat { |
| 23 | case "RGBA_8888": |
| 24 | fmt.Println("****************************************************************************)") |
| 25 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)") |
| 26 | fmt.Println("****************************************************************************)") |
| 27 | cflags = append(cflags, "-DRECOVERY_RGBA") |
| 28 | break |
| 29 | |
| 30 | case "RGBX_8888": |
| 31 | fmt.Println("****************************************************************************)") |
| 32 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)") |
| 33 | fmt.Println("****************************************************************************)") |
| 34 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 35 | break |
| 36 | |
| 37 | case "BGRA_8888": |
| 38 | fmt.Println("****************************************************************************)") |
| 39 | fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)") |
| 40 | fmt.Println("****************************************************************************)") |
| 41 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 42 | break |
| 43 | |
| 44 | case "RGB_565": |
| 45 | cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565") |
| 46 | break |
| 47 | } |
| 48 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 49 | pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 50 | switch pixelFormat { |
| 51 | case "ABGR_8888": |
| 52 | cflags = append(cflags, "-DRECOVERY_ABGR") |
| 53 | break |
| 54 | |
| 55 | case "RGBX_8888": |
| 56 | cflags = append(cflags, "-DRECOVERY_RGBX") |
| 57 | break |
| 58 | |
| 59 | case "BGRA_8888": |
| 60 | cflags = append(cflags, "-DRECOVERY_BGRA") |
| 61 | break |
| 62 | } |
| 63 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 64 | var tw_rotation = getMakeVars(ctx, "TW_ROTATION") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 65 | switch tw_rotation { |
| 66 | case "0": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 67 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 68 | case "90": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 69 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 70 | case "180": |
bigbiff | dd16123 | 2021-11-08 19:00:33 -0500 | [diff] [blame] | 71 | fallthrough |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 72 | case "270": |
| 73 | cflags = append(cflags, "-DTW_ROTATION="+tw_rotation) |
| 74 | default: |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 75 | if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 76 | cflags = append(cflags, "-DTW_ROTATION=180") |
| 77 | } else { |
| 78 | cflags = append(cflags, "-DTW_ROTATION=0") |
| 79 | } |
| 80 | } |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 81 | return cflags |
| 82 | } |
| 83 | |
| 84 | func globalSrcs(ctx android.BaseContext) []string { |
| 85 | var srcs []string |
| 86 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 87 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 88 | srcs = append(srcs, "graphics_overlay.cpp") |
| 89 | } |
| 90 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 91 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 92 | _ = matches |
| 93 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 94 | srcs = append(srcs, "graphics_drm.cpp") |
| 95 | } |
| 96 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 97 | if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 98 | srcs = append(srcs, "tspdrv.cpp") |
| 99 | } |
| 100 | return srcs |
| 101 | } |
| 102 | |
| 103 | func globalIncludes(ctx android.BaseContext) []string { |
| 104 | var includes []string |
| 105 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 106 | if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" { |
| 107 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 108 | includes = append(includes, getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 109 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 110 | if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 111 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 112 | } else { |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 113 | includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS")) |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } else { |
| 117 | includes = append(includes, "bootable/recovery/minuitwrp") |
| 118 | } |
| 119 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 120 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 121 | includes = append(includes, "external/jpeg") |
| 122 | } |
| 123 | |
| 124 | return includes |
| 125 | } |
| 126 | |
| 127 | func globalStaticLibs(ctx android.BaseContext) []string { |
| 128 | var staticLibs []string |
| 129 | |
nebrassy | 0c3533f | 2021-11-14 16:05:51 +0100 | [diff] [blame] | 130 | matches, err := filepath.Glob("external/libdrm/Android.*") |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 131 | _ = matches |
| 132 | if err == nil { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 133 | matches, err = filepath.Glob("external/libdrm/Android.common.mk") |
| 134 | if err != nil { |
| 135 | staticLibs = append(staticLibs, "libdrm_platform") |
| 136 | } else { |
| 137 | staticLibs = append(staticLibs, "libdrm") |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return staticLibs |
| 142 | } |
| 143 | |
| 144 | func globalSharedLibs(ctx android.BaseContext) []string { |
| 145 | var sharedLibs []string |
| 146 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 147 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 148 | sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2") |
| 149 | sharedLibs = append(sharedLibs, "libhidlbase") |
| 150 | } |
| 151 | |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 152 | if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" { |
Woomymy | fb8aff5 | 2022-08-03 18:34:59 +0200 | [diff] [blame] | 153 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-ndk_platform") |
| 154 | sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-cpp") |
nebrassy | 76224bd | 2021-04-05 11:52:44 +0200 | [diff] [blame] | 155 | } |
| 156 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 157 | if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" { |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 158 | sharedLibs = append(sharedLibs, "libjpeg") |
| 159 | } |
| 160 | return sharedLibs |
| 161 | } |
| 162 | |
| 163 | func globalRequiredModules(ctx android.BaseContext) []string { |
| 164 | var requiredModules []string |
| 165 | |
bigbiff | 6e0ca7d | 2021-02-06 19:15:16 -0500 | [diff] [blame] | 166 | if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" { |
| 167 | var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr" |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 168 | requiredModules = append(requiredModules, kernelDir) |
| 169 | } |
| 170 | return requiredModules |
| 171 | } |
| 172 | |
| 173 | func libMinuiTwrpDefaults(ctx android.LoadHookContext) { |
| 174 | type props struct { |
| 175 | Target struct { |
| 176 | Android struct { |
| 177 | Cflags []string |
| 178 | Enabled *bool |
| 179 | } |
| 180 | } |
| 181 | Cflags []string |
| 182 | Srcs []string |
| 183 | Include_dirs []string |
| 184 | Static_libs []string |
| 185 | Shared_libs []string |
| 186 | Required []string |
| 187 | } |
| 188 | |
| 189 | p := &props{} |
| 190 | p.Cflags = globalFlags(ctx) |
| 191 | s := globalSrcs(ctx) |
| 192 | p.Srcs = s |
| 193 | i := globalIncludes(ctx) |
| 194 | p.Include_dirs = i |
| 195 | staticLibs := globalStaticLibs(ctx) |
| 196 | p.Static_libs = staticLibs |
| 197 | sharedLibs := globalSharedLibs(ctx) |
| 198 | p.Shared_libs = sharedLibs |
| 199 | requiredModules := globalRequiredModules(ctx) |
| 200 | p.Required = requiredModules |
| 201 | ctx.AppendProperties(p) |
| 202 | } |
| 203 | |
| 204 | func init() { |
| 205 | android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory) |
| 206 | } |
| 207 | |
| 208 | func libMinuiTwrpDefaultsFactory() android.Module { |
| 209 | module := cc.DefaultsFactory() |
| 210 | android.AddLoadHook(module, libMinuiTwrpDefaults) |
| 211 | |
| 212 | return module |
| 213 | } |