* 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.
+2013-08-22 Vladimir Serbinenko <phcoder@gmail.com>
+
+ 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.
+
2013-08-22 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_size): Adapt for
starfield_theme_files = $(srcdir)/themes/starfield/blob_w.png $(srcdir)/themes/starfield/boot_menu_c.png $(srcdir)/themes/starfield/boot_menu_e.png $(srcdir)/themes/starfield/boot_menu_ne.png $(srcdir)/themes/starfield/boot_menu_n.png $(srcdir)/themes/starfield/boot_menu_nw.png $(srcdir)/themes/starfield/boot_menu_se.png $(srcdir)/themes/starfield/boot_menu_s.png $(srcdir)/themes/starfield/boot_menu_sw.png $(srcdir)/themes/starfield/boot_menu_w.png $(srcdir)/themes/starfield/slider_c.png $(srcdir)/themes/starfield/slider_n.png $(srcdir)/themes/starfield/slider_s.png $(srcdir)/themes/starfield/starfield.png $(srcdir)/themes/starfield/terminal_box_c.png $(srcdir)/themes/starfield/terminal_box_e.png $(srcdir)/themes/starfield/terminal_box_ne.png $(srcdir)/themes/starfield/terminal_box_n.png $(srcdir)/themes/starfield/terminal_box_nw.png $(srcdir)/themes/starfield/terminal_box_se.png $(srcdir)/themes/starfield/terminal_box_s.png $(srcdir)/themes/starfield/terminal_box_sw.png $(srcdir)/themes/starfield/terminal_box_w.png $(srcdir)/themes/starfield/theme.txt $(srcdir)/themes/starfield/README $(srcdir)/themes/starfield/COPYING.CC-BY-SA-3.0
-build-grub-mkfont: util/grub-mkfont.c grub-core/unidata.c grub-core/kern/emu/argp_common.c grub-core/kern/emu/misc.c util/misc.c grub-core/gnulib/progname.c
- $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -I$(top_srcdir)/grub-core/gnulib -DGRUB_MKFONT=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) $(LIBINTL)
+build-grub-mkfont: util/grub-mkfont.c grub-core/unidata.c grub-core/kern/emu/misc.c util/misc.c
+ $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-mkfont\" $^ $(build_freetype_cflags) $(build_freetype_libs)
build-grub-gen-asciih: util/grub-gen-asciih.c
- $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -I$(top_srcdir)/grub-core/gnulib -DGRUB_MKFONT=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) $(LIBINTL) -Wall -Werror
+ $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) -Wall -Werror
build-grub-gen-widthspec: util/grub-gen-widthspec.c
- $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -I$(top_srcdir)/grub-core/gnulib -DGRUB_MKFONT=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) $(LIBINTL) -Wall -Werror
+ $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) -Wall -Werror
if COND_STARFIELD
starfield_DATA = dejavu_10.pf2 dejavu_12.pf2 dejavu_bold_14.pf2 dejavu_14.pf2 dejavu_16.pf2 $(starfield_theme_files)
condition = COND_APPLE_CC;
};
-program = {
- name = grub-pe2elf;
- mansection = 1;
- common = util/grub-pe2elf.c;
-
- ldadd = libgrubmods.a;
- ldadd = libgrubgcry.a;
- ldadd = libgrubkern.a;
- ldadd = grub-core/gnulib/libgnu.a;
- ldadd = '$(LIBINTL)';
- condition = COND_GRUB_PE2ELF;
-};
-
program = {
name = grub-fstest;
mansection = 1;
#define DISK_CACHE_STATS @DISK_CACHE_STATS@
#define BOOT_TIME_STATS @BOOT_TIME_STATS@
-#if defined (GRUB_UTIL) || !defined (GRUB_MACHINE)
+#if defined (GRUB_BUILD)
+#define BUILD_SIZEOF_LONG @BUILD_SIZEOF_LONG@
+#define BUILD_SIZEOF_VOID_P @BUILD_SIZEOF_VOID_P@
+#if defined __APPLE__
+# if defined __BIG_ENDIAN__
+# define BUILD_WORDS_BIGENDIAN 1
+# else
+# define BUILD_WORDS_BIGENDIAN 0
+# endif
+#else
+#define BUILD_WORDS_BIGENDIAN @BUILD_WORDS_BIGENDIAN@
+#endif
+#elif defined (GRUB_UTIL) || !defined (GRUB_MACHINE)
#include <config-util.h>
#else
/* Define if C symbols get an underscore after compilation. */
AC_SYS_LARGEFILE
# Identify characteristics of the host architecture.
+unset ac_cv_c_bigendian
+
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long)
# For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format])
case "${target_os}" in
- cygwin) TARGET_OBJ2ELF='$(top_builddir)/grub-pe2elf';
+ cygwin) TARGET_OBJ2ELF='./build-grub-pe2elf';
# FIXME: put proper test here
NEED_REGISTER_FRAME_INFO=1
;;
fi
fi
+unset ac_cv_header_ft2build_h
+
if test x"$grub_mkfont_excuse" = x ; then
# Check for freetype libraries.
freetype_cflags=`$FREETYPE --cflags`
SAVED_CPPFLAGS="$CPPFLAGS"
CC="$BUILD_CC"
CFLAGS="$BUILD_CFLAGS"
-CPPFLAGS="$SAVED_CPPFLAGS"
+CPPFLAGS="$BUILD_CPPFLAGS"
+
+unset ac_cv_c_bigendian
+unset ac_cv_header_ft2build_h
+
+AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
+AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
+AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
+
+if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
+ AC_MSG_ERROR([couldnt determine build endianness])
+fi
+
+AC_SUBST([BUILD_SIZEOF_LONG])
+AC_SUBST([BUILD_SIZEOF_VOID_P])
+AC_SUBST([BUILD_WORDS_BIGENDIAN])
if test x"$grub_build_mkfont_excuse" = x ; then
# Check for freetype libraries.
- AC_CHECK_TOOLS([BUILD_FREETYPE], [freetype-config])
+ AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
if test "x$BUILD_FREETYPE" = x ; then
grub_build_mkfont_excuse=["need freetype2 library"]
fi
AC_SUBST([FONT_SOURCE])
-if test x"$FONT_SOURCE" = x && test x"$DJVU_FONT_SOURCE" = x; then
+if test x"$FONT_SOURCE" = x && test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
grub_build_mkfont_excuse="no fonts"
fi
else
echo With libzfs support: No "($libzfs_excuse)"
fi
-if [ x"$build_grub_mkfont_excuse" = x ]; then
+if [ x"$grub_build_mkfont_excuse" = x ]; then
echo Build-time grub-mkfont: Yes
if test "x$FONT_SOURCE" = x ; then
echo "Without unifont"
echo "With unifont from $FONT_SOURCE"
fi
else
- echo Build-time grub-mkfont: No "($build_grub_mkfont_excuse)"
+ echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
echo "Without unifont (no build-time grub-mkfont)"
fi
if test "x$LIBLZMA" = x ; then
CPPFLAGS_LIBRARY += $(CPPFLAGS_PLATFORM)
CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
+build-grub-pe2elf: $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
+ $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pe2elf\" $^
+
# gentrigtables
gentrigtables: gentrigtables.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $< -lm
return newstr;
}
-#ifndef GRUB_MKFONT
+#if !defined (GRUB_MKFONT) && !defined (GRUB_BUILD)
char *
xasprintf (const char *fmt, ...)
{
#include <grub/cpu/types.h>
#endif
-#ifdef GRUB_UTIL
+#ifdef GRUB_BUILD
+# define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P
+# define GRUB_CPU_SIZEOF_LONG BUILD_SIZEOF_LONG
+# if BUILD_WORDS_BIGENDIAN
+# define GRUB_CPU_WORDS_BIGENDIAN 1
+# else
+# undef GRUB_CPU_WORDS_BIGENDIAN
+# endif
+#elif defined (GRUB_UTIL)
# define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P
# define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG
# ifdef WORDS_BIGENDIAN
#include <stdlib.h>
#include <string.h>
+#ifndef GRUB_BUILD
#define _GNU_SOURCE 1
#include <argp.h>
+#endif
#include <assert.h>
+#include <errno.h>
+
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TAGS_H
#define FT_ERROR_END_LIST };
#include FT_ERRORS_H
+#ifndef GRUB_BUILD
#include "progname.h"
+#endif
#define GRUB_FONT_DEFAULT_SIZE 16
fclose (file);
}
+#ifndef GRUB_BUILD
static struct argp_option options[] = {
{"output", 'o', N_("FILE"), 0, N_("save output in FILE [required]"), 0},
/* TRANSLATORS: bitmaps are images like e.g. in JPEG. */
- {"width-spec", 0x103, 0, 0,
- /* TRANSLATORS: this refers to creating a file containing the width of
- every glyph but not the glyphs themselves. */
- N_("create width summary file"), 0},
{"index", 'i', N_("NUM"), 0,
/* TRANSLATORS: some font files may have multiple faces (fonts).
This option is used to chose among them, the first face being '0'.
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
{ 0, 0, 0, 0, 0, 0 }
};
+#define my_argp_parse argp_parse
+#define MY_ARGP_KEY_ARG ARGP_KEY_ARG
+#define my_error_t error_t
+#define MY_ARGP_ERR_UNKNOWN ARGP_ERR_UNKNOWN
+
+#else
+
+#define my_error_t int
+#define MY_ARGP_ERR_UNKNOWN -1
+#define MY_ARGP_KEY_ARG -1
+#define my_argp_parse(a, argc, argv, b, c, st) my_argp_parse_real(argc, argv, st)
+struct my_argp_state
+{
+ void *input;
+};
+
+#endif
struct arguments
{
enum file_formats file_format;
};
-static error_t
-argp_parser (int key, char *arg, struct argp_state *state)
+static int
+has_argument (int v)
+{
+ return v =='o' || v == 'i' || v == 'r' || v == 'n' || v == 's'
+ || v == 'd' || v == 'c';
+}
+
+static my_error_t
+argp_parser (int key, char *arg, struct my_argp_state *state)
{
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
font_verbosity++;
break;
- case ARGP_KEY_ARG:
+ case MY_ARGP_KEY_ARG:
assert (arguments->nfiles < arguments->files_max);
arguments->files[arguments->nfiles++] = xstrdup(arg);
break;
default:
- return ARGP_ERR_UNKNOWN;
+ return MY_ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+#ifdef GRUB_BUILD
+
+/* We don't require host platform to have argp. In the same time configuring
+ gnulib for build would result in even worse mess. So we have our
+ minimalistic argp replacement just enough for build system. Most
+ argp features are omitted. */
+
+static int
+my_argp_parse_real (int argc, char **argv, void *st)
+{
+ int curar;
+ struct my_argp_state p;
+
+ p.input = st;
+
+ for (curar = 1; curar < argc; )
+ {
+ if (argv[curar][0] == '-')
+ {
+ if (has_argument (argv[curar][1])
+ && curar + 1 >= argc)
+ return 1;
+ if (has_argument (argv[curar][1]))
+ {
+ if (argp_parser (argv[curar][1], argv[curar + 1], &p))
+ return 1;
+ curar += 2;
+ continue;
+ }
+ if (argp_parser (argv[curar][1], NULL, &p))
+ return 1;
+ curar++;
+ continue;
+ }
+ if (argp_parser (MY_ARGP_KEY_ARG, argv[curar], &p))
+ return 1;
+ curar++;
}
return 0;
}
+#endif
+#ifndef GRUB_BUILD
static struct argp argp = {
options, argp_parser, N_("[OPTIONS] FONT_FILES"),
N_("Convert common font file formats into PF2"),
NULL, NULL, NULL
};
+#endif
int
main (int argc, char *argv[])
FT_Library ft_lib;
struct arguments arguments;
+#ifndef GRUB_BUILD
set_program_name (argv[0]);
+#endif
grub_util_init_nls ();
memset (arguments.files, 0, (arguments.files_max + 1)
* sizeof (arguments.files[0]));
- if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
+ if (my_argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
{
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
exit(1);
#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
*
{
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]);
-
- if (optind + 1 < argc)
- optind++;
+ in = argv[1];
+ if (argc > 2)
+ out = argv[2];
+ else
+ out = in;
+ image = grub_util_read_image (in);
- 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);
#include <grub/script_sh.h>
#define ENABLE_RELOCATABLE 0
+#ifdef GRUB_BUILD
+const char *program_name = GRUB_BUILD_PROGRAM_NAME;
+#else
#include "progname.h"
+#endif
/* Include malloc.h, only if memalign is available. It is known that
memalign is declared in malloc.h in all systems, if present. */