Mirai's Miscellaneous Misadventures
M51 / meson.build
1# license: AGPLv3 or later
2# copyright 2024 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/video.c',
15 'core/effects.c',
16 'core/ground.c',
17 'core/dialogues.c',
18 'core/math.c',
19 'core/motion.c',
20 'core/logo.c',
21 'core/logos.c',
22 'core/packbits.c',
23 'core/stages.c',
24 'models/all.c',
25]
26
27possible_engines = ['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 = []
35
36foreach name : ['wasm', 'sdl2']
37 option = get_option(name)
38 if option.enabled() and not name in possible_engines
39 error('wrong host machine for target ' + name)
40 endif
41 if option.enabled() or option.auto() and name in possible_engines
42 engine_names += name
43 endif
44endforeach
45
46if 'wasm' in engine_names
47 wasm_opt = find_program('wasm-opt')
48endif
49
50if engine_names.length() == 0
51 error('no engines specified')
52endif
53
54c_args_dict = {
55 'fbdev': ['-D_XOPEN_SOURCE=500'],
56}
57
58link_args_dict = {
59 'wasm': ['-Wl,--export-memory'],
60}
61
62cc = meson.get_compiler('c')
63
64install_headers('include/mimimi.h')
65mimimi = library('mimimi', sources,
66 include_directories: 'include',
67 install: true,
68)
69
70chapters = []
71
72foreach engine_name : engine_names
73 c_args = c_args_dict.get(engine_name, [])
74 link_args = link_args_dict.get(engine_name, [])
75 dependencies = []
76 if engine_name == 'minifb'
77 dependencies = [cc.find_library('minifb', has_headers: 'MiniFB.h'), dependency('x11'), dependency('gl'), dependency('xkbcommon')]
78 endif
79 if engine_name == 'sdl2'
80 dependencies = dependency('sdl2')
81 endif
82
83 engine = library('mimimi-' + engine_name, 'engines' / (engine_name + '.c'),
84 include_directories: 'include',
85 c_args: c_args,
86 install: true,
87 dependencies: dependencies,
88 )
89
90 if engine_name == 'wasm'
91 install_data('index.html')
92 endif
93
94 foreach chapter_name : chapter_names
95 name = 'mimimi-' + chapter_name + '-' + engine_name
96 if engine_name == 'wasm'
97 name = 'mimimi-' + chapter_name
98 endif
99
100 chapter = static_library(name, 'chapters' / chapter_name / 'setup.c',
101 include_directories: 'include',
102 link_args: link_args,
103 install: true,
104 )
105
106 chapter_libraries = []
107 if chapter_name == 'loader'
108 chapter_libraries = chapters
109 else
110 chapters += chapter
111 endif
112
113 exe = executable(name, 'chapters/main.c',
114 include_directories: 'include',
115 c_args: c_args + [
116 '-DMIMIMI_ENGINE=mimimi_' + engine_name,
117 '-DMIMIMI_CHAPTER=mimimi_' + chapter_name.replace('-', '_'),
118 '-DMIMIMI_TICK=mimimi_' + chapter_name.replace('-', '_') + '_tick',
119 ],
120 link_args: link_args,
121 link_with: [mimimi, engine, chapter] + chapter_libraries,
122 install: true,
123 dependencies: dependencies,
124 )
125
126 if engine_name == 'wasm'
127 async = custom_target(
128 output: name + '-async.wasm',
129 input: exe,
130 command: [wasm_opt, '-O4', '--asyncify', '-o', '@OUTPUT@', '@INPUT@'],
131 install: true,
132 install_dir: get_option('prefix') / get_option('bindir'),
133 )
134
135 if chapter_name == 'chapter-I'
136 install_symlink('mimimi.wasm',
137 install_dir: get_option('prefix') / get_option('datadir') / 'mimimi',
138 pointing_to: get_option('prefix') / get_option('bindir') / (name + '-async.wasm'),
139 )
140 endif
141 endif
142 endforeach
143endforeach