1 | #
|
---|
2 | # Copyright (c) 2019 Jiří Zárevúcky
|
---|
3 | # All rights reserved.
|
---|
4 | #
|
---|
5 | # Redistribution and use in source and binary forms, with or without
|
---|
6 | # modification, are permitted provided that the following conditions
|
---|
7 | # are met:
|
---|
8 | #
|
---|
9 | # - Redistributions of source code must retain the above copyright
|
---|
10 | # notice, this list of conditions and the following disclaimer.
|
---|
11 | # - Redistributions in binary form must reproduce the above copyright
|
---|
12 | # notice, this list of conditions and the following disclaimer in the
|
---|
13 | # documentation and/or other materials provided with the distribution.
|
---|
14 | # - The name of the author may not be used to endorse or promote products
|
---|
15 | # derived from this software without specific prior written permission.
|
---|
16 | #
|
---|
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | #
|
---|
28 |
|
---|
29 | if GRUB_ARCH == 'pc'
|
---|
30 | MULTIBOOT_CMD = 'multiboot'
|
---|
31 | MODULE_CMD = 'module'
|
---|
32 | INSMODS = [ 'insmod vbe', 'insmod vga' ]
|
---|
33 | elif GRUB_ARCH == 'efi'
|
---|
34 | MULTIBOOT_CMD = 'multiboot2'
|
---|
35 | MODULE_CMD = 'module2'
|
---|
36 | INSMODS = [ 'insmod efi_gop', 'insmod efi_uga' ]
|
---|
37 | endif
|
---|
38 |
|
---|
39 | # TODO
|
---|
40 | install_snippet = 'mkdir -p ${DIST_DIR}/`dirname @1@`; cp @0@ ${DIST_DIR}/@1@'
|
---|
41 | dist_dirname = 'grub_dist'
|
---|
42 |
|
---|
43 | if GRUB_LOADER == 'multiboot'
|
---|
44 | build_dist_text = []
|
---|
45 | build_dist_deps = []
|
---|
46 | foreach init : rd_init_binaries
|
---|
47 | target = 'boot/' + run_command(basename, init[1], check: true).stdout().strip()
|
---|
48 |
|
---|
49 | build_dist_text += install_snippet.format(init[0].full_path(), target)
|
---|
50 | build_dist_deps += init[0]
|
---|
51 | endforeach
|
---|
52 |
|
---|
53 | LOADS = [ 'echo \'Loading kernel\'' ]
|
---|
54 | LOADS += [ MULTIBOOT_CMD + ' /boot/kernel.elf' ]
|
---|
55 |
|
---|
56 | MODULES = rd_init + [ 'boot/initrd.img' ]
|
---|
57 |
|
---|
58 | foreach module : MODULES
|
---|
59 | module = '/boot/' + run_command(basename, module, check: true).stdout().strip()
|
---|
60 | LOADS += 'echo \'Loading @0@\''.format(module)
|
---|
61 | LOADS += '@0@ @1@ @1@'.format(MODULE_CMD, module)
|
---|
62 | endforeach
|
---|
63 | endif
|
---|
64 |
|
---|
65 | if GRUB_LOADER == 'chainloader'
|
---|
66 | # init binaries are already part of the chainloaded boot image.
|
---|
67 | build_dist_text = [ install_snippet.format(boot_image.full_path(), 'boot/' + boot_image_name) ]
|
---|
68 | build_dist_deps = [ boot_image ]
|
---|
69 |
|
---|
70 | LOADS = [
|
---|
71 | 'echo \'Loading ' + boot_image_name + '\'',
|
---|
72 | 'chainloader /boot/' + boot_image_name,
|
---|
73 | 'boot',
|
---|
74 | ]
|
---|
75 | endif
|
---|
76 |
|
---|
77 | build_dist_sh = configure_file(
|
---|
78 | input: 'build_dist.sh.in',
|
---|
79 | output: 'build_dist.sh',
|
---|
80 | configuration: { 'text' : '\n'.join(build_dist_text) },
|
---|
81 | )
|
---|
82 |
|
---|
83 |
|
---|
84 | grub_cfg = configure_file(
|
---|
85 | input: 'grub.cfg.in',
|
---|
86 | output: 'grub.cfg',
|
---|
87 | configuration: {
|
---|
88 | 'INSMODS' : '\n'.join(INSMODS),
|
---|
89 | 'RELEASE' : HELENOS_RELEASE,
|
---|
90 | 'LOADS' : '\n'.join(LOADS),
|
---|
91 | },
|
---|
92 | )
|
---|
93 |
|
---|
94 | grub_dir = meson.current_source_dir() / BARCH + '-' + GRUB_ARCH
|
---|
95 |
|
---|
96 | dist_dir = custom_target(dist_dirname,
|
---|
97 | output: dist_dirname,
|
---|
98 | input: [ build_dist_sh, grub_cfg, build_dist_deps ],
|
---|
99 | command: [ sh, '@INPUT0@', '@OUTPUT@', grub_dir, '@INPUT1@' ],
|
---|
100 | )
|
---|
101 |
|
---|
102 |
|
---|
103 | # Create .iso image.
|
---|
104 |
|
---|
105 | grub_image = 'boot/grub' / GRUB_ARCH + '.img'
|
---|
106 |
|
---|
107 | if GRUB_ARCH == 'pc'
|
---|
108 | genisoimage_args = [ '-eltorito-boot', grub_image, '-no-emul-boot', '-boot-info-table' ]
|
---|
109 | elif GRUB_ARCH == 'efi'
|
---|
110 | if genisoimage_type == 'mkisofs'
|
---|
111 | genisoimage_args = [ '-eltorito-platform', 'efi', '-eltorito-boot', grub_image, '-no-emul-boot' ]
|
---|
112 | else
|
---|
113 | genisoimage_args = [ '--efi-boot', grub_image ]
|
---|
114 | endif
|
---|
115 | endif
|
---|
116 |
|
---|
117 | image_iso = custom_target('image.iso',
|
---|
118 | output: 'image.iso',
|
---|
119 | input: dist_dir,
|
---|
120 | command: [
|
---|
121 | genisoimage,
|
---|
122 | '-J',
|
---|
123 | '-r',
|
---|
124 | '-input-charset', 'utf-8',
|
---|
125 | '-V', 'HelenOS-CD',
|
---|
126 | genisoimage_args,
|
---|
127 | '-o', '@OUTPUT@',
|
---|
128 | '@INPUT@',
|
---|
129 | ],
|
---|
130 | )
|
---|
131 |
|
---|
132 | POST_INPUT = image_iso
|
---|