grub-mkimage doesn't delete zero-sized output file if some error occurred

Yuri Zaporozhets <[email protected]> Mon, 23 Dec 2024 19:11:26 +0100
Newsgroups gmane.comp.boot-loaders.grub.bugs
Message-ID <[email protected]>
Hi,

I have the following command in my Makefile:

    grub-mkimage -d out -o grub-riscv64.efi -O riscv64-efi -p /boot/grub \
        part_gpt.mod ext2.mod normal.mod multiboot3.mod

Some of the modules specified are deliberately not there (and also some dependencies from moddep.lst).
The program detects this and prints the following message:

    grub-mkimage: error: cannot open `out/fshelp.mod': No such file or directory.

Then it exits with an error. The problem is that it leaves the zero-sized output file, which then confuses
the "make" program, and it doesn't remake it saying "grub-riscv64.efi" is up-to-date.

    $ ls -la
    -rw-rw-r--  1 yuriz yuriz    0 Dec 23 19:06 grub-riscv64.efi

I consider this a bug, and therefore I'm reporting it.

-- 
Regards,
Yuri