Use kernel build system for linux-2.4.
authorBen Pfaff <blp@nicira.com>
Tue, 3 Jun 2008 00:05:42 +0000 (17:05 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 3 Jun 2008 21:02:13 +0000 (14:02 -0700)
Based on changes originally by Bobby Holley <bobbyholley@stanford.edu>.

INSTALL
configure.ac
datapath/Modules.mk
datapath/linux-2.4/Kbuild.in [new file with mode: 0644]
datapath/linux-2.4/Makefile.in
datapath/linux-2.4/Makefile.main.in [new file with mode: 0644]
datapath/linux-2.6/Kbuild.in
datapath/linux-2.6/Makefile.main.in

diff --git a/INSTALL b/INSTALL
index 7f49351..fbacb67 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -281,6 +281,13 @@ To build for a running instance of Linux 2.4:
 
       % ./configure --with-l24=/lib/modules/`uname -r`/build
 
+If you wish to build OpenFlow for an architecture other than the architecture
+used for compilation, you may specify the kernel architecture string using the
+KARCH variable when invoking the configure script. For example, to build
+OpenFlow for MIPS with Linux 2.4:
+
+      % ./configure --with-l24=/path/to/linux-2.4 KARCH=mips
+
 If you have hardware that supports accelerated OpenFlow switching, and
 you have obtained a hardware table module for your hardware and
 extracted it into the OpenFlow reference distribution source tree,
index 2c2b427..d22a71b 100644 (file)
@@ -47,6 +47,9 @@ for d in $hw_tables; do
 done
 AC_SUBST(HW_TABLES)
 
+AC_ARG_VAR(KARCH, [Kernel Architecture String])
+AC_SUBST(KARCH)
+
 CHECK_LINUX(l26, 2.6, 2.6, KSRC26, L26_ENABLED)
 CHECK_LINUX(l24, 2.4, 2.4, KSRC24, L24_ENABLED)
 
@@ -119,6 +122,8 @@ third-party/Makefile
 datapath/linux-2.6/Kbuild
 datapath/linux-2.6/Makefile
 datapath/linux-2.6/Makefile.main
-datapath/linux-2.4/Makefile])
+datapath/linux-2.4/Kbuild
+datapath/linux-2.4/Makefile
+datapath/linux-2.4/Makefile.main])
 
 AC_OUTPUT
index 6c0509c..099be0e 100644 (file)
@@ -36,6 +36,5 @@ dist_sources = $(foreach module,$(dist_modules),$($(module)_sources))
 dist_headers = $(foreach module,$(dist_modules),$($(module)_headers))
 all_sources = $(foreach module,$(all_modules),$($(module)_sources))
 all_headers = $(foreach module,$(all_modules),$($(module)_headers))
