2.4.0-pre5 Replacement for make modules_install

From: Keith Owens (kaos@ocs.com.au)
Date: Mon Jul 31 2000 - 09:19:52 EST


Problem with make modules_install:

Any Makefile that defines modules has to include MOD_LIST_NAME := XXX.
All the 'XXX' names should be unique because the first thing the
Rules.make entries do is erase any existing $(MOD_LIST_NAME). Two
kernel directories cannot write to the same MOD_LIST_NAME, one will
replace the other's list of module names. At install time, any module
not listed in an XXX entry is installed in misc.

But we have conflicts, from 2.3.99-pre6

net/ipv4/Makefile:MOD_LIST_NAME := IPV4_MODULES
net/ipv4/netfilter/Makefile:MOD_LIST_NAME := IPV4_MODULES

net/irda/Makefile:MOD_LIST_NAME := IRDA_MODULES
net/irda/compressors/Makefile:MOD_LIST_NAME := IRDA_MODULES
net/irda/irlan/Makefile:MOD_LIST_NAME := IRDA_MODULES

net/Makefile:MOD_LIST_NAME := NET_MISC_MODULES
net/econet/Makefile:MOD_LIST_NAME := NET_MISC_MODULES
net/netlink/Makefile:MOD_LIST_NAME := NET_MISC_MODULES
net/packet/Makefile:MOD_LIST_NAME := NET_MISC_MODULES

drivers/net/Makefile:MOD_LIST_NAME := NET_MODULES
net/khttpd/Makefile:MOD_LIST_NAME := NET_MODULES

This guarantees that some files go in misc. Even worse, which ones go
in misc and which ones go in the correct directory will depend on the
order that the directories were scanned during module compile, last
compiled will be stored correctly, earlier goes in misc.

What happens when you have khttpd built in? A normal "make modules"
does the drivers tree first, then net, leaving the drivers/net modules
in NET_MODULES. Now configure khttpd as a module, make modules will
compile net/khttpd last and replace NET_MODULES. make modules_install
puts khttpd in modules/.../net and installs all the drivers/net modules
in modules/.../misc. Even worse, it does not erase the old entries
from modules/... so you end up with two copies of the network modules,
one in net, one in misc. And the net entries (the older set) get
scanned first!

Besides the name conflicts above, the top level Makefile has to map the
'XXX' names to directories under /lib/modules/`uname -r`. So we have
insanity like this

  if [ -f PCMCIA_NET_MODULES ]; then inst_mod PCMCIA_NET_MODULES pcmcia; fi; \
  if [ -f PCMCIA_CHAR_MODULES ]; then inst_mod PCMCIA_CHAR_MODULES pcmcia; fi; \
  if [ -f PCMCIA_SCSI_MODULES ]; then inst_mod PCMCIA_SCSI_MODULES pcmcia; fi; \

We have to test for different 'XXX' names (required because of
Rules.make), but they all map to the same target directory.

Whenever a new directory is created under /lib/modules/..., modutils
has to be updated to scan the new directory.

To quote mec, "This system is crud all the way down".

Solution:

A simple one to one mapping between the kernel tree and
/lib/modules/.../kernel removes all the mapping problems. Forget
MOD_LIST_NAME. Remove linux/modules entirely. Copy modules to
/lib/modules/`uname -r` in the same tree as the kernel. So you have

/lib/modules/`uname -r` Text files only, etc.), no modules.
   kernel All the kernel modules, same directory structure as the
            kernel.
   pcmcia PCMCIA external modules, i.e. those from pcmcia-cs.
   vmware Example of third party modules, each has their own
            directory under /lib/modules/...

modutils 2.3.12 will scan kernel recursively, then the old names (net,
misc, block, usb etc.), then any directories not already scanned.

make modules_install will erase /lib/modules/`uname -r`/kernel before
installing a new one, ensuring that no old entries are lying around.

It will also create modules.dep at install time if System.map exists.
This avoids problems with read only media and kmod on the first boot.

