summaryrefslogtreecommitdiff
path: root/android/meson.build
blob: ddd3f030cbefac7347d14e8af860efd0996abcb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
android_package = 'org.musicpd'
android_package_path = join_paths(android_package.split('.'))

android_ndk = get_option('android_ndk')
android_sdk = get_option('android_sdk')
android_abi = get_option('android_abi')

android_sdk_build_tools_version = '27.0.0'
android_sdk_platform = 'android-21'

android_build_tools_dir = join_paths(android_sdk, 'build-tools', android_sdk_build_tools_version)
android_sdk_platform_dir = join_paths(android_sdk, 'platforms', android_sdk_platform)

android_aidl = join_paths(android_build_tools_dir, 'aidl')
android_aapt = join_paths(android_build_tools_dir, 'aapt')
android_dx = join_paths(android_build_tools_dir, 'dx')
android_zipalign = join_paths(android_build_tools_dir, 'zipalign')

javac = find_program('javac')
jarsigner = find_program('jarsigner')
rsvg_convert = find_program('rsvg-convert')
convert = find_program('convert')
zip = find_program('zip')

common_cppflags += '-I' + join_paths(meson.current_build_dir(), 'include')

#
# AIDL
#

IMainCallback_java = custom_target(
  'IMainCallback.java',
  output: 'IMainCallback.java',
  input: join_paths(meson.current_source_dir(), 'src', 'IMainCallback.aidl'),
  command: [
    join_paths(meson.current_source_dir(), 'run-aidl.sh'),
    android_aidl,
    '@INPUT@',
    '@OUTPUT@',
    join_paths(meson.current_build_dir(), 'src'),
    android_package_path,
  ],
)

IMain_java = custom_target(
  'IMain.java',
  output: 'IMain.java',
  input: join_paths(meson.current_source_dir(), 'src', 'IMain.aidl'),
  depends: IMainCallback_java,
  command: [
    join_paths(meson.current_source_dir(), 'run-aidl.sh'),
    android_aidl,
    '@INPUT@',
    '@OUTPUT@',
    join_paths(meson.current_build_dir(), 'src'),
    android_package_path,
  ],
)

#
# Resources
#

android_icon = custom_target(
  'Android icon',
  output: 'icon.png',
  input: '../mpd.svg',
  command: [
    rsvg_convert, '--width=48', '--height=48', '@INPUT@', '-o', '@OUTPUT@',
  ],
)

android_notification_icon = custom_target(
  'Android notification icon',
  output: 'notification_icon.png',
  input: android_icon,
  command: [
    convert, '@INPUT@', '-colorspace', 'Gray', '-gamma', '2.2', '@OUTPUT@',
  ],
)

resources_apk = custom_target(
  'resources.apk',
  output: ['resources.apk', 'R.java'],
  input: [
    'res/layout/custom_notification_gb.xml',
    'res/layout/log_item.xml',
    'res/layout/settings.xml',
    'res/values/strings.xml',
    android_icon,
    android_notification_icon,
  ],
  command: [
    join_paths(meson.current_source_dir(), 'make-resources-apk.sh'),
    android_aapt,
    join_paths(android_sdk_platform_dir, 'android.jar'),
    android_package,
    android_package_path,
    '@OUTPUT0@',
  ],
)

#
# Compile Java
#

classes_jar = custom_target(
  'classes.jar',
  output: 'classes.jar',
  input: [
    'src/Bridge.java',
    'src/Loader.java',
    'src/Main.java',
    'src/Receiver.java',
    'src/Settings.java',
    IMain_java,
    IMainCallback_java,
    resources_apk[1],
  ],
  command: [
    join_paths(meson.current_source_dir(), 'run-javac.sh'),
    javac,
    join_paths(android_sdk_platform_dir, 'android.jar'),
    android_package_path,
    zip,
    '@OUTPUT@',
    '@INPUT@',
  ],
)

classes_dex = custom_target(
  'classes.dex',
  output: 'classes.dex',
  input: classes_jar,
  command: [
    android_dx,
    '--dex', '--output', '@OUTPUT@',
    '@INPUT@',
  ],
)