-all_objects = $(patsubst %.c,%.o,$(all_sources))
-all_objdirs = $(addprefix $(builddir)/,$(sort $(dir $(all_objects))))
-all_dummies = $(addsuffix /.dummy,$(all_objdirs))
+all_links = $(notdir $(all_sources))
+all_objects = $(notdir $(patsubst %.c,%.o,$(all_sources)))
diff --git a/datapath/linux-2.4/Kbuild.in b/datapath/linux-2.4/Kbuild.in
new file mode 100644 (file)
index 0000000..1a6c617
--- /dev/null
@@ -0,0 +1,79 @@
+# -*- makefile -*-
+builddir = @abs_builddir@
+srcdir = @abs_srcdir@
+top_srcdir = @abs_top_srcdir@
+KSRC = @KSRC24@
+VERSION = @VERSION@
+
+# File Lists
+include $(srcdir)/../Modules.mk
+include $(srcdir)/Modules.mk
+include @HW_TABLES@
+
+# This is somewhat hacky. We want to include our compatibility headers before
+# any header files in the kernel by the same name. Unfortunately, the only
+# mechanism the kernel provides to add cflags is the EXTRA_CFLAGS variable,
+# which gets inserted into the build command after the internal kernel CFLAGS.
+# Since our stuff needs to come first, we override the variable.
+OF_CFLAGS = -I$(srcdir)/compat-2.4/include -I$(srcdir)/compat-2.4/include-$(ARCH) \
+            -I$(srcdir)/compat-2.4 -I$(srcdir)/.. -I$(srcdir)/../../include \
+                                                -I$(builddir)/.. $(CFLAGS) -DVERSION=\"$(VERSION)\"
+override CFLAGS := $(OF_CFLAGS)
+
+# Multipart objects
+list-multi := $(patsubst %,%_mod.o,$(all_modules))
+
+# Module objects that we can build
+obj-m += $(list-multi)
+
+# Object Parts
+define parts_template
+$(1)_mod-objs = $$(patsubst %.c,%.o,$(notdir $($(1)_sources)))
+endef
+$(foreach module,$(all_modules),$(eval $(call parts_template,$(module))))
+
+# Objects that export symbols
+export-objs = $(all_objects)
+
+# Include the kernel's global Rules.make
+include $(TOPDIR)/Rules.make
+
+# Link rules for multi-part objects
+define link_template
+$(1)_mod.o: $($(1)_mod-objs)
+       $(LD) -r -o $$@ $($(1)_mod-objs)
+endef
+$(foreach module,$(all_modules),$(eval $(call link_template,$(module))))
+
+# Build system rewrite May 2008: Bobby Holley <bh10@stanford.edu>
+#
+# A few bits and pieces of this file might be derived from Intel's e1000
+# distribution, with the following license:
+
+################################################################################
+#
+# Intel PRO/1000 Linux driver
+# Copyright(c) 1999 - 2007 Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The full GNU General Public License is included in this distribution in
+# the file called "COPYING".
+#
+# Contact Information:
+# Linux NICS <linux.nics@intel.com>
+# e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
+# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+#
+################################################################################
index 1a68376..b30f2ba 100644 (file)
@@ -1,131 +1,9 @@
-builddir = @abs_builddir@
-srcdir = @abs_srcdir@
-top_srcdir = @abs_top_srcdir@
-KSRC = @KSRC24@
-VERSION = @VERSION@
-
-# The names vpath and VPATH are very special for GNU Make and Automake.
-# The following odd construction works around these oddities, whereas
-# the straightforward "VPATH = $(srcdir)/.." will not work.
-v = $(srcdir)/..
-VPATH = $(v)
-
-include $(srcdir)/../Modules.mk
-include $(srcdir)/Modules.mk
-include @HW_TABLES@
-
-default:
-distclean: clean
-distdir: clean
-install:
-all: default
-clean:
-       rm -f $(all_objects) *_mod.o $(all_dummies)
-       for d in $(all_objdirs); do             \
-               while                           \
-                       rmdir $$d 2> /dev/null; \
-               do                              \
-                       d=`dirname $$d`;        \
-               done;                           \
-       done
-
-check: all
-
-ifneq (,$(KSRC))
-ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
-  KOBJ :=  /lib/modules/$(shell uname -r)/build
-else
-  KOBJ :=  $(KSRC)
-endif
-
-ifneq ($(shell grep -c 'PATCHLEVEL = 4' $(KSRC)/Makefile),1)
-  $(error Linux kernel source in $(KSRC) not 2.4)
-endif
-
-VERSION_FILE := $(KOBJ)/include/linux/version.h
-ifeq (,$(wildcard $(VERSION_FILE)))
-  $(error Linux kernel source not configured - missing version.h)
-endif
-
-CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
-ifeq (,$(wildcard $(CONFIG_FILE)))
-  $(error Linux kernel source not configured - missing autoconf.h)
-endif
-
-K_SUBLEVEL := $(shell sed -n 's/SUBLEVEL = // p' $(KSRC)/Makefile)
-ifeq ($(shell test $(K_SUBLEVEL) -le 20; echo $?), 0)
-  # 2.4.20 and before require GCC 2.95.
-  CC := gcc-2.95
+ifneq ($(MAKING_MODULES),1)
+# We're being called directly by running make in this directory.
+include Makefile.main
 else
-  # Later 2.4 versions are more flexible.
-  CC := gcc-3.4 gcc-3.3 gcc-2.95
-endif
-test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
-CC := $(foreach cc, $(CC), $(test_cc))
-CC := $(firstword $(CC))
-ifeq (,$(CC))
-  $(error Compiler not found)
-endif
-
-CFLAGS = -DVERSION=\"$(VERSION)\" -O2 -g
-CFLAGS += -I $(srcdir)/.. -I $(builddir)/.. -I $(top_srcdir)/include
-ifeq ($(ARCH),)
-  ARCH := $(shell uname -m | sed 's/i.86/i386/')
-endif
-CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
-CFLAGS += -I$(srcdir)/compat-2.4/include-$(ARCH)
-CFLAGS += -I$(srcdir)/compat-2.4/include
-CFLAGS += -I$(srcdir)/compat-2.4
-CFLAGS += -I$(KSRC)/include -I.
-CFLAGS += -Wno-sign-compare -fno-strict-aliasing
-CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
-            echo "-DMODVERSIONS -DEXPORT_SYMTAB \
-                  -include $(KSRC)/include/linux/modversions.h")
-
-$(all_objects): $(all_dummies)
-$(all_dummies):
-       mkdir -p $(@D)
-       touch $@
-
-default: $(patsubst %,%_mod.o,$(all_modules))
-
-define module_template
-$(1)_objects = $$(patsubst %.c,%.o,$($(1)_sources))
-$($(1)_sources): $(headers)
-$(1)_mod.o: $$($(1)_objects)
-       $(LD) $(LDFLAGS) -r $$^ -o $$@
-endef
-
-$(foreach module,$(all_modules),$(eval $(call module_template,$(module))))
+# We're being included by the Linux kernel build system
+include Kbuild
 endif
 
-# Much of the kernel build system in this file is derived from Intel's
-# e1000 distribution, with the following license:
 
