Mirai's Miscellaneous Misadventures

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