From 6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:29:51 +0200 Subject: Adding upstream version 2.06. Signed-off-by: Daniel Baumann --- util/grub-glue-efi.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 util/grub-glue-efi.c (limited to 'util/grub-glue-efi.c') diff --git a/util/grub-glue-efi.c b/util/grub-glue-efi.c new file mode 100644 index 0000000..07fa430 --- /dev/null +++ b/util/grub-glue-efi.c @@ -0,0 +1,125 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2012,2013 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + +#include +#include +#include +#include +#include + +#define _GNU_SOURCE 1 + +#include +#include +#include +#include +#include + +#pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#include +#pragma GCC diagnostic error "-Wmissing-prototypes" +#pragma GCC diagnostic error "-Wmissing-declarations" + +#include "progname.h" + +struct arguments +{ + char *input32; + char *input64; + char *output; + int verbosity; +}; + +static struct argp_option options[] = { + {"input32", '3', N_("FILE"), 0, + N_("set input filename for 32-bit part."), 0}, + {"input64", '6', N_("FILE"), 0, + N_("set input filename for 64-bit part."), 0}, + {"output", 'o', N_("FILE"), 0, + N_("set output filename. Default is STDOUT"), 0}, + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, + { 0, 0, 0, 0, 0, 0 } +}; + +static error_t +argp_parser (int key, char *arg, struct argp_state *state) +{ + /* Get the input argument from argp_parse, which we + know is a pointer to our arguments structure. */ + struct arguments *arguments = state->input; + + switch (key) + { + case '6': + arguments->input64 = xstrdup (arg); + break; + case '3': + arguments->input32 = xstrdup (arg); + break; + + case 'o': + arguments->output = xstrdup (arg); + break; + + case 'v': + arguments->verbosity++; + break; + + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} + +static struct argp argp = { + options, argp_parser, N_("[OPTIONS]"), + N_("Glue 32-bit and 64-bit binary into Apple universal one."), + NULL, NULL, NULL +}; + +int +main (int argc, char *argv[]) +{ + struct arguments arguments; + + grub_util_host_init (&argc, &argv); + + /* Check for options. */ + memset (&arguments, 0, sizeof (struct arguments)); + if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0) + { + fprintf (stderr, "%s", _("Error in parsing command line arguments\n")); + exit(1); + } + + if (!arguments.input32 || !arguments.input64) + { + fprintf (stderr, "%s", _("Missing input file\n")); + exit(1); + } + + grub_util_glue_efi (arguments.input32, + arguments.input64, + arguments.output); + + return 0; +} -- cgit v1.2.3