Mirai's Miscellaneous Misadventures

M45 / 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']
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
56install_headers('include/mimimi.h')
57mimimi = library('mimimi', sources,
58	include_directories: 'include',
59	install: true,
60)
61
62chapters = []
63
64foreach engine_name : engine_names
65	c_args = c_args_dict.get(engine_name, [])
66	link_args = link_args_dict.get(engine_name, [])
67	
68	engine = library('mimimi-' + engine_name, 'engines' / (engine_name + '.c'),
69		include_directories: 'include',
70		c_args: c_args,
71		install: true,
72	)
73	
74	if engine_name == 'wasm'
75		install_data('index.html', install_tag: 'runtime')
76	endif
77	
78	foreach chapter_name : chapter_names
79		name = 'mimimi-' + chapter_name + '-' + engine_name
80		
81		name_suffix = []
82		if engine_name == 'wasm'
83			name_suffix = 'wasm'
84			name = 'mimimi-' + chapter_name
85			install_symlink(name + '.wasm',
86				install_dir: get_option('prefix') / get_option('datadir') / 'mimimi',
87				pointing_to: get_option('prefix') / get_option('bindir') / (name + '.wasm'),
88				install_tag: 'runtime',
89			)
90		endif
91		
92		chapter = static_library(name, 'chapters' / chapter_name / 'setup.c',
93			include_directories: 'include',
94			link_args: link_args,
95			install: true,
96		)
97		
98		chapter_libraries = []
99		if chapter_name == 'loader'
100			chapter_libraries = chapters
101		else
102			chapters += chapter
103		endif
104		
105		executable(name, 'chapters/main.c',
106			include_directories: 'include',
107			c_args: c_args + [
108				'-DMIMIMI_ENGINE=mimimi_' + engine_name,
109				'-DMIMIMI_CHAPTER=mimimi_' + chapter_name.replace('-', '_'),
110				'-DMIMIMI_TICK=mimimi_' + chapter_name.replace('-', '_') + '_tick',
111			],
112			link_args: link_args,
113			link_with: [mimimi, engine, chapter] + chapter_libraries,
114			name_suffix: name_suffix,
115			install: true,
116		)
117	endforeach
118endforeach