Revamp OpenFlow kernel module build system.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 28 Apr 2008 20:28:31 +0000 (13:28 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 30 Apr 2008 01:34:47 +0000 (18:34 -0700)
The new build system supports using a build tree separate from the
source tree, which makes it easier to build for multiple targets
using a single source tree.  It also factors out the means for specifying
the modules to be built and the source files that comprise those
modules into simple files named Modules.mk.  This is intended to
make it easier to add support for separate hardware table modules in
an upcoming commit.

15 files changed:
configure.ac
datapath/Makefile.am
datapath/Modules.mk [new file with mode: 0644]
datapath/linux-2.4/.gitignore
datapath/linux-2.4/Makefile.in
datapath/linux-2.4/Modules.mk [new file with mode: 0644]
datapath/linux-2.4/kbuild.inc [deleted file]
datapath/linux-2.4/kernel-src.inc.in [deleted file]
datapath/linux-2.6/.gitignore
datapath/linux-2.6/Kbuild.in [new file with mode: 0644]
datapath/linux-2.6/Makefile.in
datapath/linux-2.6/Makefile.main.in [new file with mode: 0644]
datapath/linux-2.6/Modules.mk [new file with mode: 0644]
datapath/linux-2.6/kbuild.inc [deleted file]
datapath/linux-2.6/kernel-src.inc.in [deleted file]

index 7b3ac1c3a922615cf235b4892c070f99d043db6d..a5f5b3c586582b6c5e4bc0352e9750323ba0bb31 100644 (file)
@@ -91,7 +91,9 @@ switch/Makefile
 tests/Makefile
 datapath/tests/Makefile
 third-party/Makefile
+datapath/linux-2.6/Kbuild
 datapath/linux-2.6/Makefile
+datapath/linux-2.6/Makefile.main
 datapath/linux-2.4/Makefile])
 
 AC_OUTPUT
index 64c5077a80b306d583c70836db9718f7f88b80e1..f2cb4ecd546115288866f2665c0c830c87f0cd4c 100644 (file)
@@ -6,27 +6,8 @@ if L24_ENABLED
 SUBDIRS += linux-2.4
 endif
 
-EXTRA_DIST = linux-2.6 linux-2.4\
-                       datapath.c snap.h chain.c  crc32.c  crc_t.c\
-                       flow.h forward.h table-hash.c\
-            unit.c unit.h datapath.h  chain.h  crc32.h\
-            flow.c  forward.c  forward_t.c table.h\
-            table-linear.c  table_t.c    unit-exports.c\
-                       datapath_t.c datapath_t.h compat.h\
-                       dp_dev.c
+EXTRA_DIST = $(dist_headers) $(dist_sources)
 
-# Do not include header and source files from the top of the linux-*
-# directories, as these are just symbolic links to the files in
-# "datapath".
-dist-hook:
-       rm -rf `find $(distdir)/linux-* -name Module.symvers`
-       rm -rf `find $(distdir)/linux-* -name .*.cmd`
-       rm -rf `find $(distdir)/linux-* -name .*.swp`
-       rm -rf `find $(distdir)/linux-* -name .*.d`
-       rm -rf `find $(distdir)/linux-* -name .tmp_versions`
-       rm -rf `find $(distdir)/linux-* -name *.o`
-       rm -rf `find $(distdir)/linux-* -name *.ko`
-       rm -rf `find $(distdir)/linux-* -name Makefile`
-       rm -rf `find $(distdir)/linux-* -name .gitignore`
-       rm -f $(distdir)/linux-*/*.h
-       rm -f $(distdir)/linux-*/*.c
+include Modules.mk
+include linux-2.4/Modules.mk
+include linux-2.6/Modules.mk
diff --git a/datapath/Modules.mk b/datapath/Modules.mk
new file mode 100644 (file)
index 0000000..c1b31b3
--- /dev/null
@@ -0,0 +1,39 @@
+all_modules = $(dist_modules)
+dist_modules = openflow unit
+
+openflow_sources = \
+       chain.c \
+       crc32.c \
+       datapath.c \
+       datapath_t.c \
+       dp_dev.c \
+       flow.c \
+       forward.c \
+       table-hash.c \
+       table-linear.c \
+       unit-exports.c
+
+openflow_headers = \
+       chain.h \
+       compat.h \
+       crc32.h \
+       datapath.h \
+       datapath_t.h \
+       flow.h \
+       forward.h \
+       snap.h \
+       table.h \
+       unit.h
+
+unit_sources = \
+       crc_t.c \
+       forward_t.c \
+       table_t.c \
+       unit.c
+
+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))))
index c7afe5b255dc28f6fd1c36a015eee157db42a5a2..af45ff28e49d28be499ddd47f9f87f350cd43ae0 100644 (file)
@@ -8,12 +8,10 @@
 /forward.c
 /forward_t.c
 /datapath_t.c
