grub-glue-efi.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010,2012,2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <config.h>
  19. #include <grub/util/misc.h>
  20. #include <grub/i18n.h>
  21. #include <grub/term.h>
  22. #include <grub/macho.h>
  23. #include <grub/util/install.h>
  24. #define _GNU_SOURCE 1
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <errno.h>
  30. #pragma GCC diagnostic ignored "-Wmissing-prototypes"
  31. #pragma GCC diagnostic ignored "-Wmissing-declarations"
  32. #include <argp.h>
  33. #pragma GCC diagnostic error "-Wmissing-prototypes"
  34. #pragma GCC diagnostic error "-Wmissing-declarations"
  35. #include "progname.h"
  36. struct arguments
  37. {
  38. char *input32;
  39. char *input64;
  40. char *output;
  41. int verbosity;
  42. };
  43. static struct argp_option options[] = {
  44. {"input32", '3', N_("FILE"), 0,
  45. N_("set input filename for 32-bit part."), 0},
  46. {"input64", '6', N_("FILE"), 0,
  47. N_("set input filename for 64-bit part."), 0},
  48. {"output", 'o', N_("FILE"), 0,
  49. N_("set output filename. Default is STDOUT"), 0},
  50. {"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
  51. { 0, 0, 0, 0, 0, 0 }
  52. };
  53. static error_t
  54. argp_parser (int key, char *arg, struct argp_state *state)
  55. {
  56. /* Get the input argument from argp_parse, which we
  57. know is a pointer to our arguments structure. */
  58. struct arguments *arguments = state->input;
  59. switch (key)
  60. {
  61. case '6':
  62. arguments->input64 = xstrdup (arg);
  63. break;
  64. case '3':
  65. arguments->input32 = xstrdup (arg);
  66. break;
  67. case 'o':
  68. arguments->output = xstrdup (arg);
  69. break;
  70. case 'v':
  71. arguments->verbosity++;
  72. break;
  73. default:
  74. return ARGP_ERR_UNKNOWN;
  75. }
  76. return 0;
  77. }
  78. static struct argp argp = {
  79. options, argp_parser, N_("[OPTIONS]"),
  80. N_("Glue 32-bit and 64-bit binary into Apple universal one."),
  81. NULL, NULL, NULL
  82. };
  83. int
  84. main (int argc, char *argv[])
  85. {
  86. struct arguments arguments;
  87. grub_util_host_init (&argc, &argv);
  88. /* Check for options. */
  89. memset (&arguments, 0, sizeof (struct arguments));
  90. if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
  91. {
  92. fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
  93. exit(1);
  94. }
  95. if (!arguments.input32 || !arguments.input64)
  96. {
  97. fprintf (stderr, "%s", _("Missing input file\n"));
  98. exit(1);
  99. }
  100. grub_util_glue_efi (arguments.input32,
  101. arguments.input64,
  102. arguments.output);
  103. return 0;
  104. }