This patch is backwards compatible with the old names, automatically
removes any obsolete modules, reduces the maintenance effort for kernel
developers, removes the need to update modutils for new directory
names, fixes first boot problems. Now if I can only get it to brew my
coffee ...

Index: 0-test5.1/Rules.make
--- 0-test5.1/Rules.make Fri, 23 Jun 2000 07:53:48 +1000 kaos (linux-2.4/B/c/24_Rules.make 1.2 644)
+++ 0-test5.4/Rules.make Mon, 31 Jul 2000 23:56:06 +1000 kaos (linux-2.4/B/c/24_Rules.make 1.3 644)
@@ -32,8 +32,6 @@
 unexport MIX_OBJS
 unexport SYMTAB_OBJS
 
-unexport MOD_LIST_NAME
-
 #
 # Get things started.
 #
@@ -132,37 +130,32 @@
 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
 endif
 
-ifdef MOD_SUB_DIRS
-$(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) : dummy
+unexport MOD_DIRS
+MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
+ifneq "$(strip $(MOD_DIRS))" ""
+.PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
+$(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
         $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
-endif
 
-ifdef MOD_IN_SUB_DIRS
-$(patsubst %,_modinsubdir_%,$(MOD_IN_SUB_DIRS)) : dummy
- $(MAKE) -C $(patsubst _modinsubdir_%,%,$@) modules
+.PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
+$(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
+ $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
 endif
 
+.PHONY: modules
 modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy \
- $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) \
- $(patsubst %,_modinsubdir_%,$(MOD_IN_SUB_DIRS))
-ifneq "$(strip $(MOD_LIST_NAME))" ""
- rm -f $$TOPDIR/modules/$(MOD_LIST_NAME)
-ifdef MOD_SUB_DIRS
- for i in $(MOD_SUB_DIRS); do \
- echo `basename $$i`.o >> $$TOPDIR/modules/$(MOD_LIST_NAME); done
-endif
-ifneq "$(strip $(ALL_MOBJS))" ""
- echo $(ALL_MOBJS) >> $$TOPDIR/modules/$(MOD_LIST_NAME)
-endif
-ifneq "$(strip $(MOD_TO_LIST))" ""
- echo $(MOD_TO_LIST) >> $$TOPDIR/modules/$(MOD_LIST_NAME)
-endif
-endif
+ $(patsubst %,_modsubdir_%,$(MOD_DIRS))
+
+.PHONY: _modinst__
+_modinst__: dummy
 ifneq "$(strip $(ALL_MOBJS))" ""
- echo $(PDWN)
- cd $$TOPDIR/modules; for i in $(ALL_MOBJS); do \
- ln -sf ../$(PDWN)/$$i $$i; done
+ mkdir -p $(MODLIB)/kernel/$(PDWN)
+ cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)
 endif
+
+.PHONY: modules_install
+modules_install: _modinst__ \
+ $(patsubst %,_modinst_%,$(MOD_DIRS))
 
 #
 # A rule to do nothing
Index: 0-test5.1/Makefile
--- 0-test5.1/Makefile Fri, 28 Jul 2000 11:39:59 +1000 kaos (linux-2.4/B/c/27_Makefile 1.1.2.2.2.4.1.7 644)
+++ 0-test5.4/Makefile Mon, 31 Jul 2000 23:56:06 +1000 kaos (linux-2.4/B/c/27_Makefile 1.1.2.2.2.4.1.8 644)
@@ -35,6 +35,7 @@
 OBJDUMP = $(CROSS_COMPILE)objdump
 MAKEFILES = $(TOPDIR)/.config
 GENKSYMS = /sbin/genksyms
+DEPMOD = /sbin/depmod
 MODFLAGS = -DMODULE
 CFLAGS_KERNEL =
 PERL = perl
@@ -77,6 +78,9 @@
 # makefile but the arguement can be passed to make if needed.
 #
 
+MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
+export MODLIB
+
 #
 # standard CFLAGS
 #
