1cc = meson.get_compiler('c')
2
3conf = configuration_data()
4conf.set_quoted('PACKAGE_NAME', meson.project_name())
5conf.set_quoted('PACKAGE_VERSION', meson.project_version())
6conf.set_quoted('PACKAGE_STRING', '@0@-@1@'.format(meson.project_name(), meson.project_version()))
7conf.set_quoted('PACKAGE_DATADIR', gdict_datadir)
8conf.set_quoted('PACKAGE_LIBDIR', gdict_libdir)
9conf.set_quoted('PACKAGE_LOCALE_DIR', join_paths(gdict_datadir, 'locale'))
10conf.set_quoted('PACKAGE_LIBEXECDIR', gdict_libexecdir)
11conf.set('VERSION', 'PACKAGE_VERSION')
12conf.set('GETTEXT_PACKAGE', 'PACKAGE_NAME')
13conf.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
14conf.set10('ENABLE_NLS', true) # Always enabled
15conf.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
16
17# Compiler flags
18if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
19  test_cflags = [
20    '-fno-strict-aliasing',
21    '-Wno-c++11-extensions',
22    '-Wno-missing-include-dirs',
23    '-Wno-typedef-redefinition',
24    '-Wcast-align',
25    '-Wduplicated-branches',
26    '-Wduplicated-cond',
27    '-Wformat=2',
28    '-Wformat-nonliteral',
29    '-Wformat-security',
30    '-Wignored-qualifiers',
31    '-Wimplicit-function-declaration',
32    '-Wlogical-op',
33    '-Wmisleading-indentation',
34    '-Wmissing-format-attribute',
35    '-Wmissing-include-dirs',
36    '-Wmissing-noreturn',
37    '-Wnested-externs',
38    '-Wnull-dereference',
39    '-Wold-style-definition',
40    '-Wpointer-arith',
41    '-Wshadow',
42    '-Wstrict-prototypes',
43    '-Wundef',
44    '-Wuninitialized',
45    '-Wunused',
46    '-Werror=address',
47    '-Werror=array-bounds',
48    '-Werror=empty-body',
49    '-Werror=implicit',
50    '-Werror=implicit-fallthrough',
51    '-Werror=init-self',
52    '-Werror=int-to-pointer-cast',
53    '-Werror=main',
54    '-Werror=missing-braces',
55    '-Werror=missing-declarations',
56    '-Werror=missing-prototypes',
57    '-Werror=nonnull',
58    '-Werror=pointer-to-int-cast',
59    '-Werror=redundant-decls',
60    '-Werror=return-type',
61    '-Werror=sequence-point',
62    '-Werror=trigraphs',
63    '-Werror=vla',
64    '-Werror=write-strings',
65  ]
66else
67  test_cflags = []
68endif
69
70common_cflags = cc.get_supported_arguments(test_cflags)
71
72debug_cflags = []
73if debug
74  debug_cflags += '-DGDICT_ENABLE_DEBUG'
75elif optimization in ['2', '3', 's']
76  debug_cflags += '-DG_DISABLE_CAST_CHECKS'
77endif
78
79if buildtype == 'release'
80  debug_cflags += [ '-DG_DISABLE_ASSERT', '-DG_DISABLE_CHECKS', '-DG_DISABLE_CAST_CHECKS', ]
81endif
82
83ipv6_deps = []
84
85if use_ipv6
86  ipv6_prog = '''
87#include <sys/socket.h>
88#include <sys/types.h>
89
90int main (void) {
91  struct sockaddr_storage ss;
92  socket(AF_INET6, SOCK_STREAM, 0);
93  return 0;
94}
95  '''
96  has_ipv6 = cc.compiles(ipv6_prog, name: 'AF_INET6 is available')
97  has_getaddrinfo = cc.has_function('getaddrinfo')
98
99  # Look for getaddrinfo in all the known places
100  if not has_getaddrinfo
101    found_getaddrinfo = false
102    foreach l: [ 'bsd', 'socket', 'inet' ]
103      dep = cc.find_library(l, required: false)
104      if not found_getaddrinfo and dep.found()
105        has_getaddrinfo = cc.has_function('getaddrinfo', dependencies: dep)
106        if has_getaddrinfo
107          ipv6_deps += dep
108        endif
109      endif
110    endforeach
111  endif
112
113  use_ipv6 = has_ipv6 and has_getaddrinfo
114endif
115
116conf.set10('ENABLE_IPV6', use_ipv6)
117
118configure_file(output: 'config.h', configuration: conf)
119
120gdict_headers = [
121  'gdict-context.h',
122  'gdict-client-context.h',
123  'gdict-database-chooser.h',
124  'gdict-database-chooser-button.h',
125  'gdict-defbox.h',
126  'gdict-source-chooser.h',
127  'gdict-source-loader.h',
128  'gdict-source.h',
129  'gdict-speller.h',
130  'gdict-strategy-chooser.h',
131  'gdict-utils.h',
132]
133
134app_sources = [
135  'gdict-about.c',
136  'gdict-app.c',
137  'gdict-app.h',
138  'gdict-client-context.c',
139  'gdict-common.c',
140  'gdict-context.c',
141  'gdict-database-chooser.c',
142  'gdict-database-chooser-button.c',
143  'gdict-defbox.c',
144  'gdict-pref-dialog.c',
145  'gdict-print.c',
146  'gdict-sidebar.c',
147  'gdict-source-chooser.c',
148  'gdict-source-dialog.c',
149  'gdict-source-loader.c',
150  'gdict-source.c',
151  'gdict-speller.c',
152  'gdict-strategy-chooser.c',
153  'gdict-utils.c',
154  'gdict-window.c',
155  'main.c',
156]
157
158gdict_enums = gnome.mkenums('gdict-enum-types',
159  sources: gdict_headers,
160  h_template: 'gdict-enum-types.h.in',
161  c_template: 'gdict-enum-types.c.in',
162  install_header: false,
163)
164
165gdict_marshal = gnome.genmarshal('gdict-marshal',
166  sources: 'gdict-marshal.list',
167  prefix: 'gdict_marshal',
168)
169
170gdict_resources = gnome.compile_resources('gdict-resources',
171  'gdict.gresource.xml',
172  source_dir: '.',
173  c_name: 'gdict',
174)
175
176gdict_cflags = [
177  '-D_GNU_SOURCE',
178  '-DG_LOG_DOMAIN="Gdict"',
179  '-DG_LOG_USE_STRUCTURED=1',
180  '-DPREFIX="@0@"'.format(gdict_prefix),
181  '-DSYSCONFDIR="@0@"'.format(gdict_sysconfdir),
182  '-DLIBDIR="@0@"'.format(gdict_libdir),
183  '-DDATADIR="@0@"'.format(gdict_datadir),
184  '-DPKGDATADIR="@0@"'.format(join_paths(gdict_datadir, 'gnome-dictionary')),
185  '-DGNOMELOCALEDIR="@0@"'.format(join_paths(gdict_datadir, 'locale')),
186  '-DAPPLICATION_ID="@0@"'.format(application_id),
187  '-DGDICTSOURCESDIR="@0@"'.format(join_paths(gdict_datadir, 'gdict-1.0', 'sources')),
188  '-DGDICT_ENABLE_INTERNALS=1',
189  '-DGDICT_MAJOR_VERSION=@0@'.format(gdict_major_version),
190  '-DGDICT_MINOR_VERSION=@0@'.format(gdict_minor_version),
191  '-DGDICT_MICRO_VERSION=@0@'.format(gdict_micro_version),
192]
193
194if profile == 'devel' or gdict_is_devel
195  gdict_cflags += [
196    '-DDEVELOPMENT_BUILD',
197  ]
198endif
199
200mathlib = cc.find_library('m', required: false)
201
202gio_dep = dependency('gio-2.0', version: '>= 2.42.0')
203gtk_dep = dependency('gtk+-3.0', version: '>= 3.21.2')
204
205executable('gnome-dictionary',
206  sources: [ app_sources, gdict_enums, gdict_marshal, gdict_resources ],
207  c_args: [ common_cflags, debug_cflags, gdict_cflags ],
208  dependencies: [ gio_dep, gtk_dep, ipv6_deps, mathlib ],
209  install: true,
210)
211