blob: 8c738c5300679416845a96252f60c283f30ca7f9 [file] [log] [blame]
bigbiffd81833a2021-01-17 11:06:57 -05001package twrp
2
3import (
4 "android/soong/android"
5 "android/soong/cc"
6 "fmt"
7 "path/filepath"
8 "strings"
9)
10
11func globalFlags(ctx android.BaseContext) []string {
12 var cflags []string
13
nebrassy0c3533f2021-11-14 16:05:51 +010014 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -050015 _ = matches
16 if err == nil {
17 cflags = append(cflags, "-DHAS_DRM")
18 }
19
bigbiff6e0ca7d2021-02-06 19:15:16 -050020 var pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050021
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
bigbiff6e0ca7d2021-02-06 19:15:16 -050049 pixelFormat = strings.Replace(getMakeVars(ctx, "TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
bigbiffd81833a2021-01-17 11:06:57 -050050 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
bigbiff6e0ca7d2021-02-06 19:15:16 -050064 var tw_rotation = getMakeVars(ctx, "TW_ROTATION")
bigbiffd81833a2021-01-17 11:06:57 -050065 switch tw_rotation {
66 case "0":
bigbiffdd161232021-11-08 19:00:33 -050067 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -050068 case "90":
bigbiffdd161232021-11-08 19:00:33 -050069 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -050070 case "180":
bigbiffdd161232021-11-08 19:00:33 -050071 fallthrough
bigbiffd81833a2021-01-17 11:06:57 -050072 case "270":
73 cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
74 default:
bigbiff6e0ca7d2021-02-06 19:15:16 -050075 if getMakeVars(ctx, "BOARD_HAS_FLIPPED_SCREEN") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050076 cflags = append(cflags, "-DTW_ROTATION=180")
77 } else {
78 cflags = append(cflags, "-DTW_ROTATION=0")
79 }
80 }
bigbiffd81833a2021-01-17 11:06:57 -050081 return cflags
82}
83
84func globalSrcs(ctx android.BaseContext) []string {
85 var srcs []string
86
bigbiff6e0ca7d2021-02-06 19:15:16 -050087 if getMakeVars(ctx, "TW_TARGET_USES_QCOM_BSP") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050088 srcs = append(srcs, "graphics_overlay.cpp")
89 }
90
nebrassy0c3533f2021-11-14 16:05:51 +010091 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -050092 _ = matches
93 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -050094 srcs = append(srcs, "graphics_drm.cpp")
95 }
96
bigbiff6e0ca7d2021-02-06 19:15:16 -050097 if getMakeVars(ctx, "TW_HAPTICS_TSPDRV") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -050098 srcs = append(srcs, "tspdrv.cpp")
99 }
100 return srcs
101}
102
103func globalIncludes(ctx android.BaseContext) []string {
104 var includes []string
105
bigbiff6e0ca7d2021-02-06 19:15:16 -0500106 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")
bigbiffd81833a2021-01-17 11:06:57 -0500109 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500110 if getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500111 includes = append(includes, "bootable/recovery/minuitwrp")
112 } else {
bigbiff6e0ca7d2021-02-06 19:15:16 -0500113 includes = append(includes, getMakeVars(ctx, "TARGET_CUSTOM_KERNEL_HEADERS"))
bigbiffd81833a2021-01-17 11:06:57 -0500114 }
115 }
116 } else {
117 includes = append(includes, "bootable/recovery/minuitwrp")
118 }
119
bigbiff6e0ca7d2021-02-06 19:15:16 -0500120 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500121 includes = append(includes, "external/jpeg")
122 }
123
124 return includes
125}
126
127func globalStaticLibs(ctx android.BaseContext) []string {
128 var staticLibs []string
129
nebrassy0c3533f2021-11-14 16:05:51 +0100130 matches, err := filepath.Glob("external/libdrm/Android.*")
bigbiffd81833a2021-01-17 11:06:57 -0500131 _ = matches
132 if err == nil {
bigbiffd81833a2021-01-17 11:06:57 -0500133 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
144func globalSharedLibs(ctx android.BaseContext) []string {
145 var sharedLibs []string
146
bigbiff6e0ca7d2021-02-06 19:15:16 -0500147 if getMakeVars(ctx, "TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
bigbiffd81833a2021-01-17 11:06:57 -0500148 sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
149 sharedLibs = append(sharedLibs, "libhidlbase")
150 }
151
nebrassy76224bd2021-04-05 11:52:44 +0200152 if getMakeVars(ctx, "TW_SUPPORT_INPUT_AIDL_HAPTICS") == "true" {
Woomymyfb8aff52022-08-03 18:34:59 +0200153 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-ndk_platform")
154 sharedLibs = append(sharedLibs, "android.hardware.vibrator-V2-cpp")
nebrassy76224bd2021-04-05 11:52:44 +0200155 }
156
bigbiff6e0ca7d2021-02-06 19:15:16 -0500157 if getMakeVars(ctx, "TW_INCLUDE_JPEG") != "" {
bigbiffd81833a2021-01-17 11:06:57 -0500158 sharedLibs = append(sharedLibs, "libjpeg")
159 }
160 return sharedLibs
161}
162
163func globalRequiredModules(ctx android.BaseContext) []string {
164 var requiredModules []string
165
bigbiff6e0ca7d2021-02-06 19:15:16 -0500166 if getMakeVars(ctx, "TARGET_PREBUILT_KERNEL") != "" {
167 var kernelDir = getMakeVars(ctx, "TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
bigbiffd81833a2021-01-17 11:06:57 -0500168 requiredModules = append(requiredModules, kernelDir)
169 }
170 return requiredModules
171}
172
173func 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
204func init() {
205 android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
206}
207
208func libMinuiTwrpDefaultsFactory() android.Module {
209 module := cc.DefaultsFactory()
210 android.AddLoadHook(module, libMinuiTwrpDefaults)
211
212 return module
213}