Messages in this thread Patch in this message |  | | Date | Mon, 2 Oct 2000 08:06:08 -0500 (CDT) | From | Jeff Garzik <> | Subject | PATCH 2.4.0.9.8: support for external module building |
| |
Linus,
The attached patch against 2.4.0-test9-pre8 greatly improves support for maintaining open source modules outside the kernel.
This patch changes linux/Makefile to export all important Make settings with each kernel build, so that external modules can then pick up that info and build with the -exact- configuration that the kernel itself was built with.
The patch also includes docs for the feature, and adds include/linux/module.mak for use in external module Makefiles.
(this was authored by one of the Olaf's... Titz or Kirsch. Damn me, I can't remember who, to properly credit)
Jeff
diff -urN linux.vanilla/Documentation/external-modules.txt linux_2_3/Documentation/external-modules.txt --- linux.vanilla/Documentation/external-modules.txt Thu Jan 1 01:00:00 1970 +++ linux_2_3/Documentation/external-modules.txt Mon Oct 2 12:59:51 2000 @@ -0,0 +1,34 @@ +To compile external modules, you need the include tree of a configured +kernel (after doing at least "make dep"). + +Set up a Makefile in the module's directory which contains at least +these lines: + + # Object files which make up the module: without exported symbols + M_OBJS=foo.o bar.o + # ...and with exported symbols + MX_OBJS=fred.o + # Target into which the M_OBJS and MX_OBJS files are linked + M_TARGET=squish.o + + # set this to your kernel include directory. Use this variable name. + # make sure it ends in /include. + HPATH=/var/export/src/linux-2.3.99-pre3/include + include $(HPATH)/linux/module.mak + + +Then you can do... to do... + +make dep update the ksym tables if needed, + generate a dependencies file +make modules compile the objects and link them into a module +make modules_install install the module into its final location +make clean to clean up everything + +The module Makefile can define other variables, such as: + +EXTRA_CFLAGS additional CFLAGS for all objects +CFLAGS_foo.o additional CFLAGS for foo.o +PRE_CFLAGS additional CFLAGS for all objects, set first on + CC command line +INSTALL_MOD_PATH module installation root (default /) diff -urN linux.vanilla/Makefile linux_2_3/Makefile --- linux.vanilla/Makefile Mon Oct 2 13:05:12 2000 +++ linux_2_3/Makefile Mon Oct 2 12:59:47 2000 @@ -345,6 +345,26 @@ $(patsubst %, _modinst_%, $(SUBDIRS)) : $(MAKE) -C $(patsubst _modinst_%, %, $@) modules_install +include/linux/module.mak: dummy + @echo VERSION = $(VERSION) > .ver + @echo PATCHLEVEL = $(PATCHLEVEL) >> .ver + @echo SUBLEVEL = $(SUBLEVEL) >> .ver + @echo EXTRAVERSION = $(EXTRAVERSION) >> .ver + @echo ARCH = $(ARCH) >> .ver + @echo CC = $(CROSS_COMPILE)gcc >> .ver + @echo LD = $(LD) >> .ver + @echo GENKSYMS = $(GENKSYMS) >> .ver +ifdef CONFIG_SMP + @echo CONFIG_SMP = 1 >> .ver +endif +ifdef CONFIG_MODVERSIONS + @echo CONFIG_MODVERSIONS = 1 >> .ver +endif + @(echo CFLAGS = $(CFLAGS) $(MODFLAGS) | sed 's,$(TOPDIR)/include,$$(HPATH),g') >> .ver + @echo LINUX_COMPILER = \"`$(CC) -v 2>&1 | tail -1`\" >> .ver + @echo include '$$(HPATH)/linux/module.rules' >> .ver + @mv -f .ver $@ + # modules disabled.... else @@ -355,13 +375,18 @@ @echo "Then build a kernel with module support enabled." @echo @exit 1 + +include/linux/module.mak: dummy + @echo modules modules_install: > .ver + @$(MAKE) -n modules | sed -n "s/^e/ @e/p" >> .ver + @mv -f .ver $@ + endif clean: archclean rm -f kernel/ksyms.lst include/linux/compile.h - find . -name '*.[oas]' -type f -print | grep -v lxdialog/ | xargs rm -f - rm -f core `find . -type f -name 'core' -print` - rm -f core `find . -type f -name '.*.flags' -print` + find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' \) -type f -print | \ + grep -v lxdialog/ | xargs rm -f rm -f vmlinux System.map rm -f .tmp* rm -f drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c @@ -376,7 +401,9 @@ $(MAKE) -C Documentation/DocBook clean mrproper: clean archmrproper - rm -f include/linux/autoconf.h include/linux/version.h + find . \( -name .depend -o -name core -o -size 0 \) -type f -print | \ + xargs rm -f + rm -f include/linux/autoconf.h include/linux/version.h include/linux/module.mak rm -f drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h rm -f drivers/net/hamradio/soundmodem/sm_tbl_{hapn4800,psk4800}.h rm -f drivers/net/hamradio/soundmodem/sm_tbl_{afsk2400_7,afsk2400_8}.h @@ -394,8 +421,6 @@ rm -f .menuconfig.log rm -f include/asm rm -rf include/config - rm -f .depend `find . -type f -name .depend -print` - rm -f core `find . -type f -size 0 -print` rm -f .hdepend scripts/mkdep scripts/split-include scripts/docproc rm -f $(TOPDIR)/include/linux/modversions.h rm -rf $(TOPDIR)/include/linux/modules @@ -427,7 +452,7 @@ sums: find . -type f -print | sort | xargs sum > .SUMS -dep-files: scripts/mkdep archdep include/linux/version.h +dep-files: scripts/mkdep archdep include/linux/version.h include/linux/module.mak scripts/mkdep init/*.c > .depend scripts/mkdep `find $(FINDHPATH) -name SCCS -prune -o -follow -name \*.h ! -name modversions.h -print` > .hdepend $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" diff -urN linux.vanilla/include/linux/module.rules linux_2_3/include/linux/module.rules --- linux.vanilla/include/linux/module.rules Thu Jan 1 01:00:00 1970 +++ linux_2_3/include/linux/module.rules Mon Oct 2 13:00:57 2000 @@ -0,0 +1,135 @@ +# This file is included by $(HPATH)/linux/module.mak. + +KERNELRELEASE = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) + +.PHONY: dummy +unexport EXTRA_AFLAGS +unexport EXTRA_CFLAGS +unexport EXTRA_LDFLAGS +unexport EXTRA_ARFLAGS +unexport SUBDIRS +unexport SUB_DIRS +unexport ALL_SUB_DIRS +unexport MOD_SUB_DIRS +unexport O_TARGET +unexport O_OBJS +unexport L_OBJS +unexport M_OBJS +unexport MI_OBJS +unexport ALL_MOBJS +unexport OX_OBJS +unexport LX_OBJS +unexport MX_OBJS +unexport MIX_OBJS +unexport SYMTAB_OBJS + +ALL_OBJS = $(M_OBJS) $(MX_OBJS) +ifdef M_TARGET +I_OBJ = $(M_TARGET) $(MI_OBJS) +else +I_OBJ = $(ALL_OBJS) $(MI_OBJS) +endif + +# Generate dependencies first if necessary + +ifeq (.depend, $(wildcard .depend)) +all modules: modules_compile +include .depend +else +all modules: + $(MAKE) depend + $(MAKE) modules_compile +endif + +dep fastdep depend:: .depend + +.depend: $(wildcard *.[hc]) + @$(CC) $(CFLAGS) -M $(ALL_OBJS:.o=.c) > .tmp + @for i in $(SYMTAB_OBJS); do echo CFLAGS_$$i += -DEXPORT_SYMTAB; done >> .tmp + @mv -f .tmp .depend + +# Compilation targets + +modules_compile: check_compiler_version $(I_OBJ) $(O_OBJS) $(OX_OBJS) + +modules_install: modules + @( \ + if [ "$(MOD_GROUP)" ]; then \ + MODLIB=$(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)/$(MOD_GROUP);\ + else \ + MODLIB=$(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)/misc;\ + fi; \ + echo Installing modules under $$MODLIB; \ + mkdir -p $$MODLIB; \ + cp $(I_OBJ) $$MODLIB; \ + ) + +check_compiler_version: + @if [ "`$(CC) -v 2>&1 | tail -1`" != $(LINUX_COMPILER) ]; \ + then echo WARNING: compiler mismatch; \ + fi + +dummy $(M_TARGET): $(ALL_OBJS) + $(LD) -r -o $(M_TARGET) $(ALL_OBJS) + +%.s: %.c + $(CC) $(PRE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@ + +%.i: %.c + $(CC) $(PRE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -E $< > $@ + +%.o: %.c + $(CC) $(PRE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $< + +%.o: %.S + $(CC) $(PRE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $< + +# Update the symbol version tables + +SYMTAB_OBJS = $(MX_OBJS) $(OX_OBJS) + +ifdef CONFIG_MODVERSIONS +ifneq "$(strip $(SYMTAB_OBJS))" "" + +MODINCL = $(HPATH)/linux/modules + +ifdef CONFIG_SMP + genksyms_smp_prefix := -p smp_ +else + genksyms_smp_prefix := +endif + +$(MODINCL)/%.ver: %.c + @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \ + echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \ + echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \ + $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \ + | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \ + else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \ + fi; touch $(MODINCL)/$*.stamp + +$(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(HPATH)/linux/autoconf.h + +$(HPATH)/linux/modversions.h: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)) + @echo updating $(HPATH)/linux/modversions.h + @(echo "#ifndef _LINUX_MODVERSIONS_H";\ + echo "#define _LINUX_MODVERSIONS_H"; \ + echo "#include <linux/modsetver.h>"; \ + cd $(HPATH)/linux/modules; \ + for f in *.ver; do \ + if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \ + done; \ + echo "#endif"; \ + ) > $@ + +dep fastdep depend:: $(HPATH)/linux/modversions.h + +endif +endif + +# Clean + +clean mrproper:: + -rm -f *.o *.a .depend + - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/
|  |