Mirai's Miscellaneous Misadventures

M46 / meson.build

1# license: AGPLv3 or later
2# copyright 2023 zamfofex
3
4project('mimimi', 'c', default_options: ['c_std=c89', 'warning_level=3'])
5
6sources = [
7	'core/sprites.c',
8	'core/controls.c',
9	'core/cameras.c',
10	'core/animations.c',
11	'core/displays.c',
12	'core/font.c',
13	'core/text.c',
14	'core/collisions.c',
15	'core/video.c',
16	'core/effects.c',
17	'core/ground.c',
18	'core/dialogues.c',
19	'core/math.c',
20	'core/mechanics.c',
21	'models/all.c',
22]
23
24possible_engines = ['fbdev', 'minifb', 'sdl2']
25if host_machine.cpu() == 'wasm32'
26	possible_engines = ['wasm']
27endif
28
29# note: 'loader' must come last
30chapter_names = ['test', 'chapter-I', 'loader']
31engine_names = get_option('engines')
32
33foreach engine_name : engine_names
34	if engine_name not in possible_engines
35		error('engine ' + engine_name + ' is not allowed for the host machine')
36	endif
37endforeach
38
39c_args_dict = {
40	'fbdev': [
41		'-D_XOPEN_SOURCE=500',
42	],
43}
44
45link_args_dict = {
46	'wasm': [
47		'-Wl,--stack-first,-z,stack-size=0x100000',
48		'-Wl,--export=__heap_base,--export=main',
49		'-Wl,--export-table,--growable-table',
50		'-Wl,--export=mimimi_wasm_texture',
51		'-Wl,--export=mimimi_wasm_invalidate',
52		'-Wl,--export=mimimi_wasm_stamp',
53	],
54}
55
56cc = meson.get_compiler('c')
57
58install_headers('include/mimimi.h')
59mimimi = library('mimimi', sources,
60	include_directories: 'include',
61	install: true,
62)
63
64chapters = []
65
66foreach engine_name : engine_names
67	c_args = c_args_dict.get(engine_name, [])
68	link_args = link_args_dict.get(engine_name, [])
69	dependencies = []
70	if engine_name == 'minifb'
71		dependencies = [cc.find_library('minifb', has_headers: 'MiniFB.h'), dependency('x11'), dependency('gl'), dependency('xkbcommon')]
72	endif
73	if engine_name == 'sdl2'
74		dependencies = dependency('sdl2')
75	endif
76	
77	engine = library('mimimi-' + engine_name, 'engines' / (engine_name + '.c'),
78		include_directories: 'include',
79		c_args: c_args,
80		install: true,
81		dependencies: dependencies,
82	)
83	
84	if engine_name == 'wasm'
85		install_data('index.html', install_tag: 'runtime')
86	endif
87	
88	foreach chapter_name : chapter_names
89		name = 'mimimi-' + chapter_name + '-' + engine_name
90		
91		name_suffix = []
92		if engine_name == 'wasm'
93			name_suffix = 'wasm'
94			name = 'mimimi-' + chapter_name
95			install_symlink(name + '.wasm',
96				install_dir: get_option('prefix') / get_option('datadir') / 'mimimi',
97				pointing_to: get_option('prefix') / get_option('bindir') / (name + '.wasm'),
98				install_tag: 'runtime',
99			)
100		endif
101		
102		chapter = static_library(name, 'chapters' / chapter_name / 'setup.c',
103			include_directories: 'include',
104			link_args: link_args,
105			install: true,
106		)
107		
108		chapter_libraries = []
109		if chapter_name == 'loader'
110			chapter_libraries = chapters
111		else
112			chapters += chapter
113		endif
114		
115		executable(name, 'chapters/main.c',
116			include_directories: 'include',
117			c_args: c_args + [
118				'-DMIMIMI_ENGINE=mimimi_' + engine_name,
119				'-DMIMIMI_CHAPTER=mimimi_' + chapter_name.replace('-', '_'),
120				'-DMIMIMI_TICK=mimimi_' + chapter_name.replace('-', '_') + '_tick',
121			],
122			link_args: link_args,
123			link_with: [mimimi, engine, chapter] + chapter_libraries,
124			name_suffix: name_suffix,
125			install: true,
126			dependencies: dependencies,
127		)
128	endforeach
129endforeach