summaryrefslogtreecommitdiff
path: root/packages/sys-boot/grub/grub.exlib
blob: b9488bf888d1c16749900cb2a4f212f63b84e53d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Copyright 2007 Bryan Østergaard <bryan.ostergaard@gmail.com>
# Distributed under the terms of the GNU General Public License v2

require gnu [ suffix=tar.xz ] \
    flag-o-matic \
    autotools [ supported_autoconf=[ 2.5 ] supported_automake=[ 1.16 1.15 ] ]

if ever is_scm ; then
    DOWNLOADS=""
    SCM_REPOSITORY="https://git.savannah.gnu.org/git/${PN}.git"
    require scm-git
fi

export_exlib_phases pkg_setup src_prepare src_configure src_compile src_install

SUMMARY="GRUB (Grand Unified Boot) bootloader"

LICENCES="GPL-3"
MYOPTIONS="
    bios          [[ description = [ Build for BIOS platform ] ]]
    device-mapper [[ description = [ Ability to detect and use device-mapper devices ] ]]
    efi           [[ description = [ Build for EFI platform ] ]]
    grub-mount    [[ description = [ FUSE driver for filesystems that GRUB understands ] ]]
    mkfont        [[ description = [ Build grub-mkfont which can create GRUB font files ] ]]
    ( providers: eudev systemd ) [[ number-selected = exactly-one ]]
    ( efi bios ) [[ number-selected = at-least-one ]]
"

# TODO: needs qemu-system-i386
RESTRICT="test"

DEPENDENCIES="
    build:
        sys-apps/help2man [[ note = [ man pages won't get created otherwise resulting in empty man dirs ] ]]
        sys-devel/bison
        sys-devel/flex[>=2.5.35]
        sys-devel/make
        device-mapper? ( sys-fs/lvm2 )
        grub-mount? ( sys-fs/fuse:0 )
        mkfont? (
            fonts/unifont
            media-libs/freetype:2
        )
    build+run:
        app-arch/xz
        sys-devel/gettext [[ note = [ required for grub-mkconfig, grep gettext in /etc/grub.d ] ]]
        !sys-boot/grub-static [[ description = [ /sbin/grub-install collides ] resolution = manual ]]
        providers:eudev? ( sys-apps/eudev )
        providers:systemd? ( sys-apps/systemd )
    run:
        efi? ( sys-boot/efibootmgr )
    suggestion:
        sys-boot/os-prober [[
            description = [ Ability to add other OSs automatically to grub.cfg via grub-mkconf ]
        ]]
"

AT_M4DIR=( m4 )

grub_pkg_setup() {
    # grub2 should be compiled with -Os, other optimizations may result in oversized core images
    replace-flags -O* -Os
    # retpoline flag is incompatible with the -mcmodel=large flag used by grub
    filter-flags -mindirect-branch=thunk
}

grub_src_prepare() {
    edo sed \
        -e "s/.*Running autoreconf.*/exit 0/" \
        -i autogen.sh

    edo ./autogen.sh

    autotools_src_prepare
}


_cfg_n_build_grub_bios() {
    filter-flags -mfloat-abi=hard
    unset CFLAGS CPPFLAGS LDFLAGS

    myconf=(
        "CPP=${CC} -E"
        BUILD_CC=$(exhost --build)-cc
        BUILD_CFLAGS="$(print-build-flags CFLAGS)"
        BUILD_CPPFLAGS="$(print-build-flags CPPFLAGS)"
        BUILD_LDFLAGS="$(print-build-flags LDFLAGS)"
        --with-bootdir=/boot
        --with-grubdir=grub
        --with-platform=pc
        --enable-cache-stats
        --disable-libzfs
        --disable-werror
        # TODO: for now disable emulation utils
        --disable-efiemu
        --disable-grub-emu-sdl
        --disable-grub-emu-pci
        --disable-mm-debug
        gt_cv_func_gnugettext{1,2}_libc=yes
    )

    econf "${myconf[@]}" \
        $(option_enable device-mapper) \
        $(option_enable grub-mount) \
        $(option_enable mkfont grub-mkfont)

    emake && emake DESTDIR="${IMAGE}" install
    emake distclean
}

_cfg_n_build_grub_efi() {
    filter-flags -mfloat-abi=hard
    unset CFLAGS CPPFLAGS LDFLAGS

    myconf=(
        "CPP=${CC} -E"
        BUILD_CC=$(exhost --build)-cc
        BUILD_CFLAGS="$(print-build-flags CFLAGS)"
        BUILD_CPPFLAGS="$(print-build-flags CPPFLAGS)"
        BUILD_LDFLAGS="$(print-build-flags LDFLAGS)"
        --with-bootdir=/boot
        --with-grubdir=grub
        --with-platform=efi
        --enable-cache-stats
        --disable-libzfs
        --disable-werror
        # TODO: for now disable emulation utils
        --disable-efiemu
        --disable-grub-emu-sdl
        --disable-grub-emu-pci
        --disable-mm-debug
        gt_cv_func_gnugettext{1,2}_libc=yes
    )

    econf "${myconf[@]}" \
        $(option_enable device-mapper) \
        $(option_enable grub-mount) \
        $(option_enable mkfont grub-mkfont)

    emake && emake DESTDIR="${IMAGE}" install
    emake distclean
}

grub_src_configure() {
    if option bios; then
        _cfg_n_build_grub_bios
    fi

    if option efi; then
        _cfg_n_build_grub_efi
    fi
}

grub_src_compile() {
    :
}

grub_src_install() {
    dodoc "${WORK}"/docs/grub.cfg

    edo rm -f "${IMAGE}"/usr/$(exhost --target)/lib/charset.alias

    edo rm "${IMAGE%/}"/etc/bash_completion.d/${PN}
    edo rmdir "${IMAGE%/}"/etc/bash_completion.d/
}