@@ -294,64 +298,49 @@
 MODFLAGS += -DMODVERSIONS -include $(HPATH)/linux/modversions.h
 endif
 
+.PHONY: modules
 modules: $(patsubst %, _mod_%, $(SUBDIRS))
 
-modules/MARKER:
- mkdir -p modules
- touch modules/MARKER
-
-$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER modules/MARKER
+.PHONY: $(patsubst %, _mod_%, $(SUBDIRS))
+$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER
         $(MAKE) -C $(patsubst _mod_%, %, $@) CFLAGS="$(CFLAGS) $(MODFLAGS)" MAKING_MODULES=1 modules
 
-modules_install:
- @( \
- MODLIB=$(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE); \
- mkdir -p $$MODLIB; \
- rm -f $$MODLIB/build; \
- ln -s $TOPDIR $$MODLIB/build; \
- cd modules; \
- MODULES=""; \
- inst_mod() { These="`cat $$1`"; MODULES="$$MODULES $$These"; \
- mkdir -p $$MODLIB/$$2; cp $$These $$MODLIB/$$2; \
- echo Installing modules under $$MODLIB/$$2; \
- }; \
- \
- if [ -f BLOCK_MODULES ]; then inst_mod BLOCK_MODULES block; fi; \
- if [ -f NET_MODULES ]; then inst_mod NET_MODULES net; fi; \
- if [ -f IPV4_MODULES ]; then inst_mod IPV4_MODULES ipv4; fi; \
- if [ -f IPV6_MODULES ]; then inst_mod IPV6_MODULES ipv6; fi; \
- if [ -f ATM_MODULES ]; then inst_mod ATM_MODULES atm; fi; \
- if [ -f IDE_MODULES ]; then inst_mod IDE_MODULES ide; fi; \
- if [ -f SCSI_MODULES ]; then inst_mod SCSI_MODULES scsi; fi; \
- if [ -f FS_MODULES ]; then inst_mod FS_MODULES fs; fi; \
- if [ -f NLS_MODULES ]; then inst_mod NLS_MODULES fs; fi; \
- if [ -f CDROM_MODULES ]; then inst_mod CDROM_MODULES cdrom; fi; \
- if [ -f HAM_MODULES ]; then inst_mod HAM_MODULES net; fi; \
- if [ -f SOUND_MODULES ]; then inst_mod SOUND_MODULES sound; fi; \
- if [ -f VIDEO_MODULES ]; then inst_mod VIDEO_MODULES video; fi; \
- if [ -f FC4_MODULES ]; then inst_mod FC4_MODULES fc4; fi; \
- if [ -f IRDA_MODULES ]; then inst_mod IRDA_MODULES net; fi; \
- if [ -f SK98LIN_MODULES ]; then inst_mod SK98LIN_MODULES net; fi; \
- if [ -f SKFP_MODULES ]; then inst_mod SKFP_MODULES net; fi; \
- if [ -f USB_MODULES ]; then inst_mod USB_MODULES usb; fi; \
- if [ -f USB_STORAGE_MODULES ]; then inst_mod USB_STORAGE_MODULES usb; fi; \
- if [ -f USB_SERIAL_MODULES ]; then inst_mod USB_SERIAL_MODULES usb; fi; \
- if [ -f IEEE1394_MODULES ]; then inst_mod IEEE1394_MODULES ieee1394; fi; \
- if [ -f MTD_MODULES ]; then inst_mod MTD_MODULES mtd; fi; \
- if [ -f PCMCIA_MODULES ]; then inst_mod PCMCIA_MODULES pcmcia; fi; \
- if [ -f PCMCIA_NET_MODULES ]; then inst_mod PCMCIA_NET_MODULES pcmcia; fi; \
- if [ -f PCMCIA_CHAR_MODULES ]; then inst_mod PCMCIA_CHAR_MODULES pcmcia; fi; \
- if [ -f PCMCIA_SCSI_MODULES ]; then inst_mod PCMCIA_SCSI_MODULES pcmcia; fi; \
- \
- ls -1 -U *.o | sort > $$MODLIB/.allmods; \
- if [ -f $$MODLIB/net/3c59x.o ]; then \
- mkdir -p $$MODLIB/pcmcia; \
- ln -nfs ../net/3c59x.o $$MODLIB/pcmcia/3c575_cb.o; \
- MODULES="$$MODULES 3c575_cb.o"; fi; \
- echo $$MODULES | tr ' ' '\n' | sort | comm -23 $$MODLIB/.allmods - > $$MODLIB/.misc; \
- if [ -s $$MODLIB/.misc ]; then inst_mod $$MODLIB/.misc misc; fi; \
- rm -f $$MODLIB/.misc $$MODLIB/.allmods; \
- )
+.PHONY: modules_install
+modules_install: _modinst_ $(patsubst %, _modinst_%, $(SUBDIRS)) _modinst_post
+
+.PHONY: _modinst_
+_modinst_:
+ @rm -rf $(MODLIB)/kernel
+ @rm -f $(MODLIB)/build
+ @mkdir -p $(MODLIB)/kernel
+ @ln -s $(TOPDIR) $(MODLIB)/build
+
+# If System.map exists, run depmod. This deliberately does not have a
+# dependency on System.map since that would run the dependency tree on
+# vmlinux. This depmod is only for convenience to give the initial
+# boot a modules.dep even before / is mounted read-write. However the
+# boot script depmod is the master version.
+ifeq "$(strip $(INSTALL_MOD_PATH))" ""
+depmod_opts :=
+else
+depmod_opts := -b $(INSTALL_MOD_PATH) -r
+endif
+.PHONY: _modinst_post
+_modinst_post: _modinst_post_pcmcia
+ if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
+
+# Backwards compatibilty symlinks for people still using old versions
+# of pcmcia-cs with hard coded pathnames on insmod. Remove
+# _modinst_post_pcmcia for kernel 2.4.1.
+.PHONY: _modinst_post_pcmcia
+_modinst_post_pcmcia:
+ cd $(MODLIB); \
+ mkdir -p pcmcia; \
+ find kernel -path '*/pcmcia/*' -name '*.o' | xargs -i -r ln -sf ../{} pcmcia
+
+.PHONY: $(patsubst %, _modinst_%, $(SUBDIRS))
+$(patsubst %, _modinst_%, $(SUBDIRS)) :
+ $(MAKE) -C $(patsubst _modinst_%, %, $@) modules_install
 
 # modules disabled....
 
