Mirai's Miscellaneous Misadventures

M44 / 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	'models/all.c',
21]
22
23possible_engines = ['fbdev']
24if host_machine.cpu() == 'wasm32'
25	possible_engines = ['wasm']
26endif
27
28# note: 'loader' must come last
29chapter_names = ['test', 'chapter-I', 'loader']
30engine_names = get_option('engines')
31
32foreach engine_name : engine_names
33	if engine_name not in possible_engines
34		error('engine ' + engine_name + ' is not allowed for the host machine')
35	endif
36endforeach
37
38c_args_dict = {
39	'fbdev': [
40		'-D_XOPEN_SOURCE=500',
41	],
42}
43
44link_args_dict = {
45	'wasm': [
46		'-Wl,--stack-first,-z,stack-size=0x100000',
47		'-Wl,--export=__heap_base,--export=main',
48		'-Wl,--export-table,--growable-table',
49		'-Wl,--export=mimimi_wasm_texture',
50		'-Wl,--export=mimimi_wasm_invalidate',
51		'-Wl,--export=mimimi_wasm_stamp',
52	],
53}
54
55install_headers('include/mimimi.h')
56mimimi = library('mimimi', sources,
57	include_directories: 'include',
58	install: true,
59)
60
61chapters = []
62
63foreach engine_name : engine_names
64	c_args = c_args_dict.get(engine_name, [])
65	link_args = link_args_dict.get(engine_name, [])
66	
67	engine = library('mimimi-' + engine_name, 'engines' / (engine_name + '.c'),
68		include_directories: 'include',
69		c_args: c_args,
70		install: true,
71	)
72	
73	if engine_name == 'wasm'
74		install_data('index.html', install_tag: 'runtime')
75	endif
76	
77	foreach chapter_name : chapter_names
78		name = 'mimimi-' + chapter_name + '-' + engine_name
79		
80		name_suffix = []
81		if engine_name == 'wasm'
82			name_suffix = 'wasm'
83			name = 'mimimi-' + chapter_name
84			install_symlink(name + '.wasm',
85				install_dir: get_option('prefix') / get_option('datadir') / 'mimimi',
86				pointing_to: get_option('prefix') / get_option('bindir') / (name + '.wasm'),
87				install_tag: 'runtime',
88			)
89		endif
90		
91		chapter = static_library(name, 'chapters' / chapter_name / 'setup.c',
92			include_directories: 'include',
93			link_args: link_args,
94			install: true,
95		)
96		
97		chapter_libraries = []
98		if chapter_name == 'loader'
99			chapter_libraries = chapters
100		else
101			chapters += chapter
102		endif
103		
104		executable(name, 'chapters/main.c',
105			include_directories: 'include',
106			c_args: c_args + [
107				'-DMIMIMI_ENGINE=mimimi_' + engine_name,
108				'-DMIMIMI_CHAPTER=mimimi_' + chapter_name.replace('-', '_'),
109				'-DMIMIMI_TICK=mimimi_' + chapter_name.replace('-', '_') + '_tick',
110			],
111			link_args: link_args,
112			link_with: [mimimi, engine, chapter] + chapter_libraries,
113			name_suffix: name_suffix,
114			install: true,
115		)
116	endforeach
117endforeach