-/kernel-src.inc
 /table-hash.c
 /table-linear.c
 /table-mac.c
 /table_t.c
 /unit-exports.c
 /unit.c
-/kernel-src.inc
 /tmp
index 25a53b379aab0bd0c1f77e40b5e7139c993aedf7..74f4c9999aa5d4c72a3c05bf31538261cc736800 100644 (file)
-export builddir = @abs_builddir@
-export srcdir = @abs_srcdir@
-export top_srcdir = @abs_top_srcdir@
-export KSRC = @KSRC24@
-export KVERSION = 2.4
-export VMDIR = @VMDIR@
-
-SHAREDFILES = ../chain.c ../crc32.c ../table-hash.c ../table-linear.c  \
-              ../forward.c ../flow.c ../unit-exports.c  \
-                         ../dp_dev.c ../datapath_t.c
-
-SIMLINKFILES = $(patsubst ../%,%, $(SHAREDFILES))
-
-CFILES = datapath.c $(SIMLINKFILES)
-
-# create local symlinks of shared files
-%.c : ../%.c
-       ln -s $< $@
-
-COMPAT24_CFILES =                              \
-       compat-2.4/random32.c                   \
-       compat-2.4/genetlink.c                  \
-       compat-2.4/netlink.c                    \
-       compat-2.4/attr.c                       \
-       compat-2.4/rcupdate.c                   \
-       compat-2.4/string.c                     \
-       compat-2.4/kernel.c                     \
-       compat-2.4/compat24.c
-
-UNIT_CFILES =                                  \
-       ../table_t.c                            \
-       ../unit.c
-
-SHARED_T_FILES =                                \
-    ../forward_t.c                             \
-    ../table_t.c                                \
-    ../crc_t.c                                  \
-    ../unit.c
-UNIT_CFILES = $(patsubst ../%,%, $(SHARED_T_FILES))
-
-HFILES = ../datapath.h                                 \
-       ../chain.h                              \
-       ../crc32.h                              \
-       ../flow.h                               \
-       ../forward.h                            \
-       ../table.h                              \
-       ../datapath_t.h                         \
-       compat-2.4/include/linux/rcupdate.h     \
-       compat-2.4/include/linux/jiffies.h      \
-       compat-2.4/include/linux/ipv6.h         \
-       compat-2.4/include/linux/timer.h        \
-       compat-2.4/include/linux/if_vlan.h      \
-       compat-2.4/include/linux/types.h        \
-       compat-2.4/include/linux/skbuff.h       \
-       compat-2.4/include/linux/etherdevice.h  \
-       compat-2.4/include/linux/tcp.h          \
-       compat-2.4/include/linux/genetlink.h    \
-       compat-2.4/include/linux/sockios.h      \
-       compat-2.4/include/linux/list.h         \
-       compat-2.4/include/linux/udp.h          \
-       compat-2.4/include/linux/slab.h         \
-       compat-2.4/include/linux/random.h       \
-       compat-2.4/include/linux/mutex.h        \
-       compat-2.4/include/linux/ip.h           \
-       compat-2.4/include/linux/string.h       \
-       compat-2.4/include/linux/netlink.h      \
-       compat-2.4/include/linux/compiler.h     \
-       compat-2.4/include/linux/kernel.h       \
-       compat-2.4/include/linux/if_ether.h     \
-       compat-2.4/include/net/checksum.h       \
-       compat-2.4/include/net/genetlink.h      \
-       compat-2.4/include/net/netlink.h        \
-       compat-2.4/include/asm/system.h         \
-       compat-2.4/compat24.h
-
+builddir = @abs_builddir@
+srcdir = @abs_srcdir@
+top_srcdir = @abs_top_srcdir@
+KSRC = @KSRC24@
+VMDIR = @VMDIR@
 VERSION = @VERSION@
 
-CFLAGS_EXTRA += -DVERSION=\"$(VERSION)\"
-CFLAGS_EXTRA += -O2 -g
-CFLAGS_EXTRA += -I $(srcdir)/.. -I $(top_srcdir)/include
+# 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
+
+default:
+distclean: clean
+distdir: clean
+install:
+all: default
+clean:
+       rm -f $(all_objects) *_mod.o
+       for d in $(all_objdirs); do             \
+               while                           \
+                       rmdir $$d 2> /dev/null; \
+               do                              \
+                       d=`dirname $$d`;        \
+               done;                           \
+       done
+
+check: all
 