Index: 0-test5.1/Documentation/Changes
--- 0-test5.1/Documentation/Changes Wed, 26 Jul 2000 15:10:34 +1000 kaos (linux-2.4/G/c/25_Changes 1.1.1.4 644)
+++ 0-test5.4/Documentation/Changes Mon, 31 Jul 2000 23:56:06 +1000 kaos (linux-2.4/G/c/25_Changes 1.1.1.5 644)
@@ -43,7 +43,7 @@
 o Gnu C 2.7.2.3 # gcc --version
 o binutils 2.9.1.0.22 # ld -v
 o util-linux 2.10g # chsh -v
-o modutils 2.3.10 # insmod -V
+o modutils 2.3.13 # insmod -V
 o e2fsprogs 1.18 # /sbin/tune2fs --version
 o pcmcia-cs 3.1.13 # cardmgr -V
 o PPP 2.4.0b1 # pppd --version
@@ -266,8 +266,8 @@
 
 Modutils
 --------
-o ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils/v2.3/modutils-2.3.9.tar.gz
- <ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils/v2.3/modutils-2.3.9.tar.gz>
+o ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils/v2.3/modutils-2.3.13.tar.gz
+ <ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils/v2.3/modutils-2.3.13.tar.gz>
 
 E2fsprogs
 ---------

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jul 31 2000 - 21:00:33 EST