ieee1275: split up grub_machine_get_bootlocation
[grub.git] / util / grub-glue-efi.c
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
19 #include <config.h>
20
21 #include <grub/util/misc.h>
22 #include <grub/i18n.h>
23 #include <grub/term.h>
24 #include <grub/macho.h>
25 #include <grub/util/install.h>
26
27 #define _GNU_SOURCE     1
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <errno.h>
34
35 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
36 #pragma GCC diagnostic ignored "-Wmissing-declarations"
37 #include <argp.h>
38 #pragma GCC diagnostic error "-Wmissing-prototypes"
39 #pragma GCC diagnostic error "-Wmissing-declarations"
40
41 #include "progname.h"
42
43 struct arguments
44 {
45   char *input32;
46   char *input64;
47   char *output;
48   int verbosity;
49 };
50
51 static struct argp_option options[] = {
52   {"input32",  '3', N_("FILE"), 0,
53    N_("set input filename for 32-bit part."), 0},
54   {"input64",  '6', N_("FILE"), 0,
55    N_("set input filename for 64-bit part."), 0},
56   {"output",  'o', N_("FILE"), 0,
57    N_("set output filename. Default is STDOUT"), 0},
58   {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
59   { 0, 0, 0, 0, 0, 0 }
60 };
61
62 static error_t
63 argp_parser (int key, char *arg, struct argp_state *state)
64 {
65   /* Get the input argument from argp_parse, which we
66      know is a pointer to our arguments structure. */
67   struct arguments *arguments = state->input;
68
69   switch (key)
70     {
71     case '6':
72       arguments->input64 = xstrdup (arg);
73       break;
74     case '3':
75       arguments->input32 = xstrdup (arg);
76       break;
77
78     case 'o':
79       arguments->output = xstrdup (arg);
80       break;
81
82     case 'v':
83       arguments->verbosity++;
84       break;
85
86     default:
87       return ARGP_ERR_UNKNOWN;
88     }
89
90   return 0;
91 }
92
93 static struct argp argp = {
94   options, argp_parser, N_("[OPTIONS]"),
95   N_("Glue 32-bit and 64-bit binary into Apple universal one."),
96   NULL, NULL, NULL
97 };
98
99 int
100 main (int argc, char *argv[])
101 {
102   struct arguments arguments;
103
104   grub_util_host_init (&argc, &argv);
105
106   /* Check for options.  */
107   memset (&arguments, 0, sizeof (struct arguments));
108   if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
109     {
110       fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
111       exit(1);
112     }
113
114   if (!arguments.input32 || !arguments.input64)
115     {
116       fprintf (stderr, "%s", _("Missing input file\n"));
117       exit(1);
118     }
119
120   grub_util_glue_efi (arguments.input32,
121                       arguments.input64,
122                       arguments.output);
123
124   return 0;
125 }