-# Conditional include so that make dist doesn't puke when
-# this build isn't turned on by automake
 ifneq (,$(KSRC))
-include $(srcdir)/kbuild.inc
+ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
+  KOBJ :=  /lib/modules/$(shell uname -r)/build
 else
-clean:
+  KOBJ :=  $(KSRC)
 endif
 
-distclean : clean
-distdir : clean
-install :
+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
 
-PWD       := $(shell pwd)
+CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
+ifeq (,$(wildcard $(CONFIG_FILE)))
+  $(error Linux kernel source not configured - missing autoconf.h)
+endif
 
-all: default
+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
+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 $(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_objdirs)
+$(all_objdirs):
+       mkdir -p $@
+
+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))))
+endif
 
-check: all
+# 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/Modules.mk b/datapath/linux-2.4/Modules.mk
new file mode 100644 (file)
index 0000000..43a5ef3
--- /dev/null
@@ -0,0 +1,58 @@
+dist_modules += compat24
+
+compat24_sources = \
+       linux-2.4/compat-2.4/attr.c \
+       linux-2.4/compat-2.4/compat24.c \
+       linux-2.4/compat-2.4/genetlink.c \
+       linux-2.4/compat-2.4/kernel.c \
+       linux-2.4/compat-2.4/kthread.c \
+       linux-2.4/compat-2.4/netlink.c \
+       linux-2.4/compat-2.4/random32.c \
+       linux-2.4/compat-2.4/rcupdate.c \
+       linux-2.4/compat-2.4/string.c
+
+compat24_headers = \
+       linux-2.4/compat-2.4/compat24.h \
+       linux-2.4/compat-2.4/include-arm/asm/atomic.h \
+       linux-2.4/compat-2.4/include-i386/asm/atomic.h \
+       linux-2.4/compat-2.4/include-mips/asm/atomic.h \
+       linux-2.4/compat-2.4/include-mips/asm/barrier.h \
+       linux-2.4/compat-2.4/include-mips/asm/break.h \
+       linux-2.4/compat-2.4/include-mips/asm/page.h \
+       linux-2.4/compat-2.4/include-mips/asm/system.h \
+       linux-2.4/compat-2.4/include/asm/system.h \
+       linux-2.4/compat-2.4/include/linux/compiler.h \
+       linux-2.4/compat-2.4/include/linux/delay.h \
+       linux-2.4/compat-2.4/include/linux/etherdevice.h \
+       linux-2.4/compat-2.4/include/linux/genetlink.h \
+       linux-2.4/compat-2.4/include/linux/gfp.h \
+       linux-2.4/compat-2.4/include/linux/if_ether.h \
+       linux-2.4/compat-2.4/include/linux/if_vlan.h \
+       linux-2.4/compat-2.4/include/linux/ip.h \
+       linux-2.4/compat-2.4/include/linux/ipv6.h \
+       linux-2.4/compat-2.4/include/linux/jiffies.h \
+       linux-2.4/compat-2.4/include/linux/kernel.h \
+       linux-2.4/compat-2.4/include/linux/kthread.h \
+       linux-2.4/compat-2.4/include/linux/list.h \
+       linux-2.4/compat-2.4/include/linux/llc.h \
+       linux-2.4/compat-2.4/include/linux/module.h \
+       linux-2.4/compat-2.4/include/linux/mutex.h \
+       linux-2.4/compat-2.4/include/linux/netdevice.h \
+       linux-2.4/compat-2.4/include/linux/netlink.h \
+       linux-2.4/compat-2.4/include/linux/random.h \
+       linux-2.4/compat-2.4/include/linux/rcupdate.h \
+       linux-2.4/compat-2.4/include/linux/skbuff.h \
+       linux-2.4/compat-2.4/include/linux/slab.h \
+       linux-2.4/compat-2.4/include/linux/sockios.h \
+       linux-2.4/compat-2.4/include/linux/spinlock.h \
+       linux-2.4/compat-2.4/include/linux/string.h \
+       linux-2.4/compat-2.4/include/linux/tcp.h \
+       linux-2.4/compat-2.4/include/linux/timer.h \
+       linux-2.4/compat-2.4/include/linux/types.h \
+       linux-2.4/compat-2.4/include/linux/udp.h \
+       linux-2.4/compat-2.4/include/net/checksum.h \
+       linux-2.4/compat-2.4/include/net/genetlink.h \
+       linux-2.4/compat-2.4/include/net/llc_pdu.h \
+       linux-2.4/compat-2.4/include/net/netlink.h
+
+EXTRA_DIST += linux-2.4/compat-2.4/TODO
diff --git a/datapath/linux-2.4/kbuild.inc b/datapath/linux-2.4/kbuild.inc
deleted file mode 100644 (file)
index faa25e6..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-# The remainder of this file is 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
-#
-################################################################################
-ifeq (,$(BUILD_KERNEL))
-BUILD_KERNEL=$(shell uname -r)
-endif
-
-###########################################################################
-# Environment tests
-
-# Kernel Search Path
-# All the places we look for kernel source
-KSP :=  /lib/modules/$(BUILD_KERNEL)/build \
-        /lib/modules/$(BUILD_KERNEL)/source \
-        /usr/src/linux-$(BUILD_KERNEL) \
-        /usr/src/linux-$($(BUILD_KERNEL) | sed 's/-.*//') \
-        /usr/src/kernel-headers-$(BUILD_KERNEL) \
-        /usr/src/kernel-source-$(BUILD_KERNEL) \
-        /usr/src/linux-$($(BUILD_KERNEL) | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
-        /usr/src/linux
-
-# prune the list down to only values that exist
-# and have an include/linux sub-directory
-test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
-KSP := $(foreach dir, $(KSP), $(test_dir))
-
-# we will use this first valid entry in the search path
-ifeq (,$(KSRC))
-  KSRC := $(firstword $(KSP))
-endif
-
-CFLAGS += $(CFLAGS_EXTRA)
-
-ifeq (,$(KSRC))
-  $(error Linux kernel source not found)
-else
-ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
-  KOBJ :=  /lib/modules/$(shell uname -r)/build
-else
-  KOBJ :=  $(KSRC)
-endif
-endif
-
-# version 2.4 or 2.6?
-K_VERSION:=$(shell if grep -q 'PATCHLEVEL = 4' $(KSRC)/Makefile; then echo 2.4; else echo 2.6; fi)
-
-ifneq ($(K_VERSION),2.4)
-  $(error Linux kernel source in $(KSRC) not 2.4)
-endif
-
-# check for version.h and autoconf.h for running kernel in /boot (SUSE)
-ifneq (,$(wildcard /boot/vmlinuz.version.h))
-  VERSION_FILE := /boot/vmlinuz.version.h
-  CONFIG_FILE  := /boot/vmlinuz.autoconf.h
-  KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | \
-          grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
-  ifeq ($(KVER),$(shell uname -r))
-    # set up include path to override headers from kernel source
-    x:=$(shell rm -rf include)
-    x:=$(shell mkdir -p include/linux)
-    x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
-    x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
-    CFLAGS += -I./include
-  else
-    ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
-      VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
-    else
-      VERSION_FILE := $(KOBJ)/include/linux/version.h
-    endif
-    CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
-  endif
-else
-  ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
-    VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
-  else
-    VERSION_FILE := $(KOBJ)/include/linux/version.h
-  endif
-  CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
-endif
-
-ifeq (,$(wildcard $(VERSION_FILE)))
-  $(error Linux kernel source not configured - missing version.h)
-endif
-
-ifeq (,$(wildcard $(CONFIG_FILE)))
-  $(error Linux kernel source not configured - missing autoconf.h)
-endif
-
-# pick a compiler
-ifeq ($(K_VERSION),2.6)
-  CC := gcc cc
-else
-  # Older kernels require GCC 2.95
-  K_SUBLEVEL:=$(shell sed -n 's/SUBLEVEL = // p' $(KSRC)/Makefile)
-  ifeq ($(K_SUBLEVEL),20)
-    CC := gcc-2.95
-  else
-    CC := gcc-3.4 gcc-3.3 gcc-2.95
-  endif
-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
-
-# we need to know what platform the driver is being built on
-# some additional features are only built on Intel platforms
-ifeq ($(ARCH),)
-  # Set the architecture if it hasn't been already set for cross-compilation
-  ARCH := $(shell uname -m | sed 's/i.86/i386/')
-endif
-ifeq ($(ARCH),alpha)
-  CFLAGS += -ffixed-8 -mno-fp-regs
-endif
-ifeq ($(ARCH),x86_64)
-  CFLAGS += -mcmodel=kernel -mno-red-zone
-endif
-ifeq ($(ARCH),ppc)
-  CFLAGS += -msoft-float
-endif
-ifeq ($(ARCH),ppc64)
-  CFLAGS += -m64 -msoft-float
-  LDFLAGS += -melf64ppc
-endif
-
-# standard flags for module builds
-CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
-CFLAGS += -I$(KSRC)/include -I.
-CFLAGS += -I$(srcdir)/compat-2.4 -I$(srcdir)/compat-2.4/include
-CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
-            echo "-DMODVERSIONS -DEXPORT_SYMTAB \
-                  -include $(KSRC)/include/linux/modversions.h")
-
-RHC := $(KSRC)/include/linux/rhconfig.h
-ifneq (,$(wildcard $(RHC)))
-  # 7.3 typo in rhconfig.h
-  ifneq (,$(shell $(CC) $(CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
-       CFLAGS += -D__module_bigmem
-  endif
-endif
-
-# get the kernel version - we use this to find the correct install path
-KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
-        awk '{ print $$3 }' | sed 's/\"//g')
-
-# assume source symlink is the same as build, otherwise adjust KOBJ
-ifneq (,$(wildcard /lib/modules/$(KVER)/build))
-ifneq ($(KSRC),$(shell cd /lib/modules/$(KVER)/build ; pwd -P))
-  KOBJ=/lib/modules/$(KVER)/build
-endif
-endif
-
-KKVER := $(shell echo $(KVER) | \
-         awk '{ if ($$0 ~ /2\.[4-9]\./) print "1"; else print "0"}')
-ifeq ($(KKVER), 0)
-  $(error *** Aborting the build. \
-          *** This driver is not supported on kernel versions older than 2.4.0)
-endif
-
-# look for SMP in config.h
-SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
-         grep -w CONFIG_SMP | awk '{ print $$3 }')
-ifneq ($(SMP),1)
-  SMP := 0
-endif
-
-#ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
-#  $(warning ***)
-#  ifeq ($(SMP),1)
-#    $(warning *** Warning: kernel source configuration (SMP))
-#    $(warning *** does not match running kernel (UP))
-#  else
-#    $(warning *** Warning: kernel source configuration (UP))
-#    $(warning *** does not match running kernel (SMP))
-#  endif
-#  $(warning *** Continuing with build,)
-#  $(warning *** resulting driver may not be what you want)
-#  $(warning ***)
-#endif
-
-ifeq ($(SMP),1)
-  CFLAGS += -D__SMP__
-endif
-
-###########################################################################
-# 2.4.x 
-
-# Makefile for 2.4.x kernel
-TARGET = openflow_mod.o unit_mod.o compat24_mod.o
-
-CFLAGS += -Wno-sign-compare -fno-strict-aliasing
-CFLAGS := -I $(srcdir)/compat-2.4/include $(CFLAGS)
-CFLAGS := -I $(srcdir)/compat-2.4/include-$(ARCH) $(CFLAGS)
-
-default: $(TARGET)
-
-openflow_mod.o: $(filter-out $(TARGET), $(CFILES:.c=.o))
-       $(LD) $(LDFLAGS) -r $^ -o $@
-unit_mod.o: $(UNIT_CFILES:.c=.o)
-       $(LD) $(LDFLAGS) -r $^ -o $@
-compat24_mod.o: $(COMPAT24_CFILES:.c=.o)
-       $(LD) $(LDFLAGS) -r $^ -o $@
-
-ALL_CFILES = $(FILES) $(UNIT_CFILES) $(COMPAT24_CFILES)
-$(ALL_CFILES:.c=.o): $(HFILES) Makefile
-
-# depmod version for rpm builds
-DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
-          awk 'BEGIN {FS="."} NR==1 {print $$2}')
-
-.PHONY: clean
-
-clean:
-       rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c)\
-    $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(COMPAT24_CFILES:.c=.o)\
-    $(UNIT_CFILES:.c=.o) $(MANFILE).gz .*cmd .tmp_versions\
-    compat24_mod.o unit_mod.o tmp/ \
diff --git a/datapath/linux-2.4/kernel-src.inc.in b/datapath/linux-2.4/kernel-src.inc.in
deleted file mode 100644 (file)
index 399cfef..0000000
+++ /dev/null
@@ -1 +0,0 @@
-KSRC=@KSRC24@
index 098a312eebded9b5ed9e58b58cb8a563fb02309a..eee68d01e9d5d145c2b01c3db4791fa2a89c0233 100644 (file)
@@ -1,18 +1,19 @@
+/Kbuild
 /Makefile
