-
Notifications
You must be signed in to change notification settings - Fork 1
/
meson.build
163 lines (148 loc) · 6.36 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
# Copyright (c) 2021-2022, 2024 Guilherme Janczak <guilherme.janczak@yandex.com>
#
# 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.2.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')
if cc.get_id() == 'msvc'
# Spectre mitigations are off by default under MSVC for some ungodly reason.
args += '/Qspectre'
# 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
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 host_machine.system() == 'windows' or host_machine.system() == 'cygwin'
# Build a .txt version of the manual too. For producing the installer.
# 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)
unix2dos = find_program('unix2dos')
# Convert Unix newlines to DOS newlines.
man = custom_target('man',
command: [unix2dos],
input: [man_unix],
feed: true,
output: ['dictpw.txt'],
capture: true,
build_by_default: true)
# 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)
fs = import('fs')
inst_cmd = [find_program('makensis'), '-NOCD',
'-INPUTCHARSET', 'UTF8', '-OUTPUTCHARSET', 'UTF8',
'-XSetCompressor /SOLID /FINAL lzma',
'-DMESON=true',
'-DOUTFILE=setup-dictpw.exe',
'-DEXEFILE=' + fs.name(dictpw.full_path()),
'-DMANFILE=' + fs.name(man.full_path()),
'-DLICENSE=' + fs.name(license.full_path()),
'-DREADME=' + fs.name(readme.full_path()),
# This goes into the string file information block and is
# free-form.
'-DPROJECT_VERSION=' + meson.project_version(),
# This goes into the fixed file information block and is in the
# form of 4 integers separated by a dot, e.g. '1.2.3.4'
# We append '.0' to our SemVer to match that format.
'-DVI_VERSION=' + meson.project_version() + '.0' ]
if libbsd_dep.found() and libbsd_dep.type_name() == 'internal'
inst_cmd += '-DLIBOBSD_LICENSE=true'
endif
# Programs built in Cygwin and MSYS2's MSYS environment 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
run_target('installer',
command: inst_cmd + ['--', files('src/dictpw.nsi')],
depends: [dictpw, man, license, readme, dll_copy])
endif