-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeson.build
191 lines (176 loc) · 7.35 KB
/
meson.build
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Copyright (c) 2021-2022, 2024-2025
# Guilherme Janczak <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
project('dictpw', 'c', version: '1.3.0', license: 'ISC',
default_options: ['c_std=c99', 'warning_level=3'],
meson_version: '>=1.4.0')
# Makes all functions, including BSD functions, visible on GNU.
args = ['-D_GNU_SOURCE']
cc = meson.get_compiler('c')
# Spectre mitigations are off by default under MSVC for some ungodly reason.
args += cc.get_supported_arguments('/Qspectre')
if host_machine.system() == 'windows'
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/multithreaded-libraries-performance?view=msvc-170#maximizing-performance
args += '-D_CRT_DISABLE_PERFCRIT_LOCKS'
endif
add_project_arguments(args, language: 'c')
subdir('compat')
funcs = {
'arc4random_uniform': '#include <stdlib.h>',
'errx': '#include <err.h>',
'getprogname': '#include <stdlib.h>',
'strtonum': '#include <stdlib.h>',
'warnx': '#include <err.h>',
}
libbsd_dep = dependency('', required: false)
foreach func, header : funcs
if not cc.has_function(func, prefix: header, args: args)
libbsd_dep = dependency('libbsd-overlay',
default_options: 'default_library=static')
break
endif
endforeach
# Force subproject to be included by `meson dist --include-subprojects`
if get_option('release')
subproject('libobsd')
endif
gen_dict = executable('gen_dict',
'src/gen_dict.c',
native: true)
gen_dict_h = custom_target('gen_dict',
output: 'gen_dict.h',
capture: true,
input: get_option('dict'),
feed: true,
depend_files: get_option('dict'),
command: gen_dict)
dictpw = executable('dictpw',
'src/dict.c',
'src/dictpw.c',
caps_c,
gen_dict_h,
install: true,
dependencies: libbsd_dep,
include_directories: incdir,
win_subsystem: 'console')
subdir('test')
install_man('src/dictpw.1')
if not ['windows', 'cygwin'].contains(host_machine.system())
if not get_option('installer').auto()
error('The \'installer\' feature is only for Windows hosts.')
endif
else
# Build a .txt version of the manual too. For producing the installer.
unix2dos = find_program('unix2dos')
# Convert Unix newlines to DOS newlines.
# Put copies of the license and the README with DOS newlines in the build
# directory too.
license = custom_target('license',
command: [unix2dos],
input: ['LICENSE.md'],
feed: true,
output: ['LICENSE.txt'],
capture: true,
build_by_default: true)
readme = custom_target('readme',
command: [unix2dos],
input: ['README.md'],
feed: true,
output: ['README.txt'],
capture: true,
build_by_default: true)
if get_option('installer').allowed()
# Create groff IR version of the manual.
man_groff = custom_target('man_groff',
command: [find_program('groff'), '-mdoc',
'-Tascii', '-Z'],
input: [files('src/dictpw.1')],
feed: true,
output: ['dictpw.groff'],
capture: true)
# Convert groff to ASCII with Unix newlines.
# '-bcou' means "don't use ANSI escapes".
man_unix = custom_target('man_unix',
command: [find_program('grotty'), '-bcou'],
input: [man_groff],
feed: true,
output: ['dictpw.txt.unix'],
capture: true)
man = custom_target('man',
command: [unix2dos],
input: [man_unix],
feed: true,
output: ['dictpw.txt'],
capture: true,
build_by_default: true)
inst_cmd = [find_program('iscc'),
'-DBUILDDIR=' + meson.current_build_dir(),
'-Fsetup-dictpw',
'-DMESON',
'-DNAME=' + meson.project_name(),
'-DVERSION=' + meson.project_version(),
'-DURL=https://github.com/guijan/dictpw',
'-DEXEFILE=' + dictpw.full_path(),
'-DLICENSE=' + license.full_path(),
'-DMANFILE=' + man.full_path(),
'-DREADME=' + readme.full_path()]
fs = import('fs')
if libbsd_dep.found() and libbsd_dep.type_name() == 'internal'
# Meson doesn't have a way to pass files from subprojects, so we work
# around it by passing the filename of a known location.
inst_cmd += '-DLIBOBSD_LICENSE=subprojects/libobsd/LICENSE_libobsd.txt'
endif
# Cygwin and MSYS environment programs are linked against a special DLL
# with their implementations of Unix inside, distribute it.
dll_copy = []
if host_machine.system() == 'cygwin'
dlls = ['/usr/bin/msys-2.0.dll', '/bin/cygwin1.dll']
found = false
foreach dll : dlls
if fs.is_file(dll)
dll_copy += fs.copyfile(dll)
inst_cmd += '-DMSYS_DLL=' + fs.name(dll)
found = true
break
endif
endforeach
if not found
error('cygwin/msys2 DLL not found')
endif
endif
# Mapping between:
# https://mesonbuild.com/Reference-tables.html
# https://jrsoftware.org/ishelp/index.php?topic=archidentifiers
meson_to_iscc_arch = {
'arm': 'arm32compatible',
'aarch64': 'arm64',
'x86_64': 'x64compatible',
'x86': 'x86compatible'
}
inst_cmd += '-DARCH=' + meson_to_iscc_arch[host_machine.cpu_family()]
if cc.get_id() == 'msvc'
# https://learn.microsoft.com/en-us/visualstudio/releases/2022/compatibility#build-apps-that-run-on-windows-clients
winmin = '6.1sp1'
else
# https://www.msys2.org/docs/windows_support/
# Minimum package requirement, not minimum toolchain requirement, I'm not
# going to bother figuring out which is right, so use the highest one.
winmin = '6.3'
endif
inst_cmd += '-DWIN_MIN=' + winmin
run_target('installer',
command: inst_cmd + files('src/dictpw.iss'),
depends: [dictpw, man, license, readme, dll_copy])
endif
endif