-/datapath.c
+/Makefile.main
 /chain.c
 /crc32.c
 /crc_t.c
+/datapath.c
+/datapath_t.c
 /dp_dev.c
 /flow.c
 /forward.c
 /forward_t.c
-/datapath_t.c
-/kernel-src.inc
 /table-hash.c
 /table-linear.c
 /table-mac.c
 /table_t.c
+/tmp
 /unit-exports.c
 /unit.c
-/tmp
diff --git a/datapath/linux-2.6/Kbuild.in b/datapath/linux-2.6/Kbuild.in
new file mode 100644 (file)
index 0000000..dbf7e64
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- makefile -*-
+export builddir = @abs_builddir@
+export srcdir = @abs_srcdir@
+export top_srcdir = @abs_top_srcdir@
+export VERSION = @VERSION@
+
+include $(srcdir)/../Modules.mk
+include $(srcdir)/Modules.mk
+
+EXTRA_CFLAGS := -DVERSION=\"$(VERSION)\"
+EXTRA_CFLAGS += -I$(srcdir)/.. 
+EXTRA_CFLAGS += -I$(srcdir)/datapath
+EXTRA_CFLAGS += -I$(top_srcdir)/include
+
+# These include directories have to go before -I$(KSRC)/include.
+# NOSTDINC_FLAGS just happens to be a variable that goes in the
+# right place, even though it's conceptually incorrect.
+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))
+endef
+
+$(foreach module,$(all_modules),$(eval $(call module_template,$(module))))
index 15402038b21c3987558d171df3a4b3906cdb1af4..efc1663e4753c89db3ab5039b5c01aa199ce5ca7 100644 (file)
@@ -1,65 +1,9 @@
-export builddir = @abs_builddir@
-export srcdir = @abs_srcdir@
-export top_srcdir = @abs_top_srcdir@
-export KSRC = @KSRC26@
-export KVERSION = 2.6
-export VMDIR = @VMDIR@
-export VERSION = @VERSION@
-
-CFLAGS_EXTRA += -DVERSION=\"$(VERSION)\"
-CFLAGS_EXTRA += -I $(srcdir)/.. -I $(srcdir)/datapath/  -I $(top_srcdir)/include
-
-# Files shared between 2.4 and 2.6 builds
-
-SHAREDFILES = ../chain.c ../crc32.c ../table-hash.c ../table-linear.c  \
-                       ../forward.c ../flow.c ../unit-exports.c \
-                       ../datapath_t.c ../dp_dev.c \
-                       compat-2.6/genetlink.c \
-                       compat-2.6/random32.c 
-
-HFILES = ../datapath.h ../chain.h ../crc32.h ../flow.h ../forward.h    \
-                       ../table.h ../datapath_t.h \
-                       compat-2.6/include/compat26.h \
-                       compat-2.6/include/linux/ip.h \
-                       compat-2.6/include/linux/ipv6.h \
-                       compat-2.6/include/linux/lockdep.h \
-                       compat-2.6/include/linux/mutex.h \
-                       compat-2.6/include/linux/netlink.h \
-                       compat-2.6/include/linux/random.h \
-                       compat-2.6/include/linux/skbuff.h \
-                       compat-2.6/include/linux/tcp.h \
-                       compat-2.6/include/linux/timer.h \
-                       compat-2.6/include/linux/types.h \
-                       compat-2.6/include/linux/udp.h \
-                       compat-2.6/include/net/checksum.h \
-                       compat-2.6/include/net/genetlink.h 
-
-SIMLINKFILES = $(patsubst ../%,%, $(SHAREDFILES))
-
-CFILES = datapath.c $(SIMLINKFILES)
-
-# Testing files used for both 2.6 and 2.4 kernels.  Are symlinked
-# locally
-SHARED_T_FILES = ../table_t.c ../crc_t.c ../forward_t.c ../unit.c
-
-UNIT_CFILES = $(patsubst ../%,%, $(SHARED_T_FILES))
-
-# General rule to create symlinks of shared files 
-%.c : ../%.c 
-       ln -s $< $@
-
-# Conditional include so that make dist doesn't puke when
-# this build isn't turned on by automake
-ifneq (,$(KSRC))
-include $(srcdir)/kbuild.inc
+ifeq ($(KERNELRELEASE),)
+# We're being called directly by running make in this directory.
+include Makefile.main
 else
