On Sat, Nov 01, 2008 at 01:32:29PM +0100, Robert Millan wrote:
>
> Hi,
>
> Attached patch makes it possible to build modules externally, by:
>
> - Installing headers in system include dir.
>
> - Exporting two ABI tags (a build-time macro and a run-time variable)
> for run-time comparison.
>
> - Exporting a makefile with COMMON_*FLAGS variables.
Looks like I missed some important details. The headers and some macros are
not enough, as we need to reproduce part of the build system to build a module
externally. This new patch provides the following:
In pkgdata: genmodsrc.sh genmk.rb
In pkglib: config.h grub_script.tab.h build_env.mk
In includedir: header files
How to use:
cat > Makefile.in << EOF
srcdir = /usr/share/grub
builddir = /usr/lib/grub/i386-pc
include $(builddir)/build_env.mk
pkglib_MODULES += mymod.mod
mymod_mod_SOURCES = mymod.c
mymod_mod_CFLAGS = $(COMMON_CFLAGS)
mymod_mod_LDFLAGS = $(COMMON_LDFLAGS)
EOF
ruby /usr/share/grub/genmk.rb < Makefile.in > Makefile
make
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
2008-11-01 Robert Millan <[EMAIL PROTECTED]>
* Makefile.in (PKGLIB): Add $(pkglib_BUILDDIR).
(PKGDATA): Add $(pkgdata_SRCDIR).
(pkglib_BUILDDIR): New variable.
(pkgdata_SRCDIR): New variable.
(build_env.mk): New target.
(include_DATA): New variable.
(install-local): Install $(include_DATA) files in $(includedir).
* include/grub/misc.h (GRUB_ABI): New macro (initialize as 0).
(grub_abi): New variable prototype.
* kern/main.c (grub_abi): New variable (initialize as GRUB_ABI).
Index: Makefile.in
===================================================================
--- Makefile.in (revision 1891)
+++ Makefile.in (working copy)
@@ -105,8 +105,8 @@
MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES))
PKGLIB = $(pkglib_IMAGES) $(pkglib_MODULES) $(pkglib_PROGRAMS) \
- $(pkglib_DATA) $(lib_DATA)
-PKGDATA = $(pkgdata_DATA)
+ $(pkglib_DATA) $(lib_DATA) $(pkglib_BUILDDIR)
+PKGDATA = $(pkgdata_DATA) $(pkgdata_SRCDIR)
PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES)
SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS)
@@ -163,6 +163,22 @@
ruby $(srcdir)/util/unifont2pff.rb 0x0-0x7f $(UNICODE_ARROWS) $(UNICODE_LINES) $(UNIFONT_HEX) > $@
endif
+# Used for building modules externally
+pkglib_BUILDDIR += build_env.mk
+build_env.mk: Makefile
+ (\
+ echo "TARGET_CC=$(TARGET_CC)" ; \
+ echo "TARGET_CFLAGS=$(TARGET_CFLAGS)" ; \
+ echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir)" ; \
+ echo "STRIP=$(STRIP)" ; \
+ echo "COMMON_ASFLAGS=$(COMMON_ASFLAGS)" ; \
+ echo "COMMON_CFLAGS=$(COMMON_CFLAGS)" ; \
+ echo "COMMON_LDFLAGS=$(COMMON_LDFLAGS)"\
+ ) > $@
+pkglib_BUILDDIR += config.h grub_script.tab.h
+pkgdata_SRCDIR += genmodsrc.sh genmk.rb
+include_DATA += $(shell find include -name \*.h) include/grub/cpu
+
all-local: $(PROGRAMS) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(MKFILES)
install: install-local
@@ -175,6 +191,19 @@
dest="`echo $$file | sed 's,.*/,,'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkglibdir)/$$dest; \
done
+ $(mkinstalldirs) $(DESTDIR)$(includedir)
+ @list='$(include_DATA)'; \
+ for file in $$list; do \
+ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
+ dest="`echo $$file | sed 's,include/,,'`"; \
+ destdir="`echo $$dest | sed 's,\(^\|/\)[^/]*$$,,g'`"; \
+ $(mkinstalldirs) $(DESTDIR)$(includedir)/$$destdir; \
+ if test -f "$$dir$$file"; then \
+ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(includedir)/$$dest; \
+ elif test -L "$$dir$$file"; then \
+ cp -d $$dir$$file $(DESTDIR)$(includedir)/$$dest; \
+ fi; \
+ done
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)
@list='$(PKGDATA)'; \
for file in $$list; do \
Index: kern/main.c
===================================================================
--- kern/main.c (revision 1891)
+++ kern/main.c (working copy)
@@ -28,6 +28,8 @@
#include <grub/env.h>
#include <grub/mm.h>
+grub_uint32_t grub_abi = GRUB_ABI;
+
void
grub_module_iterate (int (*hook) (struct grub_module_header *header))
{
Index: include/grub/misc.h
===================================================================
--- include/grub/misc.h (revision 1891)
+++ include/grub/misc.h (working copy)
@@ -25,6 +25,10 @@
#include <grub/symbol.h>
#include <grub/err.h>
+/* Increase this number every time GRUB ABI is changed. */
+#define GRUB_ABI 0
+extern grub_uint32_t EXPORT_VAR(grub_abi);
+
#define ALIGN_UP(addr, align) (((grub_uint64_t)addr + align - 1) & ~(align - 1))
#define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, __LINE__, condition, fmt, ## args);
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel