Handle grub-pe2elf and grub-mkfont for cases when build != host.

* Makefile.am (build-grub-mkfont): Don't include gnulib.
	(build-grub-gen-asciih): Likewise.
	(build-grub-gen-widthspec): Likewise.
	* Makefile.util.def (grub-pe2elf): Remove.
	* config.h.in [GRUB_BUILD]: Use build rather than host constants.
	* configure.ac: Separate tests for build.
	Move ./build-grub-pe2elf to grub-core.
	Fix typo.
	* grub-core/Makefile.am (build-grub-pe2elf): New target.
	* grub-core/kern/emu/misc.c (xasprintf): Don't compile if GRUB_BUILD is
	defined.
	* include/grub/types.h [GRUB_BUILD]: Use build rather than host
	constants.
	* util/grub-mkfont.c [GRUB_BUILD]: Simplify not to rely on argp.
	* util/grub-pe2elf.c: Simplify not to rely on getopt.
	* util/misc.c (program_name) [GRUB_BUILD]: Define to static string.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-08-22 17:00:59 +02:00
parent 984cfd8a79
commit 7b780018f5
11 changed files with 174 additions and 102 deletions

View file

@ -30,37 +30,9 @@
#include <stdlib.h>
#include <getopt.h>
#include "progname.h"
/* Please don't internationalise this file. It's pointless. */
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static void __attribute__ ((noreturn))
usage (int status)
{
if (status)
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] input [output]\n\
\n\
Tool to convert pe image to elf.\n\
\nOptions:\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
exit (status);
}
/*
* Section layout
*
@ -490,54 +462,27 @@ main (int argc, char *argv[])
{
char *image;
FILE* fp;
set_program_name (argv[0]);
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "hVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'h':
usage (0);
break;
case 'V':
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
char *in, *out;
/* Obtain PATH. */
if (optind >= argc)
if (1 >= argc)
{
fprintf (stderr, "Filename not specified.\n");
usage (1);
return 1;
}
image = grub_util_read_image (argv[optind]);
in = argv[1];
if (argc > 2)
out = argv[2];
else
out = in;
image = grub_util_read_image (in);
if (optind + 1 < argc)
optind++;
fp = fopen (argv[optind], "wb");
fp = fopen (out, "wb");
if (! fp)
grub_util_error ("cannot open %s", argv[optind]);
grub_util_error ("cannot open %s", out);
convert_pe (fp, argv[optind], image);
convert_pe (fp, out, image);
fclose (fp);