-################################################################################
-#
-# Intel PRO/1000 Linux driver
-# Copyright(c) 1999 - 2007 Intel Corporation.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms and conditions of the GNU General Public License,
-# version 2, as published by the Free Software Foundation.
-#
-# This program is distributed in the hope it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# The full GNU General Public License is included in this distribution in
-# the file called "COPYING".
-#
-# Contact Information:
-# Linux NICS <linux.nics@intel.com>
-# e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
-# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
-#
-################################################################################
diff --git a/datapath/linux-2.4/Makefile.main.in b/datapath/linux-2.4/Makefile.main.in
new file mode 100644 (file)
index 0000000..4b54259
--- /dev/null
@@ -0,0 +1,70 @@
+# -*- makefile -*-
+builddir = @abs_builddir@
+srcdir = @abs_srcdir@
+top_srcdir = @abs_top_srcdir@
+KSRC = @KSRC24@
+VERSION = @VERSION@
+AC_CC = @CC@
+KARCH = @KARCH@
+
+# File Lists
+include $(srcdir)/../Modules.mk
+include $(srcdir)/Modules.mk
+include @HW_TABLES@
+
+all: default
+default: $(all_links)
+$(foreach m,$(all_modules), \
+  $(foreach s,$($(m)_sources), \
+    $(eval $(notdir $(s)): ; ln -s $(srcdir)/../$(s) .)))
+
+# Verify Kernel Sources
+ifneq ($(shell grep -c 'PATCHLEVEL = 4' $(KSRC)/Makefile),1)
+  $(error Linux kernel source in $(KSRC) not 2.4)
+endif
+
+ifneq (,$(KSRC))
+ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
+  KOBJ :=  /lib/modules/$(shell uname -r)/build
+else
+  KOBJ :=  $(KSRC)
+endif
+
+VERSION_FILE := $(KOBJ)/include/linux/version.h
+ifeq (,$(wildcard $(VERSION_FILE)))
+  $(error Linux kernel source not configured - missing version.h)
+endif
+
+CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
+ifeq (,$(wildcard $(CONFIG_FILE)))
+  $(error Linux kernel source not configured - missing autoconf.h)
+endif
+
+# Determine the Cross-compile string for the kernel, which should just be the
+# c compiler with 'gcc' removed from the end. We're obviously assuming gcc
+# here.
+CROSS_COMPILE = $(shell echo $(AC_CC) | perl -p -e 's/(.*)gcc.*/$$1/')
+
+# Determine if we want to override the ARCH for the kernel
+ifneq (,$(KARCH))
+       ARCH_OVERRIDE := ARCH=$(KARCH)
+else
+       ARCH_OVERRIDE :=
+endif
+
+.PHONY: all distclean distdir clean check
+
+# Invoke the kernel build system
+all:
+       $(MAKE) -C $(KSRC) $(ARCH_OVERRIDE) CROSS_COMPILE=$(CROSS_COMPILE) SUBDIRS=$(PWD) modules
+
+distclean: clean
+distdir: clean
+clean:
+       rm -f *.o *_mod.o .*.o.flags
+       for d in $(all_links); do if test -h $$d; then rm $$d; fi; done
+
+check: all
+install:
+
+endif # (,$(KSRC))
index 9174b79..36eb871 100644 (file)
@@ -21,7 +21,7 @@ NOSTDINC_FLAGS += -I$(srcdir)/compat-2.6 -I$(srcdir)/compat-2.6/include
 obj-m := $(patsubst %,%_mod.o,$(all_modules))
 
 define module_template
-$(1)_mod-y = $$(patsubst %.c,%.o,$($(1)_sources))
+$(1)_mod-y = $$(notdir $$(patsubst %.c,%.o,$($(1)_sources)))
 endef
 
 $(foreach module,$(all_modules),$(eval $(call module_template,$(module))))
index 10ea36e..1b75075 100644 (file)
@@ -9,10 +9,11 @@ include $(srcdir)/../Modules.mk
 include $(srcdir)/Modules.mk
 include @HW_TABLES@
 
-default: $(all_sources)
-$(all_sources):
-       mkdir -p `dirname $@`
-       ln -s $(srcdir)/../$@ $@
+default: $(all_links)
+
+$(foreach m,$(all_modules), \
+  $(foreach s,$($(m)_sources), \
+    $(eval $(notdir $(s)): ; ln -s $(srcdir)/../$(s) $@)))
 
 default:
 distclean: clean
@@ -21,13 +22,8 @@ install:
 all: default
 check: all
 clean:
-       rm -f $(all_objects) *.ko *_mod.* Module.symvers
-       rm -f `find . -name \*.cmd`
-       for d in $(all_sources); do             \
-               if test -h $$d; then            \
-                       rm $$d;                 \
-               fi;                             \
-       done
+       rm -f *.o *.ko *_mod.* Module.symvers *.cmd
+       for d in $(all_links); do if test -h $$d; then rm $$d; fi; done
 
 ifneq ($(KSRC),)