-clean:
+# We're being included by the Linux kernel build system
+include Kbuild
 endif
 
-distclean : clean
-distdir : clean
-install :
-
-all: default
 
-check: all
diff --git a/datapath/linux-2.6/Makefile.main.in b/datapath/linux-2.6/Makefile.main.in
new file mode 100644 (file)
index 0000000..5fc97ea
--- /dev/null
@@ -0,0 +1,87 @@
+# -*- makefile -*-
+export builddir = @abs_builddir@
+export srcdir = @abs_srcdir@
+export top_srcdir = @abs_top_srcdir@
+export KSRC = @KSRC26@
+export VMDIR = @VMDIR@
+export VERSION = @VERSION@
+
+include $(srcdir)/../Modules.mk
+include $(srcdir)/Modules.mk
+
+default: $(all_sources)
+$(all_sources):
+       mkdir -p `dirname $@`
+       ln -s $(srcdir)/../$@ $@
+
+default:
+distclean: clean
+distdir: clean
+install:
+all: default
+check: all
+clean:
+       rm -f $(all_objects) *.ko *_mod.* Module.symvers
+       rm -f `find . -name \*.cmd`
+       for d in $(sources); do                 \
+               if test -h $$d; then            \
+                       rm $$d;                 \
+               fi;                             \
+       done
+
+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 = 6' $(KSRC)/Makefile),1)
+  $(error Linux kernel source in $(KSRC) not 2.6)
+endif
+
+VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
+ifeq (,$(wildcard $(VERSION_FILE)))
+  $(error Linux kernel source not configured - missing utsrelease.h)
+endif
+
+CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
+ifeq (,$(wildcard $(CONFIG_FILE)))
+  $(error Linux kernel source not configured - missing autoconf.h)
+endif
+
+default:
+       $(MAKE) -C $(KSRC) M=$(builddir) modules
+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.6/Modules.mk b/datapath/linux-2.6/Modules.mk
new file mode 100644 (file)
index 0000000..3a1d653
--- /dev/null
@@ -0,0 +1,19 @@
+openflow_sources += \
+       linux-2.6/compat-2.6/genetlink.c \
+       linux-2.6/compat-2.6/random32.c
+
+openflow_headers += \
+       linux-2.6/compat-2.6/compat26.h \
+       linux-2.6/compat-2.6/include/linux/ip.h \
+       linux-2.6/compat-2.6/include/linux/ipv6.h \
+       linux-2.6/compat-2.6/include/linux/lockdep.h \
+       linux-2.6/compat-2.6/include/linux/mutex.h \
+       linux-2.6/compat-2.6/include/linux/netlink.h \
+       linux-2.6/compat-2.6/include/linux/random.h \
+       linux-2.6/compat-2.6/include/linux/skbuff.h \
+       linux-2.6/compat-2.6/include/linux/tcp.h \
+       linux-2.6/compat-2.6/include/linux/timer.h \
+       linux-2.6/compat-2.6/include/linux/types.h \
+       linux-2.6/compat-2.6/include/linux/udp.h \
+       linux-2.6/compat-2.6/include/net/checksum.h \
+       linux-2.6/compat-2.6/include/net/genetlink.h
diff --git a/datapath/linux-2.6/kbuild.inc b/datapath/linux-2.6/kbuild.inc
deleted file mode 100644 (file)
index 92f8026..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-# The remainder of this file is 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
-#
-################################################################################
-ifeq (,$(BUILD_KERNEL))
-BUILD_KERNEL=$(shell uname -r)
-endif
-
-###########################################################################
-# Environment tests
-
-ifeq (,$(CC))
-  CC_CANDIDATES := gcc cc
-  test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
-  CC := $(foreach cc,$(CC_CANDIDATES), $(test_cc))
-  CC := $(firstword $(CC))
-  ifeq (,$(CC))
-    $(error Compiler not found)
-  endif
-endif
-
-ifeq (,$(KSRC))
-  $(error Linux kernel source not found)
-else
-ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
-  KOBJ :=  /lib/modules/$(shell uname -r)/build
-else
-  KOBJ :=  $(KSRC)
-endif
-endif
-
-# version 2.4 or 2.6? (we assume 2.2 isn't in use anymore
-K_VERSION:=$(shell if grep -q 'PATCHLEVEL = 4' $(KSRC)/Makefile; then echo 2.4; else echo 2.6; fi)
-
-ifneq ($(K_VERSION),2.6)
-  $(error Linux kernel source not not 2.6)
-endif
-
-# check for version.h and autoconf.h for running kernel in /boot (SUSE)
-ifneq (,$(wildcard /boot/vmlinuz.version.h))
-  VERSION_FILE := /boot/vmlinuz.version.h
-  CONFIG_FILE  := /boot/vmlinuz.autoconf.h
-  KVER := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(VERSION_FILE) | \
-          grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
-  ifeq ($(KVER),$(shell uname -r))
-    # set up include path to override headers from kernel source
-    x:=$(shell rm -rf include)
-    x:=$(shell mkdir -p include/linux)
-    x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
-    x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
-    EXTRA_CFLAGS += -I./include
-  else
-    ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
-      VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
-    else
-      VERSION_FILE := $(KOBJ)/include/linux/version.h
-    endif
-    CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
-  endif
-else
-  ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
-    VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
-  else
-    VERSION_FILE := $(KOBJ)/include/linux/version.h
-  endif
-  CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
-endif
-
-ifeq (,$(wildcard $(VERSION_FILE)))
-  $(error Linux kernel source not configured - missing version.h)
-endif
-
-ifeq (,$(wildcard $(CONFIG_FILE)))
-  $(error Linux kernel source not configured - missing autoconf.h)
-endif
-
-
-# we need to know what platform the driver is being built on
-# some additional features are only built on Intel platforms
-ifeq ($(ARCH),)
-  # Set the architecture if it hasn't been already set for cross-compilation
-  ARCH := $(shell uname -m | sed 's/i.86/i386/')
-endif
-ifeq ($(ARCH),alpha)
-  EXTRA_CFLAGS += -ffixed-8 -mno-fp-regs
-endif
-ifeq ($(ARCH),x86_64)
-  EXTRA_CFLAGS += -mcmodel=kernel -mno-red-zone
-endif
-ifeq ($(ARCH),ppc)
-  EXTRA_CFLAGS += -msoft-float
-endif
-ifeq ($(ARCH),ppc64)
-  EXTRA_CFLAGS += -m64 -msoft-float
-  LDFLAGS += -melf64ppc
-endif
-
-# standard flags for module builds
-EXTRA_CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
-NOSTDINC_FLAGS += -I$(srcdir)/compat-2.6 -I$(srcdir)/compat-2.6/include 
-EXTRA_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
-            echo "-DMODVERSIONS -DEXPORT_SYMTAB \
-                  -include $(KSRC)/include/linux/modversions.h")
-
-RHC := $(KSRC)/include/linux/rhconfig.h
-ifneq (,$(wildcard $(RHC)))
-  # 7.3 typo in rhconfig.h
-  ifneq (,$(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
-       EXTRA_CFLAGS += -D__module_bigmem
-  endif
-endif
-
-# get the kernel version - we use this to find the correct install path
-KVER := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
-        awk '{ print $$3 }' | sed 's/\"//g')
-
-# assume source symlink is the same as build, otherwise adjust KOBJ
-ifneq (,$(wildcard /lib/modules/$(KVER)/build))
-ifneq ($(KSRC),$(shell cd /lib/modules/$(KVER)/build ; pwd -P))
-  KOBJ=/lib/modules/$(KVER)/build
-endif
-endif
-
-KKVER := $(shell echo $(KVER) | \
-         awk '{ if ($$0 ~ /2\.[6]\./) print "1"; else print "0"}')
-ifeq ($(KKVER), 0)
-  $(error *** Aborting the build. \
-          *** This driver is not supported on kernel versions older than 2.6.0)
-endif
-
-# look for SMP in config.h
-SMP := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(CONFIG_FILE) | \
-         grep -w CONFIG_SMP | awk '{ print $$3 }')
-ifneq ($(SMP),1)
-  SMP := 0
-endif
-
-#ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
-#  $(warning ***)
-#  ifeq ($(SMP),1)
-#    $(warning *** Warning: kernel source configuration (SMP))
-#    $(warning *** does not match running kernel (UP))
-#  else
-#    $(warning *** Warning: kernel source configuration (UP))
-#    $(warning *** does not match running kernel (SMP))
-#  endif
-#  $(warning *** Continuing with build,)
-#  $(warning *** resulting driver may not be what you want)
-#  $(warning ***)
-#endif
-
-ifeq ($(SMP),1)
-  EXTRA_CFLAGS += -D__SMP__
-endif
-
-###########################################################################
-# Makefile for 2.6.x kernel
-all: $(TARGET)
-TARGET = openflow_mod.ko unit_mod.ko
-
-$(UNIT_CFILES): 
-       $(foreach UNIT_CFILE, $(UNIT_CFILES), $(shell ln -s $(patsubst %,../t/%,$(UNIT_CFILE)) $(UNIT_CFILE)))
-
-ifneq ($(PATCHLEVEL),)
-EXTRA_CFLAGS += $(CFLAGS_EXTRA)
-obj-m += openflow_mod.o unit_mod.o
-openflow_mod-objs := $(CFILES:.c=.o)
-unit_mod-objs := $(UNIT_CFILES:.c=.o)
-else
-default:
-ifeq ($(KOBJ),$(KSRC))
-       $(MAKE) -C $(KSRC) SUBDIRS=$(shell pwd) modules
-else
-       $(MAKE) -C $(KSRC) O=$(KOBJ) SUBDIRS=$(shell pwd) modules
-endif
-endif
-
-# depmod version for rpm builds
-DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
-          awk 'BEGIN {FS="."} NR==1 {print $$2}')
-
-.PHONY: clean
-
-clean:
-       rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c) \
-    $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(MANFILE).gz .*cmd \
-    .tmp_versions t/ *.o tmp/
diff --git a/datapath/linux-2.6/kernel-src.inc.in b/datapath/linux-2.6/kernel-src.inc.in
deleted file mode 100644 (file)
index 531f7bc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-KSRC=@KSRC26@