Hi,
I needed to compile usbvideo outside of the kernel tree and run into
some problems. The attached file contains makefile changes that allow
to retrieve kernel compile options automatically from the kernel
makefiles and .config. It was tested with kernel 2.4.16 but should work
with other 2.4 kernels.
Please apply,
Rui Sousa
diff -uNr usbvideo.orig/Makefile usbvideo/Makefile
--- usbvideo.orig/Makefile Fri Dec 21 18:18:50 2001
+++ usbvideo/Makefile Fri Dec 21 20:50:41 2001
@@ -1,51 +1,36 @@
#
# This is the Makefile to build usbvideo outside
-# of kernel tree. Naturally, compiler options below
-# may not match ones that you use to compile the kernel.
-# So be warned and use whatever options you need instead.
+# of kernel tree.
#
-#ver2 = 1
-#hw_a21m = 1
+KERNEL_SOURCE:=/usr/src/kernel/linux-2.4.16
-# The location of the kernel headers:
-LINUX_HEADERS=/usr/src/linux/include
-MODUTILS_DIR=/sbin
-
-# This is the directory into which the modules will be installed.
-# The magic invocation will return something like this:
-# /lib/modules/2.4.0/kernel/drivers/usb
-KVER = $(shell grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"')
-MODDIR := /lib/modules/$(KVER)/kernel/drivers/usb
-
-
-ifdef hw_a21m
-
-CFLAGS = -D__KERNEL__ -I$(LINUX_HEADERS) -Wall \
--Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing \
--pipe -march=i686 -DMODULE
-
-else
-
-ifdef ver2
+export KERNEL_SOURCE
-CFLAGS = -D__KERNEL__ -I$(LINUX_HEADERS) -Wall -Wstrict-prototypes \
--O2 -fomit-frame-pointer -pipe -march=i686 -malign-functions=4 \
--fno-strict-aliasing -DMODULE -DMODVERSIONS -include \
-$(LINUX_HEADERS)/linux/modversions.h
+MODUTILS_DIR=/sbin
+CC :=
+CFLAGS :=
+MODFLAGS :=
+MODLIB :=
+MODDIR = $(MODLIB)/kernel/drivers/usb
+
+OBJECTS = ibmcam.o ultracam.o webcamgo.o
+EXPORT-OBJS = usbvideo.o
+
+.PHONY : get_options
+
+ifeq (.opts,$(wildcard .opts))
+ include .opts
+ do-it-all: all
else
-
-CFLAGS = -D__KERNEL__ -I$(LINUX_HEADERS) \
- -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
- -fno-strict-aliasing -pipe -march=i586 -DMODULE
-
-endif
+ do-it-all: opts
endif
-OBJECTS = ibmcam.o ultracam.o webcamgo.o usbvideo.o
+opts:
+ cd scripts; $(MAKE); cd ..
-all : notice usbvideo.o ibmdrv.o ultradrv.o webcamgodrv.o
+all: notice usbvideo.o ibmdrv.o ultradrv.o webcamgodrv.o
ibmdrv.o : ibmcam.o
$(LD) -r -o $@ $+
@@ -58,18 +43,23 @@
%.o : %.c usbvideo.h
@echo "--- Compiling $< ---"
- @$(CC) $(CFLAGS) -c -o $@ $<
+ @$(CC) $(CFLAGS) $(MODFLAGS) -c -o $@ $<
+
+$(EXPORT-OBJS) : %.o : %.c usbvideo.h
+ @echo "--- Compiling $< ---"
+ @$(CC) $(CFLAGS) $(MODFLAGS) -DEXPORT_SYMTAB -c -o $@ $<
full: clean all
clean:
- rm -f $(OBJECTS) ibmdrv.o ultradrv.o webcamgodrv.o
+ rm -f $(OBJECTS) $(EXPORT-OBJS) ibmdrv.o ultradrv.o webcamgodrv.o
+ cd scripts; $(MAKE) clean; cd ..
install: all
- @install -v -D -o root -g root usbvideo.o $(MODDIR)/usbvideo.o
- @install -v -D -o root -g root ibmdrv.o $(MODDIR)/ibmdrv.o
- @install -v -D -o root -g root ultradrv.o $(MODDIR)/ultradrv.o
- @install -v -D -o root -g root webcamgodrv.o $(MODDIR)/webcamgodrv.o
+ @install -v -D -o root -g root -m 644 usbvideo.o $(MODDIR)/usbvideo.o
+ @install -v -D -o root -g root -m 644 ibmdrv.o $(MODDIR)/ibmdrv.o
+ @install -v -D -o root -g root -m 644 ultradrv.o $(MODDIR)/ultradrv.o
+ @install -v -D -o root -g root -m 644 webcamgodrv.o $(MODDIR)/webcamgodrv.o
$(MODUTILS_DIR)/depmod -a
uninstall:
@@ -81,6 +71,8 @@
notice:
@echo ""
+ @echo "Building for kernel version $(KERNEL_VERSION) in $(KERNEL_SOURCE)"
+ @echo ""
@echo "*** Important Notice ***"
@echo ""
@echo "This CVS build is now creating Linux kernel module for usbvideo."
diff -uNr usbvideo.orig/scripts/Makefile usbvideo/scripts/Makefile
--- usbvideo.orig/scripts/Makefile Thu Jan 1 01:00:00 1970
+++ usbvideo/scripts/Makefile Fri Dec 21 19:56:52 2001
@@ -0,0 +1,18 @@
+CURR_DIR :=$(shell pwd)
+
+export CURR_DIR
+
+.PHONY: get_version
+
+all: get_version get_options
+
+get_version:
+ $(CC) -I$(KERNEL_SOURCE)/include get_version.c -o get_version
+
+get_options:
+ $(MAKE) -f $(CURR_DIR)/Makefile.get_options -C $(KERNEL_SOURCE)
+get_version_target
+
+clean:
+ $(RM) get_version ../.opts
+
+distclean: clean
diff -uNr usbvideo.orig/scripts/Makefile.get_options
usbvideo/scripts/Makefile.get_options
--- usbvideo.orig/scripts/Makefile.get_options Thu Jan 1 01:00:00 1970
+++ usbvideo/scripts/Makefile.get_options Fri Dec 21 20:02:58 2001
@@ -0,0 +1,19 @@
+KERNEL_VERSION := $(shell $(CURR_DIR)/get_version)
+KERNEL_RELEASE := $(shell echo $(KERNEL_VERSION) | cut -d\" -f2| cut -c-5)
+
+# this is for redhat default kernel headers,
+# might work with other distributions too
+ifneq (.config,$(wildcard .config))
+ifeq (configs,$(wildcard configs))
+include $(KERNEL_SOURCE)/configs/kernel-$(KERNEL_RELEASE)-i686.config
+endif
+endif
+
+include $(KERNEL_SOURCE)/Makefile
+
+get_version_target:
+ echo "KERNEL_VERSION := $(KERNEL_VERSION)" >> $(CURR_DIR)/../.opts
+ echo "CFLAGS += $(CFLAGS)" >> $(CURR_DIR)/../.opts
+ echo "CC := $(CC)" >> $(CURR_DIR)/../.opts
+ echo "MODFLAGS += $(MODFLAGS)" >> $(CURR_DIR)/../.opts
+ echo "MODLIB := $(MODLIB)" >> $(CURR_DIR)/../.opts
diff -uNr usbvideo.orig/scripts/get_version.c usbvideo/scripts/get_version.c
--- usbvideo.orig/scripts/get_version.c Thu Jan 1 01:00:00 1970
+++ usbvideo/scripts/get_version.c Thu Nov 15 15:51:12 2001
@@ -0,0 +1,6 @@
+#include <linux/version.h>
+#include <stdio.h>
+main()
+{
+ printf("%s", UTS_RELEASE);
+}
diff -uNr usbvideo.orig/usbvideo.c usbvideo/usbvideo.c
--- usbvideo.orig/usbvideo.c Fri Sep 21 05:55:28 2001
+++ usbvideo/usbvideo.c Fri Dec 21 19:09:51 2001
@@ -17,7 +17,7 @@
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/list.h>
-#include <linux/malloc.h>
+#include <linux/slab.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/smp_lock.h>