From 2859bc1db2bd2d809fcbbc170bae04f1887eccee Mon Sep 17 00:00:00 2001 From: Gerhard Jaeger Date: Wed, 14 Apr 2004 19:14:13 +0000 Subject: [PATCH] added to make kernel-module compilation easier. --- doc/plustek/MakeModule.sh | 103 ++++++++++++++ doc/plustek/Makefile.kernel24 | 253 ++++++++++++++++++++++++++++++++++ doc/plustek/Makefile.kernel26 | 118 ++++++++++++++++ doc/plustek/Makefile.module | 21 +-- 4 files changed, 485 insertions(+), 10 deletions(-) create mode 100755 doc/plustek/MakeModule.sh create mode 100644 doc/plustek/Makefile.kernel24 create mode 100644 doc/plustek/Makefile.kernel26 diff --git a/doc/plustek/MakeModule.sh b/doc/plustek/MakeModule.sh new file mode 100755 index 000000000..1b2a8d107 --- /dev/null +++ b/doc/plustek/MakeModule.sh @@ -0,0 +1,103 @@ +#!/bin/bash +#****************************************************************************** +# +# Bash-Script to create Plustek-Scannerdriver modules for Kernel 2.4 & 2.6 +# out of the backend sources... +# + +BUILD_DIR=$PWD/build +SRC_DIR=$PWD/../../backend +MAKEFILE=$PWD/Makefile.kernel26 +KERNEL_V=`uname -r` +OSMINOR=`uname -r | cut -b 3` +OSMAJOR=`uname -r | cut -b 1` + +# +# some intro ;-) +# +echo "This script will try and build a suitable kernel-module for your system." +echo "If you'd like to make the module WITH debug output, restart this script" +echo "with as follows:" +echo "./MakeModule.sh DEBUG=y" +echo "Press to continue or to cancel." +read + +# +# we need to be root user... +# +echo -n "Check for root..." +if [ $EUID -ne 0 ]; then + echo -e "\b\b\b - failed" + echo "Please retry as root user." + exit -1 +fi +echo -e "\b\b\b - done." + +# +# +# +echo -e "\nCheck for kernelversion:" +if [ "$OSMINOR" == "6" ]; then + echo "Using makefile for kernel 2.6.x" + MAKEFILE=$PWD/Makefile.kernel26 +elif [ "$OSMINOR" == "4" ]; then + echo "Using makefile for kernel 2.4.x" + MAKEFILE=$PWD/Makefile.kernel24 +else + echo "Your kernelversion >"$OSMAJOR"."$OSMINOR"< is probably not supported" + exit -2 +fi + +echo -e "Build-directory: \n"$BUILD_DIR +echo -n "Removing build-directory..." +rm -rf $BUILD_DIR +echo -e "\b\b\b - done." + +echo -n "Creating build-directory..." +mkdir $BUILD_DIR +cd $BUILD_DIR +echo -e "\b\b\b - done.\n" + +echo -n "Linking source files..." +C_FILES=`ls $SRC_DIR/plustek-pp_*.c` +H_FILES=`ls $SRC_DIR/plustek-pp_*.h` + +for F in $C_FILES $H_FILES $SRC_DIR/plustek-pp.h; do + ln -s $F . +done +echo -e "\b\b\b - done." + +echo -n "Copying Makefile to build-directory..." +cp $MAKEFILE Makefile +echo -e "\b\b\b - done." + +echo "Making the module..." +if [ "$OSMINOR" == "4" ]; then + make all $1 +else + make -C /lib/modules/$KERNEL_V/build/ SUBDIRS=$BUILD_DIR modules $1 +fi + +cd .. +echo "done." + +echo "Should I install the module?" +echo "Press to continue or to cancel." +read + +make -C $BUILD_DIR install + +echo "Should I try and load the module?" +echo "If this step fails, check the kernel-log." +echo "Press to continue or to cancel." +read + +make -C $BUILD_DIR load +echo "done." + +echo "Should I remove the build directory?" +echo "Press to continue or to cancel." +read + +rm -rf $BUILD_DIR +echo "done." diff --git a/doc/plustek/Makefile.kernel24 b/doc/plustek/Makefile.kernel24 new file mode 100644 index 000000000..41d8a9af9 --- /dev/null +++ b/doc/plustek/Makefile.kernel24 @@ -0,0 +1,253 @@ +# Makefile for the plustek scanner driver (kernel-module) +# +############################################################################### +# +# define the directories +# +HOME_DIR := . +SRC_DIR := $(HOME_DIR) +INC_DIR := $(SRC_DIR) +OBJ_DIR := $(HOME_DIR)/obj +DOC_DIR := $(HOME_DIR)/doc +BACKEND := $(SRC_DIR) + +# +# define the used tools +# +MD = mkdir -p +CC = gcc +TAR = tar +REF = cxref + +# +# Comment/uncomment the following line to disable/enable debugging +# can also be set by commandline parameter: make all DEBUG=y +# +#DEBUG = y + +# +# common compiler options +# +OPT = -fomit-frame-pointer -D_PTDRV_V1=$(VERSION1) \ +-D_PTDRV_V0=$(VERSION0) -D_PTDRV_BUILD=$(BUILD) + +# +# cxref options +# +REFOPT = -xref-all -index-all -html32 + +# +# Comment out if you are not running SMP. Someone take this out of here +# when the SMP stuff gets moved out of the kernel Makefile. +# SMP = 1 +# SMP_PROF = 1 + +# +# add the following to get assembly listing +# -Wa,-alh,-L -g + +# +# get some version numbers +# +ifeq ($(LINUXVERSION),) + LINUXVERSION = $(shell uname -r) +endif +VERSION0 = $(shell cat ./../VERSION0) +VERSION1 = $(shell cat ./../VERSION1) +BUILD = $(shell cat ./../BUILD) + +# Change it here or specify it on the "make" commandline +ifeq ($(HEADER_PATH),) +MACHTYPE = $(shell env | grep debian-linux | wc -l | sed 's/ //g') +ifeq ($(MACHTYPE),1) +# debian + HEADER_PATH = /usr/src/kernel-headers-$(LINUXVERSION)/include +else +# redhat, slackware + HEADER_PATH = /usr/src/linux/include +endif +# HEADER_PATH = /usr/include +endif + +ifeq ($(DEBUG),y) + DEBFLAGS = -O -g -DDEBUG # "-O" is needed to expand inlines +else + DEBFLAGS = -O2 +endif + +# +# the new style reference +# +K24_HEADER_PATH = /lib/modules/$(LINUXVERSION)/build/include + +# +# try to autodetect if we can use the new style header include references +# +KERNEL_HEADERS = $(shell if test -d $(K24_HEADER_PATH); then \ + echo $(K24_HEADER_PATH); \ + else \ + echo $(HEADER_PATH); \ + fi; ) + +# +# seems to be necessary for kernels 2.4.x +# +MODVERFILE = $(shell if [ -e $(KERNEL_HEADERS)/linux/modversions.h ]; then \ + echo $(KERNEL_HEADERS)/linux/modversions.h ; \ + else \ + echo $(KERNEL_HEADERS)/linux/modsetver.h ; \ + fi ) + +MODFLAGS = -DMODULE + +# +# set MODVERSIONS if the kernel uses it +# +VERSUSED = $(shell grep 'define CONFIG_MODVERSIONS' \ + $(KERNEL_HEADERS)/linux/autoconf.h | wc -l | sed 's/ //g') +ifeq ($(VERSUSED),1) + MODFLAGS += -DMODVERSIONS -include $(MODVERFILE) +endif + + +WARNFLAGS = -Wall -Wstrict-prototypes +CFLAGS = $(WARNFLAGS) $(OPT) -D__KERNEL__ -I$(KERNEL_HEADERS) -I$(INC_DIR) -I$(BACKEND) $(DEBFLAGS) $(MODFLAGS) +MODLIB = /lib/modules/$(LINUXVERSION) + +ifdef SMP +CFLAGS += -D__SMP__ + +ifdef SMP_PROF +CFLAGS += -D__SMP_PROF__ +endif +endif + +TARGET = pt_drv + +OBJ = $(TARGET).o +NAMES := dac detect genericio image map misc models io procfs +NAMES := $(NAMES) motor p9636 ptdrv scale tpa p48xx p12 p12ccd +NAMES := $(addprefix plustek-pp_, $(NAMES)) +SRCS := $(addprefix $(SRC_DIR)/, $(NAMES)) +SRCS := $(addsuffix .c, $(SRCS)) +OBJS := $(addprefix $(OBJ_DIR)/, $(NAMES)) +OBJS := $(addsuffix .o, $(OBJS)) +INCS := scan dbg types scandata procs hwdefs sysdep +INCS := $(addsuffix .h, $(INCS)) +HDRS = $(addprefix $(INC_DIR)/plustek-pp_, $(INCS)) + +# +# the header files we need from the backend +# +BACKINCS := plustek-pp.h +BACKINCS := $(addprefix $(BACKEND)/, $(BACKINCS)) + +group = "root" +mode = "644" +INST_DIR = /lib/modules/$(LINUXVERSION)/kernel/drivers/char + +info: + @clear + @echo "Makefile to create the Plustek-Scanner kernel-module:" + @echo "all ... builds the module" + @echo "all DEBUG=y ... builds the module with debug-messages enabled" + @echo "clean ... cleans up the show" + @echo "install ... installs the module to the library path" + @echo "uninstall ... removes the module from the library path" + @echo "load ... tries to load the module and creates device nodes" + @echo "unload ... unloads the module" + + +all: .depend chkdir $(OBJ) + +# +# create object directory +# +.PHONY : chkdir +chkdir: + @-$(MD) $(OBJ_DIR) + @-$(MD) $(DOC_DIR) + +$(OBJ): $(OBJS) + $(LD) -r $^ -o $@ + +$(OBJS): Makefile $(HDRS) $(BACKINCS) + +$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJ_DIR)/$(OBJ): VERSION1 VERSION0 + +# +# copy the driver to the modules directory +# +install: + mkdir -p $(INST_DIR) + install -c -m $(mode) $(OBJ) $(INST_DIR) + /sbin/depmod -a + +# +# remove it +# +uninstall: + rm -f $(INST_DIR)/$(OBJ) + +# +# use modprobe to load the driver, remember to set the +# parameter in /etc/modules.conf (see sane-plustek_pp.man for more details) +# +load: $(INST_DIR)/$(OBJ) +# invoke modprobe with all arguments we got + /sbin/modprobe $(TARGET) || exit 1 + +# Remove stale nodes and replace them, then give gid and perms + rm -f /dev/$(TARGET)* + +# when using the devfs support, we check the /dev/scanner entries +# and only create links to the devfs nodes +# at least we create one link + @if [ -e /dev/scanner/$(TARGET)* ]; then \ + ln -s /dev/scanner/$(TARGET)0 /dev/$(TARGET); \ + for name in `ls /dev/scanner | grep $(TARGET)`; do \ + ln -s /dev/scanner/$$name /dev/$$name ; \ + done \ + else \ + mknod /dev/$(TARGET) c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 0; \ + mknod /dev/$(TARGET)0 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 0; \ + mknod /dev/$(TARGET)1 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 1; \ + mknod /dev/$(TARGET)2 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 2; \ + mknod /dev/$(TARGET)3 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 3; \ + \ + chgrp $(group) /dev/$(TARGET)*; \ + chmod $(mode) /dev/$(TARGET)*; \ + fi + +# +# unload the driver +# +unload: + /sbin/modprobe -r $(TARGET) || exit 1 + +# Remove stale nodes + rm -f /dev/$(TARGET)* + +# +# create reference docu +# +doc: chkdir + $(REF) $(REFOPT) $(INC_DIR)/*.h $(SRC_DIR)/*.c $(BACKEND)/plustek-share.h \ + -D__KERNEL__ -I$(KERNEL_HEADERS) -I$(INC_DIR) -I$(BACKEND) $(MODFLAGS) \ + -D_PTDRV_V1=$(VERSION1) -D_PTDRV_V0=$(VERSION0) -D_PTDRV_BUILD=$(BUILD) -O$(DOC_DIR) + +clean: + @-rm -f $(OBJ_DIR)/*.o .depend depend dep $(REF).* *.html $(TARGET).o + @-rm -rf $(OBJ_DIR) + @-rm -rf $(DOC_DIR) + +depend .depend dep: + $(CC) $(CFLAGS) -M $(SRCS) > $@ + +ifeq (.depend,$(wildcard .depend)) +#include .depend +endif + diff --git a/doc/plustek/Makefile.kernel26 b/doc/plustek/Makefile.kernel26 new file mode 100644 index 000000000..ae7c4713f --- /dev/null +++ b/doc/plustek/Makefile.kernel26 @@ -0,0 +1,118 @@ +# Makefile for the plustek scanner driver (kernel-module) +# +############################################################################### + +# +# retrieve the version numbers +# +ifeq ($(LINUXVERSION),) + LINUXVERSION = $(shell uname -r) +endif +VERSION0 = $(shell cat $(SUBDIRS)/../VERSION0) +VERSION1 = $(shell cat $(SUBDIRS)/../VERSION1) +BUILD = $(shell cat $(SUBDIRS)/../BUILD) + +# +# extra flags +# +EXTRA_CFLAGS += -D_PTDRV_V1=$(VERSION1) -D_PTDRV_V0=$(VERSION0) -D_PTDRV_BUILD=$(BUILD) + +ifeq ($(DEBUG),y) + EXTRA_CFLAGS += -DDEBUG +endif + +# +# the module name +# +TARGET := pt_drv +MODULE := $(TARGET).ko + +# +# our files... +# +NAMES := dac detect genericio image map misc models io procfs +NAMES := $(NAMES) motor p9636 ptdrv scale tpa p48xx p12 p12ccd +NAMES := $(addprefix plustek-pp_, $(NAMES)) +OBJS := $(addsuffix .o, $(NAMES)) + +# +# now the kernel magic +# +ifneq ($(KERNELRELEASE),) +obj-m := $(TARGET).o + +$(TARGET)-objs := $(OBJS) + +else +KDIR := /lib/modules/$(shell uname -r)/build +PWD := $(shell pwd) + +default: + $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules +endif + +# +# the installation stuff +# +group = "root" +mode = "644" +INST_DIR = /lib/modules/$(LINUXVERSION)/kernel/drivers/parport + +# +# copy the driver to the modules directory +# +install: + mkdir -p $(INST_DIR) + install -c -m $(mode) $(MODULE) $(INST_DIR) + /sbin/depmod -a + +# +# +# +uninstall: + rm -f $(INST_DIR)/$(MODULE) + +# +# use modprobe to load the driver, remember to set the +# parameter in /etc/conf.modules (see INSTALL for more details) +# +load: $(INST_DIR)/$(MODULE) +# invoke modprobe with all arguments we got + /sbin/modprobe $(TARGET) || exit 1 + +# Remove stale nodes and replace them, then give gid and perms + rm -f /dev/$(TARGET)* + +# when using the devfs support, we check the /dev/scanner entries +# and only create links to the devfs nodes +# at least we create one link + @if [ -e /dev/scanner/$(TARGET)* ]; then \ + ln -s /dev/scanner/$(TARGET)0 /dev/$(TARGET); \ + for name in `ls /dev/scanner | grep $(TARGET)`; do \ + ln -s /dev/scanner/$$name /dev/$$name ; \ + done \ + else \ + mknod /dev/$(TARGET) c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 0; \ + mknod /dev/$(TARGET)0 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 0; \ + mknod /dev/$(TARGET)1 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 1; \ + mknod /dev/$(TARGET)2 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 2; \ + mknod /dev/$(TARGET)3 c `cat /proc/devices | sed -ne "s/\([0-9]*\) pt_drv/\1/p"` 3; \ + \ + chgrp $(group) /dev/$(TARGET)*; \ + chmod $(mode) /dev/$(TARGET)*; \ + fi + +# +# unload the driver +# +unload: + /sbin/modprobe -r $(TARGET) || exit 1 + +# Remove stale nodes + rm -f /dev/$(TARGET)* + +# +# cleanup the show +# +clean: + @-rm -f *.o .depend depend dep $(MODULE) $(TARGET).o $(TARGET).mod.c .*.cmd diff --git a/doc/plustek/Makefile.module b/doc/plustek/Makefile.module index 6bdb02f6a..37a5ef2a2 100644 --- a/doc/plustek/Makefile.module +++ b/doc/plustek/Makefile.module @@ -52,6 +52,8 @@ REFOPT = -xref-all -index-all -html32 ifeq ($(LINUXVERSION),) LINUXVERSION = $(shell uname -r) endif +OSMINOR = $(shell uname -r | cut -b 3 ) +OSMAJOR = $(shell uname -r | cut -b 1 ) VERSION0 = $(shell cat VERSION0) VERSION1 = $(shell cat VERSION1) BUILD = $(shell cat BUILD) @@ -110,7 +112,6 @@ ifeq ($(VERSUSED),1) endif - WARNFLAGS = -Wall -Wstrict-prototypes CFLAGS = $(WARNFLAGS) $(OPT) -D__KERNEL__ -I$(KERNEL_HEADERS) -I$(INC_DIR) -I$(BACKEND) $(DEBFLAGS) $(MODFLAGS) MODLIB = /lib/modules/$(LINUXVERSION) @@ -159,7 +160,7 @@ info: @echo "unload ... unloads the module" -all: .depend chkdir $(TARGET).o +all: .depend chkdir $(OBJ) # # create object directory @@ -169,7 +170,7 @@ chkdir: @-$(MD) $(OBJ_DIR) @-$(MD) $(DOC_DIR) -$(TARGET).o: $(OBJS) +$(OBJ): $(OBJS) $(LD) -r $^ -o $@ $(OBJS): Makefile.module $(HDRS) $(BACKINCS) @@ -177,27 +178,27 @@ $(OBJS): Makefile.module $(HDRS) $(BACKINCS) $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(CC) $(CFLAGS) -c $< -o $@ -$(OBJ_DIR)/ptdrv.o: VERSION1 VERSION0 +$(OBJ_DIR)/$(OBJ): VERSION1 VERSION0 # # copy the driver to the modules directory # install: mkdir -p /lib/modules/$(LINUXVERSION)/misc - install -c -m $(mode) $(TARGET).o /lib/modules/$(LINUXVERSION)/misc + install -c -m $(mode) $(OBJ) /lib/modules/$(LINUXVERSION)/misc /sbin/depmod -a # -# +# remove it # uninstall: - rm -f /lib/modules/$(LINUXVERSION)/misc/$(TARGET).o + rm -f /lib/modules/$(LINUXVERSION)/misc/$(OBJ) # # use modprobe to load the driver, remember to set the -# parameter in /etc/conf.modules (see INSTALL for more details) +# parameter in /etc/modules.conf (see sane-plustek_pp.man for more details) # -load: /lib/modules/$(LINUXVERSION)/misc/$(TARGET).o +load: /lib/modules/$(LINUXVERSION)/misc/$(OBJ) # invoke modprobe with all arguments we got /sbin/modprobe $(TARGET) || exit 1 @@ -241,7 +242,7 @@ doc: chkdir -D_PTDRV_V1=$(VERSION1) -D_PTDRV_V0=$(VERSION0) -D_PTDRV_BUILD=$(BUILD) -O$(DOC_DIR) clean: - @-rm -f $(OBJ_DIR)/*.o .depend depend dep $(OBJ) $(REF).* *.html + @-rm -f $(OBJ_DIR)/*.o .depend depend dep $(REF).* *.html $(TARGET).ko $(TARGET).o @-rm -rf $(OBJ_DIR) @-rm -rf $(DOC_DIR)