From 34b307bea6c6695c4037ca2ed2dbd87926a029f1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 2 Jun 2008 17:05:42 -0700 Subject: [PATCH] Use kernel build system for linux-2.4. Based on changes originally by Bobby Holley . --- INSTALL | 7 ++ configure.ac | 7 +- datapath/Modules.mk | 5 +- datapath/linux-2.4/Kbuild.in | 79 +++++++++++++++++ datapath/linux-2.4/Makefile.in | 132 ++-------------------------- datapath/linux-2.4/Makefile.main.in | 70 +++++++++++++++ datapath/linux-2.6/Kbuild.in | 2 +- datapath/linux-2.6/Makefile.main.in | 18 ++-- 8 files changed, 177 insertions(+), 143 deletions(-) create mode 100644 datapath/linux-2.4/Kbuild.in create mode 100644 datapath/linux-2.4/Makefile.main.in diff --git a/INSTALL b/INSTALL index 7f493514..fbacb67b 100644 --- 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, diff --git a/configure.ac b/configure.ac index 2c2b427e..d22a71bd 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/datapath/Modules.mk b/datapath/Modules.mk index 6c0509c7..099be0e4 100644 --- a/datapath/Modules.mk +++ b/datapath/Modules.mk @@ -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 index 00000000..1a6c617a --- /dev/null +++ b/datapath/linux-2.4/Kbuild.in @@ -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 +# +# 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 +# e1000-devel Mailing List +# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 +# +################################################################################ diff --git a/datapath/linux-2.4/Makefile.in b/datapath/linux-2.4/Makefile.in index 1a68376c..b30f2ba7 100644 --- a/datapath/linux-2.4/Makefile.in +++ b/datapath/linux-2.4/Makefile.in @@ -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 -# e1000-devel Mailing List -# 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 index 00000000..4b542592 --- /dev/null +++ b/datapath/linux-2.4/Makefile.main.in @@ -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)) diff --git a/datapath/linux-2.6/Kbuild.in b/datapath/linux-2.6/Kbuild.in index 9174b790..36eb8716 100644 --- a/datapath/linux-2.6/Kbuild.in +++ b/datapath/linux-2.6/Kbuild.in @@ -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)))) diff --git a/datapath/linux-2.6/Makefile.main.in b/datapath/linux-2.6/Makefile.main.in index 10ea36e1..1b75075f 100644 --- a/datapath/linux-2.6/Makefile.main.in +++ b/datapath/linux-2.6/Makefile.main.in @@ -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),) -- 2.30.2