ref: 6d5e003446292f20c769c2a32674f9f2f4b41389 mrsh/meson.build -rw-r--r-- 4.0 KiB View raw
                                                                                
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
project(
	'mrsh',
	'c',
	version: '0.0.0',
	license: 'MIT',
	meson_version: '>=0.47.0',
	default_options: [
		'c_std=c99',
		'warning_level=3',
		'werror=true',
	],
)

cc = meson.get_compiler('c')

add_project_arguments(cc.get_supported_arguments([
	'-Wundef',
	'-Wlogical-op',
	'-Wmissing-include-dirs',
	'-Wold-style-definition',
	'-Wpointer-arith',
	'-Winit-self',
	'-Wfloat-equal',
	'-Wstrict-prototypes',
	'-Wredundant-decls',
	'-Wimplicit-fallthrough=2',
	'-Wendif-labels',
	'-Wstrict-aliasing=2',
	'-Woverflow',
	'-Wformat=2',

	'-Wno-missing-braces',
	'-Wno-missing-field-initializers',
	'-Wno-unused-parameter',
]), language: 'c')

if get_option('readline-provider') == 'readline'
	readline = cc.find_library('readline', required: get_option('readline'))
	if readline.found()
		add_project_arguments('-DHAVE_READLINE', language: 'c')
	endif
else # editline
	readline = dependency('libedit', required: get_option('readline'))
	if readline.found()
		add_project_arguments('-DHAVE_EDITLINE', language: 'c')
	endif
endif

mrsh_inc = include_directories('include')

install_subdir('include/mrsh', install_dir: get_option('includedir'))

libmrsh_gnu_sym_path = join_paths(meson.current_source_dir(), 'libmrsh.gnu.sym')
libmrsh_gnu_sym_ldflag = '-Wl,--version-script=' + libmrsh_gnu_sym_path
libmrsh_darwin_sym_path = join_paths(meson.current_source_dir(), 'libmrsh.darwin.sym')
# On FreeBSD, -Wl,--version-script only works with -shared
if cc.links('', name: '-Wl,--version-script', args: ['-shared', libmrsh_gnu_sym_ldflag])
	# GNU ld
	link_args = [libmrsh_gnu_sym_ldflag]
elif host_machine.system() == 'darwin' and cc.has_multi_link_arguments('-Wl,-exported_symbols_list', libmrsh_darwin_sym_path)
	# Clang on Darwin
	link_args = ['-Wl,-exported_symbols_list', libmrsh_darwin_sym_path]
else
	error('Linker doesn\'t support --version-script or -exported_symbols_list')
endif

lib_mrsh = library(
	meson.project_name(),
	files(
		'arithm.c',
		'array.c',
		'ast_print.c',
		'ast.c',
		'buffer.c',
		'builtin/alias.c',
		'builtin/builtin.c',
		'builtin/cd.c',
		'builtin/colon.c',
		'builtin/dot.c',
		'builtin/eval.c',
		'builtin/exit.c',
		'builtin/export.c',
		'builtin/false.c',
		'builtin/getopts.c',
		'builtin/pwd.c',
		'builtin/read.c',
		'builtin/set.c',
		'builtin/shift.c',
		'builtin/times.c',
		'builtin/true.c',
		'builtin/type.c',
		'builtin/ulimit.c',
		'builtin/umask.c',
		'builtin/unalias.c',
		'builtin/unset.c',
		'builtin/unspecified.c',
		'getopt.c',
		'hashtable.c',
		'parser/arithm.c',
		'parser/parser.c',
		'parser/program.c',
		'parser/word.c',
		'shell/arithm.c',
		'shell/entry.c',
		'shell/job.c',
		'shell/path.c',
		'shell/process.c',
		'shell/redir.c',
		'shell/shell.c',
		'shell/task/assignment.c',
		'shell/task/ast.c',
		'shell/task/async.c',
		'shell/task/binop.c',
		'shell/task/case_clause.c',
		'shell/task/command_builtin.c',
		'shell/task/command_function.c',
		'shell/task/command_process.c',
		'shell/task/command.c',
		'shell/task/for_clause.c',
		'shell/task/function_definition.c',
		'shell/task/if_clause.c',
		'shell/task/list.c',
		'shell/task/loop_clause.c',
		'shell/task/pipeline.c',
		'shell/task/subshell.c',
		'shell/task/task.c',
		'shell/task/word.c',
		'shell/word.c',
	),
	include_directories: mrsh_inc,
	version: meson.project_version(),
	link_args: link_args,
	install: true,
)

mrsh = declare_dependency(
	link_with: lib_mrsh,
	include_directories: mrsh_inc,
)

shell_deps = [mrsh]
shell_files = [
	'main.c'
]
if readline.found()
	shell_deps += [readline]
	shell_files += ['frontend/readline.c']
else
	shell_files += ['frontend/basic.c']
endif

mrsh_exe = executable(
	'mrsh',
	files(shell_files),
	dependencies: shell_deps,
	install: true,
)

executable(
	'highlight',
	files([
		'highlight.c',
	]),
	dependencies: [mrsh],
)

subdir('test')

pkgconfig = import('pkgconfig')
pkgconfig.generate(
	libraries: lib_mrsh,
	version: meson.project_version(),
	filebase: meson.project_name(),
	name: meson.project_name(),
	description: 'POSIX shell library',
)

status = [
	'',
	'Features:',
	'  readline: @0@'.format(readline.found()),
]
message('\n'.join(status))